libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
libopencm3 STM32F1xx FLASH Memory More...
Functions | |
void | flash_prefetch_enable (void) |
This buffer is used for instruction fetches and may or may not be enabled by default, depending on platform. More... | |
void | flash_prefetch_disable (void) |
Note carefully the clock restrictions under which the prefetch buffer may be set to disabled. More... | |
void | flash_set_ws (uint32_t ws) |
Set the Number of Wait States. More... | |
void | flash_unlock_option_bytes (void) |
Unlock the Option Byte Access. More... | |
void | flash_clear_pgerr_flag (void) |
Unlock the Flash Program and Erase Controller. More... | |
void | flash_clear_wrprterr_flag (void) |
Clear the Write Protect Error Status Flag. More... | |
void | flash_wait_for_last_operation (void) |
Wait until Last Operation has Ended. More... | |
void | flash_program_word (uint32_t address, uint32_t data) |
Program a 32 bit Word to FLASH. More... | |
void | flash_erase_option_bytes (void) |
Erase All Option Bytes. More... | |
void | flash_program_option_bytes (uint32_t address, uint16_t data) |
Program the Option Bytes. More... | |
void | flash_unlock (void) |
Unlock the Flash Program and Erase Controller This enables write access to the Flash memory. More... | |
void | flash_lock (void) |
Lock the Flash Program and Erase Controller Used to prevent spurious writes to FLASH. More... | |
void | flash_clear_eop_flag (void) |
Clear the End of OPeration flag. More... | |
void | flash_halfcycle_enable (void) |
Enable the FLASH Half Cycle Mode. More... | |
void | flash_halfcycle_disable (void) |
Disable the FLASH Half Cycle Mode. More... | |
void | flash_unlock_upper (void) |
Unlock the Flash Program and Erase Controller, upper Bank. More... | |
void | flash_lock_upper (void) |
Lock the Flash Program and Erase Controller, upper Bank. More... | |
void | flash_clear_pgerr_flag_upper (void) |
Clear the Programming Error Status Flag, upper Bank. More... | |
void | flash_clear_eop_flag_upper (void) |
Clear the End of Operation Status Flag, upper Bank. More... | |
void | flash_clear_wrprterr_flag_upper (void) |
Clear the Write Protect Error Status Flag, upper Bank. More... | |
void | flash_clear_status_flags (void) |
Clear All Status Flags. More... | |
uint32_t | flash_get_status_flags (void) |
Read All Status Flags. More... | |
void | flash_program_half_word (uint32_t address, uint16_t data) |
Program a Half Word to FLASH. More... | |
void | flash_erase_page (uint32_t page_address) |
Erase a Page of FLASH. More... | |
void | flash_erase_all_pages (void) |
Erase All FLASH. More... | |
libopencm3 STM32F1xx FLASH Memory
For the STM32F1xx, accessing FLASH memory is described briefly in section 3.3.3 of the STM32F10x Reference Manual. For detailed programming information see: PM0075 programming manual: STM32F10xxx Flash programming August 2010, Doc ID 17863 Rev 1 https://github.com/libopencm3/libopencm3-archive/blob/master/st_micro/CD00283419.pdf
FLASH memory may be used for data storage as well as code, and may be programmatically modified. Note that for firmware upload the STM32F1xx provides a built-in bootloader in system memory that can be entered from a running program.
FLASH must first be unlocked before programming. In this module a write to FLASH is a blocking operation until the end-of-operation flag is asserted.
For the large memory XL series, with two banks of FLASH, the upper bank is accessed with a second set of registers. In principle both banks can be written simultaneously, or one read while the other is written. This module does not support the simultaneous write feature.
LGPL License Terms libopencm3 License
void flash_clear_eop_flag | ( | void | ) |
Clear the End of OPeration flag.
Definition at line 41 of file flash_common_f.c.
References FLASH_SR, and FLASH_SR_EOP.
Referenced by flash_clear_status_flags().
void flash_clear_eop_flag_upper | ( | void | ) |
Clear the End of Operation Status Flag, upper Bank.
Definition at line 139 of file flash.c.
References desig_get_flash_size(), FLASH_SR2, and FLASH_SR_EOP.
Referenced by flash_clear_status_flags().
void flash_clear_pgerr_flag | ( | void | ) |
Unlock the Flash Program and Erase Controller.
This enables write access to the Flash memory. It is locked by default on reset.
Clear the Programming Error Status Flag
Definition at line 42 of file flash_common_f01.c.
References FLASH_SR, and FLASH_SR_PGERR.
Referenced by flash_clear_status_flags().
void flash_clear_pgerr_flag_upper | ( | void | ) |
Clear the Programming Error Status Flag, upper Bank.
Definition at line 127 of file flash.c.
References desig_get_flash_size(), FLASH_SR2, and FLASH_SR_PGERR.
Referenced by flash_clear_status_flags().
void flash_clear_status_flags | ( | void | ) |
Clear All Status Flags.
Clear all status flags.
Program error, end of operation, write protect error, busy. Both banks cleared.
Definition at line 164 of file flash.c.
References desig_get_flash_size(), flash_clear_eop_flag(), flash_clear_eop_flag_upper(), flash_clear_pgerr_flag(), flash_clear_pgerr_flag_upper(), flash_clear_wrprterr_flag(), and flash_clear_wrprterr_flag_upper().
void flash_clear_wrprterr_flag | ( | void | ) |
Clear the Write Protect Error Status Flag.
Definition at line 52 of file flash_common_f01.c.
References FLASH_SR, and FLASH_SR_WRPRTERR.
Referenced by flash_clear_status_flags().
void flash_clear_wrprterr_flag_upper | ( | void | ) |
Clear the Write Protect Error Status Flag, upper Bank.
Definition at line 151 of file flash.c.
References desig_get_flash_size(), FLASH_SR2, and FLASH_SR_WRPRTERR.
Referenced by flash_clear_status_flags().
void flash_erase_all_pages | ( | void | ) |
Erase All FLASH.
This performs all operations necessary to erase all user pages in the FLASH memory. The information block is unaffected.
Definition at line 284 of file flash.c.
References FLASH_CR, FLASH_CR2, FLASH_CR_MER, FLASH_CR_STRT, and flash_wait_for_last_operation().
void flash_erase_option_bytes | ( | void | ) |
Erase All Option Bytes.
This performs all operations necessary to erase the option bytes. These must first be fully erased before attempting to program them, therefore it is recommended to check these after an erase attempt.
Definition at line 96 of file flash_common_f01.c.
References FLASH_CR, FLASH_CR_OPTER, FLASH_CR_OPTWRE, FLASH_CR_STRT, flash_unlock_option_bytes(), and flash_wait_for_last_operation().
void flash_erase_page | ( | uint32_t | page_address | ) |
Erase a Page of FLASH.
This performs all operations necessary to erase a page in FLASH memory. The page should be checked to ensure that it was properly erased. A page must first be fully erased before attempting to program it.
Note that the page sizes differ between devices. See the reference manual or the FLASH programming manual for details.
[in] | page_address | Full address of flash page to be erased. |
Definition at line 252 of file flash.c.
References desig_get_flash_size(), FLASH_AR, FLASH_AR2, FLASH_BASE, FLASH_CR, FLASH_CR2, FLASH_CR_PER, FLASH_CR_STRT, and flash_wait_for_last_operation().
uint32_t flash_get_status_flags | ( | void | ) |
Read All Status Flags.
The programming error, end of operation, write protect error and busy flags are returned in the order of appearance in the status register.
Flags for the upper bank, where appropriate, are combined with those for the lower bank using bitwise OR, without distinction.
Definition at line 189 of file flash.c.
References desig_get_flash_size(), FLASH_SR, FLASH_SR2, FLASH_SR_BSY, FLASH_SR_EOP, FLASH_SR_PGERR, and FLASH_SR_WRPRTERR.
Referenced by flash_wait_for_last_operation().
void flash_halfcycle_disable | ( | void | ) |
void flash_halfcycle_enable | ( | void | ) |
Enable the FLASH Half Cycle Mode.
This mode is used for power saving during read access. It is disabled by default on reset.
Note carefully the clock restrictions under which the half cycle mode may be enabled or disabled. This mode may only be used while the clock is running at 8MHz. See the reference manual for details.
Definition at line 76 of file flash.c.
References FLASH_ACR, and FLASH_ACR_HLFCYA.
void flash_lock | ( | void | ) |
Lock the Flash Program and Erase Controller Used to prevent spurious writes to FLASH.
Definition at line 35 of file flash_common_f.c.
References FLASH_CR, and FLASH_CR_LOCK.
void flash_lock_upper | ( | void | ) |
Lock the Flash Program and Erase Controller, upper Bank.
Used to prevent spurious writes to FLASH.
Definition at line 117 of file flash.c.
References FLASH_CR2, and FLASH_CR_LOCK.
void flash_prefetch_disable | ( | void | ) |
Note carefully the clock restrictions under which the prefetch buffer may be set to disabled.
See the reference manual for details.
Definition at line 31 of file flash_common_all.c.
References FLASH_ACR.
void flash_prefetch_enable | ( | void | ) |
This buffer is used for instruction fetches and may or may not be enabled by default, depending on platform.
(F1: yes, most others: no)
Note carefully the clock restrictions under which the prefetch buffer may be enabled or disabled. Changes are normally made while the clock is running in the power-on low frequency mode before being set to a higher speed mode.
Note carefully that prefetch may also results in increased consumption and can only improve performance on "mostly linear" workloads where there is at least one flash wait state.
See the reference manual for your particular target for more details.
Definition at line 26 of file flash_common_all.c.
References FLASH_ACR, and FLASH_ACR_PRFTEN.
void flash_program_half_word | ( | uint32_t | address, |
uint16_t | data | ||
) |
Program a Half Word to FLASH.
This performs all operations necessary to program a 16 bit word to FLASH memory. The program error flag should be checked separately for the event that memory was not properly erased.
Status bit polling is used to detect end of operation.
[in] | address | Full address of flash half word to be programmed. |
[in] | data | half word to write |
Definition at line 218 of file flash.c.
References desig_get_flash_size(), FLASH_BASE, FLASH_CR, FLASH_CR2, FLASH_CR_PG, flash_wait_for_last_operation(), and MMIO16.
Referenced by flash_program_word().
void flash_program_option_bytes | ( | uint32_t | address, |
uint16_t | data | ||
) |
Program the Option Bytes.
This performs all operations necessary to program the option bytes. The write protect error flag should be checked separately for the event that an option byte had not been properly erased before calling this function.
Only the lower 8 bits of the data is significant.
[in] | address | Address of option byte from Option Byte Addresses. |
[in] | data | value to write |
Definition at line 123 of file flash_common_f01.c.
References FLASH_CR, FLASH_CR_OPTPG, FLASH_CR_OPTWRE, flash_unlock_option_bytes(), flash_wait_for_last_operation(), and MMIO16.
void flash_program_word | ( | uint32_t | address, |
uint32_t | data | ||
) |
Program a 32 bit Word to FLASH.
This performs all operations necessary to program a 32 bit word to FLASH memory. The program error flag should be checked separately for the event that memory was not properly erased.
Status bit polling is used to detect end of operation.
[in] | address | Full address of flash word to be programmed. |
[in] | data | word to write |
Definition at line 82 of file flash_common_f01.c.
References flash_program_half_word().
void flash_set_ws | ( | uint32_t | ws | ) |
Set the Number of Wait States.
Used to match the system clock to the FLASH memory access time. See the programming manual for more information on clock speed ranges. The latency must be changed to the appropriate value before any increase in clock speed, or after any decrease in clock speed.
[in] | ws | values from FLASH Wait States. |
Definition at line 36 of file flash_common_all.c.
References FLASH_ACR, FLASH_ACR_LATENCY_MASK, and FLASH_ACR_LATENCY_SHIFT.
Referenced by rcc_clock_setup_in_hse_12mhz_out_72mhz(), rcc_clock_setup_in_hse_16mhz_out_72mhz(), rcc_clock_setup_in_hse_25mhz_out_72mhz(), rcc_clock_setup_in_hse_8mhz_out_24mhz(), rcc_clock_setup_in_hse_8mhz_out_72mhz(), rcc_clock_setup_in_hsi_out_24mhz(), rcc_clock_setup_in_hsi_out_48mhz(), rcc_clock_setup_in_hsi_out_64mhz(), and rcc_clock_setup_pll().
void flash_unlock | ( | void | ) |
Unlock the Flash Program and Erase Controller This enables write access to the Flash memory.
It is locked by default on reset.
Definition at line 28 of file flash_common_f.c.
References FLASH_KEYR, FLASH_KEYR_KEY1, and FLASH_KEYR_KEY2.
void flash_unlock_option_bytes | ( | void | ) |
Unlock the Option Byte Access.
This enables write access to the option bytes. It is locked by default on reset.
Definition at line 46 of file flash_common_all.c.
References FLASH_OPTKEYR, FLASH_OPTKEYR_KEY1, and FLASH_OPTKEYR_KEY2.
Referenced by flash_erase_option_bytes(), and flash_program_option_bytes().
void flash_unlock_upper | ( | void | ) |
Unlock the Flash Program and Erase Controller, upper Bank.
This enables write access to the upper bank of the Flash memory in XL devices. It is locked by default on reset.
Definition at line 98 of file flash.c.
References desig_get_flash_size(), FLASH_CR2, FLASH_CR_LOCK, FLASH_KEYR2, FLASH_KEYR_KEY1, and FLASH_KEYR_KEY2.
void flash_wait_for_last_operation | ( | void | ) |
Wait until Last Operation has Ended.
This loops indefinitely until an operation (write or erase) has completed by testing the busy flag.
Definition at line 64 of file flash_common_f01.c.
References flash_get_status_flags(), and FLASH_SR_BSY.
Referenced by flash_erase_all_pages(), flash_erase_option_bytes(), flash_erase_page(), flash_program_half_word(), and flash_program_option_bytes().