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

STM32G4 internal-flash public-layer implementation. More...

#include "common/phal_G4/flash/flash.h"
#include "common/phal_G4/flash/flash_priv.h"
#include "stm32g474xx.h"
Include dependency graph for flash.c:

Functions

static bool flash_range_is_valid (uint32_t address, uint32_t length_bytes)
 
static bool flash_write_range_is_valid (uint32_t address, uint32_t length_bytes, uint32_t *program_length_bytes)
 
static bool flash_range_is_erased (uint32_t address, uint32_t length_bytes)
 
static uint64_t flash_build_double_word (const uint8_t *source, uint32_t length_bytes)
 
static bool flash_double_word_matches (uint32_t address, uint64_t expected)
 
static bool flash_page_is_erased (uint32_t page_address, uint32_t page_size_bytes)
 
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.
 

Detailed Description

STM32G4 internal-flash public-layer implementation.

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

This layer validates byte ranges, derives page/programming boundaries, and verifies results without exposing FLASH controller registers to callers.

Function Documentation

◆ flash_build_double_word()

static uint64_t flash_build_double_word ( const uint8_t * source,
uint32_t length_bytes )
static

Build an erased-padded 64-bit value for one programming operation.

Here is the caller graph for this function:

◆ flash_double_word_matches()

static bool flash_double_word_matches ( uint32_t address,
uint64_t expected )
static

Verify both 32-bit halves after a double-word program operation.

Here is the caller graph for this function:

◆ flash_page_is_erased()

static bool flash_page_is_erased ( uint32_t page_address,
uint32_t page_size_bytes )
static

Verify every word in a complete erased page.

Here is the caller graph for this function:

◆ flash_range_is_erased()

static bool flash_range_is_erased ( uint32_t address,
uint32_t length_bytes )
static

Confirm every double word in a write range is still erased (all 0xFF).

Here is the caller graph for this function:

◆ flash_range_is_valid()

static bool flash_range_is_valid ( uint32_t address,
uint32_t length_bytes )
static

Validate an absolute flash address range without wrapping arithmetic.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flash_write_range_is_valid()

static bool flash_write_range_is_valid ( uint32_t address,
uint32_t length_bytes,
uint32_t * program_length_bytes )
static

Validate write alignment and round the requested range to double-word size. The rounded range is checked because padding bytes are also programmed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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: