fmc_spi读flah和spi读flash
时间: 2023-11-24 10:53:24 浏览: 51
FMC(SRAM)和SPI都可以用来读取Flash,但是它们的实现方式不同。FMC(SRAM)是通过CPU的总线来访问Flash,而SPI是通过SPI总线来访问Flash。下面是两种读取Flash的例子:
1. FMC(SRAM)读取Flash
```c
#define SRAM_BANK_ADDR ((uint32_t)0x60000000)
#define FLASH_ADDR ((uint32_t)0x08000000)
uint32_t read_flash(uint32_t addr)
{
uint32_t data = 0;
data = *(volatile uint32_t *)(SRAM_BANK_ADDR + (addr - FLASH_ADDR));
return data;
}
```
2. SPI读取Flash
```c
#define FLASH_CS_LOW() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET)
#define FLASH_CS_HIGH() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET)
void spi_read_flash(uint32_t addr, uint8_t *data, uint32_t size)
{
FLASH_CS_LOW();
SPI_FLASH_SendByte(Read_data);
SPI_FLASH_SendByte((addr >> 16) & 0xff);
SPI_FLASH_SendByte((addr >> 8) & 0xff);
SPI_FLASH_SendByte(addr & 0xff);
while (size--)
{
*data = SPI_FLASH_SendByte(Dummy_Byte);
data++;
}
FLASH_CS_HIGH();
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)