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:
427 {
429  {
430  return(FAPI_STATUS_FSM_ERROR);
431  }
432  else
433  {
434  return(FAPI_STATUS_SUCCESS);
435  }
436 }
#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:
457 {
459  {
460  return(FAPI_STATUS_FSM_BUSY);
461  }
462  else
463  {
464  return(FAPI_STATUS_FSM_READY);
465  }
466 }
#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
445 {
446  // Configure flash back to read mode
447  SetReadMode();
448 
449  // Disable Level 1 Protection.
451 
452  // Disable all sectors for erase and programming.
453  HWREG(FLASH_BASE + FLASH_O_FBSE) = 0x0000;
454 
455  // Enable Level 1 Protection.
456  HWREG(FLASH_BASE + FLASH_O_FBPROT) = 0;
457 
458  // Protect sectors from sector erase.
460  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR1) = 0xFFFFFFFF;
461  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR2) = 0xFFFFFFFF;
463 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:185
#define FSM_REG_WRT_ENABLE
Definition: flash.h:184
static void SetReadMode(void)
Definition: flash.c:477

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
386 {
387  bool bStatus;
388 
389  // Make sure the clock for the efuse is enabled
391 
392  // Set timing for EFUSE read operations.
395 
396  // Clear status register.
397  HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) = 0;
398 
399  // Select the FuseROM block 0.
400  HWREG(FLASH_BASE + FLASH_O_EFUSEADDR) = 0x00000000;
401 
402  // Start the read operation.
403  HWREG(FLASH_BASE + FLASH_O_EFUSE) =
405  (ui32RowAddress & FLASH_EFUSE_DUMPWORD_M);
406 
407  // Wait for operation to finish.
409  {
410  }
411 
412  // Check if error reported.
414  {
415  // Set error status.
416  bStatus = 1;
417 
418  // Clear data.
419  *pui32EfuseData = 0;
420  }
421  else
422  {
423  // Set ok status.
424  bStatus = 0;
425 
426  // No error. Get data from data register.
427  *pui32EfuseData = HWREG(FLASH_BASE + FLASH_O_DATALOWER);
428  }
429 
430  // Disable the efuse clock to conserve power
432 
433  // Return the data.
434  return(bStatus);
435 }
#define DUMPWORD_INSTR
Definition: flash.h:232
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
633 {
634  uint32_t ui32TempVal;
635 
636  ui32TempVal = 0;
637 
638  if(ui32IntFlags & FLASH_INT_FSM_DONE)
639  {
640  ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
641  }
642 
643  if(ui32IntFlags & FLASH_INT_RV)
644  {
645  ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
646  }
647 
648  // Clear the flash interrupt source.
649  HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
650 }
#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
562 {
564  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
566 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:185
#define FSM_REG_WRT_ENABLE
Definition: flash.h:184
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
540 {
542  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
544 }
#define FSM_REG_WRT_DISABLE
Definition: flash.h:185
#define FSM_REG_WRT_ENABLE
Definition: flash.h:184
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.
491 {
492  // Register the interrupt handler.
493  IntRegister(INT_FLASH, pfnHandler);
494 
495  // Enable the flash interrupt.
496  IntEnable(INT_FLASH);
497 }
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().
580 {
581  uint32_t ui32IntFlags;
582 
583  ui32IntFlags = 0;
584 
585  // Check if FSM_DONE interrupt status is set.
587  {
588  ui32IntFlags = FLASH_INT_FSM_DONE;
589  }
590 
591  // Check if RVF_INT interrupt status is set.
593  {
594  ui32IntFlags |= FLASH_INT_RV;
595  }
596 
597  return(ui32IntFlags);
598 }
#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.
516 {
517  // Disable the interrupts.
518  IntDisable(INT_FLASH);
519 
520  // Unregister the interrupt handler.
521  IntUnregister(INT_FLASH);
522 }
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:
175 {
176  uint32_t ui32PowerMode;
177  uint32_t ui32BankPwrMode;
178 
179  ui32BankPwrMode = HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
181 
182  if((ui32BankPwrMode == FBFALLBACK_SLEEP) &&
183  ((HWREG(FLASH_BASE + FLASH_O_FWFLAG) & FW_PWRMODE_DEPRECATED) == FW_PWRMODE_DEPRECATED))
184  {
185  ui32PowerMode = FLASH_PWR_DEEP_STDBY_MODE;
186  }
187  else if((ui32BankPwrMode == FBFALLBACK_SLEEP) &&
188  ((HWREG(FLASH_BASE + FLASH_O_FWFLAG) & FW_PWRMODE_DEPRECATED) == 0))
189  {
190  ui32PowerMode = FLASH_PWR_OFF_MODE;
191  }
192  else
193  {
194  ui32PowerMode = FLASH_PWR_ACTIVE_MODE;
195  }
196 
197  // Return power mode.
198  return(ui32PowerMode);
199 }
#define FLASH_PWR_OFF_MODE
Definition: flash.h:125
#define FW_PWRMODE_DEPRECATED
Definition: flash.h:217
#define FBFALLBACK_SLEEP
Definition: flash.h:192
#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.

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.

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  // Initialize flag requesting deprecated power mode
125  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 5;
127  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 0;
128 
129  switch(ui32PowerMode)
130  {
132  // Set bank power mode to ACTIVE.
133  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) =
134  (HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
136 
137  // Set charge pump power mode to ACTIVE mode.
138  HWREG(FLASH_BASE + FLASH_O_FPAC1) =
140  break;
141 
143  // Deprecated power mode requested. Set flag.
144  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 5;
146  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 0;
147  // Fall through to force FLASH_PWR_OFF_MODE power mode
148  case FLASH_PWR_OFF_MODE:
149  // Set bank grace period.
150  HWREG(FLASH_BASE + FLASH_O_FBAC) =
151  (HWREG(FLASH_BASE + FLASH_O_FBAC) & (~FLASH_FBAC_BAGP_M)) |
152  ((ui32BankGracePeriod << FLASH_FBAC_BAGP_S) & FLASH_FBAC_BAGP_M);
153 
154  // Set pump grace period.
155  HWREG(FLASH_BASE + FLASH_O_FPAC2) =
157  ((ui32PumpGracePeriod << FLASH_FPAC2_PAGP_S) & FLASH_FPAC2_PAGP_M);
158 
159  // Set bank power mode to SLEEP.
161 
162  // Set charge pump power mode to SLEEP mode.
164  break;
165  }
166 }
#define FLASH_PWR_OFF_MODE
Definition: flash.h:125
#define FW_PWRMODE_DEPRECATED
Definition: flash.h:217
#define ASSERT(expr)
Definition: debug.h:73
#define FBFALLBACK_ACTIVE
Definition: flash.h:194
#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().

360 {
361  uint32_t ui32ErrorReturn;
362  FlashPrgPointer_t FuncPointer;
363 
364  // Check the arguments.
365  ASSERT((ui32Address + ui32Count) <= (FLASHMEM_BASE + FlashSizeGet()));
366 
367  // Call ROM function that handles the actual program operation
368  FuncPointer = (uint32_t (*)(uint8_t *, uint32_t, uint32_t)) (ROM_API_FLASH_TABLE[6]);
369  ui32ErrorReturn = FuncPointer( pui8DataBuffer, ui32Address, ui32Count);
370 
371  // Enable standby in flash bank since ROM function might have disabled it
373 
374  // Return status of operation.
375  return(ui32ErrorReturn);
376 
377 }
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:273
#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:254

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

246 {
247  uint32_t ui32SectorProtect;
248  uint32_t ui32SectorNumber;
249 
250  // Check the arguments.
251  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
252  FlashSectorSizeGet()));
253  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
254 
255  ui32SectorProtect = FLASH_NO_PROTECT;
256  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
257 
258  if(ui32SectorNumber <= 31)
259  {
260  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) & (1 << ui32SectorNumber)) &&
261  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) & (1 << ui32SectorNumber)))
262  {
263  ui32SectorProtect = FLASH_WRITE_PROTECT;
264  }
265  }
266  else if(ui32SectorNumber <= 63)
267  {
268  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) &
269  (1 << (ui32SectorNumber & 0x1F))) &&
270  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) &
271  (1 << (ui32SectorNumber & 0x1F))))
272  {
273  ui32SectorProtect = FLASH_WRITE_PROTECT;
274  }
275  }
276 
277  return(ui32SectorProtect);
278 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:251
#define FLASH_NO_PROTECT
Definition: flash.h:135
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:273
#define ASSERT(expr)
Definition: debug.h:73
#define FLASH_WRITE_PROTECT
Definition: flash.h:136

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:
287 {
288  uint32_t ui32ErrorReturn;
289  uint32_t ui32SectorNumber;
290  uint32_t ui32CcfgSectorAddr;
291  uint32_t ui32ProgBuf;
292 
293  ui32ErrorReturn = FAPI_STATUS_SUCCESS;
294 
295  // Check the arguments.
296  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
297  FlashSectorSizeGet()));
298  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
299 
300  if(FlashProtectionGet(ui32SectorAddress) == FLASH_WRITE_PROTECT)
301  {
302  // Find sector number for specified sector.
303  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
304  ui32CcfgSectorAddr = FLASHMEM_BASE + FlashSizeGet() - FlashSectorSizeGet();
305 
306  // Adjust CCFG address to the 32-bit CCFG word holding the
307  // protect-bit for the specified sector.
308  ui32CcfgSectorAddr += (((ui32SectorNumber >> 5) * 4) + CCFG_OFFSET_SECT_PROT);
309 
310  // Find value to program by setting the protect-bit which
311  // corresponds to specified sector number, to 0.
312  // Leave other protect-bits unchanged.
313  ui32ProgBuf = (~(1 << (ui32SectorNumber & 0x1F))) &
314  *(uint32_t *)ui32CcfgSectorAddr;
315 
316  ui32ErrorReturn = FlashProgram((uint8_t*)&ui32ProgBuf, ui32CcfgSectorAddr,
318  }
319 
320  // Return status.
321  return(ui32ErrorReturn);
322 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:251
uint32_t FlashProtectionGet(uint32_t ui32SectorAddress)
Get sector protection.
Definition: flash.c:245
#define FAPI_STATUS_SUCCESS
Definition: flash.h:103
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:273
#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:136
uint32_t FlashProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected flash sectors in the main bank.
Definition: flash.c:359

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
208 {
209  uint32_t ui32SectorNumber;
210 
211  // Check the arguments.
212  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
213  FlashSectorSizeGet()));
214  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
215 
216  if(ui32ProtectMode == FLASH_WRITE_PROTECT)
217  {
218  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) /
221 
222  if(ui32SectorNumber <= 31)
223  {
224  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) |= (1 << ui32SectorNumber);
225  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) |= (1 << ui32SectorNumber);
226  }
227  else if(ui32SectorNumber <= 63)
228  {
229  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) |=
230  (1 << (ui32SectorNumber & 0x1F));
231  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) |=
232  (1 << (ui32SectorNumber & 0x1F));
233  }
234 
236  }
237 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:251
#define FSM_REG_WRT_DISABLE
Definition: flash.h:185
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:273
#define FSM_REG_WRT_ENABLE
Definition: flash.h:184
#define ASSERT(expr)
Definition: debug.h:73
#define FLASH_WRITE_PROTECT
Definition: flash.h:136

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:
331 {
332  uint32_t ui32ErrorReturn;
333  FlashSectorErasePointer_t FuncPointer;
334 
335  // Check the arguments.
336  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
337  FlashSectorSizeGet()));
338  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
339 
340  // Call ROM function that handles the actual erase operation
341  FuncPointer = (uint32_t (*)(uint32_t)) (ROM_API_FLASH_TABLE[5]);
342  ui32ErrorReturn = FuncPointer(ui32SectorAddress);
343 
344  // Enable standby in flash bank since ROM function might have disabled it
346 
347  // Return status of operation.
348  return(ui32ErrorReturn);
349 
350 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:251
uint32_t(* FlashSectorErasePointer_t)(uint32_t)
Definition: flash.c:99
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:273
#define ASSERT(expr)
Definition: debug.h:73
#define ROM_API_FLASH_TABLE
Definition: rom.h:254

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

252 {
253  uint32_t ui32SectorSizeInKbyte;
254 
255  ui32SectorSizeInKbyte = (HWREG(FLASH_BASE + FLASH_O_FCFG_B0_SSIZE0) &
258 
259  // Return flash sector size in number of bytes.
260  return(ui32SectorSizeInKbyte * 1024);
261 }
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().

274 {
275  uint32_t ui32NoOfSectors;
276 
277  // Get number of flash sectors
278  ui32NoOfSectors = (HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
281 
282  // Return flash size in number of bytes
283  return(ui32NoOfSectors * FlashSectorSizeGet());
284 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:251

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

Referenced by SetReadMode().

#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_PWRMODE_DEPRECATED   0x00000002
#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.

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