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

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

Collaboration diagram for FLASH Defines:

Modules

 FLASH Wait States
 

Macros

#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_OBL_LAUNCH   (1 << 13)
 
#define FLASH_OBR_DATA1_SHIFT   24
 
#define FLASH_OBR_DATA1   (0xFF << FLASH_OBR_DATA1_SHIFT)
 
#define FLASH_OBR_DATA0_SHIFT   16
 
#define FLASH_OBR_DATA0   (0xFF << FLASH_OBR_DATA0_SHIFT)
 
#define FLASH_OBR_USER_SHIFT   8
 
#define FLASH_OBR_USER   (0xFF << FLASH_OBR_USER_SHIFT)
 
#define FLASH_OBR_RDPRT   (3 << FLASH_OBR_RDPRT_SHIFT)
 
#define FLASH_OBR_RDPRT_L0   (0 << FLASH_OBR_RDPRT_SHIFT)
 
#define FLASH_OBR_RDPRT_L1   (1 << FLASH_OBR_RDPRT_SHIFT)
 
#define FLASH_OBR_RDPRT_L2   (3 << FLASH_OBR_RDPRT_SHIFT)
 
#define FLASH_RDP_L0   ((uint8_t)0xa5)
 
#define FLASH_RDP_L1   ((uint8_t)0xf0) /* any value */
 
#define FLASH_RDP_L2   ((uint8_t)0xcc)
 
#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_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 GD32F1x0 Flash memory

Version
1.0.0
Author
© 2013 Frantisek Burian BuFra.nosp@m.n@se.nosp@m.znam..nosp@m.cz
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_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_OBL_LAUNCH

#define FLASH_CR_OBL_LAUNCH   (1 << 13)

Definition at line 69 of file gd32/f1x0/flash.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_DATA0

#define FLASH_OBR_DATA0   (0xFF << FLASH_OBR_DATA0_SHIFT)

Definition at line 76 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_DATA0_SHIFT

#define FLASH_OBR_DATA0_SHIFT   16

Definition at line 75 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_DATA1

#define FLASH_OBR_DATA1   (0xFF << FLASH_OBR_DATA1_SHIFT)

Definition at line 74 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_DATA1_SHIFT

#define FLASH_OBR_DATA1_SHIFT   24

Definition at line 73 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_OPTERR

#define FLASH_OBR_OPTERR   (1 << 0)

Definition at line 91 of file flash_common_f01.h.

◆ FLASH_OBR_RDPRT

#define FLASH_OBR_RDPRT   (3 << FLASH_OBR_RDPRT_SHIFT)

Definition at line 80 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_RDPRT_L0

#define FLASH_OBR_RDPRT_L0   (0 << FLASH_OBR_RDPRT_SHIFT)

Definition at line 81 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_RDPRT_L1

#define FLASH_OBR_RDPRT_L1   (1 << FLASH_OBR_RDPRT_SHIFT)

Definition at line 82 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_RDPRT_L2

#define FLASH_OBR_RDPRT_L2   (3 << FLASH_OBR_RDPRT_SHIFT)

Definition at line 83 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_RDPRT_SHIFT

#define FLASH_OBR_RDPRT_SHIFT   1

Definition at line 90 of file flash_common_f01.h.

◆ FLASH_OBR_USER

#define FLASH_OBR_USER   (0xFF << FLASH_OBR_USER_SHIFT)

Definition at line 78 of file gd32/f1x0/flash.h.

◆ FLASH_OBR_USER_SHIFT

#define FLASH_OBR_USER_SHIFT   8

Definition at line 77 of file gd32/f1x0/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_L0

#define FLASH_RDP_L0   ((uint8_t)0xa5)

Definition at line 90 of file gd32/f1x0/flash.h.

◆ FLASH_RDP_L1

#define FLASH_RDP_L1   ((uint8_t)0xf0) /* any value */

Definition at line 91 of file gd32/f1x0/flash.h.

◆ FLASH_RDP_L2

#define FLASH_RDP_L2   ((uint8_t)0xcc)

Definition at line 92 of file gd32/f1x0/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 65 of file gd32/f1x0/flash.h.

◆ FLASH_SR_BSY [2/2]

#define FLASH_SR_BSY   (1 << 0)

Definition at line 73 of file flash_common_f01.h.

◆ FLASH_SR_EOP [1/2]

#define FLASH_SR_EOP   (1 << 5)

Definition at line 62 of file gd32/f1x0/flash.h.

◆ FLASH_SR_EOP [2/2]

#define FLASH_SR_EOP   (1 << 5)

Definition at line 70 of file flash_common_f01.h.

◆ FLASH_SR_PGERR [1/2]

#define FLASH_SR_PGERR   (1 << 2)

Definition at line 64 of file gd32/f1x0/flash.h.

◆ FLASH_SR_PGERR [2/2]

#define FLASH_SR_PGERR   (1 << 2)

Definition at line 72 of file flash_common_f01.h.

◆ FLASH_SR_WRPRTERR [1/2]

#define FLASH_SR_WRPRTERR   (1 << 4)

Definition at line 63 of file gd32/f1x0/flash.h.

◆ FLASH_SR_WRPRTERR [2/2]

#define FLASH_SR_WRPRTERR   (1 << 4)

Definition at line 71 of file flash_common_f01.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_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_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_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 140 of file flash.c.

References FLASH_CR, 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 120 of file flash.c.

References FLASH_AR, FLASH_CR, 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.

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

Definition at line 73 of file flash.c.

References FLASH_SR, FLASH_SR_BSY, FLASH_SR_EOP, FLASH_SR_PGERR, and FLASH_SR_WRPRTERR.

Referenced by flash_wait_for_last_operation().

Here is the caller 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.

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

References FLASH_CR, 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 flash_options.
[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: