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:
425 {
426  if(HWREG(FLASH_BASE + FLASH_O_FMSTAT) & FLASH_FMSTAT_CSTAT)
427  {
428  return(FAPI_STATUS_FSM_ERROR);
429  }
430  else
431  {
432  return(FAPI_STATUS_SUCCESS);
433  }
434 }
#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:
455 {
456  if(HWREG(FLASH_BASE + FLASH_O_STAT) & FLASH_STAT_BUSY)
457  {
458  return(FAPI_STATUS_FSM_BUSY);
459  }
460  else
461  {
462  return(FAPI_STATUS_FSM_READY);
463  }
464 }
#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().

443 {
444  // Configure flash back to read mode
445  SetReadMode();
446 
447  // Disable Level 1 Protection.
448  HWREG(FLASH_BASE + FLASH_O_FBPROT) = FLASH_FBPROT_PROTL1DIS;
449 
450  // Disable all sectors for erase and programming.
451  HWREG(FLASH_BASE + FLASH_O_FBSE) = 0x0000;
452 
453  // Enable Level 1 Protection.
454  HWREG(FLASH_BASE + FLASH_O_FBPROT) = 0;
455 
456  // Protect sectors from sector erase.
457  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
458  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR1) = 0xFFFFFFFF;
459  HWREG(FLASH_BASE + FLASH_O_FSM_SECTOR2) = 0xFFFFFFFF;
460  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
461 }
#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:475
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().

384 {
385  bool bStatus;
386 
387  // Make sure the clock for the efuse is enabled
388  HWREG(FLASH_BASE + FLASH_O_CFG) &= ~FLASH_CFG_DIS_EFUSECLK;
389 
390  // Set timing for EFUSE read operations.
391  HWREG(FLASH_BASE + FLASH_O_EFUSEREAD) |= ((5 << FLASH_EFUSEREAD_READCLOCK_S) &
392  FLASH_EFUSEREAD_READCLOCK_M);
393 
394  // Clear status register.
395  HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) = 0;
396 
397  // Select the FuseROM block 0.
398  HWREG(FLASH_BASE + FLASH_O_EFUSEADDR) = 0x00000000;
399 
400  // Start the read operation.
401  HWREG(FLASH_BASE + FLASH_O_EFUSE) =
402  (DUMPWORD_INSTR << FLASH_EFUSE_INSTRUCTION_S) |
403  (ui32RowAddress & FLASH_EFUSE_DUMPWORD_M);
404 
405  // Wait for operation to finish.
406  while(!(HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) & FLASH_EFUSEERROR_DONE))
407  {
408  }
409 
410  // Check if error reported.
411  if(HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) & FLASH_EFUSEERROR_CODE_M)
412  {
413  // Set error status.
414  bStatus = 1;
415 
416  // Clear data.
417  *pui32EfuseData = 0;
418  }
419  else
420  {
421  // Set ok status.
422  bStatus = 0;
423 
424  // No error. Get data from data register.
425  *pui32EfuseData = HWREG(FLASH_BASE + FLASH_O_DATALOWER);
426  }
427 
428  // Disable the efuse clock to conserve power
429  HWREG(FLASH_BASE + FLASH_O_CFG) |= FLASH_CFG_DIS_EFUSECLK;
430 
431  // Return the data.
432  return(bStatus);
433 }
#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
631 {
632  uint32_t ui32TempVal;
633 
634  ui32TempVal = 0;
635 
636  if(ui32IntFlags & FLASH_INT_FSM_DONE)
637  {
638  ui32TempVal = FLASH_FEDACSTAT_FSM_DONE;
639  }
640 
641  if(ui32IntFlags & FLASH_INT_RV)
642  {
643  ui32TempVal |= FLASH_FEDACSTAT_RVF_INT;
644  }
645 
646  // Clear the flash interrupt source.
647  HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) = ui32TempVal;
648 }
#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
560 {
561  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
562  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) &= ~ui32IntFlags;
563  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
564 }
#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
538 {
539  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
540  HWREG(FLASH_BASE + FLASH_O_FSM_ST_MACHINE) |= ui32IntFlags;
541  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
542 }
#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.
489 {
490  // Register the interrupt handler.
491  IntRegister(INT_FLASH, pfnHandler);
492 
493  // Enable the flash interrupt.
494  IntEnable(INT_FLASH);
495 }
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().
578 {
579  uint32_t ui32IntFlags;
580 
581  ui32IntFlags = 0;
582 
583  // Check if FSM_DONE interrupt status is set.
584  if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_FSM_DONE)
585  {
586  ui32IntFlags = FLASH_INT_FSM_DONE;
587  }
588 
589  // Check if RVF_INT interrupt status is set.
590  if(HWREG(FLASH_BASE + FLASH_O_FEDACSTAT) & FLASH_FEDACSTAT_RVF_INT)
591  {
592  ui32IntFlags |= FLASH_INT_RV;
593  }
594 
595  return(ui32IntFlags);
596 }
#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.
514 {
515  // Disable the interrupts.
516  IntDisable(INT_FLASH);
517 
518  // Unregister the interrupt handler.
519  IntUnregister(INT_FLASH);
520 }
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().

173 {
174  uint32_t ui32PowerMode;
175  uint32_t ui32BankPwrMode;
176 
177  ui32BankPwrMode = HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &
178  FLASH_FBFALLBACK_BANKPWR0_M;
179 
180  if((ui32BankPwrMode == FBFALLBACK_SLEEP) &&
181  ((HWREG(FLASH_BASE + FLASH_O_FWFLAG) & FW_PWRMODE_DEPRECATED) == FW_PWRMODE_DEPRECATED))
182  {
183  ui32PowerMode = FLASH_PWR_DEEP_STDBY_MODE;
184  }
185  else if((ui32BankPwrMode == FBFALLBACK_SLEEP) &&
186  ((HWREG(FLASH_BASE + FLASH_O_FWFLAG) & FW_PWRMODE_DEPRECATED) == 0))
187  {
188  ui32PowerMode = FLASH_PWR_OFF_MODE;
189  }
190  else
191  {
192  ui32PowerMode = FLASH_PWR_ACTIVE_MODE;
193  }
194 
195  // Return power mode.
196  return(ui32PowerMode);
197 }
#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.

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 
135  // Set charge pump power mode to ACTIVE mode.
136  HWREG(FLASH_BASE + FLASH_O_FPAC1) =
137  (HWREG(FLASH_BASE + FLASH_O_FPAC1) & ~FLASH_FPAC1_PUMPPWR_M) | (1 << FLASH_FPAC1_PUMPPWR_S);
138  break;
139 
141  // Deprecated power mode requested. Set flag.
142  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 5;
143  HWREG(FLASH_BASE + FLASH_O_FWFLAG) |= FW_PWRMODE_DEPRECATED;
144  HWREG(FLASH_BASE + FLASH_O_FWLOCK) = 0;
145  // Fall through to force FLASH_PWR_OFF_MODE power mode
146  case FLASH_PWR_OFF_MODE:
147  // Set bank grace period.
148  HWREG(FLASH_BASE + FLASH_O_FBAC) =
149  (HWREG(FLASH_BASE + FLASH_O_FBAC) & (~FLASH_FBAC_BAGP_M)) |
150  ((ui32BankGracePeriod << FLASH_FBAC_BAGP_S) & FLASH_FBAC_BAGP_M);
151 
152  // Set pump grace period.
153  HWREG(FLASH_BASE + FLASH_O_FPAC2) =
154  (HWREG(FLASH_BASE + FLASH_O_FPAC2) & (~FLASH_FPAC2_PAGP_M)) |
155  ((ui32PumpGracePeriod << FLASH_FPAC2_PAGP_S) & FLASH_FPAC2_PAGP_M);
156 
157  // Set bank power mode to SLEEP.
158  HWREG(FLASH_BASE + FLASH_O_FBFALLBACK) &= ~FLASH_FBFALLBACK_BANKPWR0_M;
159 
160  // Set charge pump power mode to SLEEP mode.
161  HWREG(FLASH_BASE + FLASH_O_FPAC1) &= ~FLASH_FPAC1_PUMPPWR_M;
162  break;
163  }
164 }
#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().

358 {
359  uint32_t ui32ErrorReturn;
360  FlashPrgPointer_t FuncPointer;
361 
362  // Check the arguments.
363  ASSERT((ui32Address + ui32Count) <= (FLASHMEM_BASE + FlashSizeGet()));
364 
365  // Call ROM function that handles the actual program operation
366  FuncPointer = (uint32_t (*)(uint8_t *, uint32_t, uint32_t)) (ROM_API_FLASH_TABLE[6]);
367  ui32ErrorReturn = FuncPointer( pui8DataBuffer, ui32Address, ui32Count);
368 
369  // Enable standby in flash bank since ROM function might have disabled it
370  HWREGBITW(FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_STANDBY_BITN ) = 0;
371 
372  // Return status of operation.
373  return(ui32ErrorReturn);
374 
375 }
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().

244 {
245  uint32_t ui32SectorProtect;
246  uint32_t ui32SectorNumber;
247 
248  // Check the arguments.
249  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
250  FlashSectorSizeGet()));
251  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
252 
253  ui32SectorProtect = FLASH_NO_PROTECT;
254  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
255 
256  if(ui32SectorNumber <= 31)
257  {
258  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) & (1 << ui32SectorNumber)) &&
259  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) & (1 << ui32SectorNumber)))
260  {
261  ui32SectorProtect = FLASH_WRITE_PROTECT;
262  }
263  }
264  else if(ui32SectorNumber <= 63)
265  {
266  if((HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) &
267  (1 << (ui32SectorNumber & 0x1F))) &&
268  (HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) &
269  (1 << (ui32SectorNumber & 0x1F))))
270  {
271  ui32SectorProtect = FLASH_WRITE_PROTECT;
272  }
273  }
274 
275  return(ui32SectorProtect);
276 }
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().

285 {
286  uint32_t ui32ErrorReturn;
287  uint32_t ui32SectorNumber;
288  uint32_t ui32CcfgSectorAddr;
289  uint32_t ui32ProgBuf;
290 
291  ui32ErrorReturn = FAPI_STATUS_SUCCESS;
292 
293  // Check the arguments.
294  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
295  FlashSectorSizeGet()));
296  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
297 
298  if(FlashProtectionGet(ui32SectorAddress) == FLASH_WRITE_PROTECT)
299  {
300  // Find sector number for specified sector.
301  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
302  ui32CcfgSectorAddr = FLASHMEM_BASE + FlashSizeGet() - FlashSectorSizeGet();
303 
304  // Adjust CCFG address to the 32-bit CCFG word holding the
305  // protect-bit for the specified sector.
306  ui32CcfgSectorAddr += (((ui32SectorNumber >> 5) * 4) + CCFG_OFFSET_SECT_PROT);
307 
308  // Find value to program by setting the protect-bit which
309  // corresponds to specified sector number, to 0.
310  // Leave other protect-bits unchanged.
311  ui32ProgBuf = (~(1 << (ui32SectorNumber & 0x1F))) &
312  *(uint32_t *)ui32CcfgSectorAddr;
313 
314  ui32ErrorReturn = FlashProgram((uint8_t*)&ui32ProgBuf, ui32CcfgSectorAddr,
316  }
317 
318  // Return status.
319  return(ui32ErrorReturn);
320 }
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:243
#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:357
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().

206 {
207  uint32_t ui32SectorNumber;
208 
209  // Check the arguments.
210  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
211  FlashSectorSizeGet()));
212  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
213 
214  if(ui32ProtectMode == FLASH_WRITE_PROTECT)
215  {
216  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) /
218  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_ENABLE;
219 
220  if(ui32SectorNumber <= 31)
221  {
222  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE0) |= (1 << ui32SectorNumber);
223  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP0) |= (1 << ui32SectorNumber);
224  }
225  else if(ui32SectorNumber <= 63)
226  {
227  HWREG(FLASH_BASE + FLASH_O_FSM_BSLE1) |=
228  (1 << (ui32SectorNumber & 0x1F));
229  HWREG(FLASH_BASE + FLASH_O_FSM_BSLP1) |=
230  (1 << (ui32SectorNumber & 0x1F));
231  }
232 
233  HWREG(FLASH_BASE + FLASH_O_FSM_WR_ENA) = FSM_REG_WRT_DISABLE;
234  }
235 }
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().

329 {
330  uint32_t ui32ErrorReturn;
331  FlashSectorErasePointer_t FuncPointer;
332 
333  // Check the arguments.
334  ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() -
335  FlashSectorSizeGet()));
336  ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00);
337 
338  // Call ROM function that handles the actual erase operation
339  FuncPointer = (uint32_t (*)(uint32_t)) (ROM_API_FLASH_TABLE[5]);
340  ui32ErrorReturn = FuncPointer(ui32SectorAddress);
341 
342  // Enable standby in flash bank since ROM function might have disabled it
343  HWREGBITW(FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_STANDBY_BITN ) = 0;
344 
345  // Return status of operation.
346  return(ui32ErrorReturn);
347 
348 }
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