[sw] bootloader: send wake up command to flash before trying to speak with it (#552)

This commit is contained in:
Stephan 2023-03-17 08:44:15 +01:00 committed by GitHub
commit 7a267a1954
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 137 additions and 111 deletions

View file

@ -45,6 +45,7 @@ The SPI flash has to support single-byte read and write operations, 24-bit addre
* `0x04`: Write disable (for volatile status register)
* `0x05`: Read (first) status register
* `0x06`: Write enable (for volatile status register)
* `0xAB`: Wake-up from sleep mode (optional)
* `0xD8`: Block erase (64kB)
.Custom Configuration
@ -166,6 +167,11 @@ manually restarted via the `r` command.
The bootloader allows to execute an application right from flash using the <<_execute_in_place_module_xip>> module.
This requires a pre-programmed flash. The bootloader's "store" option can **not** be used to program an XIP image.
.SPI Flash Power Down Mode
[NOTE]
The bootloader will issue a "wake-up" command prior to using the SPI flash to ensure it is not
in sleep mode / power-down mode (see https://github.com/stnolting/neorv32/pull/552).
.Default Configuration
[TIP]
More information regarding the default SPI, GPIO, XIP, etc. configuration can be found in the User Guide
@ -174,7 +180,7 @@ section https://stnolting.github.io/neorv32/ug/#_customizing_the_internal_bootlo
.SPI Flash Programming
[TIP]
For detailed information on using an SPI flash for application storage see User Guide section
https://stnolting.github.io/neorv32/ug/#_programming_an_external_spi_flash_via_the_bootloader[Programming an ExternalSPI Flash via the Bootloader].
https://stnolting.github.io/neorv32/ug/#_programming_an_external_spi_flash_via_the_bootloader[Programming an External SPI Flash via the Bootloader].
:sectnums:

View file

@ -1,8 +1,8 @@
-- The NEORV32 RISC-V Processor: https://github.com/stnolting/neorv32
-- Auto-generated memory initialization file (for BOOTLOADER) from source file <bootloader/main.bin>
-- Size: 4028 bytes
-- Size: 4044 bytes
-- MARCH: default
-- Built: 08.03.2023 19:27:04
-- Built: 16.03.2023 20:18:06
-- prototype defined in 'neorv32_package.vhd'
package body neorv32_bootloader_image is
@ -40,7 +40,7 @@ x"00000e93",
x"00000f13",
x"00000f93",
x"00001597",
x"f4058593",
x"f5058593",
x"80010617",
x"f7c60613",
x"80010697",
@ -104,7 +104,7 @@ x"03812423",
x"03912223",
x"03a12023",
x"01b12e23",
x"a2478793",
x"a3478793",
x"30579073",
x"fe802783",
x"00080737",
@ -187,64 +187,64 @@ x"30479073",
x"00800793",
x"3007a073",
x"ffff1537",
x"db450513",
x"6a0000ef",
x"dc450513",
x"6b0000ef",
x"f1302573",
x"624000ef",
x"ffff1537",
x"dec50513",
x"68c000ef",
x"fe402503",
x"610000ef",
x"ffff1537",
x"df450513",
x"678000ef",
x"fe002503",
x"5fc000ef",
x"634000ef",
x"ffff1537",
x"dfc50513",
x"664000ef",
x"30102573",
x"5e8000ef",
x"69c000ef",
x"fe402503",
x"620000ef",
x"ffff1537",
x"e0450513",
x"650000ef",
x"fc002573",
x"5d4000ef",
x"688000ef",
x"fe002503",
x"60c000ef",
x"ffff1537",
x"e0c50513",
x"63c000ef",
x"674000ef",
x"30102573",
x"5f8000ef",
x"ffff1537",
x"e1450513",
x"660000ef",
x"fc002573",
x"5e4000ef",
x"ffff1537",
x"e1c50513",
x"64c000ef",
x"fe802503",
x"ffff1437",
x"ffff1937",
x"5b8000ef",
x"5c8000ef",
x"ffff1537",
x"e1450513",
x"620000ef",
x"e2450513",
x"630000ef",
x"ff802503",
x"5a4000ef",
x"e1c40513",
x"610000ef",
x"5b4000ef",
x"e2c40513",
x"620000ef",
x"ff002503",
x"594000ef",
x"5a4000ef",
x"ffff1537",
x"e2850513",
x"5fc000ef",
x"e3850513",
x"60c000ef",
x"ffc02503",
x"580000ef",
x"e1c40513",
x"5ec000ef",
x"590000ef",
x"e2c40513",
x"5fc000ef",
x"ff402503",
x"570000ef",
x"db090513",
x"5dc000ef",
x"580000ef",
x"dc090513",
x"5ec000ef",
x"fe802783",
x"00020737",
x"00e7f7b3",
x"04078c63",
x"ffff1537",
x"e3050513",
x"5c0000ef",
x"e4050513",
x"5d0000ef",
x"2bc000ef",
x"fe002403",
x"00040a37",
@ -261,18 +261,18 @@ x"0157f7b3",
x"0a078063",
x"ffff1537",
x"fa402783",
x"e5c50513",
x"578000ef",
x"e6c50513",
x"588000ef",
x"ffff1a37",
x"e68a0513",
x"56c000ef",
x"e78a0513",
x"57c000ef",
x"06c00a93",
x"07800b93",
x"07300c13",
x"06500c93",
x"ffff17b7",
x"ee878513",
x"550000ef",
x"ef878513",
x"560000ef",
x"fa002783",
x"00010737",
x"00e7f7b3",
@ -280,9 +280,9 @@ x"fe078ae3",
x"fa402403",
x"0ff47413",
x"00040513",
x"4a4000ef",
x"db090513",
x"528000ef",
x"4b4000ef",
x"dc090513",
x"538000ef",
x"07200793",
x"06f41063",
x"ffff02b7",
@ -303,21 +303,21 @@ x"f485e4e3",
x"00b41463",
x"f53560e3",
x"00100513",
x"708000ef",
x"db090513",
x"4cc000ef",
x"718000ef",
x"dc090513",
x"4dc000ef",
x"00000513",
x"059000ef",
x"069000ef",
x"19540863",
x"028ae463",
x"19940863",
x"06800793",
x"e68a0513",
x"e78a0513",
x"02f40c63",
x"03f00793",
x"18f40c63",
x"ffff1537",
x"f8c50513",
x"f9c50513",
x"0240006f",
x"07500793",
x"02f40263",
@ -326,25 +326,25 @@ x"ff8414e3",
x"0044a403",
x"02041063",
x"ffff1537",
x"ef050513",
x"474000ef",
x"f0050513",
x"484000ef",
x"f19ff06f",
x"00000513",
x"69c000ef",
x"6ac000ef",
x"f0dff06f",
x"ffff1537",
x"f0c50513",
x"458000ef",
x"f1c50513",
x"468000ef",
x"00040513",
x"3dc000ef",
x"3ec000ef",
x"ffff1537",
x"f1450513",
x"444000ef",
x"f2450513",
x"454000ef",
x"00400537",
x"3c8000ef",
x"3d8000ef",
x"ffff1537",
x"f2c50513",
x"430000ef",
x"f3c50513",
x"440000ef",
x"00010737",
x"fa002783",
x"00e7f7b3",
@ -352,16 +352,16 @@ x"fe078ce3",
x"fa402983",
x"0ff9f993",
x"00098513",
x"384000ef",
x"394000ef",
x"07900793",
x"eaf998e3",
x"2a0000ef",
x"00050663",
x"00300513",
x"450000ef",
x"460000ef",
x"ffff1537",
x"f3850513",
x"3ec000ef",
x"f4850513",
x"3fc000ef",
x"01045b13",
x"004009b7",
x"00010db7",
@ -389,7 +389,7 @@ x"00072583",
x"00fd0533",
x"00d12623",
x"00bd8db3",
x"25c000ef",
x"26c000ef",
x"004007b7",
x"004d0d13",
x"00c12683",
@ -398,27 +398,27 @@ x"fc8d6ce3",
x"4788d5b7",
x"afe58593",
x"00400537",
x"238000ef",
x"248000ef",
x"00040593",
x"00498513",
x"22c000ef",
x"23c000ef",
x"00898513",
x"41b005b3",
x"220000ef",
x"230000ef",
x"ffff1537",
x"d9850513",
x"da850513",
x"ec1ff06f",
x"00100513",
x"ec5ff06f",
x"0044a783",
x"e4079ee3",
x"ffff1537",
x"f4850513",
x"f5850513",
x"ea5ff06f",
x"00100513",
x"e4dff06f",
x"ffff1537",
x"f5850513",
x"f6850513",
x"e91ff06f",
x"f9402583",
x"f9002503",
@ -525,16 +525,20 @@ x"02010113",
x"00008067",
x"ff010113",
x"00112623",
x"fa5ff0ef",
x"fc1ff0ef",
x"ed9ff0ef",
x"0ab00513",
x"e7dff0ef",
x"e65ff0ef",
x"f95ff0ef",
x"fb1ff0ef",
x"00257793",
x"fff00513",
x"02078063",
x"ec5ff0ef",
x"eb5ff0ef",
x"00400513",
x"e69ff0ef",
x"e51ff0ef",
x"fa1ff0ef",
x"e59ff0ef",
x"e41ff0ef",
x"f91ff0ef",
x"01e51513",
x"41f55513",
x"00c12083",
@ -554,17 +558,17 @@ x"00400993",
x"00c10793",
x"008787b3",
x"0007ca03",
x"f31ff0ef",
x"e61ff0ef",
x"f21ff0ef",
x"e51ff0ef",
x"00200513",
x"e05ff0ef",
x"df5ff0ef",
x"00848933",
x"00090513",
x"e11ff0ef",
x"e01ff0ef",
x"000a0513",
x"df1ff0ef",
x"dd9ff0ef",
x"f29ff0ef",
x"de1ff0ef",
x"dc9ff0ef",
x"f19ff0ef",
x"00157513",
x"fe051ce3",
x"00140413",
@ -596,7 +600,7 @@ x"07800513",
x"ffff14b7",
x"fbdff0ef",
x"01c00413",
x"f9848493",
x"fa848493",
x"ffc00993",
x"008957b3",
x"00f7f793",
@ -638,13 +642,13 @@ x"ff010113",
x"00812423",
x"00050413",
x"ffff1537",
x"d5050513",
x"d6050513",
x"00112623",
x"f91ff0ef",
x"00241793",
x"ffff1537",
x"008787b3",
x"fa850513",
x"fb850513",
x"00f50533",
x"f79ff0ef",
x"00800793",
@ -691,7 +695,7 @@ x"fe802783",
x"00020737",
x"00e7f7b3",
x"02078863",
x"bc5ff0ef",
x"bb5ff0ef",
x"fe002783",
x"fff00713",
x"f8e02c23",
@ -735,7 +739,7 @@ x"00040737",
x"00e7f7b3",
x"04078263",
x"ffff1537",
x"d5850513",
x"d6850513",
x"e11ff0ef",
x"00048513",
x"d95ff0ef",
@ -748,7 +752,7 @@ x"d65ff0ef",
x"34302573",
x"d75ff0ef",
x"ffff1537",
x"db050513",
x"dc050513",
x"dddff0ef",
x"00440413",
x"34141073",
@ -770,23 +774,23 @@ x"00fb2023",
x"00050413",
x"02051863",
x"ffff1537",
x"d6450513",
x"d7450513",
x"d85ff0ef",
x"004005b7",
x"00040513",
x"b0dff0ef",
x"afdff0ef",
x"4788d7b7",
x"afe78793",
x"04f50863",
x"00000513",
x"0380006f",
x"ffff1537",
x"d8450513",
x"d9450513",
x"d59ff0ef",
x"00400537",
x"cddff0ef",
x"ffff1537",
x"d9050513",
x"da050513",
x"d45ff0ef",
x"fe802783",
x"00080737",
@ -794,17 +798,17 @@ x"00e7f7b3",
x"00079663",
x"00300513",
x"d85ff0ef",
x"bc5ff0ef",
x"bb5ff0ef",
x"fa0502e3",
x"ff1ff06f",
x"004009b7",
x"00498593",
x"00040513",
x"aa5ff0ef",
x"a95ff0ef",
x"00050a13",
x"00898593",
x"00040513",
x"a95ff0ef",
x"a85ff0ef",
x"ff002c03",
x"00050a93",
x"ffca7b93",
@ -817,7 +821,7 @@ x"015484b3",
x"00200513",
x"fa0494e3",
x"ffff1537",
x"d9850513",
x"da850513",
x"cc9ff0ef",
x"02c12083",
x"02812403",
@ -835,7 +839,7 @@ x"00812c03",
x"03010113",
x"00008067",
x"00040513",
x"a19ff0ef",
x"a09ff0ef",
x"012c07b3",
x"00a484b3",
x"00a7a023",
@ -850,12 +854,12 @@ x"ff002403",
x"00050463",
x"40400437",
x"ffff1537",
x"d9c50513",
x"dac50513",
x"c45ff0ef",
x"00040513",
x"bc9ff0ef",
x"ffff1537",
x"dac50513",
x"dbc50513",
x"c31ff0ef",
x"fa002783",
x"fe07cee3",
@ -894,8 +898,8 @@ x"72656461",
x"0a3e3e20",
x"444c420a",
x"4d203a56",
x"20207261",
x"30322038",
x"31207261",
x"30322036",
x"480a3332",
x"203a5657",
x"00000020",

View file

@ -166,6 +166,7 @@ enum SPI_FLASH_CMD_enum {
SPI_FLASH_CMD_WRITE_DISABLE = 0x04, /**< Disallow write access */
SPI_FLASH_CMD_READ_STATUS = 0x05, /**< Get status register */
SPI_FLASH_CMD_WRITE_ENABLE = 0x06, /**< Allow write access */
SPI_FLASH_CMD_WAKE = 0xAB, /**< Wake up from sleep mode */
SPI_FLASH_CMD_SECTOR_ERASE = 0xD8 /**< Erase complete sector */
};
@ -245,6 +246,7 @@ void system_error(uint8_t err_code);
void print_hex_word(uint32_t num);
// SPI flash driver functions
void spi_flash_wakeup(void);
int spi_flash_check(void);
uint8_t spi_flash_read_byte(uint32_t addr);
void spi_flash_write_byte(uint32_t addr, uint8_t wdata);
@ -740,6 +742,18 @@ void print_hex_word(uint32_t num) {
// SPI flash driver functions
// -------------------------------------------------------------------------------------
/**********************************************************************//**
* Wake up flash from deep sleep state
**************************************************************************/
void spi_flash_wakeup(void) {
#if (SPI_EN != 0)
neorv32_spi_cs_en(SPI_FLASH_CS);
neorv32_spi_trans(SPI_FLASH_CMD_WAKE);
neorv32_spi_cs_dis();
#endif
}
/**********************************************************************//**
* 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.
@ -749,6 +763,8 @@ void print_hex_word(uint32_t num) {
int spi_flash_check(void) {
#if (SPI_EN != 0)
// The flash may have been set to sleep prior to reaching this point. Make sure it's alive
spi_flash_wakeup();
// set WEL
spi_flash_write_enable();