本来是想测试一下低功耗,看到要割板子,就留后面再测试,先来跑一下外挂flash的功能。
1.确定硬件部分
(1)我们先查看datasheet确定SPI0接口如下
PB3:SPI_SCK
PB4:SPI0_MISO
PB5:SPI0_MOSI
PB6:SPI0_IO2
PB7:SPI0_IO3
PB1:SPI0_CS
(2)查找一下flash管脚图
(3)搭一个flash小板,对应上面IO,电源,GND连到开发板。
2.添加软件部分
- 添加驱动部分Soft_Drive(gd25qxx.c和gd25qxx.h);
- 初始化SPI0 GPIO and parameter
spi_flash_init();
- 擦除flash
void spi_flash_sector_erase(uint32_t sector_addr);
擦除一个sector: 0x0000-0x0fff
void spi_flash_block_erase(uint8_t block_addr);
擦除一个block: 0x000000-0x00ffff
void spi_flash_bulk_erase(void);
擦除整个chip
- 读写flash
/* write block of data to the flash using qspi */
void qspi_flash_buffer_write(uint8_t *pbuffer, uint32_t write_addr, uint16_t num_byte_to_write);
/* read a block of data from the flash using qspi */
void qspi_flash_buffer_read(uint8_t *pbuffer, uint32_t read_addr, uint16_t num_byte_to_read);
(5)下载程序,打印结果
3.关于不同flash,quad模式的设置
- void qspi_flash_quad_enable(void)
- {
- /* enable the write access to the flash */
- spi_flash_write_enable();
- /* select the flash: chip select low */
- SPI_FLASH_CS_LOW();
- /* send "write status register" instruction */
- spi_flash_send_byte(WRSR);
-
- spi_flash_send_byte(0x00);
- spi_flash_send_byte(0x20);
-
- /* deselect the flash: chip select high */
- SPI_FLASH_CS_HIGH();
- /* wait the end of flash writing */
- spi_flash_wait_for_write_end();
- }
查阅GD的datasheet,可以看到QE的设置
- spi_flash_send_byte(0x00);
- spi_flash_send_byte(0x20);
查阅KH的datasheet,可以看到QE的设置
- spi_flash_send_byte(0x40);
- spi_flash_send_byte(0x00);
|