NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
Enumerations
main.c File Reference

Demo for the the execute in place (XIP) module. More...

#include <neorv32.h>

Macros

User configuration
#define BAUD_RATE   19200
 
#define XIP_PAGE_BASE_ADDR   0x40000000
 
#define FLASH_BASE   0x00400000
 
#define FLASH_ABYTES   3
 
#define XIP_CLK_PRSC   CLK_PRSC_128
 

Enumerations

enum  SPI_FLASH_CMD {
  SPI_FLASH_CMD_WRITE = 0x02 , SPI_FLASH_CMD_READ = 0x03 , SPI_FLASH_CMD_READ_STATUS = 0x05 , SPI_FLASH_CMD_WRITE_ENABLE = 0x06 ,
  SPI_FLASH_CMD_SECTOR_ERASE = 0xD8
}
 

Functions

Prototypes
int erase_sector_xip_flash (uint32_t base_addr)
 
int program_xip_flash (uint32_t *src, uint32_t base_addr, uint32_t size)
 

Simple demo program to be stored to the XIP flash.

Note
This is a the "raw HEX version" from the rv32i-only "sw/example/demo_blink_led" demo program (using "make clean_all hex"). This program has been compiled using a modified linker script: rom ORIGIN = XIP base page + flash base address (= XIP_PAGE_BASE_ADDR + FLASH_BASE)
const uint32_t xip_program []
 
int main ()
 

Detailed Description

Demo for the the execute in place (XIP) module.

Author
Stephan Nolting

Macro Definition Documentation

◆ BAUD_RATE

#define BAUD_RATE   19200

UART BAUD rate

◆ FLASH_ABYTES

#define FLASH_ABYTES   3

Flash address bytes

◆ FLASH_BASE

#define FLASH_BASE   0x00400000

Flash base address (32-bit)

◆ XIP_CLK_PRSC

#define XIP_CLK_PRSC   CLK_PRSC_128

XIP SPI clock prescaler select

◆ XIP_PAGE_BASE_ADDR

#define XIP_PAGE_BASE_ADDR   0x40000000

XIP page base address (32-bit)

Enumeration Type Documentation

◆ SPI_FLASH_CMD

SPI flash commands

Enumerator
SPI_FLASH_CMD_WRITE 

Write data

SPI_FLASH_CMD_READ 

Read data

SPI_FLASH_CMD_READ_STATUS 

Get status register

SPI_FLASH_CMD_WRITE_ENABLE 

Allow write access

SPI_FLASH_CMD_SECTOR_ERASE 

Erase complete sector

Function Documentation

◆ erase_sector_xip_flash()

int erase_sector_xip_flash ( uint32_t  base_addr)

Erase sector starting at base address.

Parameters
[in]base_addrBase address of sector to erase.

◆ main()

int main ( void  )

Main function: configure the XIP module, program a small program to the attached flash and run that program from there. The program shows an incrementing counter at the lowest 8-bits of the GPIO output port. This demo is meant for a SPI flash/EEPROM with 16-bit addresses.

Note
This program requires the XIP module, UART0 and the GPIO module.
Returns
0 if execution was successful

◆ program_xip_flash()

int program_xip_flash ( uint32_t *  src,
uint32_t  base_addr,
uint32_t  size 
)

Helper function to program the XIP flash via the direct SPI feature of the XIP module.

Warning
This function can only be used BEFORE the XIP-mode is activated!
Note
This function is blocking and performs individual writes for each byte (little-endian byte order!).
Parameters
[in]srcPointer to data that will be copied to flash (32-bit).
[in]base_addrImage base address (in flash).
[in]sizeImage size in bytes.
Returns
Returns 0 if write was successful.

Variable Documentation

◆ xip_program

const uint32_t xip_program[]

Main function: configure the XIP module, program a small program to the attached flash and run that program from there. The program shows an incrementing counter at the lowest 8-bits of the GPIO output port. This demo is meant for a SPI flash/EEPROM with 16-bit addresses.

Note
This program requires the XIP module, UART0 and the GPIO module.
Returns
0 if execution was successful