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

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:
421 {
423  {
424  return(FAPI_STATUS_FSM_ERROR);
425  }
426  else
427  {
428  return(FAPI_STATUS_SUCCESS);
429  }
430 }
#define FAPI_STATUS_SUCCESS
Definition: flash.h:103
#define FAPI_STATUS_FSM_ERROR
Definition: flash.h:108
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:
451 {
453  {
454  return(FAPI_STATUS_FSM_BUSY);
455  }
456  else
457  {
458  return(FAPI_STATUS_FSM_READY);
459  }
460 }
#define FAPI_STATUS_FSM_READY
Definition: flash.h:105
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:104
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
452 {
453  // Configure flash back to read mode
454  SetReadMode();
455 
456  // Disable Level 1 Protection.
458 
459  // Disable all sectors for erase and programming.
460  HWREG(FLASH_BASE + FLASH_O_FBSE) = 0x0000;
461 
462  // Enable Level 1 Protection.
463  HWREG(FLASH_BASE + FLASH_O_FBPROT) = 0;
464 
465  // Protect sectors from sector erase.
467  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR1) = 0xFFFFFFFF;
468  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR2) = 0xFFFFFFFF;
470 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:184
#define FSM_REG_WRT_ENABLE
Definition: flash.h:183
static void SetReadMode(void)
Definition: flash.c:484

Here is the call graph for this function:

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
393 {
394  bool bStatus;
395 
396  // Make sure the clock for the efuse is enabled
398 
399  // Set timing for EFUSE read operations.
402 
403  // Clear status register.
404  HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) = 0;
405 
406  // Select the FuseROM block 0.
407  HWREG(FLASH_BASE + FLASH_O_EFUSEADDR) = 0x00000000;
408 
409  // Start the read operation.
410  HWREG(FLASH_BASE + FLASH_O_EFUSE) =
412  (ui32RowAddress & FLASH_EFUSE_DUMPWORD_M);
413 
414  // Wait for operation to finish.
416  {
417  }
418 
419  // Check if error reported.
421  {
422  // Set error status.
423  bStatus = 1;
424 
425  // Clear data.
426  *pui32EfuseData = 0;
427  }
428  else
429  {
430  // Set ok status.
431  bStatus = 0;
432 
433  // No error. Get data from data register.
434  *pui32EfuseData = HWREG(FLASH_BASE + FLASH_O_DATALOWER);
435  }
436 
437  // Disable the efuse clock to conserve power
439 
440  // Return the data.
441  return(bStatus);
442 }
#define DUMPWORD_INSTR
Definition: flash.h:230
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
627 {
628  uint32_t ui32TempVal;
629 
630  ui32TempVal = 0;
631 
632  if(ui32IntFlags & FLASH_INT_FSM_DONE)
633  {
634  ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
635  }
636 
637  if(ui32IntFlags & FLASH_INT_RV)
638  {
639  ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
640  }
641 
642  // Clear the flash interrupt source.
643  HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
644 }
#define FLASH_INT_FSM_DONE
Definition: flash.h:116
#define FLASH_INT_RV
Definition: flash.h:117
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
556 {
558  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
560 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:184
#define FSM_REG_WRT_ENABLE
Definition: flash.h:183
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
534 {
536  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
538 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:184
#define FSM_REG_WRT_ENABLE
Definition: flash.h:183
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.
485 {
486  // Register the interrupt handler.
487  IntRegister(INT_FLASH, pfnHandler);
488 
489  // Enable the flash interrupt.
490  IntEnable(INT_FLASH);
491 }
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
Definition: interrupt.c:153
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt or system exception.
Definition: interrupt.c:283

Here is the call graph for this function:

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().
574 {
575  uint32_t ui32IntFlags;
576 
577  ui32IntFlags = 0;
578 
579  // Check if FSM_DONE interrupt status is set.
581  {
582  ui32IntFlags = FLASH_INT_FSM_DONE;
583  }
584 
585  // Check if RVF_INT interrupt status is set.
587  {
588  ui32IntFlags |= FLASH_INT_RV;
589  }
590 
591  return(ui32IntFlags);
592 }
#define FLASH_INT_FSM_DONE
Definition: flash.h:116
#define FLASH_INT_RV
Definition: flash.h:117
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.
510 {
511  // Disable the interrupts.
512  IntDisable(INT_FLASH);
513 
514  // Unregister the interrupt handler.
515  IntUnregister(INT_FLASH);
516 }
void IntUnregister(uint32_t ui32Interrupt)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:189
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt or system exception.
Definition: interrupt.c:327

Here is the call graph for this function:

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:
184 {
185  uint32_t ui32PowerMode;
186  uint32_t ui32BankPwrMode;
187 
188  ui32BankPwrMode = HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
190 
191  if(ui32BankPwrMode == FBFALLBACK_SLEEP)
192  {
193  ui32PowerMode = FLASH_PWR_OFF_MODE;
194  }
195  else if(ui32BankPwrMode == FBFALLBACK_DEEP_STDBY)
196  {
197  ui32PowerMode = FLASH_PWR_DEEP_STDBY_MODE;
198  }
199  else
200  {
201  ui32PowerMode = FLASH_PWR_ACTIVE_MODE;
202  }
203 
204  // Return power mode.
205  return(ui32PowerMode);
206 }
#define FLASH_PWR_OFF_MODE
Definition: flash.h:125
#define FBFALLBACK_DEEP_STDBY
Definition: flash.h:192
#define FBFALLBACK_SLEEP
Definition: flash.h:191
#define FLASH_PWR_ACTIVE_MODE
Definition: flash.h:124
#define FLASH_PWR_DEEP_STDBY_MODE
Definition: flash.h:126
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.

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
116 {
117  // Check the arguments.
118  ASSERT(ui32PowerMode == FLASH_PWR_ACTIVE_MODE ||
119  ui32PowerMode == FLASH_PWR_OFF_MODE ||
120  ui32PowerMode == FLASH_PWR_DEEP_STDBY_MODE);
121  ASSERT(ui32BankGracePeriod <= 0xFF);
122  ASSERT(ui32PumpGracePeriod <= 0xFFFF);
123 
124  switch(ui32PowerMode)
125  {
127  // Set bank power mode to ACTIVE.
128  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) =
129  (HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
131 
132  // Set charge pump power mode to ACTIVE mode.
133  HWREG(FLASH_BASE + FLASH_O_FPAC1) =
135  break;
136 
137  case FLASH_PWR_OFF_MODE:
138  // Set bank grace period.
139  HWREG(FLASH_BASE + FLASH_O_FBAC) =
140  (HWREG(FLASH_BASE + FLASH_O_FBAC) & (~FLASH_FBAC_BAGP_M)) |
141  ((ui32BankGracePeriod << FLASH_FBAC_BAGP_S) & FLASH_FBAC_BAGP_M);
142 
143  // Set pump grace period.
144  HWREG(FLASH_BASE + FLASH_O_FPAC2) =
146  ((ui32PumpGracePeriod << FLASH_FPAC2_PAGP_S) & FLASH_FPAC2_PAGP_M);
147 
148  // Set bank power mode to SLEEP.
150 
151  // Set charge pump power mode to SLEEP mode.
153  break;
154 
156  // Set bank grace period.
157  HWREG(FLASH_BASE + FLASH_O_FBAC) =
158  (HWREG(FLASH_BASE + FLASH_O_FBAC) & (~FLASH_FBAC_BAGP_M)) |
159  ((ui32BankGracePeriod << FLASH_FBAC_BAGP_S) & FLASH_FBAC_BAGP_M);
160 
161  // Set pump grace period.
162  HWREG(FLASH_BASE + FLASH_O_FPAC2) =
164  ((ui32PumpGracePeriod << FLASH_FPAC2_PAGP_S) & FLASH_FPAC2_PAGP_M);
165 
166  // Set bank power mode to DEEP STANDBY mode.
167  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) =
168  (HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
170 
171  // Set charge pump power mode to STANDBY mode.
173  break;
174  }
175 }
#define FLASH_PWR_OFF_MODE
Definition: flash.h:125
#define FBFALLBACK_DEEP_STDBY
Definition: flash.h:192
#define ASSERT(expr)
Definition: debug.h:73
#define FBFALLBACK_ACTIVE
Definition: flash.h:193
#define FLASH_PWR_ACTIVE_MODE
Definition: flash.h:124
#define FLASH_PWR_DEEP_STDBY_MODE
Definition: flash.h:126
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 FlashProtectionSave().

367 {
368  uint32_t ui32ErrorReturn;
369  FlashPrgPointer_t FuncPointer;
370 
371  // Check the arguments.
372  ASSERT((ui32Address + ui32Count) <= (FLASHMEM_BASE + FlashSizeGet()));
373 
374  // Call ROM function that handles the actual program operation
375  FuncPointer = (uint32_t (*)(uint8_t *, uint32_t, uint32_t)) (ROM_API_FLASH_TABLE[6]);
376  ui32ErrorReturn = FuncPointer( pui8DataBuffer, ui32Address, ui32Count);
377 
378  // Enable standby in flash bank since ROM function might have disabled it
380 
381  // Return status of operation.
382  return(ui32ErrorReturn);
383 
384 }
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:73
uint32_t(* FlashPrgPointer_t)(uint8_t *, uint32_t, uint32_t)
Definition: flash.c:97
#define ROM_API_FLASH_TABLE
Definition: rom.h:253

Here is the call graph for this function:

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().

253 {
254  uint32_t ui32SectorProtect;
255  uint32_t ui32SectorNumber;
256 
257  // Check the arguments.
258  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
259  FlashSectorSizeGet()));
260  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
261 
262  ui32SectorProtect = FLASH_NO_PROTECT;
263  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
264 
265  if(ui32SectorNumber <= 31)
266  {
267  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) & (1 << ui32SectorNumber)) &&
268  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) & (1 << ui32SectorNumber)))
269  {
270  ui32SectorProtect = FLASH_WRITE_PROTECT;
271  }
272  }
273  else if(ui32SectorNumber <= 63)
274  {
275  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) &
276  (1 << (ui32SectorNumber & 0x1F))) &&
277  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) &
278  (1 << (ui32SectorNumber & 0x1F))))
279  {
280  ui32SectorProtect = FLASH_WRITE_PROTECT;
281  }
282  }
283 
284  return(ui32SectorProtect);
285 }
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:134
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:73
#define FLASH_WRITE_PROTECT
Definition: flash.h:135

Here is the call graph for this function:

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:
294 {
295  uint32_t ui32ErrorReturn;
296  uint32_t ui32SectorNumber;
297  uint32_t ui32CcfgSectorAddr;
298  uint32_t ui32ProgBuf;
299 
300  ui32ErrorReturn = FAPI_STATUS_SUCCESS;
301 
302  // Check the arguments.
303  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
304  FlashSectorSizeGet()));
305  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
306 
307  if(FlashProtectionGet(ui32SectorAddress) == FLASH_WRITE_PROTECT)
308  {
309  // Find sector number for specified sector.
310  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
311  ui32CcfgSectorAddr = FLASHMEM_BASE + FlashSizeGet() - FlashSectorSizeGet();
312 
313  // Adjust CCFG address to the 32-bit CCFG word holding the
314  // protect-bit for the specified sector.
315  ui32CcfgSectorAddr += (((ui32SectorNumber >> 5) * 4) + CCFG_OFFSET_SECT_PROT);
316 
317  // Find value to program by setting the protect-bit which
318  // corresponds to specified sector number, to 0.
319  // Leave other protect-bits unchanged.
320  ui32ProgBuf = (~(1 << (ui32SectorNumber & 0x1F))) &
321  *(uint32_t *)ui32CcfgSectorAddr;
322 
323  ui32ErrorReturn = FlashProgram((uint8_t*)&ui32ProgBuf, ui32CcfgSectorAddr,
325  }
326 
327  // Return status.
328  return(ui32ErrorReturn);
329 }
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:252
#define FAPI_STATUS_SUCCESS
Definition: flash.h:103
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:73
#define CCFG_OFFSET_SECT_PROT
Definition: flash.c:80
#define CCFG_SIZE_SECT_PROT
Definition: flash.c:82
#define FLASH_WRITE_PROTECT
Definition: flash.h:135
uint32_t FlashProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected flash sectors in the main bank.
Definition: flash.c:366

Here is the call graph for this function:

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
215 {
216  uint32_t ui32SectorNumber;
217 
218  // Check the arguments.
219  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
220  FlashSectorSizeGet()));
221  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
222 
223  if(ui32ProtectMode == FLASH_WRITE_PROTECT)
224  {
225  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) /
228 
229  if(ui32SectorNumber <= 31)
230  {
231  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) |= (1 << ui32SectorNumber);
232  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) |= (1 << ui32SectorNumber);
233  }
234  else if(ui32SectorNumber <= 63)
235  {
236  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) |=
237  (1 << (ui32SectorNumber & 0x1F));
238  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) |=
239  (1 << (ui32SectorNumber & 0x1F));
240  }
241 
243  }
244 }
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:184
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define FSM_REG_WRT_ENABLE
Definition: flash.h:183
#define ASSERT(expr)
Definition: debug.h:73
#define FLASH_WRITE_PROTECT
Definition: flash.h:135

Here is the call graph for this function:

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:
338 {
339  uint32_t ui32ErrorReturn;
340  FlashSectorErasePointer_t FuncPointer;
341 
342  // Check the arguments.
343  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
344  FlashSectorSizeGet()));
345  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
346 
347  // Call ROM function that handles the actual erase operation
348  FuncPointer = (uint32_t (*)(uint32_t)) (ROM_API_FLASH_TABLE[5]);
349  ui32ErrorReturn = FuncPointer(ui32SectorAddress);
350 
351  // Enable standby in flash bank since ROM function might have disabled it
353 
354  // Return status of operation.
355  return(ui32ErrorReturn);
356 
357 }
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:99
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:271
#define ASSERT(expr)
Definition: debug.h:73
#define ROM_API_FLASH_TABLE
Definition: rom.h:253

Here is the call graph for this function:

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) &
256 
257  // Return flash sector size in number of bytes.
258  return(ui32SectorSizeInKbyte * 1024);
259 }
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) &
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

#define ADDR_OFFSET   (0x1F800000 - FLASHMEM_BASE)
#define DUMPWORD_INSTR   0x04

Referenced by FlashEfuseReadRow().

#define FAPI_STATUS_FSM_BUSY   0x00000001

Referenced by FlashCheckFsmForReady().

#define FAPI_STATUS_FSM_ERROR   0x00000004

Referenced by FlashCheckFsmForError().

#define FAPI_STATUS_FSM_READY   0x00000002

Referenced by FlashCheckFsmForReady().

#define FAPI_STATUS_INCORRECT_DATABUFFER_LENGTH   0x00000003
#define FAPI_STATUS_SUCCESS   0x00000000
#define FBFALLBACK_ACTIVE   3

Referenced by FlashPowerModeSet().

#define FBFALLBACK_DEEP_STDBY   1
#define FBFALLBACK_SLEEP   0

Referenced by FlashPowerModeGet().

#define FCFG1_OFFSET   0x1000
#define FLASH_BAGP   0x14
#define FLASH_CMD_EXEC   0x15
#define FLASH_INT_FSM_DONE   0x00400000

Referenced by FlashIntClear(), and FlashIntStatus().

#define FLASH_INT_RV   0x00010000

Referenced by FlashIntClear(), and FlashIntStatus().

#define FLASH_MODULE_CLK_FREQ   48
#define FLASH_NO_PROTECT   0x00000000

Referenced by FlashProtectionGet().

#define FLASH_PAGP   0x14
#define FLASH_PWR_ACTIVE_MODE   0x00000000
#define FLASH_PWR_DEEP_STDBY_MODE   0x00000002
#define FLASH_PWR_OFF_MODE   0x00000001
#define FLASH_WRITE_PROTECT   0x00000001
#define FSM_REG_WRT_DISABLE   2
#define FSM_REG_WRT_ENABLE   5
#define FW_WRT_TRIMMED   0x00000001
#define FWPWRITE_BYTE_ADDRESS   ((tFwpWriteByte *)((FLASH_BASE + FLASH_O_FWPWRITE0)))
#define PATTERN_BITS   0x20

Enumeration Type Documentation

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.

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