PER Firmware
Loading...
Searching...
No Matches
flash.h File Reference

STM32G4 internal-flash public API. More...

#include <stdbool.h>
#include <stdint.h>
Include dependency graph for flash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool PHAL_FLASH_read (uint32_t address, void *destination, uint32_t length_bytes)
 Copy bytes from internal flash into a buffer.
 
bool PHAL_FLASH_write (uint32_t address, const void *source, uint32_t length_bytes)
 Program bytes into erased internal flash.
 
bool PHAL_FLASH_erase (uint32_t address, uint32_t length_bytes)
 Erase every internal flash page touched by a range.
 

Variables

static constexpr uint32_t PHAL_FLASH_WRITE_ALIGNMENT_BYTES = 8U
 

Detailed Description

STM32G4 internal-flash public API.

Author
Ronak Jain (jain7.nosp@m.17@p.nosp@m.urdue.nosp@m..edu)

The public layer accepts byte ranges and hides controller unlock, cache, bank, page, and status-register details in flash_priv.c.

Function Documentation

◆ PHAL_FLASH_erase()

bool PHAL_FLASH_erase ( uint32_t address,
uint32_t length_bytes )

Erase every internal flash page touched by a range.

The address may be unaligned. Every complete page touched by the range is erased. A zero-length erase succeeds without modifying flash.

Parameters
addressAddress of the first byte in the range.
length_bytesNumber of bytes in the range.
Returns
true when every affected page is erased and verified; false on an invalid range or flash error.
Warning
Erase operates on complete pages. Bytes outside the range are erased when they share an affected page.
Note
Erase and write operations are serialized and temporarily manage the flash controller's cache and lock state.
Here is the call graph for this function:

◆ PHAL_FLASH_read()

bool PHAL_FLASH_read ( uint32_t address,
void * destination,
uint32_t length_bytes )

Copy bytes from internal flash into a buffer.

The requested range must be within internal flash. The address is a CPU address, not an offset from FLASH_BASE. A zero-length read succeeds without accessing either pointer.

Parameters
addressAddress of the first byte to read.
destinationBuffer that receives the data.
length_bytesNumber of bytes to read.
Returns
true when all bytes are read; false for an invalid range, null buffer, or flash error.
Here is the call graph for this function:

◆ PHAL_FLASH_write()

bool PHAL_FLASH_write ( uint32_t address,
const void * source,
uint32_t length_bytes )

Program bytes into erased internal flash.

The destination must be erased before writing. The complete programmed range is checked for erased-state bytes before any programming starts. A zero-length write succeeds without accessing either pointer.

Parameters
addressAddress of the first byte to write; must be 8-byte aligned.
sourceBuffer containing the data to write.
length_bytesNumber of bytes to write.
Returns
true when all bytes are programmed and verified; false on invalid input or flash error.
Note
A partial final double word is padded with 0xFF.
The source buffer is read only while this call is active.
Here is the call graph for this function:

Variable Documentation

◆ PHAL_FLASH_WRITE_ALIGNMENT_BYTES

uint32_t PHAL_FLASH_WRITE_ALIGNMENT_BYTES = 8U
staticconstexpr

STM32G4 flash programming granularity.

Writes are padded with erased-state bytes (0xFF) to this size when the requested length is not a multiple of the programming granularity.