STM32G4 internal-flash register-level implementation.
More...
#include "common/phal_G4/flash/flash_priv.h"
#include "stm32g474xx.h"
STM32G4 internal-flash register-level implementation.
- Author
- Ronak Jain (jain7.nosp@m.17@p.nosp@m.urdue.nosp@m..edu)
This file owns FLASH, PWR, RCC, and SYSCFG register access. The public layer supplies validated requests and receives simple success/failure results.
◆ flash_acquire()
| static bool flash_acquire |
( |
void | | ) |
|
|
static |
Acquire the software operation lock with interrupts masked briefly.
◆ flash_banks_swapped()
| static bool flash_banks_swapped |
( |
void | | ) |
|
|
static |
Read SYSCFG bank remap state without leaving its clock enabled.
◆ flash_clear_status_flags()
| static void flash_clear_status_flags |
( |
void | | ) |
|
|
static |
Clear completed/error flags using FLASH_SR's write-one-to-clear behavior.
◆ flash_disable_data_cache()
Save cache state and disable D-cache before modifying flash.
◆ flash_dual_bank_enabled()
| static bool flash_dual_bank_enabled |
( |
void | | ) |
|
|
static |
Read FLASH_OPTR.DBANK to select 2 KiB or 4 KiB page geometry.
◆ flash_is_busy()
| static bool flash_is_busy |
( |
void | | ) |
|
|
static |
FLASH_SR.BSY indicates that the controller still owns the flash array.
◆ flash_lock()
| static bool flash_lock |
( |
void | | ) |
|
|
static |
Relock the controller and verify FLASH_CR.LOCK was set.
◆ FLASH_PRIV_begin_operation()
Prepare the controller for programming or page erase.
This validates the operating voltage, waits for idle, disables data cache, unlocks the controller, and clears stale status flags.
- Parameters
-
- Returns
- true when the controller is ready; false when unavailable or invalid.
◆ FLASH_PRIV_begin_read()
| bool FLASH_PRIV_begin_read |
( |
void | | ) |
|
Acquire the flash operation lock, wait for idle, and clear status.
- Returns
- true when a read operation may proceed; false if already in use or the busy wait times out.
◆ FLASH_PRIV_end_operation()
Finalize a completed operation, restore cache state, lock the controller, and release the operation lock.
- Parameters
-
- Returns
- true when the controller is idle, error-free, and locked again.
◆ FLASH_PRIV_end_read()
| bool FLASH_PRIV_end_read |
( |
void | | ) |
|
Finish a read operation and release the operation lock.
- Returns
- true when no flash error flags were set.
◆ FLASH_PRIV_erase_page()
| bool FLASH_PRIV_erase_page |
( |
uint32_t | page_address | ) |
|
Erase one complete flash page.
The page number and bank are derived from the absolute page address and the current device bank configuration.
- Parameters
-
| page_address | Address of the page start. |
- Returns
- true when erase completes without a flash error.
◆ FLASH_PRIV_get_page_size_bytes()
| uint32_t FLASH_PRIV_get_page_size_bytes |
( |
void | | ) |
|
Determine the active page size from the dual-bank option bit.
- Returns
- 2 KiB for dual-bank mode or 4 KiB for single-bank mode.
◆ FLASH_PRIV_get_size_bytes()
| uint32_t FLASH_PRIV_get_size_bytes |
( |
void | | ) |
|
Read the device-reported internal flash capacity.
- Returns
- Flash size in bytes, using the supported-device fallback if invalid.
◆ FLASH_PRIV_program_double_word()
| bool FLASH_PRIV_program_double_word |
( |
uint32_t | address, |
|
|
uint64_t | data ) |
Program one STM32G4 double word.
- Parameters
-
| address | 8-byte-aligned flash destination. |
| data | 64-bit value written low word first. |
- Returns
- true when programming completes without a flash error.
◆ flash_release()
| static void flash_release |
( |
void | | ) |
|
|
static |
Release the software operation lock while preserving interrupt state.
◆ flash_restore_caches()
Restore the cache states saved before a write or erase operation.
◆ flash_unlock()
| static bool flash_unlock |
( |
void | | ) |
|
|
static |
Unlock FLASH_CR with the required two-key sequence.
◆ flash_voltage_allows_programming()
| static bool flash_voltage_allows_programming |
( |
void | | ) |
|
|
static |
Confirm voltage scaling range 1 and a stable VOS transition.
PWR is clocked only for the duration of this check when necessary, and the caller's interrupt mask is restored before returning.
◆ flash_wait_for_last_operation()
| static bool flash_wait_for_last_operation |
( |
void | | ) |
|
|
static |
Wait for BSY, collect errors, and clear EOP/error flags.
◆ flash_wait_until_not_busy()
| static bool flash_wait_until_not_busy |
( |
void | | ) |
|
|
static |
Wait for BSY to clear with a bounded, clock-scaled timeout.
◆ g_flash_operation_active
| volatile bool g_flash_operation_active = false |
|
static |
◆ PHAL_FLASH_CONTROL_OPERATION_MASK
| uint32_t PHAL_FLASH_CONTROL_OPERATION_MASK |
|
staticconstexpr |
Initial value:= FLASH_CR_PG | FLASH_CR_PER
| FLASH_CR_MER1 | FLASH_CR_PNB_Msk | FLASH_CR_BKER | FLASH_CR_MER2 | FLASH_CR_FSTPG
◆ PHAL_FLASH_DEFAULT_SIZE_BYTES
| uint32_t PHAL_FLASH_DEFAULT_SIZE_BYTES = 512U * 1024U |
|
staticconstexpr |
◆ PHAL_FLASH_DUAL_PAGE_BYTES
| uint32_t PHAL_FLASH_DUAL_PAGE_BYTES = 2U * 1024U |
|
staticconstexpr |
◆ PHAL_FLASH_KEY_1
| uint32_t PHAL_FLASH_KEY_1 = 0x45670123U |
|
staticconstexpr |
◆ PHAL_FLASH_KEY_2
| uint32_t PHAL_FLASH_KEY_2 = 0xCDEF89ABU |
|
staticconstexpr |
◆ PHAL_FLASH_MAX_SIZE_BYTES
| uint32_t PHAL_FLASH_MAX_SIZE_BYTES = 512U * 1024U |
|
staticconstexpr |
◆ PHAL_FLASH_MAX_WAIT_ITERATIONS
| uint32_t PHAL_FLASH_MAX_WAIT_ITERATIONS = 170'000'000U |
|
staticconstexpr |
◆ PHAL_FLASH_SINGLE_PAGE_BYTES
| uint32_t PHAL_FLASH_SINGLE_PAGE_BYTES = 4U * 1024U |
|
staticconstexpr |
◆ PHAL_FLASH_STATUS_ERROR_MASK
| uint32_t PHAL_FLASH_STATUS_ERROR_MASK |
|
staticconstexpr |
Initial value:= FLASH_SR_OPERR | FLASH_SR_PROGERR
| FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | FLASH_SR_PGSERR | FLASH_SR_MISERR
| FLASH_SR_FASTERR | FLASH_SR_RDERR | FLASH_SR_OPTVERR