NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
|
Default NEORV32 bootloader. More...
Macros | |
#define | EXE_SIGNATURE 0x4788CAFE |
Bootloader configuration (override via console to customize); | |
default values are used if not explicitly customized | |
#define | EXE_BASE_ADDR 0x00000000UL |
#define | UART_EN 1 |
#define | UART_BAUD 19200 |
#define | UART_HW_HANDSHAKE_EN 0 |
#define | STATUS_LED_EN 1 |
#define | STATUS_LED_PIN 0 |
#define | AUTO_BOOT_TIMEOUT 10 |
#define | SPI_EN 1 |
#define | SPI_FLASH_CS 0 |
#define | SPI_FLASH_ADDR_BYTES 3 |
#define | SPI_FLASH_SECTOR_SIZE 65536 |
#define | SPI_FLASH_CLK_PRSC CLK_PRSC_8 |
#define | SPI_BOOT_BASE_ADDR 0x00400000UL |
#define | XIP_EN 1 |
#define | xstr(a) |
#define | str(a) |
#define | PRINT_TEXT(...) |
#define | PRINT_XNUM(a) |
#define | PRINT_GETC(a) |
#define | PRINT_PUTC(a) |
Enumerations | |
enum | EXE_STREAM_SOURCE_enum { EXE_STREAM_UART = 0 , EXE_STREAM_FLASH = 1 } |
enum | ERROR_CODES_enum { ERROR_SIGNATURE = 0 , ERROR_SIZE = 1 , ERROR_CHECKSUM = 2 , ERROR_FLASH = 3 } |
enum | SPI_FLASH_CMD_enum { SPI_FLASH_CMD_PAGE_PROGRAM = 0x02 , SPI_FLASH_CMD_READ = 0x03 , SPI_FLASH_CMD_WRITE_DISABLE = 0x04 , SPI_FLASH_CMD_READ_STATUS = 0x05 , SPI_FLASH_CMD_WRITE_ENABLE = 0x06 , SPI_FLASH_CMD_WAKE = 0xAB , SPI_FLASH_CMD_SECTOR_ERASE = 0xD8 } |
enum | SPI_FLASH_SREG_enum { FLASH_SREG_BUSY = 0 , FLASH_SREG_WEL = 1 } |
enum | NEORV32_EXECUTABLE_enum { EXE_OFFSET_SIGNATURE = 0 , EXE_OFFSET_SIZE = 4 , EXE_OFFSET_CHECKSUM = 8 , EXE_OFFSET_DATA = 12 } |
Functions | |
void | bootloader_trap_handler (void) |
void | print_help (void) |
void | start_app (int boot_xip) |
void | get_exe (int src) |
void | save_exe (void) |
uint32_t | get_exe_word (int src, uint32_t addr) |
void | system_error (uint8_t err_code) |
void | print_hex_word (uint32_t num) |
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) |
void | spi_flash_write_word (uint32_t addr, uint32_t wdata) |
void | spi_flash_erase_sector (uint32_t addr) |
void | spi_flash_write_enable (void) |
void | spi_flash_write_disable (void) |
uint8_t | spi_flash_read_status (void) |
void | spi_flash_write_addr (uint32_t addr) |
int | main (void) |
Variables | |
const char | error_message [4][5] |
volatile uint32_t | exe_available |
volatile uint32_t | getting_exe |
Default NEORV32 bootloader.
#define AUTO_BOOT_TIMEOUT 10 |
Time until the auto-boot sequence starts (in seconds); 0 = disabled
#define EXE_BASE_ADDR 0x00000000UL |
Memory base address for the executable
#define EXE_SIGNATURE 0x4788CAFE |
Valid executable identification signature
#define PRINT_GETC | ( | a | ) |
Helper macros Actual define-to-string helper
#define PRINT_PUTC | ( | a | ) |
Helper macros Actual define-to-string helper
#define PRINT_TEXT | ( | ... | ) |
Print to UART 0
#define PRINT_XNUM | ( | a | ) |
Helper macros Actual define-to-string helper
#define SPI_BOOT_BASE_ADDR 0x00400000UL |
SPI flash boot base address
#define SPI_EN 1 |
Enable SPI (default) including SPI flash boot options
#define SPI_FLASH_ADDR_BYTES 3 |
SPI flash address width (in numbers of bytes; 2,3,4)
#define SPI_FLASH_CLK_PRSC CLK_PRSC_8 |
SPI flash clock pre-scaler; see NEORV32_SPI_CTRL_enum
#define SPI_FLASH_CS 0 |
SPI flash chip select (low-active) at SPI.spi_csn_o(SPI_FLASH_CS)
#define SPI_FLASH_SECTOR_SIZE 65536 |
SPI flash sector size in bytes
#define STATUS_LED_EN 1 |
Set to 0 to disable bootloader status LED (heart beat) at GPIO.gpio_o(STATUS_LED_PIN)
#define STATUS_LED_PIN 0 |
GPIO output pin for high-active bootloader status LED (heart beat)
#define str | ( | a | ) |
Internal helper macro
#define UART_BAUD 19200 |
UART BAUD rate for serial interface
#define UART_EN 1 |
Set to 0 to disable UART interface
#define UART_HW_HANDSHAKE_EN 0 |
Set to 1 to enable UART HW handshaking
#define XIP_EN 1 |
Enable XIP boot options
#define xstr | ( | a | ) |
enum ERROR_CODES_enum |
enum SPI_FLASH_CMD_enum |
SPI flash commands
enum SPI_FLASH_SREG_enum |
void bootloader_trap_handler | ( | void | ) |
Function prototypes
Bootloader trap handler. Used for the MTIME tick and to capture any other traps.
void get_exe | ( | int | src | ) |
Get executable stream.
src | Source of executable stream data. See EXE_STREAM_SOURCE_enum. |
uint32_t get_exe_word | ( | int | src, |
uint32_t | addr ) |
Get word from executable stream
src | Source of executable stream data. See EXE_STREAM_SOURCE_enum. |
addr | Address when accessing SPI flash. |
int main | ( | void | ) |
Sanity check: Base RV32I ISA only! Bootloader main.
void print_help | ( | void | ) |
Print help menu.
void print_hex_word | ( | uint32_t | num | ) |
Print 32-bit number as 8-digit hexadecimal value (with "0x" suffix).
[in] | num | Number to print as hexadecimal. |
void save_exe | ( | void | ) |
Store content of instruction memory to SPI flash.
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.
void spi_flash_erase_sector | ( | uint32_t | addr | ) |
Erase sector (64kB) at base address.
[in] | addr | Base address of sector to erase. |
uint8_t spi_flash_read_byte | ( | uint32_t | addr | ) |
Read byte from SPI flash.
[in] | addr | Flash read address. |
uint8_t spi_flash_read_status | ( | void | ) |
Read flash status register.
void spi_flash_wakeup | ( | void | ) |
Wake up flash from deep sleep state
void spi_flash_write_addr | ( | uint32_t | addr | ) |
Send address word to flash (MSB-first, 16-bit, 24-bit or 32-bit address size).
[in] | addr | Address word. |
void spi_flash_write_byte | ( | uint32_t | addr, |
uint8_t | wdata ) |
Write byte to SPI flash.
[in] | addr | SPI flash read address. |
[in] | wdata | SPI flash read data. |
void spi_flash_write_disable | ( | void | ) |
Disable flash write access.
void spi_flash_write_enable | ( | void | ) |
Enable flash write access.
void spi_flash_write_word | ( | uint32_t | addr, |
uint32_t | wdata ) |
Write word to SPI flash.
addr | SPI flash write address. |
wdata | SPI flash write data. |
void start_app | ( | int | boot_xip | ) |
Start application program.
boot_xip | Set to boot via XIP. |
void system_error | ( | uint8_t | err_code | ) |
Output system error ID and halt.
[in] | err_code | Error code. See #ERROR_CODES and error_message. |
const char error_message[4][5] |
Error messages
volatile uint32_t exe_available |
This global variable keeps the size of the available executable in bytes. If =0 no executable is available (yet).
volatile uint32_t getting_exe |
Only set during executable fetch (required for capturing STORE BUS-TIMOUT exception).