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

libopencm3 GD32F1x0 FLASH More...

Collaboration diagram for FLASH peripheral API:

Functions

void flash_clear_status_flags (void)
 Clear All Status Flags. More...
 
uint32_t flash_get_status_flags (void)
 Read All Status Flags. 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_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_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...
 
void flash_wait_for_last_operation (void)
 Wait until Last Operation has Ended. More...
 
void flash_program_word (uint32_t address, uint32_t data)
 Program a 32 bit Word to 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...
 
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...
 

Detailed Description

libopencm3 GD32F1x0 FLASH

Version
1.0.0
Author
© 2013 Frantisek Burian BuFra.nosp@m.n@se.nosp@m.znam..nosp@m.cz
Date
14 January 2014

FLASH memory may be used for data storage as well as code, and may be programmatically modified. Note that for firmware upload the GD32F1x0 provides a built-in bootloader in system memory that can be entered from a running program.

FLASH must first be unlocked before programming. In this module a write to FLASH is a blocking operation until the end-of-operation flag is asserted.

Note
: don't forget to lock it again when all operations are complete.

LGPL License Terms libopencm3 License

Function Documentation

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

void flash_clear_status_flags ( void  )

Clear All Status Flags.

Clear all status flags.

Program error, end of operation, write protect error, busy.

Definition at line 56 of file flash.c.

References flash_clear_eop_flag(), flash_clear_pgerr_flag(), and flash_clear_wrprterr_flag().

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

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

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

◆ 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_erase_option_bytes(), and 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 64 of file flash_common_f01.c.

References flash_get_status_flags(), and FLASH_SR_BSY.

Referenced by flash_erase_all_pages(), flash_erase_option_bytes(), flash_erase_page(), flash_program_half_word(), and flash_program_option_bytes().

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