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

libopencm3 STM32L1xx FLASH More...

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...
 
void flash_unlock_pecr (void)
 Unlock primary access to the flash control/erase block You must call this before using any of the low level routines yourself. More...
 
void flash_lock_pecr (void)
 
void flash_unlock_progmem (void)
 Unlock program memory itself. More...
 
void flash_lock_progmem (void)
 
void flash_lock_option_bytes (void)
 
void flash_unlock (void)
 Unlock all segments of flash. More...
 
void flash_lock (void)
 Lock all segments of flash. More...
 
void flash_unlock_acr (void)
 Unlock RUN_PD bit from FLASH_ACR register. More...
 
void flash_erase_page (uint32_t page_address)
 Erase a page in flash. More...
 
void flash_program_half_page (uint32_t *dst, void *buf)
 Write a half page from buf to dst. More...
 
void eeprom_program_word (uint32_t address, uint32_t data)
 Write a word to eeprom. More...
 
void eeprom_program_words (uint32_t address, uint32_t *data, int length_in_words)
 Write a block of words to eeprom. More...
 
void flash_64bit_enable (void)
 Enable 64 Bit Programming Mode. More...
 
void flash_64bit_disable (void)
 Enable 32 Bit Programming Mode. More...
 

Detailed Description

libopencm3 STM32L1xx FLASH

Version
1.0.0
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
© 2012 Karl Palsson karlp.nosp@m.@twe.nosp@m.ak.ne.nosp@m.t.au
Date
14 January 2014

For the STM32L1xx, accessing FLASH memory is described briefly in section 2.3.3 of the STM32L1xx Reference Manual. For detailed programming information see: PM0062 programming manual: STM32L1xxxx Flash and EEPROM programming March 2012, Doc ID 16024 Rev 5

LGPL License Terms libopencm3 License

Function Documentation

◆ eeprom_program_word()

void eeprom_program_word ( uint32_t  address,
uint32_t  data 
)

Write a word to eeprom.

Parameters
addressassumed to be in the eeprom space, no checking
dataword to write

Definition at line 131 of file flash_common_l01.c.

References flash_lock_pecr(), FLASH_PECR, flash_unlock_pecr(), and MMIO32.

Here is the call graph for this function:

◆ eeprom_program_words()

void eeprom_program_words ( uint32_t  address,
uint32_t *  data,
int  length_in_words 
)

Write a block of words to eeprom.

Writes a block of words to EEPROM at the requested address, erasing if necessary, and locking afterwards. Only wordwise writing is safe for writing any value

Parameters
[in]addressmust point to EEPROM space, no checking!
[in]datapointer to data to write
[in]length_in_wordssize of of data in WORDS!

Definition at line 150 of file flash_common_l01.c.

References flash_lock_pecr(), FLASH_PECR, FLASH_SR, FLASH_SR_BSY, flash_unlock_pecr(), and MMIO32.

Here is the call graph for this function:

◆ flash_64bit_disable()

void flash_64bit_disable ( void  )

Enable 32 Bit Programming Mode.

This mode is a low power mode. It must be used at low frequencies and does not allow prefetch or wait states to be used.

Definition at line 69 of file flash.c.

References FLASH_ACR.

◆ flash_64bit_enable()

void flash_64bit_enable ( void  )

Enable 64 Bit Programming Mode.

Definition at line 57 of file flash.c.

References FLASH_ACR, and FLASH_ACR_ACC64.

Referenced by rcc_clock_setup_hsi(), rcc_clock_setup_msi(), and rcc_clock_setup_pll().

Here is the caller graph for this function:

◆ flash_erase_page()

void flash_erase_page ( uint32_t  page_address)

Erase a page in flash.

Parameters
page_addressFor L1, must be first word in page, L0 doesn't care Takes 1 tprog. Flash must already be unlocked!

Definition at line 100 of file flash_common_l01.c.

References FLASH_PECR, FLASH_PECR_ERASE, FLASH_PECR_PROG, FLASH_SR, FLASH_SR_BSY, and MMIO32.

◆ flash_lock()

void flash_lock ( void  )

Lock all segments of flash.

Lock the Flash Program and Erase Controller Used to prevent spurious writes to FLASH.

Definition at line 85 of file flash_common_l01.c.

References flash_lock_option_bytes(), flash_lock_pecr(), and flash_lock_progmem().

Here is the call graph for this function:

◆ flash_lock_option_bytes()

void flash_lock_option_bytes ( void  )

Definition at line 67 of file flash_common_l01.c.

References FLASH_PECR, and FLASH_PECR_OPTLOCK.

Referenced by flash_lock().

Here is the caller graph for this function:

◆ flash_lock_pecr()

void flash_lock_pecr ( void  )

Definition at line 45 of file flash_common_l01.c.

References FLASH_PECR, and FLASH_PECR_PELOCK.

Referenced by eeprom_program_word(), eeprom_program_words(), and flash_lock().

Here is the caller graph for this function:

◆ flash_lock_progmem()

void flash_lock_progmem ( void  )

Definition at line 62 of file flash_common_l01.c.

References FLASH_PECR, and FLASH_PECR_PRGLOCK.

Referenced by flash_lock().

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_hsi(), rcc_clock_setup_msi(), and rcc_clock_setup_pll().

Here is the caller graph for this function:

◆ flash_program_half_page()

void flash_program_half_page ( uint32_t *  dst,
void *  buf 
)

Write a half page from buf to dst.

This function must be in ram! (See the Ref Man for more details)

Parameters
dstwhere to write to, expected to be aligned and erased.
bufthe half page to write, size required depends on target

Definition at line 111 of file flash_common_l01.c.

References FLASH_HALF_PAGE_SIZE, FLASH_PECR, FLASH_PECR_FPRG, FLASH_PECR_PROG, FLASH_SR, and FLASH_SR_BSY.

◆ 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_hsi(), rcc_clock_setup_msi(), and rcc_clock_setup_pll().

Here is the caller graph for this function:

◆ flash_unlock()

void flash_unlock ( void  )

Unlock all segments of flash.

Unlock the Flash Program and Erase Controller This enables write access to the Flash memory.

Definition at line 75 of file flash_common_l01.c.

References flash_unlock_option_bytes(), flash_unlock_pecr(), and flash_unlock_progmem().

Here is the call graph for this function:

◆ flash_unlock_acr()

void flash_unlock_acr ( void  )

Unlock RUN_PD bit from FLASH_ACR register.

Definition at line 94 of file flash_common_l01.c.

References FLASH_PDKEYR, FLASH_PDKEYR_PDKEY1, and FLASH_PDKEYR_PDKEY2.

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

Here is the caller graph for this function:

◆ flash_unlock_pecr()

void flash_unlock_pecr ( void  )

Unlock primary access to the flash control/erase block You must call this before using any of the low level routines yourself.

See also
flash_unlock

Definition at line 39 of file flash_common_l01.c.

References FLASH_PEKEYR, FLASH_PEKEYR_PEKEY1, and FLASH_PEKEYR_PEKEY2.

Referenced by eeprom_program_word(), eeprom_program_words(), and flash_unlock().

Here is the caller graph for this function:

◆ flash_unlock_progmem()

void flash_unlock_progmem ( void  )

Unlock program memory itself.

Writes the magic sequence to unlock the program memory you must have already unlocked access to this register!

See also
flash_unlock_pecr

Definition at line 56 of file flash_common_l01.c.

References FLASH_PRGKEYR, FLASH_PRGKEYR_PRGKEY1, and FLASH_PRGKEYR_PRGKEY2.

Referenced by flash_unlock().

Here is the caller graph for this function: