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

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

Collaboration diagram for FLASH Defines:

Modules

 Flash Registers
 
 FLASH Wait States
 
 FLASH_ACR values
 Access Control register values.
 
 Flash programming width
 

Macros

#define FLASH_ACR_LATENCY_SHIFT   0
 
#define FLASH_ACR_LATENCY_MASK   0x0f
 
#define FLASH_SR_BSY   (1 << 16)
 
#define FLASH_SR_PGPERR   (1 << 6)
 
#define FLASH_SR_PGAERR   (1 << 5)
 
#define FLASH_SR_WRPERR   (1 << 4)
 
#define FLASH_SR_OPERR   (1 << 1)
 
#define FLASH_SR_EOP   (1 << 0)
 
#define FLASH_CR_LOCK   (1 << 31)
 
#define FLASH_CR_ERRIE   (1 << 25)
 
#define FLASH_CR_EOPIE   (1 << 24)
 
#define FLASH_CR_STRT   (1 << 16)
 
#define FLASH_CR_MER   (1 << 2)
 
#define FLASH_CR_SER   (1 << 1)
 
#define FLASH_CR_PG   (1 << 0)
 
#define FLASH_CR_SNB_SHIFT   3
 
#define FLASH_CR_SNB_MASK   0x1f
 
#define FLASH_CR_PROGRAM_MASK   0x3
 
#define FLASH_CR_PROGRAM_SHIFT   8
 
#define FLASH_OPTCR_NRST_STDBY   (1 << 7)
 
#define FLASH_OPTCR_NRST_STOP   (1 << 6)
 
#define FLASH_OPTCR_OPTSTRT   (1 << 1)
 
#define FLASH_OPTCR_OPTLOCK   (1 << 0)
 
#define FLASH_OPTCR_BOR_LEVEL_3   (0x00 << 2)
 
#define FLASH_OPTCR_BOR_LEVEL_2   (0x01 << 2)
 
#define FLASH_OPTCR_BOR_LEVEL_1   (0x02 << 2)
 
#define FLASH_OPTCR_BOR_OFF   (0x03 << 2)
 
#define FLASH_KEYR_KEY1   ((uint32_t)0x45670123)
 
#define FLASH_KEYR_KEY2   ((uint32_t)0xcdef89ab)
 
#define FLASH_OPTKEYR_KEY1   ((uint32_t)0x08192a3b)
 
#define FLASH_OPTKEYR_KEY2   ((uint32_t)0x4c5d6e7f)
 

Functions

void flash_lock_option_bytes (void)
 Lock the Option Byte Access. More...
 
void flash_clear_pgperr_flag (void)
 Clear programming parallelism error flag. More...
 
void flash_clear_wrperr_flag (void)
 Clear the Write Protect Error Flag. More...
 
void flash_clear_pgaerr_flag (void)
 Clear the Programming Alignment Error Flag. More...
 
void flash_erase_all_sectors (uint32_t program_size)
 Erase All FLASH. More...
 
void flash_erase_sector (uint8_t sector, uint32_t program_size)
 Erase a Sector of FLASH. More...
 
void flash_program_double_word (uint32_t address, uint64_t data)
 Program a 64 bit Word to FLASH. 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_program_byte (uint32_t address, uint8_t data)
 Program an 8 bit Byte to FLASH. More...
 
void flash_program (uint32_t address, const uint8_t *data, uint32_t len)
 Program a Data Block to FLASH. More...
 
void flash_program_option_bytes (uint32_t data)
 Program the Option Bytes. More...
 
void flash_dcache_enable (void)
 Enable the data cache. More...
 
void flash_dcache_disable (void)
 Disable the data cache. More...
 
void flash_icache_enable (void)
 Enable the Instruction Cache. More...
 
void flash_icache_disable (void)
 Disable the Instruction Cache. More...
 
void flash_dcache_reset (void)
 Reset the Data Cache. More...
 
void flash_icache_reset (void)
 Reset the Instruction Cache. More...
 

Detailed Description

Defined Constants and Types for the STM32F2xx FLASH Memory.

Version
1.0.0
Date
14 January 2014

LGPL License Terms libopencm3 License

Author
© 2010 Thomas Otto tommi.nosp@m.@via.nosp@m.dmin..nosp@m.org
© 2010 Mark Butler mbutl.nosp@m.er@p.nosp@m.hysic.nosp@m.s.ot.nosp@m.ago.a.nosp@m.c.nz

Macro Definition Documentation

◆ FLASH_ACR_LATENCY_MASK

#define FLASH_ACR_LATENCY_MASK   0x0f

Definition at line 78 of file flash_common_f24.h.

◆ FLASH_ACR_LATENCY_SHIFT

#define FLASH_ACR_LATENCY_SHIFT   0

Definition at line 77 of file flash_common_f24.h.

◆ FLASH_CR_EOPIE

#define FLASH_CR_EOPIE   (1 << 24)

Definition at line 100 of file flash_common_f24.h.

◆ FLASH_CR_ERRIE

#define FLASH_CR_ERRIE   (1 << 25)

Definition at line 99 of file flash_common_f24.h.

◆ FLASH_CR_LOCK

#define FLASH_CR_LOCK   (1 << 31)

Definition at line 98 of file flash_common_f24.h.

◆ FLASH_CR_MER

#define FLASH_CR_MER   (1 << 2)

Definition at line 102 of file flash_common_f24.h.

◆ FLASH_CR_PG

#define FLASH_CR_PG   (1 << 0)

Definition at line 104 of file flash_common_f24.h.

◆ FLASH_CR_PROGRAM_MASK

#define FLASH_CR_PROGRAM_MASK   0x3

Definition at line 107 of file flash_common_f24.h.

◆ FLASH_CR_PROGRAM_SHIFT

#define FLASH_CR_PROGRAM_SHIFT   8

Definition at line 108 of file flash_common_f24.h.

◆ FLASH_CR_SER

#define FLASH_CR_SER   (1 << 1)

Definition at line 103 of file flash_common_f24.h.

◆ FLASH_CR_SNB_MASK

#define FLASH_CR_SNB_MASK   0x1f

Definition at line 106 of file flash_common_f24.h.

◆ FLASH_CR_SNB_SHIFT

#define FLASH_CR_SNB_SHIFT   3

Definition at line 105 of file flash_common_f24.h.

◆ FLASH_CR_STRT

#define FLASH_CR_STRT   (1 << 16)

Definition at line 101 of file flash_common_f24.h.

◆ FLASH_KEYR_KEY1

#define FLASH_KEYR_KEY1   ((uint32_t)0x45670123)

Definition at line 138 of file flash_common_f24.h.

◆ FLASH_KEYR_KEY2

#define FLASH_KEYR_KEY2   ((uint32_t)0xcdef89ab)

Definition at line 139 of file flash_common_f24.h.

◆ FLASH_OPTCR_BOR_LEVEL_1

#define FLASH_OPTCR_BOR_LEVEL_1   (0x02 << 2)

Definition at line 129 of file flash_common_f24.h.

◆ FLASH_OPTCR_BOR_LEVEL_2

#define FLASH_OPTCR_BOR_LEVEL_2   (0x01 << 2)

Definition at line 128 of file flash_common_f24.h.

◆ FLASH_OPTCR_BOR_LEVEL_3

#define FLASH_OPTCR_BOR_LEVEL_3   (0x00 << 2)

Definition at line 127 of file flash_common_f24.h.

◆ FLASH_OPTCR_BOR_OFF

#define FLASH_OPTCR_BOR_OFF   (0x03 << 2)

Definition at line 130 of file flash_common_f24.h.

◆ FLASH_OPTCR_NRST_STDBY

#define FLASH_OPTCR_NRST_STDBY   (1 << 7)

Definition at line 123 of file flash_common_f24.h.

◆ FLASH_OPTCR_NRST_STOP

#define FLASH_OPTCR_NRST_STOP   (1 << 6)

Definition at line 124 of file flash_common_f24.h.

◆ FLASH_OPTCR_OPTLOCK

#define FLASH_OPTCR_OPTLOCK   (1 << 0)

Definition at line 126 of file flash_common_f24.h.

◆ FLASH_OPTCR_OPTSTRT

#define FLASH_OPTCR_OPTSTRT   (1 << 1)

Definition at line 125 of file flash_common_f24.h.

◆ FLASH_OPTKEYR_KEY1

#define FLASH_OPTKEYR_KEY1   ((uint32_t)0x08192a3b)

Definition at line 141 of file flash_common_f24.h.

◆ FLASH_OPTKEYR_KEY2

#define FLASH_OPTKEYR_KEY2   ((uint32_t)0x4c5d6e7f)

Definition at line 142 of file flash_common_f24.h.

◆ FLASH_SR_BSY

#define FLASH_SR_BSY   (1 << 16)

Definition at line 89 of file flash_common_f24.h.

◆ FLASH_SR_EOP

#define FLASH_SR_EOP   (1 << 0)

Definition at line 94 of file flash_common_f24.h.

◆ FLASH_SR_OPERR

#define FLASH_SR_OPERR   (1 << 1)

Definition at line 93 of file flash_common_f24.h.

◆ FLASH_SR_PGAERR

#define FLASH_SR_PGAERR   (1 << 5)

Definition at line 91 of file flash_common_f24.h.

◆ FLASH_SR_PGPERR

#define FLASH_SR_PGPERR   (1 << 6)

Definition at line 90 of file flash_common_f24.h.

◆ FLASH_SR_WRPERR

#define FLASH_SR_WRPERR   (1 << 4)

Definition at line 92 of file flash_common_f24.h.

Function Documentation

◆ flash_clear_pgaerr_flag()

void flash_clear_pgaerr_flag ( void  )

Clear the Programming Alignment Error Flag.

Definition at line 49 of file flash_common_f24.c.

References FLASH_SR, and FLASH_SR_PGAERR.

Referenced by flash_clear_status_flags().

Here is the caller graph for this function:

◆ flash_clear_pgperr_flag()

void flash_clear_pgperr_flag ( void  )

Clear programming parallelism error flag.

Definition at line 56 of file flash_common_f24.c.

References FLASH_SR, and FLASH_SR_PGPERR.

Referenced by flash_clear_status_flags().

Here is the caller graph for this function:

◆ flash_clear_wrperr_flag()

void flash_clear_wrperr_flag ( void  )

Clear the Write Protect Error Flag.

Definition at line 66 of file flash_common_f24.c.

References FLASH_SR, and FLASH_SR_WRPERR.

Referenced by flash_clear_status_flags().

Here is the caller graph for this function:

◆ flash_dcache_disable()

void flash_dcache_disable ( void  )

Disable the data cache.

Definition at line 32 of file flash_common_idcache.c.

References FLASH_ACR.

◆ flash_dcache_enable()

void flash_dcache_enable ( void  )

Enable the data cache.

Definition at line 27 of file flash_common_idcache.c.

References FLASH_ACR, and FLASH_ACR_DCEN.

◆ flash_dcache_reset()

void flash_dcache_reset ( void  )

Reset the Data Cache.

The data cache must be disabled for this to have effect.

Definition at line 48 of file flash_common_idcache.c.

References FLASH_ACR, and FLASH_ACR_DCRST.

◆ flash_erase_all_sectors()

void flash_erase_all_sectors ( uint32_t  program_size)

Erase All FLASH.

This performs all operations necessary to erase all sectors in the FLASH memory.

Parameters
program_size0 (8-bit), 1 (16-bit), 2 (32-bit), 3 (64-bit)

Definition at line 258 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_MER, FLASH_CR_STRT, flash_set_program_size(), and flash_wait_for_last_operation().

Here is the call graph for this function:

◆ flash_erase_sector()

void flash_erase_sector ( uint8_t  sector,
uint32_t  program_size 
)

Erase a Sector of FLASH.

This performs all operations necessary to erase a sector in FLASH memory. The page should be checked to ensure that it was properly erased. A sector must first be fully erased before attempting to program it.

See the reference manual or the FLASH programming manual for details.

Parameters
[in]sector(0 - 11 for some parts, 0-23 on others)
program_size0 (8-bit), 1 (16-bit), 2 (32-bit), 3 (64-bit)

Definition at line 229 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_SER, FLASH_CR_SNB_MASK, FLASH_CR_SNB_SHIFT, FLASH_CR_STRT, flash_set_program_size(), and flash_wait_for_last_operation().

Here is the call graph for this function:

◆ flash_icache_disable()

void flash_icache_disable ( void  )

Disable the Instruction Cache.

Definition at line 42 of file flash_common_idcache.c.

References FLASH_ACR.

◆ flash_icache_enable()

void flash_icache_enable ( void  )

Enable the Instruction Cache.

Definition at line 37 of file flash_common_idcache.c.

References FLASH_ACR, and FLASH_ACR_ICEN.

◆ flash_icache_reset()

void flash_icache_reset ( void  )

Reset the Instruction Cache.

The instruction cache must be disabled for this to have effect.

Definition at line 53 of file flash_common_idcache.c.

References FLASH_ACR, and FLASH_ACR_ICRST.

◆ flash_lock_option_bytes()

void flash_lock_option_bytes ( void  )

Lock the Option Byte Access.

This disables write access to the option bytes. It is locked by default on reset.

Definition at line 78 of file flash_common_f24.c.

References FLASH_OPTCR, and FLASH_OPTCR_OPTLOCK.

◆ flash_program()

void flash_program ( uint32_t  address,
const uint8_t *  data,
uint32_t  len 
)

Program a Data Block to FLASH.

This programs an arbitrary length data block to FLASH memory. The program error flag should be checked separately for the event that memory was not properly erased.

Parameters
[in]addressStarting address in Flash.
[in]dataPointer to start of data block.
[in]lenLength of data block.

Definition at line 205 of file flash_common_f24.c.

References flash_program_byte().

Here is the call graph for this function:

◆ flash_program_byte()

void flash_program_byte ( uint32_t  address,
uint8_t  data 
)

Program an 8 bit Byte to FLASH.

This performs all operations necessary to program an 8 bit byte to FLASH memory. The program error flag should be checked separately for the event that memory was not properly erased.

Parameters
[in]addressStarting address in Flash.
[in]databyte to write

Definition at line 179 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_PG, FLASH_CR_PROGRAM_X8, flash_set_program_size(), flash_wait_for_last_operation(), and MMIO8.

Referenced by flash_program().

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

◆ flash_program_double_word()

void flash_program_double_word ( uint32_t  address,
uint64_t  data 
)

Program a 64 bit Word to FLASH.

This performs all operations necessary to program a 64 bit word to FLASH memory. The program error flag should be checked separately for the event that memory was not properly erased.

Parameters
[in]addressStarting address in Flash.
[in]dataDouble word to write

Definition at line 94 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_PG, FLASH_CR_PROGRAM_X64, flash_set_program_size(), flash_wait_for_last_operation(), and MMIO64.

Here is the call graph for this function:

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

Parameters
[in]addressStarting address in Flash.
[in]datahalf word to write

Definition at line 154 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_PG, FLASH_CR_PROGRAM_X16, flash_set_program_size(), flash_wait_for_last_operation(), and MMIO16.

Here is the call graph for this function:

◆ flash_program_option_bytes()

void flash_program_option_bytes ( uint32_t  data)

Program the Option Bytes.

This performs all operations necessary to program the option bytes. The option bytes do not need to be erased first.

Parameters
[in]datavalue to be programmed.

Definition at line 279 of file flash_common_f24.c.

References FLASH_OPTCR, FLASH_OPTCR_OPTLOCK, FLASH_OPTCR_OPTSTRT, flash_unlock_option_bytes(), and flash_wait_for_last_operation().

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.

Parameters
[in]addressStarting address in Flash.
[in]dataword to write

Definition at line 124 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_PG, FLASH_CR_PROGRAM_X32, flash_set_program_size(), flash_wait_for_last_operation(), and MMIO32.

Here is the call graph for this function: