libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
Defined Constants and Types for the STM32F1xx FLASH Memory. More...
Modules | |
Option Byte Addresses | |
FLASH Wait States | |
Functions | |
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_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... | |
uint32_t | flash_get_status_flags (void) |
Read All Status Flags. More... | |
void | flash_program_word (uint32_t address, uint32_t data) |
Program a 32 bit Word to FLASH. 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... | |
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... | |
Defined Constants and Types for the STM32F1xx FLASH Memory.
LGPL License Terms libopencm3 License
#define FLASH_ACR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00) |
Definition at line 40 of file flash_common_f01.h.
#define FLASH_ACR_HLFCYA (1 << 3) |
Definition at line 78 of file f1/flash.h.
#define FLASH_ACR_LATENCY_MASK 7 |
Definition at line 61 of file flash_common_f01.h.
#define FLASH_ACR_LATENCY_SHIFT 0 |
Definition at line 60 of file flash_common_f01.h.
#define FLASH_ACR_PRFTBE (1 << 4) |
Definition at line 64 of file flash_common_f01.h.
#define FLASH_ACR_PRFTBS (1 << 5) |
Definition at line 63 of file flash_common_f01.h.
#define FLASH_ACR_PRFTEN FLASH_ACR_PRFTBE |
Compatibility define.
Definition at line 66 of file flash_common_f01.h.
#define FLASH_AR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14) |
Definition at line 45 of file flash_common_f01.h.
#define FLASH_AR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x54) |
Definition at line 52 of file flash_common_f01.h.
#define FLASH_CR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10) |
Definition at line 44 of file flash_common_f01.h.
#define FLASH_CR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x50) |
Definition at line 51 of file flash_common_f01.h.
#define FLASH_CR_EOPIE (1 << 12) |
Definition at line 77 of file flash_common_f01.h.
#define FLASH_CR_ERRIE (1 << 10) |
Definition at line 78 of file flash_common_f01.h.
#define FLASH_CR_LOCK (1 << 7) |
Definition at line 80 of file flash_common_f01.h.
#define FLASH_CR_MER (1 << 2) |
Definition at line 84 of file flash_common_f01.h.
#define FLASH_CR_OPTER (1 << 5) |
Definition at line 82 of file flash_common_f01.h.
#define FLASH_CR_OPTPG (1 << 4) |
Definition at line 83 of file flash_common_f01.h.
#define FLASH_CR_OPTWRE (1 << 9) |
Definition at line 79 of file flash_common_f01.h.
#define FLASH_CR_PER (1 << 1) |
Definition at line 85 of file flash_common_f01.h.
#define FLASH_CR_PG (1 << 0) |
Definition at line 86 of file flash_common_f01.h.
#define FLASH_CR_STRT (1 << 6) |
Definition at line 81 of file flash_common_f01.h.
#define FLASH_KEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04) |
Definition at line 41 of file flash_common_f01.h.
#define FLASH_KEYR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x44) |
Definition at line 49 of file flash_common_f01.h.
#define FLASH_KEYR_KEY1 ((uint32_t)0x45670123) |
Definition at line 95 of file flash_common_f01.h.
#define FLASH_KEYR_KEY2 ((uint32_t)0xcdef89ab) |
Definition at line 96 of file flash_common_f01.h.
#define FLASH_OBR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1C) |
Definition at line 46 of file flash_common_f01.h.
#define FLASH_OBR_NRST_STDBY (1 << 4) |
Definition at line 93 of file f1/flash.h.
#define FLASH_OBR_NRST_STOP (1 << 3) |
Definition at line 94 of file f1/flash.h.
#define FLASH_OBR_OPTERR (1 << 0) |
Definition at line 91 of file flash_common_f01.h.
#define FLASH_OBR_RDPRT_EN (1 << FLASH_OBR_RDPRT_SHIFT) |
Definition at line 96 of file f1/flash.h.
#define FLASH_OBR_RDPRT_SHIFT 1 |
Definition at line 90 of file flash_common_f01.h.
#define FLASH_OBR_WDG_SW (1 << 2) |
Definition at line 95 of file f1/flash.h.
Definition at line 56 of file flash_common_f01.h.
#define FLASH_OPTKEYR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08) |
Definition at line 42 of file flash_common_f01.h.
#define FLASH_OPTKEYR_KEY1 FLASH_KEYR_KEY1 |
Definition at line 98 of file flash_common_f01.h.
#define FLASH_OPTKEYR_KEY2 FLASH_KEYR_KEY2 |
Definition at line 99 of file flash_common_f01.h.
#define FLASH_RDP_KEY ((uint16_t)0x00a5) |
Definition at line 103 of file f1/flash.h.
#define FLASH_SR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C) |
Definition at line 43 of file flash_common_f01.h.
#define FLASH_SR2 MMIO32(FLASH_MEM_INTERFACE_BASE + 0x4C) |
Definition at line 50 of file flash_common_f01.h.
#define FLASH_SR_BSY (1 << 0) |
Definition at line 73 of file flash_common_f01.h.
#define FLASH_SR_BSY (1 << 0) |
Definition at line 85 of file f1/flash.h.
#define FLASH_SR_EOP (1 << 5) |
Definition at line 70 of file flash_common_f01.h.
#define FLASH_SR_EOP (1 << 5) |
Definition at line 82 of file f1/flash.h.
#define FLASH_SR_PGERR (1 << 2) |
Definition at line 72 of file flash_common_f01.h.
#define FLASH_SR_PGERR (1 << 2) |
Definition at line 84 of file f1/flash.h.
#define FLASH_SR_WRPRTERR (1 << 4) |
Definition at line 71 of file flash_common_f01.h.
#define FLASH_SR_WRPRTERR (1 << 4) |
Definition at line 83 of file f1/flash.h.
#define FLASH_WRPR MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20) |
Definition at line 47 of file flash_common_f01.h.
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_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_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_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_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.