libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
FLASH Defines

Defined Constants and Types for the STM32F1xx FLASH Memory. More...

Collaboration diagram for FLASH Defines:

Modules

 Option Byte Addresses
 
 FLASH Wait States
 

Macros

#define FLASH_ACR_HLFCYA   (1 << 3)
 
#define FLASH_SR_EOP   (1 << 5)
 
#define FLASH_SR_WRPRTERR   (1 << 4)
 
#define FLASH_SR_PGERR   (1 << 2)
 
#define FLASH_SR_BSY   (1 << 0)
 
#define FLASH_OBR_NRST_STDBY   (1 << 4)
 
#define FLASH_OBR_NRST_STOP   (1 << 3)
 
#define FLASH_OBR_WDG_SW   (1 << 2)
 
#define FLASH_OBR_RDPRT_EN   (1 << FLASH_OBR_RDPRT_SHIFT)
 
#define FLASH_RDP_KEY   ((uint16_t)0x00a5)
 
#define FLASH_ACR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
 
#define FLASH_KEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)
 
#define FLASH_OPTKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)
 
#define FLASH_SR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)
 
#define FLASH_CR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)
 
#define FLASH_AR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)
 
#define FLASH_OBR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1C)
 
#define FLASH_WRPR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)
 
#define FLASH_KEYR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x44)
 
#define FLASH_SR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x4C)
 
#define FLASH_CR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x50)
 
#define FLASH_AR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x54)
 
#define FLASH_OPTION_BYTE(i)   MMIO16(INFO_BASE+0x0800 + (i)*2)
 
#define FLASH_ACR_LATENCY_SHIFT   0
 
#define FLASH_ACR_LATENCY_MASK   7
 
#define FLASH_ACR_PRFTBS   (1 << 5)
 
#define FLASH_ACR_PRFTBE   (1 << 4)
 
#define FLASH_ACR_PRFTEN   FLASH_ACR_PRFTBE
 Compatibility define. More...
 
#define FLASH_SR_EOP   (1 << 5)
 
#define FLASH_SR_WRPRTERR   (1 << 4)
 
#define FLASH_SR_PGERR   (1 << 2)
 
#define FLASH_SR_BSY   (1 << 0)
 
#define FLASH_CR_EOPIE   (1 << 12)
 
#define FLASH_CR_ERRIE   (1 << 10)
 
#define FLASH_CR_OPTWRE   (1 << 9)
 
#define FLASH_CR_LOCK   (1 << 7)
 
#define FLASH_CR_STRT   (1 << 6)
 
#define FLASH_CR_OPTER   (1 << 5)
 
#define FLASH_CR_OPTPG   (1 << 4)
 
#define FLASH_CR_MER   (1 << 2)
 
#define FLASH_CR_PER   (1 << 1)
 
#define FLASH_CR_PG   (1 << 0)
 
#define FLASH_OBR_RDPRT_SHIFT   1
 
#define FLASH_OBR_OPTERR   (1 << 0)
 
#define FLASH_KEYR_KEY1   ((uint32_t)0x45670123)
 
#define FLASH_KEYR_KEY2   ((uint32_t)0xcdef89ab)
 
#define FLASH_OPTKEYR_KEY1   FLASH_KEYR_KEY1
 
#define FLASH_OPTKEYR_KEY2   FLASH_KEYR_KEY2
 

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...
 

Detailed Description

Defined Constants and Types for the STM32F1xx FLASH Memory.

Version
1.0.0
Date
14 January 2014

LGPL License Terms libopencm3 License

Macro Definition Documentation

◆ FLASH_ACR

#define FLASH_ACR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)

Definition at line 40 of file flash_common_f01.h.

◆ FLASH_ACR_HLFCYA

#define FLASH_ACR_HLFCYA   (1 << 3)

Definition at line 78 of file f1/flash.h.

◆ FLASH_ACR_LATENCY_MASK

#define FLASH_ACR_LATENCY_MASK   7

Definition at line 61 of file flash_common_f01.h.

◆ FLASH_ACR_LATENCY_SHIFT

#define FLASH_ACR_LATENCY_SHIFT   0

Definition at line 60 of file flash_common_f01.h.

◆ FLASH_ACR_PRFTBE

#define FLASH_ACR_PRFTBE   (1 << 4)

Definition at line 64 of file flash_common_f01.h.

◆ FLASH_ACR_PRFTBS

#define FLASH_ACR_PRFTBS   (1 << 5)

Definition at line 63 of file flash_common_f01.h.

◆ FLASH_ACR_PRFTEN

#define FLASH_ACR_PRFTEN   FLASH_ACR_PRFTBE

Compatibility define.

Definition at line 66 of file flash_common_f01.h.

◆ FLASH_AR

#define FLASH_AR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)

Definition at line 45 of file flash_common_f01.h.

◆ FLASH_AR2

#define FLASH_AR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x54)

Definition at line 52 of file flash_common_f01.h.

◆ FLASH_CR

#define FLASH_CR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)

Definition at line 44 of file flash_common_f01.h.

◆ FLASH_CR2

#define FLASH_CR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x50)

Definition at line 51 of file flash_common_f01.h.

◆ FLASH_CR_EOPIE

#define FLASH_CR_EOPIE   (1 << 12)

Definition at line 77 of file flash_common_f01.h.

◆ FLASH_CR_ERRIE

#define FLASH_CR_ERRIE   (1 << 10)

Definition at line 78 of file flash_common_f01.h.

◆ FLASH_CR_LOCK

#define FLASH_CR_LOCK   (1 << 7)

Definition at line 80 of file flash_common_f01.h.

◆ FLASH_CR_MER

#define FLASH_CR_MER   (1 << 2)

Definition at line 84 of file flash_common_f01.h.

◆ FLASH_CR_OPTER

#define FLASH_CR_OPTER   (1 << 5)

Definition at line 82 of file flash_common_f01.h.

◆ FLASH_CR_OPTPG

#define FLASH_CR_OPTPG   (1 << 4)

Definition at line 83 of file flash_common_f01.h.

◆ FLASH_CR_OPTWRE

#define FLASH_CR_OPTWRE   (1 << 9)

Definition at line 79 of file flash_common_f01.h.

◆ FLASH_CR_PER

#define FLASH_CR_PER   (1 << 1)

Definition at line 85 of file flash_common_f01.h.

◆ FLASH_CR_PG

#define FLASH_CR_PG   (1 << 0)

Definition at line 86 of file flash_common_f01.h.

◆ FLASH_CR_STRT

#define FLASH_CR_STRT   (1 << 6)

Definition at line 81 of file flash_common_f01.h.

◆ FLASH_KEYR

#define FLASH_KEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)

Definition at line 41 of file flash_common_f01.h.

◆ FLASH_KEYR2

#define FLASH_KEYR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x44)

Definition at line 49 of file flash_common_f01.h.

◆ FLASH_KEYR_KEY1

#define FLASH_KEYR_KEY1   ((uint32_t)0x45670123)

Definition at line 95 of file flash_common_f01.h.

◆ FLASH_KEYR_KEY2

#define FLASH_KEYR_KEY2   ((uint32_t)0xcdef89ab)

Definition at line 96 of file flash_common_f01.h.

◆ FLASH_OBR

#define FLASH_OBR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1C)

Definition at line 46 of file flash_common_f01.h.

◆ FLASH_OBR_NRST_STDBY

#define FLASH_OBR_NRST_STDBY   (1 << 4)

Definition at line 93 of file f1/flash.h.

◆ FLASH_OBR_NRST_STOP

#define FLASH_OBR_NRST_STOP   (1 << 3)

Definition at line 94 of file f1/flash.h.

◆ FLASH_OBR_OPTERR

#define FLASH_OBR_OPTERR   (1 << 0)

Definition at line 91 of file flash_common_f01.h.

◆ FLASH_OBR_RDPRT_EN

#define FLASH_OBR_RDPRT_EN   (1 << FLASH_OBR_RDPRT_SHIFT)

Definition at line 96 of file f1/flash.h.

◆ FLASH_OBR_RDPRT_SHIFT

#define FLASH_OBR_RDPRT_SHIFT   1

Definition at line 90 of file flash_common_f01.h.

◆ FLASH_OBR_WDG_SW

#define FLASH_OBR_WDG_SW   (1 << 2)

Definition at line 95 of file f1/flash.h.

◆ FLASH_OPTION_BYTE

#define FLASH_OPTION_BYTE (   i)    MMIO16(INFO_BASE+0x0800 + (i)*2)

Definition at line 56 of file flash_common_f01.h.

◆ FLASH_OPTKEYR

#define FLASH_OPTKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)

Definition at line 42 of file flash_common_f01.h.

◆ FLASH_OPTKEYR_KEY1

#define FLASH_OPTKEYR_KEY1   FLASH_KEYR_KEY1

Definition at line 98 of file flash_common_f01.h.

◆ FLASH_OPTKEYR_KEY2

#define FLASH_OPTKEYR_KEY2   FLASH_KEYR_KEY2

Definition at line 99 of file flash_common_f01.h.

◆ FLASH_RDP_KEY

#define FLASH_RDP_KEY   ((uint16_t)0x00a5)

Definition at line 103 of file f1/flash.h.

◆ FLASH_SR

#define FLASH_SR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)

Definition at line 43 of file flash_common_f01.h.

◆ FLASH_SR2

#define FLASH_SR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x4C)

Definition at line 50 of file flash_common_f01.h.

◆ FLASH_SR_BSY [1/2]

#define FLASH_SR_BSY   (1 << 0)

Definition at line 73 of file flash_common_f01.h.

◆ FLASH_SR_BSY [2/2]

#define FLASH_SR_BSY   (1 << 0)

Definition at line 85 of file f1/flash.h.

◆ FLASH_SR_EOP [1/2]

#define FLASH_SR_EOP   (1 << 5)

Definition at line 70 of file flash_common_f01.h.

◆ FLASH_SR_EOP [2/2]

#define FLASH_SR_EOP   (1 << 5)

Definition at line 82 of file f1/flash.h.

◆ FLASH_SR_PGERR [1/2]

#define FLASH_SR_PGERR   (1 << 2)

Definition at line 72 of file flash_common_f01.h.

◆ FLASH_SR_PGERR [2/2]

#define FLASH_SR_PGERR   (1 << 2)

Definition at line 84 of file f1/flash.h.

◆ FLASH_SR_WRPRTERR [1/2]

#define FLASH_SR_WRPRTERR   (1 << 4)

Definition at line 71 of file flash_common_f01.h.

◆ FLASH_SR_WRPRTERR [2/2]

#define FLASH_SR_WRPRTERR   (1 << 4)

Definition at line 83 of file f1/flash.h.

◆ FLASH_WRPR

#define FLASH_WRPR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)

Definition at line 47 of file flash_common_f01.h.

Function Documentation

◆ flash_clear_eop_flag_upper()

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().

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

◆ flash_clear_pgerr_flag()

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().

Here is the caller graph for this function:

◆ flash_clear_pgerr_flag_upper()

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().

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

◆ flash_clear_wrprterr_flag()

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().

Here is the caller graph for this function:

◆ flash_clear_wrprterr_flag_upper()

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().

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

◆ flash_erase_all_pages()

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().

Here is the call graph for this function:

◆ flash_erase_option_bytes()

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().

Here is the call graph for this function:

◆ flash_erase_page()

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.

Parameters
[in]page_addressFull 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().

Here is the call graph for this function:

◆ flash_get_status_flags()

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.

Returns
uint32_t. bit 0: busy, bit 2: programming error, bit 4: write protect error, bit 5: end of operation.

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().

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

◆ flash_halfcycle_disable()

void flash_halfcycle_disable ( void  )

Disable the FLASH Half Cycle Mode.

Definition at line 86 of file flash.c.

References FLASH_ACR.

◆ flash_halfcycle_enable()

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.

◆ flash_lock_upper()

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.

◆ flash_program_half_word()

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.

Parameters
[in]addressFull address of flash half word to be programmed.
[in]datahalf 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().

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

◆ flash_program_option_bytes()

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.

Parameters
[in]addressAddress of option byte from Option Byte Addresses.
[in]datavalue 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.

Here is the call graph for this function:

◆ flash_program_word()

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.

Parameters
[in]addressFull address of flash word to be programmed.
[in]dataword to write

Definition at line 82 of file flash_common_f01.c.

References flash_program_half_word().

Here is the call graph for this function:

◆ flash_unlock_upper()

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.

Here is the call graph for this function: