Midnight Sun Firmware
Loading...
Searching...
No Matches
Flash

Flash library. More...

Macros

#define FLASH_MEMORY_ALIGNMENT   4U
 Flash memory must be aligned to 4-bytes since STM32 is 32-bit device.
 
#define FLASH_BASE_ADDR   (0x08000000U)
 Flash memory begins at 0x0800 0000 as per ARM specification.
 
#define FLASH_PAGE_SIZE   0x800U
 Flash page size is 2Kbyte as per table 63. in STM32L433xx datasheet.
 
#define FLASH_PAGE_TO_ADDR(page)   (FLASH_BASE_ADDR + ((page)*FLASH_PAGE_SIZE))
 Convert page number to a memory address.
 
#define FLASH_ADDR_TO_PAGE(addr)   (((addr)-FLASH_BASE_ADDR) / FLASH_PAGE_SIZE)
 Convert memory address to a page number.
 
#define FLASH_TIMEOUT_MS   100U
 Maximum time permitted for a flash transaction.
 
#define NUM_FLASH_PAGES   128U
 Total number of flash pages in the STM32L433CCU6.
 

Functions

StatusCode flash_init ()
 Initialize flash API. More...
 
StatusCode flash_read (uintptr_t address, uint8_t *buffer, size_t buffer_len)
 Read from the flash memory and store data into a buffer. More...
 
StatusCode flash_write (uintptr_t address, uint8_t *buffer, size_t buffer_len)
 Write a buffer of data into the flash memory. More...
 
StatusCode flash_erase (uint8_t start_page, uint8_t num_pages)
 Erase pages of flash memory. More...
 

Detailed Description

Flash library.

Function Documentation

◆ flash_erase()

StatusCode flash_erase ( uint8_t  start_page,
uint8_t  num_pages 
)

Erase pages of flash memory.

Parameters
start_pageFirst page to erase
num_pagesNumber of pages to erase
Returns
STATUS_CODE_OK if flash memory was erased successfully STATUS_CODE_INVALID_ARGS if incorrect arguments were passed in STATUS_CODE_INTERNAL_ERROR if flash erase failed

◆ flash_init()

StatusCode flash_init ( )

Initialize flash API.

This initializes the mutex used in the flash API

◆ flash_read()

StatusCode flash_read ( uintptr_t  address,
uint8_t *  buffer,
size_t  buffer_len 
)

Read from the flash memory and store data into a buffer.

Parameters
addressMemory address to read from. This value MUST be 4-byte aligned
bufferPointer to the buffer to store data
buffer_lenLength of the buffer. This value MUST be 4-byte aligned
Returns
STATUS_CODE_OK if flash memory was read successfully STATUS_CODE_OUT_OF_RANGE if address is out of range STATUS_CODE_INVALID_ARGS if address or read bytes is not aligned

◆ flash_write()

StatusCode flash_write ( uintptr_t  address,
uint8_t *  buffer,
size_t  buffer_len 
)

Write a buffer of data into the flash memory.

This does not rewrite the flash memory. Once written, the data must be cleared by erasing the entire page

Parameters
addressMemory address to store the buffer. This value MUST be 4-byte aligned
bufferPointer to the buffer of data to store
buffer_lenLength of the buffer to write. This MUST also be 4-byte aligned
Returns
STATUS_CODE_OK if flash memory was written successfully STATUS_CODE_OUT_OF_RANGE if address is out of range STATUS_CODE_INTERNAL_ERROR if flash write failed