SPI flash driver.
More...
#include <neorv32.h>
#include <config.h>
#include <spi_flash.h>
◆ SPI_FLASH_CMD_enum
SPI flash commands
Enumerator |
---|
SPI_FLASH_CMD_PAGE_PROGRAM | Program page
|
SPI_FLASH_CMD_READ | Read data
|
SPI_FLASH_CMD_WRITE_DISABLE | Disallow write access
|
SPI_FLASH_CMD_READ_STATUS | Get status register
|
SPI_FLASH_CMD_WRITE_ENABLE | Allow write access
|
SPI_FLASH_CMD_WAKE | Wake up from sleep mode
|
SPI_FLASH_CMD_SECTOR_ERASE | Erase complete sector
|
◆ SPI_FLASH_SREG_enum
SPI flash status register bits
Enumerator |
---|
FLASH_SREG_BUSY | Busy, write/erase in progress when set, read-only
|
FLASH_SREG_WEL | Write access enabled when set, read-only
|
◆ spi_flash_check()
int spi_flash_check |
( |
void | | ) |
|
Check if SPI and flash are available/working by making sure the WEL flag of the flash status register can be set and cleared again.
- Returns
- 0 if success, !=0 if error
◆ spi_flash_cmd()
void spi_flash_cmd |
( |
uint8_t | cmd | ) |
|
Send single command to SPI flash.
- Parameters
-
◆ spi_flash_erase_sector()
int spi_flash_erase_sector |
( |
uint32_t | addr | ) |
|
Erase sector (64kB) at base address.
- Parameters
-
[in] | addr | Base address of sector to erase. |
- Returns
- 0 if success, !=0 if error
◆ spi_flash_read_status()
uint8_t spi_flash_read_status |
( |
void | | ) |
|
Read flash status register.
- Returns
- SPI flash status register.
◆ spi_flash_read_word()
int spi_flash_read_word |
( |
uint32_t | addr, |
|
|
uint32_t * | rdata ) |
Read byte from SPI flash.
- Parameters
-
[in] | addr | Word-aligned address. |
[in,out] | rdata | Pointer for returned data (uint32_t). |
- Returns
- 0 if success, !=0 if error
◆ spi_flash_send_addr()
void spi_flash_send_addr |
( |
uint32_t | addr | ) |
|
Send address to flash.
- Parameters
-
◆ spi_flash_write_byte()
void spi_flash_write_byte |
( |
uint32_t | addr, |
|
|
uint8_t | wdata ) |
Write byte to SPI flash.
- Parameters
-
[in] | addr | SPI flash read address. |
[in] | wdata | SPI flash read data. |
◆ spi_flash_write_word()
int spi_flash_write_word |
( |
uint32_t | addr, |
|
|
uint32_t | wdata ) |
Write word to SPI flash.
- Parameters
-
addr | SPI flash write address. |
wdata | SPI flash write data. |
- Returns
- 0 if success, !=0 if error