Nut/OS  5.0.5
API Reference
stm32f1_flash.c File Reference
#include <cfg/os.h>
#include <cfg/arch.h>
#include <cfg/clock.h>
#include <string.h>
#include <sys/atom.h>
#include <sys/event.h>
#include <sys/timer.h>
#include <sys/heap.h>
#include <sys/nutdebug.h>
#include <dev/irqreg.h>
#include <arch/cm3/stm/stm32_flash.h>
Include dependency graph for stm32f1_flash.c:

Data Structures

struct  FLASH_BankRegT

Functions

void FLASH_SetLatency (uint32_t FLASH_Latency)
 Sets the code latency value.
void FLASH_HalfCycleAccessCmd (uint32_t FLASH_HalfCycleAccess)
 Enables or disables the Half cycle flash access.
void FLASH_PrefetchBufferCmd (uint32_t FLASH_PrefetchBuffer)
 Enables or disables the Prefetch Buffer.
void FLASH_ClearFlag (uint32_t FLASH_FLAG)
 Clears the FLASH’s pending flags.
FLASH_Status FLASH_GetStatus (void)
 Returns the FLASH Status.
FLASH_Status Stm32FlashWaitReady (uint32_t Timeout)
 Waits for a Flash operation to complete or a TIMEOUT to occur.
FLASH_Status FLASH_Unlock (void *addr, size_t len)
 Unlocks the FLASH Program Erase Controller.
void FLASH_Lock (void *addr, size_t len)
 Locks the FLASH Program Erase Controller.
void FLASH_ITConfig (uint32_t FLASH_IT, FunctionalState NewState)
 Enables or disables the specified FLASH interrupts.
FLASH_Status FLASH_EraseAllBank1Pages (void)
 Erases all Bank1 FLASH pages.
FLASH_Status FLASH_EraseAllBank2Pages (void)
 Erases all Bank2 FLASH pages.
FLASH_Status FLASH_EraseAllPages (void)
 Erases all FLASH pages.

Function Documentation

void FLASH_SetLatency ( uint32_t  FLASH_Latency)

Sets the code latency value.

Note:
This function can be used for all STM32F10x devices.
Parameters:
FLASH_Latency,:specifies the FLASH Latency value. This parameter can be one of the following values:
  • FLASH_Latency_0: FLASH Zero Latency cycle
  • FLASH_Latency_1: FLASH One Latency cycle
  • FLASH_Latency_2: FLASH Two Latency cycles
Return values:
None

References FLASH, and NUTASSERT.

void FLASH_HalfCycleAccessCmd ( uint32_t  FLASH_HalfCycleAccess)

Enables or disables the Half cycle flash access.

Note:
This function can be used for all STM32F10x devices.
Parameters:
FLASH_HalfCycleAccess,:specifies the FLASH Half cycle Access mode. This parameter can be one of the following values:
  • FLASH_HalfCycleAccess_Enable: FLASH Half Cycle Enable
  • FLASH_HalfCycleAccess_Disable: FLASH Half Cycle Disable
Return values:
None

References FLASH, and NUTASSERT.

void FLASH_PrefetchBufferCmd ( uint32_t  FLASH_PrefetchBuffer)

Enables or disables the Prefetch Buffer.

Note:
This function can be used for all STM32F10x devices.
Parameters:
FLASH_PrefetchBuffer,:specifies the Prefetch buffer status. This parameter can be one of the following values:
  • FLASH_PrefetchBuffer_Enable: FLASH Prefetch Buffer Enable
  • FLASH_PrefetchBuffer_Disable: FLASH Prefetch Buffer Disable
Return values:
None

References FLASH, and NUTASSERT.

void FLASH_ClearFlag ( uint32_t  FLASH_FLAG)

Clears the FLASH’s pending flags.

Note:
This function can be used for all STM32F10x devices.
  • For STM32F10X_XL devices, this function clears Bank1 or Bank2’s pending flags
  • For other devices, it clears Bank1’s pending flags.
Parameters:
FLASH_FLAG,:specifies the FLASH flags to clear. This parameter can be any combination of the following values:
  • FLASH_FLAG_PGERR: FLASH Program error flag
  • FLASH_FLAG_WRPRTERR: FLASH Write protected error flag
  • FLASH_FLAG_EOP: FLASH End of Operation flag
Return values:
None

References FLASH.

Referenced by FLASH_EraseAllPages().

FLASH_Status FLASH_GetStatus ( void  )

Returns the FLASH Status.

Note:
This function can be used for all STM32F10x devices, it is equivalent to FLASH_GetBank1Status function.
Parameters:
addr,:Address inside bank to check status of.
Return values:
FLASHStatus: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG, FLASH_ERROR_WRP or FLASH_COMPLETE

References FLASH, FLASH_SR_BSY, FLASH_SR_PGERR, and FLASH_SR_WRPRTERR.

Referenced by Stm32FlashWaitReady().

FLASH_Status Stm32FlashWaitReady ( uint32_t  Timeout)

Waits for a Flash operation to complete or a TIMEOUT to occur.

Note:
This function can be used for all STM32F10x devices, it is equivalent to FLASH_WaitForLastBank1Operation.
  • For STM32F10X_XL devices this function waits for a Bank1 Flash operation to complete or a TIMEOUT to occur.
  • For all other devices it waits for a Flash operation to complete or a TIMEOUT to occur.
Parameters:
Timeout,:FLASH progamming Timeout
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

References FLASH_GetStatus().

Referenced by FLASH_EraseAllBank1Pages(), FLASH_EraseAllBank2Pages(), and FLASH_EraseAllPages().

Here is the call graph for this function:

FLASH_Status FLASH_Unlock ( void *  addr,
size_t  len 
)

Unlocks the FLASH Program Erase Controller.

Note:
This function can be used for all STM32F10x devices.
  • For STM32F10X_XL devices this function unlocks Bank1 and Bank2.
  • For all other devices it unlocks Bank1 and it is equivalent to FLASH_UnlockBank1 function..
Parameters:
addrStart address of area to unlock
lenLength of area to unlock
Return values:
0on success, -1 if out of flash area.

References FLASH, FLASH_CR_LOCK, and NUTASSERT.

Referenced by FLASH_EraseAllPages().

void FLASH_Lock ( void *  addr,
size_t  len 
)

Locks the FLASH Program Erase Controller.

Note:
This function can be used for all STM32F10x devices.
  • For STM32F10X_XL devices this function Locks Bank1 and Bank2.
  • For all other devices it Locks Bank1 and it is equivalent to FLASH_LockBank1 function.
Parameters:
None
Return values:
None

References FLASH, and FLASH_CR_LOCK.

Referenced by FLASH_EraseAllPages().

void FLASH_ITConfig ( uint32_t  FLASH_IT,
FunctionalState  NewState 
)

Enables or disables the specified FLASH interrupts.

Note:
This function can be used for all STM32F10x devices.
  • For STM32F10X_XL devices, enables or disables the specified FLASH interrupts for Bank1 and Bank2.
  • For other devices it enables or disables the specified FLASH interrupts for Bank1.
Parameters:
FLASH_IT,:specifies the FLASH interrupt sources to be enabled or disabled. This parameter can be any combination of the following values:
  • FLASH_IT_ERROR: FLASH Error Interrupt
  • FLASH_IT_EOP: FLASH end of operation Interrupt
NewState,:new state of the specified Flash interrupts. This parameter can be: ENABLE or DISABLE.
Return values:
None

References assert_param, DISABLE, FLASH, and IS_FUNCTIONAL_STATE.

FLASH_Status FLASH_EraseAllBank1Pages ( void  )

Erases all Bank1 FLASH pages.

Note:
This function can be used for all STM32F10x devices.
  • For STM32F10X_XL devices this function erases all Bank1 pages.
  • For all other devices it erases all Bank1 pages and it is equivalent to FLASH_EraseAllPages function.
Parameters:
None
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

References FLASH, FLASH_CR_MER, FLASH_CR_STRT, and Stm32FlashWaitReady().

Referenced by FLASH_EraseAllPages().

Here is the call graph for this function:

FLASH_Status FLASH_EraseAllBank2Pages ( void  )

Erases all Bank2 FLASH pages.

Note:
This function can be used only for STM32F10x_XL density devices.
Parameters:
None
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

References FLASH, FLASH_CR_MER, FLASH_CR_STRT, and Stm32FlashWaitReady().

Referenced by FLASH_EraseAllPages().

Here is the call graph for this function:

FLASH_Status FLASH_EraseAllPages ( void  )

Erases all FLASH pages.

Note:
This function can be used for all STM32F10x devices.
Parameters:
None
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

Returns the FLASH User Option Bytes values.

Note:
This function can be used for all STM32F10x devices.
Parameters:
None
Return values:
TheFLASH User Option Bytes values:IWDG_SW(Bit0), RST_STOP(Bit1) and RST_STDBY(Bit2).

Erases the FLASH option bytes.

Note:
This functions erases all option bytes except the Read protection (RDP).
This function can be used for all STM32F10x devices.
Parameters:
None
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

Programs a half word at a specified Option Byte Data address.

Note:
This function can be used for all STM32F10x devices.
Parameters:
Address,:specifies the address to be programmed. This parameter can be 0x1FFFF804 or 0x1FFFF806.
Data,:specifies the data to be programmed.
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

Configures to boot from Bank1 or Bank2.

Note:
This function can be used only for STM32F10x_XL density devices.
Parameters:
FLASH_BOOT,:select the FLASH Bank to boot from. This parameter can be one of the following values:
  • FLASH_BOOT_Bank1: At startup, if boot pins are set in boot from user Flash position and this parameter is selected the device will boot from Bank1(Default).
  • FLASH_BOOT_Bank2: At startup, if boot pins are set in boot from user Flash position and this parameter is selected the device will boot from Bank2 or Bank1, depending on the activation of the bank. The active banks are checked in the following order: Bank2, followed by Bank1. The active bank is recognized by the value programmed at the base address of the respective bank (corresponding to the initial stack pointer value in the interrupt vector table). For more information, please refer to AN2606 from www.st.com.
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

Get the total size of this CPU's FLASH.

Note:
This function can be used for all STM32F10x devices.
Return values:
sizeof FLASH in bytes.

Get the last valid address in the FLASH.

Note:
This function can be used for all STM32F10x devices.
Return values:
address.

Programs a half word at a specified address.

Note:
This function can be used for all STM32F10x devices.
Parameters:
Address,:specifies the address to be programmed.
Data,:specifies the data to be programmed.
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

Write protects the desired pages

Note:
This function can be used for all STM32F10x devices.
Parameters:
FLASH_Pages,:specifies the address of the pages to be write protected. This parameter can be:
  • For STM32_Low-density_devices: value between FLASH_WRProt_Pages0to3 and FLASH_WRProt_Pages28to31
  • For STM32_Medium-density_devices: value between FLASH_WRProt_Pages0to3 and FLASH_WRProt_Pages124to127
  • For STM32_High-density_devices: value between FLASH_WRProt_Pages0to1 and FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to255
  • For STM32_Connectivity_line_devices: value between FLASH_WRProt_Pages0to1 and FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to127
  • For STM32_XL-density_devices: value between FLASH_WRProt_Pages0to1 and FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to511
  • FLASH_WRProt_AllPages
Return values:
FLASHStatus: The returned value can be: FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

Returns the FLASH Write Protection Option Bytes Register value.

Note:
This function can be used for all STM32F10x devices.
Parameters:
None
Return values:
TheFLASH Write Protection Option Bytes Register value

Checks whether the FLASH Read Out Protection Status is set or not.

Note:
This function can be used for all STM32F10x devices.
Parameters:
None
Return values:
0for reset, -1 for set.

Checks whether the FLASH Prefetch Buffer status is set or not.

Note:
This function can be used for all STM32F10x devices.
Parameters:
None
Return values:
FLASHPrefetch Buffer Status (SET or RESET).

Read data from FLASH at specified address.

This function copies data from FLASH to a user provided buffer.

Parameters:
dstPointer to address where to copy data to.
srcPointer to address in FLASH to read from.
lenNumber fo bytes to copy.
Returns:
FLASH Status.

Erase FLASH Page at specified address.

This routine is called by Stm32FlashWritePage to erase before programming.

Parameters:
pagePointer to address of page to erase.
Returns:
FLASH Status.

Program FLASH Page.

This routine writes a complete page of FLASH.

Parameters:
dstPointer to beginning of a FLASH page.
srcPointer to source data to be written to page.
Returns:
FLASH Status.

Program any data to FLASH.

This function writes data from source address to FLASH. It handles erasing and assembling of data automatically.

Parameters:
dstPointer to address anywhere in FLASH.
srcPointer to source data.
lenNumber of bytes to be written.
Returns:
FLASH Status.

Nut/OS specific handling for parameters in FLASH.

This function enables to read system specific parameters from processors FLASH. The sectors used for storage are configureable via nutconf.

Parameters:
posOffset of parameter(s) in configured page(s).
dataPointer where to copy data from flash to.
lenNumber of bytes to be copied.
Returns:
FLASH_Status.

Nut/OS specific handling for parameters in FLASH.

This function enables to store system specific parameters in processors FLASH. The sectors used for storage are configureable via nutconf. FLASH is only updated if content differs.

Parameters:
posOffset of parameter(s) in configured page(s).
dataPointer to source data.
lenNumber of bytes to be written.
Returns:
FLASH_Status.

References __IO, FLASH_BankRegT::AR, FLASH_BankRegT::CR, FLASH, FLASH_ACR_PRFTBS, FLASH_ClearFlag(), FLASH_CONF_SECTOR, FLASH_CONF_SIZE, FLASH_CR_OPTER, FLASH_CR_OPTPG, FLASH_CR_PER, FLASH_CR_PG, FLASH_CR_STRT, FLASH_EraseAllBank1Pages(), FLASH_EraseAllBank2Pages(), FLASH_Lock(), FLASH_OBR_RDPRT, FLASH_SR_EOP, FLASH_SR_PGERR, FLASH_SR_WRPRTERR, FLASH_Unlock(), max, memcmp(), memcpy(), NULL, NUTASSERT, NutHeapAlloc, NutHeapFree, OB, RESET, SET, and Stm32FlashWaitReady().

Here is the call graph for this function: