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

Defined Constants and Types for the STM32L0xx Flash memory More...

Collaboration diagram for FLASH Defines:

Modules

 FLASH Wait States
 

Macros

#define FLASH_OPTR   FLASH_OBR
 
#define FLASH_WRPROT1   FLASH_WRPR1
 
#define FLASH_WRPROT2   FLASH_WRPR2
 
#define FLASH_ACR_PRE_READ   (1 << 6)
 
#define FLASH_ACR_DISAB_BUF   (1 << 5)
 
#define FLASH_PECR_NZDISABLE   (1 << 23)
 
#define FLASH_SR_RDERR   (1 << 13)
 
#define FLASH_SR_NOTZEROERR   (1 << 16)
 
#define FLASH_SR_FWWERR   (1 << 17)
 
#define FLASH_OPTR_NBOOT1   (1 << 31)
 
#define FLASH_HALF_PAGE_SIZE   16
 
#define FLASH_ACR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)
 
#define FLASH_PECR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)
 
#define FLASH_PDKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)
 
#define FLASH_PEKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)
 
#define FLASH_PRGKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)
 
#define FLASH_OPTKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)
 
#define FLASH_SR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x18)
 
#define FLASH_OBR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1c)
 
#define FLASH_WRPR1   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)
 
#define FLASH_WRPR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x80)
 
#define FLASH_ACR_RUNPD   (1 << 4)
 
#define FLASH_ACR_SLEEPPD   (1 << 3)
 
#define FLASH_ACR_PRFTEN   (1 << 1)
 
#define FLASH_ACR_LATENCY_SHIFT   0
 
#define FLASH_ACR_LATENCY_MASK   1
 
#define FLASH_PECR_OBL_LAUNCH   (1 << 18)
 
#define FLASH_PECR_ERRIE   (1 << 17)
 
#define FLASH_PECR_EOPIE   (1 << 16)
 
#define FLASH_PECR_PARALLBANK   (1 << 15)
 
#define FLASH_PECR_FPRG   (1 << 10)
 
#define FLASH_PECR_ERASE   (1 << 9)
 
#define FLASH_PECR_FTDW   (1 << 8)
 
#define FLASH_PECR_DATA   (1 << 4)
 
#define FLASH_PECR_PROG   (1 << 3)
 
#define FLASH_PECR_OPTLOCK   (1 << 2)
 
#define FLASH_PECR_PRGLOCK   (1 << 1)
 
#define FLASH_PECR_PELOCK   (1 << 0)
 
#define FLASH_PDKEYR_PDKEY1   ((uint32_t)0x04152637)
 
#define FLASH_PDKEYR_PDKEY2   ((uint32_t)0xFAFBFCFD)
 
#define FLASH_PEKEYR_PEKEY1   ((uint32_t)0x89ABCDEF)
 
#define FLASH_PEKEYR_PEKEY2   ((uint32_t)0x02030405)
 
#define FLASH_PRGKEYR_PRGKEY1   ((uint32_t)0x8C9DAEBF)
 
#define FLASH_PRGKEYR_PRGKEY2   ((uint32_t)0x13141516)
 
#define FLASH_OPTKEYR_KEY1   ((uint32_t)0xFBEAD9C8)
 
#define FLASH_OPTKEYR_KEY2   ((uint32_t)0x24252627)
 
#define FLASH_SR_OPTVERR   (1 << 11)
 
#define FLASH_SR_SIZEERR   (1 << 10)
 
#define FLASH_SR_PGAERR   (1 << 9)
 
#define FLASH_SR_WRPERR   (1 << 8)
 
#define FLASH_SR_READY   (1 << 3)
 
#define FLASH_SR_ENDHV   (1 << 2)
 
#define FLASH_SR_EOP   (1 << 1)
 
#define FLASH_SR_BSY   (1 << 0)
 
#define FLASH_OBR_BFB2   (1 << 23)
 
#define FLASH_OBR_NRST_STDBY   (1 << 22)
 
#define FLASH_OBR_NRST_STOP   (1 << 21)
 
#define FLASH_OBR_IWDG_SW   (1 << 20)
 
#define FLASH_OBR_BOR_OFF   (0x0 << 16)
 
#define FLASH_OBR_BOR_LEVEL_1   (0x8 << 16)
 
#define FLASH_OBR_BOR_LEVEL_2   (0x9 << 16)
 
#define FLASH_OBR_BOR_LEVEL_3   (0xa << 16)
 
#define FLASH_OBR_BOR_LEVEL_4   (0xb << 16)
 
#define FLASH_OBR_BOR_LEVEL_5   (0xc << 16)
 
#define FLASH_OBR_RDPRT_LEVEL_0   (0xaa)
 
#define FLASH_OBR_RDPRT_LEVEL_1   (0x00)
 
#define FLASH_OBR_RDPRT_LEVEL_2   (0xcc)
 

Functions

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

Detailed Description

Defined Constants and Types for the STM32L0xx Flash memory

Version
1.0.0

LGPL License Terms libopencm3 License

Macro Definition Documentation

◆ FLASH_ACR

#define FLASH_ACR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x00)

Definition at line 36 of file flash_common_l01.h.

◆ FLASH_ACR_DISAB_BUF

#define FLASH_ACR_DISAB_BUF   (1 << 5)

Definition at line 45 of file l0/flash.h.

◆ FLASH_ACR_LATENCY_MASK

#define FLASH_ACR_LATENCY_MASK   1

Definition at line 52 of file flash_common_l01.h.

◆ FLASH_ACR_LATENCY_SHIFT

#define FLASH_ACR_LATENCY_SHIFT   0

Definition at line 51 of file flash_common_l01.h.

◆ FLASH_ACR_PRE_READ

#define FLASH_ACR_PRE_READ   (1 << 6)

Definition at line 44 of file l0/flash.h.

◆ FLASH_ACR_PRFTEN

#define FLASH_ACR_PRFTEN   (1 << 1)

Definition at line 50 of file flash_common_l01.h.

◆ FLASH_ACR_RUNPD

#define FLASH_ACR_RUNPD   (1 << 4)

Definition at line 48 of file flash_common_l01.h.

◆ FLASH_ACR_SLEEPPD

#define FLASH_ACR_SLEEPPD   (1 << 3)

Definition at line 49 of file flash_common_l01.h.

◆ FLASH_HALF_PAGE_SIZE

#define FLASH_HALF_PAGE_SIZE   16

Definition at line 58 of file l0/flash.h.

◆ FLASH_OBR

#define FLASH_OBR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x1c)

Definition at line 43 of file flash_common_l01.h.

◆ FLASH_OBR_BFB2

#define FLASH_OBR_BFB2   (1 << 23)

Definition at line 101 of file flash_common_l01.h.

◆ FLASH_OBR_BOR_LEVEL_1

#define FLASH_OBR_BOR_LEVEL_1   (0x8 << 16)

Definition at line 106 of file flash_common_l01.h.

◆ FLASH_OBR_BOR_LEVEL_2

#define FLASH_OBR_BOR_LEVEL_2   (0x9 << 16)

Definition at line 107 of file flash_common_l01.h.

◆ FLASH_OBR_BOR_LEVEL_3

#define FLASH_OBR_BOR_LEVEL_3   (0xa << 16)

Definition at line 108 of file flash_common_l01.h.

◆ FLASH_OBR_BOR_LEVEL_4

#define FLASH_OBR_BOR_LEVEL_4   (0xb << 16)

Definition at line 109 of file flash_common_l01.h.

◆ FLASH_OBR_BOR_LEVEL_5

#define FLASH_OBR_BOR_LEVEL_5   (0xc << 16)

Definition at line 110 of file flash_common_l01.h.

◆ FLASH_OBR_BOR_OFF

#define FLASH_OBR_BOR_OFF   (0x0 << 16)

Definition at line 105 of file flash_common_l01.h.

◆ FLASH_OBR_IWDG_SW

#define FLASH_OBR_IWDG_SW   (1 << 20)

Definition at line 104 of file flash_common_l01.h.

◆ FLASH_OBR_NRST_STDBY

#define FLASH_OBR_NRST_STDBY   (1 << 22)

Definition at line 102 of file flash_common_l01.h.

◆ FLASH_OBR_NRST_STOP

#define FLASH_OBR_NRST_STOP   (1 << 21)

Definition at line 103 of file flash_common_l01.h.

◆ FLASH_OBR_RDPRT_LEVEL_0

#define FLASH_OBR_RDPRT_LEVEL_0   (0xaa)

Definition at line 111 of file flash_common_l01.h.

◆ FLASH_OBR_RDPRT_LEVEL_1

#define FLASH_OBR_RDPRT_LEVEL_1   (0x00)

Definition at line 112 of file flash_common_l01.h.

◆ FLASH_OBR_RDPRT_LEVEL_2

#define FLASH_OBR_RDPRT_LEVEL_2   (0xcc)

Definition at line 113 of file flash_common_l01.h.

◆ FLASH_OPTKEYR

#define FLASH_OPTKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x14)

Definition at line 41 of file flash_common_l01.h.

◆ FLASH_OPTKEYR_KEY1

#define FLASH_OPTKEYR_KEY1   ((uint32_t)0xFBEAD9C8)

Definition at line 87 of file flash_common_l01.h.

◆ FLASH_OPTKEYR_KEY2

#define FLASH_OPTKEYR_KEY2   ((uint32_t)0x24252627)

Definition at line 88 of file flash_common_l01.h.

◆ FLASH_OPTR

#define FLASH_OPTR   FLASH_OBR

Definition at line 39 of file l0/flash.h.

◆ FLASH_OPTR_NBOOT1

#define FLASH_OPTR_NBOOT1   (1 << 31)

Definition at line 56 of file l0/flash.h.

◆ FLASH_PDKEYR

#define FLASH_PDKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x08)

Definition at line 38 of file flash_common_l01.h.

◆ FLASH_PDKEYR_PDKEY1

#define FLASH_PDKEYR_PDKEY1   ((uint32_t)0x04152637)

Definition at line 75 of file flash_common_l01.h.

◆ FLASH_PDKEYR_PDKEY2

#define FLASH_PDKEYR_PDKEY2   ((uint32_t)0xFAFBFCFD)

Definition at line 76 of file flash_common_l01.h.

◆ FLASH_PECR

#define FLASH_PECR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x04)

Definition at line 37 of file flash_common_l01.h.

◆ FLASH_PECR_DATA

#define FLASH_PECR_DATA   (1 << 4)

Definition at line 68 of file flash_common_l01.h.

◆ FLASH_PECR_EOPIE

#define FLASH_PECR_EOPIE   (1 << 16)

Definition at line 63 of file flash_common_l01.h.

◆ FLASH_PECR_ERASE

#define FLASH_PECR_ERASE   (1 << 9)

Definition at line 66 of file flash_common_l01.h.

◆ FLASH_PECR_ERRIE

#define FLASH_PECR_ERRIE   (1 << 17)

Definition at line 62 of file flash_common_l01.h.

◆ FLASH_PECR_FPRG

#define FLASH_PECR_FPRG   (1 << 10)

Definition at line 65 of file flash_common_l01.h.

◆ FLASH_PECR_FTDW

#define FLASH_PECR_FTDW   (1 << 8)

Definition at line 67 of file flash_common_l01.h.

◆ FLASH_PECR_NZDISABLE

#define FLASH_PECR_NZDISABLE   (1 << 23)

Definition at line 48 of file l0/flash.h.

◆ FLASH_PECR_OBL_LAUNCH

#define FLASH_PECR_OBL_LAUNCH   (1 << 18)

Definition at line 61 of file flash_common_l01.h.

◆ FLASH_PECR_OPTLOCK

#define FLASH_PECR_OPTLOCK   (1 << 2)

Definition at line 70 of file flash_common_l01.h.

◆ FLASH_PECR_PARALLBANK

#define FLASH_PECR_PARALLBANK   (1 << 15)

Definition at line 64 of file flash_common_l01.h.

◆ FLASH_PECR_PELOCK

#define FLASH_PECR_PELOCK   (1 << 0)

Definition at line 72 of file flash_common_l01.h.

◆ FLASH_PECR_PRGLOCK

#define FLASH_PECR_PRGLOCK   (1 << 1)

Definition at line 71 of file flash_common_l01.h.

◆ FLASH_PECR_PROG

#define FLASH_PECR_PROG   (1 << 3)

Definition at line 69 of file flash_common_l01.h.

◆ FLASH_PEKEYR

#define FLASH_PEKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x0C)

Definition at line 39 of file flash_common_l01.h.

◆ FLASH_PEKEYR_PEKEY1

#define FLASH_PEKEYR_PEKEY1   ((uint32_t)0x89ABCDEF)

Definition at line 79 of file flash_common_l01.h.

◆ FLASH_PEKEYR_PEKEY2

#define FLASH_PEKEYR_PEKEY2   ((uint32_t)0x02030405)

Definition at line 80 of file flash_common_l01.h.

◆ FLASH_PRGKEYR

#define FLASH_PRGKEYR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x10)

Definition at line 40 of file flash_common_l01.h.

◆ FLASH_PRGKEYR_PRGKEY1

#define FLASH_PRGKEYR_PRGKEY1   ((uint32_t)0x8C9DAEBF)

Definition at line 83 of file flash_common_l01.h.

◆ FLASH_PRGKEYR_PRGKEY2

#define FLASH_PRGKEYR_PRGKEY2   ((uint32_t)0x13141516)

Definition at line 84 of file flash_common_l01.h.

◆ FLASH_SR

#define FLASH_SR   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x18)

Definition at line 42 of file flash_common_l01.h.

◆ FLASH_SR_BSY

#define FLASH_SR_BSY   (1 << 0)

Definition at line 98 of file flash_common_l01.h.

◆ FLASH_SR_ENDHV

#define FLASH_SR_ENDHV   (1 << 2)

Definition at line 96 of file flash_common_l01.h.

◆ FLASH_SR_EOP

#define FLASH_SR_EOP   (1 << 1)

Definition at line 97 of file flash_common_l01.h.

◆ FLASH_SR_FWWERR

#define FLASH_SR_FWWERR   (1 << 17)

Definition at line 53 of file l0/flash.h.

◆ FLASH_SR_NOTZEROERR

#define FLASH_SR_NOTZEROERR   (1 << 16)

Definition at line 52 of file l0/flash.h.

◆ FLASH_SR_OPTVERR

#define FLASH_SR_OPTVERR   (1 << 11)

Definition at line 91 of file flash_common_l01.h.

◆ FLASH_SR_PGAERR

#define FLASH_SR_PGAERR   (1 << 9)

Definition at line 93 of file flash_common_l01.h.

◆ FLASH_SR_RDERR

#define FLASH_SR_RDERR   (1 << 13)

Definition at line 51 of file l0/flash.h.

◆ FLASH_SR_READY

#define FLASH_SR_READY   (1 << 3)

Definition at line 95 of file flash_common_l01.h.

◆ FLASH_SR_SIZEERR

#define FLASH_SR_SIZEERR   (1 << 10)

Definition at line 92 of file flash_common_l01.h.

◆ FLASH_SR_WRPERR

#define FLASH_SR_WRPERR   (1 << 8)

Definition at line 94 of file flash_common_l01.h.

◆ FLASH_WRPR1

#define FLASH_WRPR1   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x20)

Definition at line 44 of file flash_common_l01.h.

◆ FLASH_WRPR2

#define FLASH_WRPR2   MMIO32(FLASH_MEM_INTERFACE_BASE + 0x80)

Definition at line 45 of file flash_common_l01.h.

◆ FLASH_WRPROT1

#define FLASH_WRPROT1   FLASH_WRPR1

Definition at line 40 of file l0/flash.h.

◆ FLASH_WRPROT2

#define FLASH_WRPROT2   FLASH_WRPR2

Definition at line 41 of file l0/flash.h.

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