libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
FLASH peripheral API
Collaboration diagram for FLASH peripheral API:

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...
 
static void flash_set_program_size (uint32_t psize)
 Set the Program Parallelism Size. More...
 
void flash_clear_pgaerr_flag (void)
 Clear the Programming Alignment Error Flag. 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_lock_option_bytes (void)
 Lock the Option Byte Access. 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_erase_sector (uint8_t sector, uint32_t program_size)
 Erase a Sector of FLASH. More...
 
void flash_erase_all_sectors (uint32_t program_size)
 Erase All FLASH. More...
 
void flash_program_option_bytes (uint32_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...
 
static void flash_pipeline_stall (void)
 Issue Pipeline Stall. More...
 
void flash_wait_for_last_operation (void)
 Wait until Last Operation has Ended. More...
 
void flash_clear_erserr_flag (void)
 Clear the Erase Sequence Error Flag. More...
 
void flash_clear_status_flags (void)
 Clear All Status Flags. More...
 
void flash_art_enable (void)
 Enable the ART Cache. More...
 
void flash_art_reset (void)
 Reset the ART Cache. More...
 

Detailed Description

Function Documentation

◆ flash_art_enable()

void flash_art_enable ( void  )

Enable the ART Cache.

Definition at line 90 of file flash.c.

References FLASH_ACR, and FLASH_ACR_ARTEN.

Referenced by rcc_clock_setup_hse(), and rcc_clock_setup_hsi().

Here is the caller graph for this function:

◆ flash_art_reset()

void flash_art_reset ( void  )

Reset the ART Cache.

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

Definition at line 101 of file flash.c.

References FLASH_ACR, and FLASH_ACR_ARTRST.

◆ flash_clear_eop_flag()

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

Here is the caller graph for this function:

◆ flash_clear_erserr_flag()

void flash_clear_erserr_flag ( void  )

Clear the Erase Sequence Error Flag.

This flag is set when an erase operation is performed with control register has not been correctly set.

Definition at line 65 of file flash.c.

References FLASH_SR, and FLASH_SR_ERSERR.

Referenced by flash_clear_status_flags().

Here is the caller graph for this function:

◆ 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_status_flags()

void flash_clear_status_flags ( void  )

Clear All Status Flags.

Clear all status flags.

Program error, end of operation, write protect error.

Definition at line 76 of file flash.c.

References flash_clear_eop_flag(), flash_clear_erserr_flag(), flash_clear_pgaerr_flag(), flash_clear_pgperr_flag(), and flash_clear_wrperr_flag().

Here is the call 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_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_lock()

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.

◆ 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_pipeline_stall()

static void flash_pipeline_stall ( void  )
inlinestatic

Issue Pipeline Stall.

Issue a pipeline stall to make sure all write operations completed.

RM0385: After performing a data write operation and before polling the BSY bit to be cleared, the software can issue a DSB instruction to guarantee the completion of a previous data write operation.

Definition at line 42 of file flash.c.

Referenced by flash_wait_for_last_operation().

Here is the caller graph for this function:

◆ flash_prefetch_disable()

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.

◆ flash_prefetch_enable()

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.

Referenced by rcc_clock_setup_hse(), and rcc_clock_setup_hsi().

Here is the caller graph for this function:

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

◆ flash_set_program_size()

static void flash_set_program_size ( uint32_t  psize)
inlinestatic

Set the Program Parallelism Size.

Set the programming word width. Note carefully the power supply voltage restrictions under which the different word sizes may be used. See the programming manual for more information.

Parameters
[in]psizeThe programming word width one of: Flash programming width

Definition at line 38 of file flash_common_f24.c.

References FLASH_CR, FLASH_CR_PROGRAM_MASK, and FLASH_CR_PROGRAM_SHIFT.

Referenced by flash_erase_all_sectors(), flash_erase_sector(), flash_program_byte(), flash_program_double_word(), flash_program_half_word(), and flash_program_word().

Here is the caller graph for this function:

◆ flash_set_ws()

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.

Parameters
[in]wsvalues 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_hse(), and rcc_clock_setup_hsi().

Here is the caller graph for this function:

◆ flash_unlock()

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.

◆ flash_unlock_option_bytes()

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

Here is the caller graph for this function:

◆ flash_wait_for_last_operation()

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 53 of file flash.c.

References flash_pipeline_stall(), FLASH_SR, and FLASH_SR_BSY.

Referenced by flash_erase_all_sectors(), flash_erase_sector(), flash_program_byte(), flash_program_double_word(), flash_program_half_word(), flash_program_option_bytes(), and flash_program_word().

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