CC26xx Driver Library
[flash.h] Flash

Functions

static uint32_t FlashSectorSizeGet (void)
 Get size of a flash sector in number of bytes. More...
 
static uint32_t FlashSizeGet (void)
 Get the size of the flash. More...
 
void FlashPowerModeSet (uint32_t ui32PowerMode, uint32_t ui32BankGracePeriod, uint32_t ui32PumpGracePeriod)
 Set power mode. More...
 
uint32_t FlashPowerModeGet (void)
 Get current configured power mode. More...
 
void FlashProtectionSet (uint32_t ui32SectorAddress, uint32_t ui32ProtectMode)
 Set sector protection. More...
 
uint32_t FlashProtectionGet (uint32_t ui32SectorAddress)
 Get sector protection. More...
 
uint32_t FlashProtectionSave (uint32_t ui32SectorAddress)
 Save sector protection to make it permanent. More...
 
static uint32_t FlashCheckFsmForError (void)
 Checks if the Flash state machine has detected an error. More...
 
static uint32_t FlashCheckFsmForReady (void)
 Checks if the Flash state machine is ready. More...
 
static void FlashIntRegister (void(*pfnHandler)(void))
 Registers an interrupt handler for the flash interrupt in the dynamic interrupt table. More...
 
static void FlashIntUnregister (void)
 Unregisters the interrupt handler for the flash interrupt in the dynamic interrupt table. More...
 
static void FlashIntEnable (uint32_t ui32IntFlags)
 Enables flash controller interrupt sources. More...
 
static void FlashIntDisable (uint32_t ui32IntFlags)
 Disables individual flash controller interrupt sources. More...
 
static uint32_t FlashIntStatus (void)
 Gets the current interrupt status. More...
 
static void FlashIntClear (uint32_t ui32IntFlags)
 Clears flash controller interrupt source. More...
 
uint32_t FlashSectorErase (uint32_t ui32SectorAddress)
 Erase a flash sector. More...
 
uint32_t FlashProgram (uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
 Programs unprotected flash sectors in the main bank. More...
 
bool FlashEfuseReadRow (uint32_t *pui32EfuseData, uint32_t ui32RowAddress)
 Reads efuse data from specified row. More...
 
void FlashDisableSectorsForWrite (void)
 Disables all sectors for erase and programming on the active bank. More...
 

Enumerations

enum  tFlashStateCommandsType {
  FAPI_PROGRAM_DATA = 0x0002, FAPI_ERASE_SECTOR = 0x0006, FAPI_ERASE_BANK = 0x0008, FAPI_VALIDATE_SECTOR = 0x000E,
  FAPI_CLEAR_STATUS = 0x0010, FAPI_PROGRAM_RESUME = 0x0014, FAPI_ERASE_RESUME = 0x0016, FAPI_CLEAR_MORE = 0x0018,
  FAPI_PROGRAM_SECTOR = 0x0020, FAPI_ERASE_OTP = 0x0030
}
 Defined values for Flash State Machine commands. More...
 

Detailed Description

Function Documentation

§ FlashCheckFsmForError()

static uint32_t FlashCheckFsmForError ( void  )
inlinestatic

Checks if the Flash state machine has detected an error.

This function returns the status of the Flash State Machine indicating if an error is detected or not. Primary use is to check if an Erase or Program operation has failed.

Note
Please note that code can not execute in flash while any part of the flash is being programmed or erased. This function must be called from ROM or SRAM while any part of the flash is being programmed or erased.
Returns
Returns status of Flash state machine:
426 {
427  if(HWREG(FLASH_BASE + FLASH_O_FMSTAT) & FLASH_FMSTAT_CSTAT)
428  {
429  return(FAPI_STATUS_FSM_ERROR);
430  }
431  else
432  {
433  return(FAPI_STATUS_SUCCESS);
434  }
435 }
#define FAPI_STATUS_SUCCESS
Definition: flash.h:101
#define FAPI_STATUS_FSM_ERROR
Definition: flash.h:106

§ FlashCheckFsmForReady()

static uint32_t FlashCheckFsmForReady ( void  )
inlinestatic

Checks if the Flash state machine is ready.

This function returns the status of the Flash State Machine indicating if it is ready to accept a new command or not. Primary use is to check if an Erase or Program operation has finished.

Note
Please note that code can not execute in flash while any part of the flash is being programmed or erased. This function must be called from ROM or SRAMh while any part of the flash is being programmed or erased.
Returns
Returns readiness status of Flash state machine:
456 {
457  if(HWREG(FLASH_BASE + FLASH_O_STAT) & FLASH_STAT_BUSY_M)
458  {
459  return(FAPI_STATUS_FSM_BUSY);
460  }
461  else
462  {
463  return(FAPI_STATUS_FSM_READY);
464  }
465 }
#define FAPI_STATUS_FSM_READY
Definition: flash.h:103
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:102

§ FlashDisableSectorsForWrite()

void FlashDisableSectorsForWrite ( void  )

Disables all sectors for erase and programming on the active bank.

This function disables all sectors for erase and programming on the active bank and enables the Idle Reading Power reduction mode if no low power mode is configured. Furthermore, an additional level of protection from erase is enabled.

Note
Please note that code can not execute in flash while any part of the flash is being programmed or erased.
Returns
None

Referenced by FlashIntClear().

500 {
501  uint32_t ui32BankNo;
502  // Configure flash back to read mode
503  SetReadMode();
504 
505  for(ui32BankNo = 0; ui32BankNo < ((HWREG(FLASH_BASE + FLASH_O_FCFG_BANK) &
506  FLASH_FCFG_BANK_MAIN_NUM_BANK_M)
507  >> FLASH_FCFG_BANK_MAIN_NUM_BANK_S); ui32BankNo++)
508  {
509  // Select bank
510  HWREG(FLASH_BASE + FLASH_O_FMAC) = ui32BankNo;
511 
512  // Disable Level 1 Protection.
513  HWREG(FLASH_BASE + FLASH_O_FBPROT) = FLASH_FBPROT_PROTL1DIS_M;
514 
515  // Disable all sectors for erase and programming.
516  HWREG(FLASH_BASE + FLASH_O_FBSE) = 0x0000;
517 
518  // Enable Level 1 Protection.
519  HWREG(FLASH_BASE + FLASH_O_FBPROT) = 0;
520 
521  // Protect sectors from sector erase.
522  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
523  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR1) = 0xFFFFFFFF;
524  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR2) = 0xFFFFFFFF;
525  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
526  }
527 
528  // Select bank 0
529  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x0;
530 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:183
#define FSM_REG_WRT_ENABLE
Definition: flash.h:182
static void SetReadMode(void)
Definition: flash.c:544
Here is the call graph for this function:

§ FlashEfuseReadRow()

bool FlashEfuseReadRow ( uint32_t *  pui32EfuseData,
uint32_t  ui32RowAddress 
)

Reads efuse data from specified row.

This function will read one efuse row. It is assumed that any previous efuse operation has finished.

Parameters
pui32EfuseDatais pointer to variable to be updated with efuse data.
ui32RowAddressis the efuse row number to be read. First row is row number 0.
Returns
Returns the status of the efuse read operation.
  • false : OK status.
  • true : Error status

Referenced by FlashIntClear().

441 {
442  bool bStatus;
443 
444  // Make sure the clock for the efuse is enabled
445  HWREG(FLASH_BASE + FLASH_O_CFG) &= ~FLASH_CFG_DIS_EFUSECLK;
446 
447  // Set timing for EFUSE read operations.
448  HWREG(FLASH_BASE + FLASH_O_EFUSEREAD) |= ((5 << FLASH_EFUSEREAD_READCLOCK_S) &
449  FLASH_EFUSEREAD_READCLOCK_M);
450 
451  // Clear status register.
452  HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) = 0;
453 
454  // Select the FuseROM block 0.
455  HWREG(FLASH_BASE + FLASH_O_EFUSEADDR) = 0x00000000;
456 
457  // Start the read operation.
458  HWREG(FLASH_BASE + FLASH_O_EFUSE) =
459  (DUMPWORD_INSTR << FLASH_EFUSE_INSTRUCTION_S) |
460  (ui32RowAddress & FLASH_EFUSE_DUMPWORD_M);
461 
462  // Wait for operation to finish.
463  while(!(HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) & FLASH_EFUSEERROR_DONE))
464  {
465  }
466 
467  // Check if error reported.
468  if(HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) & FLASH_EFUSEERROR_CODE_M)
469  {
470  // Set error status.
471  bStatus = 1;
472 
473  // Clear data.
474  *pui32EfuseData = 0;
475  }
476  else
477  {
478  // Set ok status.
479  bStatus = 0;
480 
481  // No error. Get data from data register.
482  *pui32EfuseData = HWREG(FLASH_BASE + FLASH_O_DATALOWER);
483  }
484 
485  // Disable the efuse clock to conserve power
486  HWREG(FLASH_BASE + FLASH_O_CFG) |= FLASH_CFG_DIS_EFUSECLK;
487 
488  // Return the data.
489  return(bStatus);
490 }
#define DUMPWORD_INSTR
Definition: flash.h:230

§ FlashIntClear()

static void FlashIntClear ( uint32_t  ui32IntFlags)
inlinestatic

Clears flash controller interrupt source.

The flash controller interrupt source is cleared, so that it no longer asserts. This must be done in the interrupt handler to keep it from being called again immediately upon exit.

Note
Due to write buffers and synchronizers in the system it may take several clock cycles from a register write clearing an event in a module and until the event is actually cleared in the NVIC of the system CPU. It is recommended to clear the event source early in the interrupt service routine (ISR) to allow the event clear to propagate to the NVIC before returning from the ISR. At the same time, an early event clear allows new events of the same type to be pended instead of ignored if the event is cleared later in the ISR. It is the responsibility of the programmer to make sure that enough time has passed before returning from the ISR to avoid false re-triggering of the cleared event. A simple, although not necessarily optimal, way of clearing an event before returning from the ISR is:
  1. Write to clear event (interrupt source). (buffered write)
  2. Dummy read from the event source module. (making sure the write has propagated)
  3. Wait two system CPU clock cycles (user code or two NOPs). (allowing cleared event to propagate through any synchronizers)
Parameters
ui32IntFlagsis the bit mask of the interrupt sources to be cleared. Can be any of:
Returns
None
632 {
633  uint32_t ui32TempVal;
634 
635  ui32TempVal = 0;
636 
637  if(ui32IntFlags & FLASH_INT_FSM_DONE)
638  {
639  ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
640  }
641 
642  if(ui32IntFlags & FLASH_INT_RV)
643  {
644  ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
645  }
646 
647  // Clear the flash interrupt source.
648  HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
649 }
#define FLASH_INT_FSM_DONE
Definition: flash.h:114
#define FLASH_INT_RV
Definition: flash.h:115
Here is the call graph for this function:

§ FlashIntDisable()

static void FlashIntDisable ( uint32_t  ui32IntFlags)
inlinestatic

Disables individual flash controller interrupt sources.

This function disables the flash controller interrupt sources.

Parameters
ui32IntFlagsis the bit mask of the interrupt sources to be disabled. The parameter is the bitwise OR of any of the following:
Returns
None
561 {
562  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
563  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
564  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
565 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:183
#define FSM_REG_WRT_ENABLE
Definition: flash.h:182

§ FlashIntEnable()

static void FlashIntEnable ( uint32_t  ui32IntFlags)
inlinestatic

Enables flash controller interrupt sources.

This function enables the flash controller interrupt sources.

Parameters
ui32IntFlagsis the bit mask of the interrupt sources to be enabled. The parameter is the bitwise OR of any of the following:
Returns
None
539 {
540  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
541  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
542  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
543 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:183
#define FSM_REG_WRT_ENABLE
Definition: flash.h:182

§ FlashIntRegister()

static void FlashIntRegister ( void(*)(void)  pfnHandler)
inlinestatic

Registers an interrupt handler for the flash interrupt in the dynamic interrupt table.

Note
Only use this function if you want to use the dynamic vector table (in SRAM)!

This function registers a function as the interrupt handler for a specific interrupt and enables the corresponding interrupt in the interrupt controller.

Specific FLASH interrupts must be enabled via FlashIntEnable(). It is the interrupt handler's responsibility to clear the interrupt source.

Parameters
pfnHandleris a pointer to the function to be called when the flash interrupt occurs.
Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
490 {
491  // Register the interrupt handler.
492  IntRegister(INT_FLASH, pfnHandler);
493 
494  // Enable the flash interrupt.
495  IntEnable(INT_FLASH);
496 }
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
Definition: interrupt.c:151
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:281
Here is the call graph for this function:

§ FlashIntStatus()

static uint32_t FlashIntStatus ( void  )
inlinestatic

Gets the current interrupt status.

This function returns the interrupt status for the Flash.

Returns
Returns the current interrupt status as values described in FlashIntEnable().
579 {
580  uint32_t ui32IntFlags;
581 
582  ui32IntFlags = 0;
583 
584  // Check if FSM_DONE interrupt status is set.
585  if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_FSM_DONE)
586  {
587  ui32IntFlags = FLASH_INT_FSM_DONE;
588  }
589 
590  // Check if RVF_INT interrupt status is set.
591  if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_RVF_INT)
592  {
593  ui32IntFlags |= FLASH_INT_RV;
594  }
595 
596  return(ui32IntFlags);
597 }
#define FLASH_INT_FSM_DONE
Definition: flash.h:114
#define FLASH_INT_RV
Definition: flash.h:115

§ FlashIntUnregister()

static void FlashIntUnregister ( void  )
inlinestatic

Unregisters the interrupt handler for the flash interrupt in the dynamic interrupt table.

This function does the actual unregistering of the interrupt handler. It clears the handler to be called when a FLASH interrupt occurs. This function also masks off the interrupt in the interrupt controller so that the interrupt handler no longer is called.

Returns
None
See also
IntRegister() for important information about registering interrupt handlers.
515 {
516  // Disable the interrupts.
517  IntDisable(INT_FLASH);
518 
519  // Unregister the interrupt handler.
520  IntUnregister(INT_FLASH);
521 }
void IntUnregister(uint32_t ui32Interrupt)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:187
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:325
Here is the call graph for this function:

§ FlashPowerModeGet()

uint32_t FlashPowerModeGet ( void  )

Get current configured power mode.

This function will return the current configured power mode.

Returns
Returns the current configured power mode. The defined power modes are:

Referenced by FlashSizeGet().

177 {
178  uint32_t ui32PowerMode;
179  uint32_t ui32BankPwrMode;
180 
181  ui32BankPwrMode = HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
182  FLASH_FBFALLBACK_BANKPWR0_M;
183 
184  if((ui32BankPwrMode == FBFALLBACK_SLEEP) &&
185  ((HWREG(FLASH_BASE + FLASH_O_FWFLAG) & FW_PWRMODE_DEPRECATED) == FW_PWRMODE_DEPRECATED))
186  {
187  ui32PowerMode = FLASH_PWR_DEEP_STDBY_MODE;
188  }
189  else if((ui32BankPwrMode == FBFALLBACK_SLEEP) &&
190  ((HWREG(FLASH_BASE + FLASH_O_FWFLAG) & FW_PWRMODE_DEPRECATED) == 0))
191  {
192  ui32PowerMode = FLASH_PWR_OFF_MODE;
193  }
194  else
195  {
196  ui32PowerMode = FLASH_PWR_ACTIVE_MODE;
197  }
198 
199  // Return power mode.
200  return(ui32PowerMode);
201 }
#define FLASH_PWR_OFF_MODE
Definition: flash.h:123
#define FW_PWRMODE_DEPRECATED
Definition: flash.h:215
#define FBFALLBACK_SLEEP
Definition: flash.h:190
#define FLASH_PWR_ACTIVE_MODE
Definition: flash.h:122
#define FLASH_PWR_DEEP_STDBY_MODE
Definition: flash.h:124

§ FlashPowerModeSet()

void FlashPowerModeSet ( uint32_t  ui32PowerMode,
uint32_t  ui32BankGracePeriod,
uint32_t  ui32PumpGracePeriod 
)

Set power mode.

This function will set the specified power mode.

Any access to the bank causes a reload of the specified bank grace period input value into the bank down counter. After the last access to the flash bank, the down counter delays from 0 to 255 prescaled HCLK clock cycles before putting the bank into one of the fallback power modes as determined by ui32PowerMode. This value must be greater than 1 when the fallback mode is not FLASH_PWR_ACTIVE_MODE.

Note: The prescaled clock used for the down counter is a clock divided by 16 from input HCLK. The ui32BankGracePeriod parameter is ignored if ui32PowerMode is equal to FLASH_PWR_ACTIVE_MODE. Any access to flash memory causes the pump grace period down counter to reload with value of ui32PumpGracePeriod. After the bank has gone to sleep, the down counter delays this number of prescaled HCLK clock cycles before entering one of the charge pump fallback power modes as determined by ui32PowerMode. The prescaled clock used for the pump grace period down counter is a clock divided by 16 from input HCLK. This parameter is ignored if ui32PowerMode is equal to FLASH_PWR_ACTIVE_MODE.

Note: The FLASH_PWR_DEEP_STDBY_MODE power mode is deprecated and shall not be used. When used this mode will force the same power mode as for FLASH_PWR_OFF_MODE. This function should not be called at any time before powering off Vims.

Changing the power mode of the flash module must be a part within a device power mode transition requiring configuration of multiple modules. Refer to documents describing the device power modes.

Parameters
ui32PowerModeis the wanted power mode. The defined flash power modes are:
ui32BankGracePeriodis the starting count value for the bank grace period down counter.
ui32PumpGracePeriodis the starting count value for the pump grace period down counter.
Returns
None

Referenced by FlashSizeGet().

114 {
115  // Check the arguments.
116  ASSERT(ui32PowerMode == FLASH_PWR_ACTIVE_MODE ||
117  ui32PowerMode == FLASH_PWR_OFF_MODE ||
118  ui32PowerMode == FLASH_PWR_DEEP_STDBY_MODE);
119  ASSERT(ui32BankGracePeriod <= 0xFF);
120  ASSERT(ui32PumpGracePeriod <= 0xFFFF);
121 
122  // Initialize flag requesting deprecated power mode
123  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 5;
124  HWREG(FLASH_BASE + FLASH_O_FWFLAG) &= ~FW_PWRMODE_DEPRECATED;
125  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 0;
126 
127  switch(ui32PowerMode)
128  {
130  // Set bank power mode to ACTIVE.
131  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) =
132  (HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
133  ~FLASH_FBFALLBACK_BANKPWR0_M) | FBFALLBACK_ACTIVE;
134  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) =
135  (HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
136  ~FLASH_FBFALLBACK_BANKPWR1_M) | (FBFALLBACK_ACTIVE << FLASH_FBFALLBACK_BANKPWR1_S);
137 
138  // Set charge pump power mode to ACTIVE mode.
139  HWREG(FLASH_BASE + FLASH_O_FPAC1) =
140  (HWREG(FLASH_BASE + FLASH_O_FPAC1) & ~FLASH_FPAC1_PUMPPWR_M) | (1 << FLASH_FPAC1_PUMPPWR_S);
141  break;
142 
144  // Deprecated power mode requested. Set flag.
145  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 5;
146  HWREG(FLASH_BASE + FLASH_O_FWFLAG) |= FW_PWRMODE_DEPRECATED;
147  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 0;
148  // Fall through to force FLASH_PWR_OFF_MODE power mode
149  case FLASH_PWR_OFF_MODE:
150  // Set bank grace period.
151  HWREG(FLASH_BASE + FLASH_O_FBAC) =
152  (HWREG(FLASH_BASE + FLASH_O_FBAC) & (~FLASH_FBAC_BAGP_M)) |
153  ((ui32BankGracePeriod << FLASH_FBAC_BAGP_S) & FLASH_FBAC_BAGP_M);
154 
155  // Set pump grace period.
156  HWREG(FLASH_BASE + FLASH_O_FPAC2) =
157  (HWREG(FLASH_BASE + FLASH_O_FPAC2) & (~FLASH_FPAC2_PAGP_M)) |
158  ((ui32PumpGracePeriod << FLASH_FPAC2_PAGP_S) & FLASH_FPAC2_PAGP_M);
159 
160  // Set bank power mode to SLEEP.
161  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &= ~FLASH_FBFALLBACK_BANKPWR0_M;
162  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &= ~FLASH_FBFALLBACK_BANKPWR1_M;
163 
164  // Set charge pump power mode to SLEEP mode.
165  HWREG(FLASH_BASE + FLASH_O_FPAC1) &= ~FLASH_FPAC1_PUMPPWR_M;
166  break;
167  }
168 }
#define FLASH_PWR_OFF_MODE
Definition: flash.h:123
#define FW_PWRMODE_DEPRECATED
Definition: flash.h:215
#define ASSERT(expr)
Definition: debug.h:71
#define FBFALLBACK_ACTIVE
Definition: flash.h:192
#define FLASH_PWR_ACTIVE_MODE
Definition: flash.h:122
#define FLASH_PWR_DEEP_STDBY_MODE
Definition: flash.h:124

§ FlashProgram()

uint32_t FlashProgram ( uint8_t *  pui8DataBuffer,
uint32_t  ui32Address,
uint32_t  ui32Count 
)

Programs unprotected flash sectors in the main bank.

This function programs a sequence of bytes into the on-chip flash. Programming each location consists of the result of an AND operation of the new data and the existing data; in other words bits that contain 1 can remain 1 or be changed to 0, but bits that are 0 cannot be changed to 1. Therefore, a byte can be programmed multiple times as long as these rules are followed; if a program operation attempts to change a 0 bit to a 1 bit, that bit will not have its value changed.

This function does not return until the data has been programmed or a programming error occurs.

Note
It is recommended to disable cache and line buffer before programming the flash. Cache and line buffer are not automatically updated if a flash program causes a mismatch between new flash content and old content in cache and line buffer. Remember to enable cache and line buffer when the program operation completes. See VIMSModeSafeSet(), VIMSLineBufDisable(), and VIMSLineBufEnable() for more information.
Warning
Please note that code can not execute in flash while any part of the flash is being programmed or erased. The application must disable interrupts that have interrupt routines in flash. This function calls a ROM function which handles the actual program operation.

The pui8DataBuffer pointer can not point to flash.

Parameters
pui8DataBufferis a pointer to the data to be programmed.
ui32Addressis the starting address in flash to be programmed.
ui32Countis the number of bytes to be programmed.
Returns
Returns status of the flash programming:

Referenced by FlashIntClear(), and FlashProtectionSave().

415 {
416  uint32_t ui32ErrorReturn;
417  FlashPrgPointer_t FuncPointer;
418 
419  // Check the arguments.
420  ASSERT((ui32Address + ui32Count) <= (FLASHMEM_BASE + FlashSizeGet()));
421 
422  // Call ROM function that handles the actual program operation
423  FuncPointer = (uint32_t (*)(uint8_t *, uint32_t, uint32_t)) (ROM_API_FLASH_TABLE[6]);
424  ui32ErrorReturn = FuncPointer( pui8DataBuffer, ui32Address, ui32Count);
425 
426  // Enable standby in flash bank since ROM function might have disabled it
427  HWREGBITW(FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_STANDBY_BITN ) = 0;
428 
429  // Return status of operation.
430  return(ui32ErrorReturn);
431 
432 }
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:71
uint32_t(* FlashPrgPointer_t)(uint8_t *, uint32_t, uint32_t)
Definition: flash.c:95
#define ROM_API_FLASH_TABLE
Definition: rom.h:252
Here is the call graph for this function:

§ FlashProtectionGet()

uint32_t FlashProtectionGet ( uint32_t  ui32SectorAddress)

Get sector protection.

This return the protection mode for the specified flash bank sector.

Parameters
ui32SectorAddressis the start address of the desired sector.
Returns
Returns the sector protection:

Referenced by FlashProtectionSave(), and FlashSizeGet().

271 {
272  uint32_t ui32SectorProtect;
273  uint32_t ui32SectorNumber;
274 
275  // Check the arguments.
276  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
277  FlashSectorSizeGet()));
278  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
279 
280  ui32SectorProtect = FLASH_NO_PROTECT;
281  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
282 
283  // Select bank 0
284  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x00;
285 
286  if(ui32SectorNumber <= 31)
287  {
288  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) & (1 << ui32SectorNumber)) &&
289  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) & (1 << ui32SectorNumber)))
290  {
291  ui32SectorProtect = FLASH_WRITE_PROTECT;
292  }
293  }
294  else if(ui32SectorNumber <= 43)
295  {
296  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) &
297  (1 << (ui32SectorNumber & 0x1F))) &&
298  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) &
299  (1 << (ui32SectorNumber & 0x1F))))
300  {
301  ui32SectorProtect = FLASH_WRITE_PROTECT;
302  }
303  }
304  else if(ui32SectorNumber <= 75)
305  {
306  // Select bank 1
307  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x01;
308  ui32SectorNumber -= 44;
309 
310  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) & (1 << ui32SectorNumber)) &&
311  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) & (1 << ui32SectorNumber)))
312  {
313  ui32SectorProtect = FLASH_WRITE_PROTECT;
314  }
315  }
316  else if(ui32SectorNumber <= 87)
317  {
318  // Select bank 1
319  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x01;
320  ui32SectorNumber -= 76;
321 
322  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) & (1 << ui32SectorNumber)) &&
323  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) & (1 << ui32SectorNumber)))
324  {
325  ui32SectorProtect = FLASH_WRITE_PROTECT;
326  }
327  }
328 
329  // Select bank 0
330  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x00;
331 
332  return(ui32SectorProtect);
333 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:249
#define FLASH_NO_PROTECT
Definition: flash.h:133
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:71
#define FLASH_WRITE_PROTECT
Definition: flash.h:134
Here is the call graph for this function:

§ FlashProtectionSave()

uint32_t FlashProtectionSave ( uint32_t  ui32SectorAddress)

Save sector protection to make it permanent.

This function will save the current protection mode for the specified flash bank sector.

This function must only be executed from ROM or SRAM.

Note
A write protected sector will become permanent write protected!! A device reset will not change the write protection!
Parameters
ui32SectorAddressis the start address of the sector to be protected.
Returns
Returns the status of the sector protection:

Referenced by FlashSizeGet().

342 {
343  uint32_t ui32ErrorReturn;
344  uint32_t ui32SectorNumber;
345  uint32_t ui32CcfgSectorAddr;
346  uint32_t ui32ProgBuf;
347 
348  ui32ErrorReturn = FAPI_STATUS_SUCCESS;
349 
350  // Check the arguments.
351  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
352  FlashSectorSizeGet()));
353  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
354 
355  if(FlashProtectionGet(ui32SectorAddress) == FLASH_WRITE_PROTECT)
356  {
357  // Find sector number for specified sector.
358  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
359  ui32CcfgSectorAddr = FLASHMEM_BASE + FlashSizeGet() - FlashSectorSizeGet();
360 
361  // Adjust CCFG address to the 32-bit CCFG word holding the
362  // protect-bit for the specified sector.
363  ui32CcfgSectorAddr += (((ui32SectorNumber >> 5) * 4) + CCFG_OFFSET_SECT_PROT);
364 
365  // Find value to program by setting the protect-bit which
366  // corresponds to specified sector number, to 0.
367  // Leave other protect-bits unchanged.
368  ui32ProgBuf = (~(1 << (ui32SectorNumber & 0x1F))) &
369  *(uint32_t *)ui32CcfgSectorAddr;
370 
371  ui32ErrorReturn = FlashProgram((uint8_t*)&ui32ProgBuf, ui32CcfgSectorAddr,
373  }
374 
375  // Return status.
376  return(ui32ErrorReturn);
377 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:249
uint32_t FlashProtectionGet(uint32_t ui32SectorAddress)
Get sector protection.
Definition: flash.c:270
#define FAPI_STATUS_SUCCESS
Definition: flash.h:101
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:71
#define CCFG_OFFSET_SECT_PROT
Definition: flash.c:78
#define CCFG_SIZE_SECT_PROT
Definition: flash.c:80
#define FLASH_WRITE_PROTECT
Definition: flash.h:134
uint32_t FlashProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected flash sectors in the main bank.
Definition: flash.c:414
Here is the call graph for this function:

§ FlashProtectionSet()

void FlashProtectionSet ( uint32_t  ui32SectorAddress,
uint32_t  ui32ProtectMode 
)

Set sector protection.

This function will set the specified protection on specified flash bank sector. A sector can either have no protection or have write protection which guards for both program and erase of that sector. Sector protection can only be changed from FLASH_NO_PROTECT to FLASH_WRITE_PROTECT! After write protecting a sector this sector can only be set back to unprotected by a device reset.

Parameters
ui32SectorAddressis the start address of the sector to protect.
ui32ProtectModeis the enumerated sector protection mode.
Returns
None

Referenced by FlashSizeGet().

210 {
211  uint32_t ui32SectorNumber;
212 
213  // Check the arguments.
214  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
215  FlashSectorSizeGet()));
216  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
217 
218  if(ui32ProtectMode == FLASH_WRITE_PROTECT)
219  {
220  // Select bank 0
221  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x00;
222 
223  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) /
225  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
226 
227  if(ui32SectorNumber <= 31)
228  {
229  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) |= (1 << ui32SectorNumber);
230  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) |= (1 << ui32SectorNumber);
231  }
232  else if(ui32SectorNumber <= 43)
233  {
234  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) |=
235  (1 << (ui32SectorNumber & 0x1F));
236  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) |=
237  (1 << (ui32SectorNumber & 0x1F));
238  }
239  else if(ui32SectorNumber <= 75)
240  {
241  // Select bank 1
242  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x1;
243  ui32SectorNumber -= 44;
244 
245  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) |= (1 << ui32SectorNumber);
246  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) |= (1 << ui32SectorNumber);
247  }
248  else if(ui32SectorNumber <= 87)
249  {
250  // Select bank 1
251  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x01;
252  ui32SectorNumber -= 76;
253 
254  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) |= (1 << ui32SectorNumber);
255  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) |= (1 << ui32SectorNumber);
256  }
257  // Select bank 0
258  HWREG(FLASH_BASE + FLASH_O_FMAC) = 0x00;
259 
260  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
261  }
262 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:249
#define FSM_REG_WRT_DISABLE
Definition: flash.h:183
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define FSM_REG_WRT_ENABLE
Definition: flash.h:182
#define ASSERT(expr)
Definition: debug.h:71
#define FLASH_WRITE_PROTECT
Definition: flash.h:134
Here is the call graph for this function:

§ FlashSectorErase()

uint32_t FlashSectorErase ( uint32_t  ui32SectorAddress)

Erase a flash sector.

This function will erase the specified flash sector. The function will not return until the flash sector has been erased or an error condition occurred. If flash top sector is erased the function will program the the device security data bytes with default values. The device security data located in the customer configuration area of the flash top sector, must have valid values at all times. These values affect the configuration of the device during boot.

Warning
Please note that code can not execute in flash while any part of the flash is being programmed or erased. The application must disable interrupts that have interrupt routines in flash. This function calls a ROM function which handles the actual program operation.
Parameters
ui32SectorAddressis the starting address in flash of the sector to be erased.
Returns
Returns the status of the sector erase:

Referenced by FlashIntClear().

386 {
387  uint32_t ui32ErrorReturn;
388  FlashSectorErasePointer_t FuncPointer;
389 
390  // Check the arguments.
391  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
392  FlashSectorSizeGet()));
393  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
394 
395  // Call ROM function that handles the actual erase operation
396  FuncPointer = (uint32_t (*)(uint32_t)) (ROM_API_FLASH_TABLE[5]);
397  ui32ErrorReturn = FuncPointer(ui32SectorAddress);
398 
399  // Enable standby in flash bank since ROM function might have disabled it
400  HWREGBITW(FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_STANDBY_BITN ) = 0;
401 
402  // Return status of operation.
403  return(ui32ErrorReturn);
404 
405 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:249
uint32_t(* FlashSectorErasePointer_t)(uint32_t)
Definition: flash.c:97
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:71
#define ROM_API_FLASH_TABLE
Definition: rom.h:252
Here is the call graph for this function:

§ FlashSectorSizeGet()

static uint32_t FlashSectorSizeGet ( void  )
inlinestatic

Get size of a flash sector in number of bytes.

This function will return the size of a flash sector in number of bytes.

Returns
Returns size of a flash sector in number of bytes.

Referenced by FlashProtectionGet(), FlashProtectionSave(), FlashProtectionSet(), FlashSectorErase(), and FlashSizeGet().

250 {
251  uint32_t ui32SectorSizeInKbyte;
252 
253  ui32SectorSizeInKbyte = (HWREG(FLASH_BASE + FLASH_O_FCFG_B0_SSIZE0) &
254  FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_M) >>
255  FLASH_FCFG_B0_SSIZE0_B0_SECT_SIZE_S;
256 
257  // Return flash sector size in number of bytes.
258  return(ui32SectorSizeInKbyte * 1024);
259 }

§ FlashSizeGet()

static uint32_t FlashSizeGet ( void  )
inlinestatic

Get the size of the flash.

This function returns the size of the flash main bank in number of bytes.

Returns
Returns the flash size in number of bytes.

Referenced by FlashProgram(), FlashProtectionGet(), FlashProtectionSave(), FlashProtectionSet(), and FlashSectorErase().

272 {
273  uint32_t ui32NoOfSectors;
274 
275  // Get number of flash sectors
276  ui32NoOfSectors = (HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
277  FLASH_FLASH_SIZE_SECTORS_M) >>
278  FLASH_FLASH_SIZE_SECTORS_S;
279 
280  // Return flash size in number of bytes
281  return(ui32NoOfSectors * FlashSectorSizeGet());
282 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:249
Here is the call graph for this function:

Macro Definition Documentation

§ ADDR_OFFSET

#define ADDR_OFFSET   (0x1F800000 - FLASHMEM_BASE)

§ DUMPWORD_INSTR

#define DUMPWORD_INSTR   0x04

Referenced by FlashEfuseReadRow().

§ FAPI_STATUS_FSM_BUSY

#define FAPI_STATUS_FSM_BUSY   0x00000001

Referenced by FlashCheckFsmForReady().

§ FAPI_STATUS_FSM_ERROR

#define FAPI_STATUS_FSM_ERROR   0x00000004

Referenced by FlashCheckFsmForError().

§ FAPI_STATUS_FSM_READY

#define FAPI_STATUS_FSM_READY   0x00000002

Referenced by FlashCheckFsmForReady().

§ FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH

#define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH   0x00000003

§ FAPI_STATUS_SUCCESS

#define FAPI_STATUS_SUCCESS   0x00000000

§ FBFALLBACK_ACTIVE

#define FBFALLBACK_ACTIVE   3

Referenced by FlashPowerModeSet().

§ FBFALLBACK_DEEP_STDBY

#define FBFALLBACK_DEEP_STDBY   1

§ FBFALLBACK_SLEEP

#define FBFALLBACK_SLEEP   0

Referenced by FlashPowerModeGet().

§ FCFG1_OFFSET

#define FCFG1_OFFSET   0x1000

Referenced by SetReadMode().

§ FLASH_BAGP

#define FLASH_BAGP   0x14

§ FLASH_CMD_EXEC

#define FLASH_CMD_EXEC   0x15

§ FLASH_INT_FSM_DONE

#define FLASH_INT_FSM_DONE   0x00400000

Referenced by FlashIntClear(), and FlashIntStatus().

§ FLASH_INT_RV

#define FLASH_INT_RV   0x00010000

Referenced by FlashIntClear(), and FlashIntStatus().

§ FLASH_MODULE_CLK_FREQ

#define FLASH_MODULE_CLK_FREQ   48

§ FLASH_NO_PROTECT

#define FLASH_NO_PROTECT   0x00000000

Referenced by FlashProtectionGet().

§ FLASH_PAGP

#define FLASH_PAGP   0x14

§ FLASH_PWR_ACTIVE_MODE

#define FLASH_PWR_ACTIVE_MODE   0x00000000

§ FLASH_PWR_DEEP_STDBY_MODE

#define FLASH_PWR_DEEP_STDBY_MODE   0x00000002

§ FLASH_PWR_OFF_MODE

#define FLASH_PWR_OFF_MODE   0x00000001

§ FLASH_WRITE_PROTECT

#define FLASH_WRITE_PROTECT   0x00000001

§ FSM_REG_WRT_DISABLE

#define FSM_REG_WRT_DISABLE   2

§ FSM_REG_WRT_ENABLE

#define FSM_REG_WRT_ENABLE   5

§ FW_PWRMODE_DEPRECATED

#define FW_PWRMODE_DEPRECATED   0x00000002

§ FW_WRT_TRIMMED

#define FW_WRT_TRIMMED   0x00000001

§ FWPWRITE_BYTE_ADDRESS

#define FWPWRITE_BYTE_ADDRESS   ((tFwpWriteByte *)((FLASH_BASE + FLASH_O_FWPWRITE0)))

§ PATTERN_BITS

#define PATTERN_BITS   0x20

Enumeration Type Documentation

§ tFlashStateCommandsType

Defined values for Flash State Machine commands.

Enumerator
FAPI_PROGRAM_DATA 

Program data.

FAPI_ERASE_SECTOR 

Erase sector.

FAPI_ERASE_BANK 

Erase bank.

FAPI_VALIDATE_SECTOR 

Validate sector.

FAPI_CLEAR_STATUS 

Clear status.

FAPI_PROGRAM_RESUME 

Program resume.

FAPI_ERASE_RESUME 

Erase resume.

FAPI_CLEAR_MORE 

Clear more.

FAPI_PROGRAM_SECTOR 

Program sector.

FAPI_ERASE_OTP 

Erase OTP.

164 {
165  FAPI_PROGRAM_DATA = 0x0002,
166  FAPI_ERASE_SECTOR = 0x0006,
167  FAPI_ERASE_BANK = 0x0008,
168  FAPI_VALIDATE_SECTOR = 0x000E,
169  FAPI_CLEAR_STATUS = 0x0010,
170  FAPI_PROGRAM_RESUME = 0x0014,
171  FAPI_ERASE_RESUME = 0x0016,
172  FAPI_CLEAR_MORE = 0x0018,
173  FAPI_PROGRAM_SECTOR = 0x0020,
174  FAPI_ERASE_OTP = 0x0030
Program data.
Definition: flash.h:165
Erase resume.
Definition: flash.h:171
Erase sector.
Definition: flash.h:166
Program sector.
Definition: flash.h:173
Erase OTP.
Definition: flash.h:174
Clear status.
Definition: flash.h:169
Erase bank.
Definition: flash.h:167
tFlashStateCommandsType
Defined values for Flash State Machine commands.
Definition: flash.h:163
Validate sector.
Definition: flash.h:168
Clear more.
Definition: flash.h:172
Program resume.
Definition: flash.h:170