STM32G4 internal-flash public-layer implementation.
More...
|
| 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.
|
| |
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.
◆ 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.
◆ 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.
◆ 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.
◆ 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).
◆ 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.
◆ 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.
◆ 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
-
| address | Address of the first byte in the range. |
| length_bytes | Number 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.
◆ 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
-
| address | Address of the first byte to read. |
| destination | Buffer that receives the data. |
| length_bytes | Number of bytes to read. |
- Returns
- true when all bytes are read; false for an invalid range, null buffer, or flash error.
◆ 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
-
| address | Address of the first byte to write; must be 8-byte aligned. |
| source | Buffer containing the data to write. |
| length_bytes | Number 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.