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...
 
uint32_t FlashProgram4X (uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
 
uint32_t FlashProgramNowait (uint32_t ui32StartAddress, uint8_t *pui8DataBuffer, uint8_t ui8NoOfBytes)
 Starts programming within unprotected main bank flash sector and returns. 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_FOURWORD = 0x0021, FAPI_PROGRAM_TWOWORD = 0x0011, FAPI_PROGRAM_ONEWORD = 0x0001, FAPI_ERASE_SECTOR = 0x0042,
  FAPI_ERASE_BANK = 0x0052, FAPI_CLEAR_STATUS = 0x0005, FAPI_READVERIFY = 0x0003
}
 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:

Referenced by FlashProgram(), FlashProgram4X(), and FlashSectorErase().

380 {
381  if(HWREG(NVMNW_BASE + NVMNW_O_STATCMD) & NVMNW_STATCMD_CMDPASS_M)
382  {
383  return(FAPI_STATUS_SUCCESS);
384  }
385  else
386  {
387  return(FAPI_STATUS_FSM_ERROR);
388  }
389 }
#define FAPI_STATUS_SUCCESS
Definition: flash.h:104
#define FAPI_STATUS_FSM_ERROR
Definition: flash.h:109

§ 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:

Referenced by FlashProgram(), FlashProgram4X(), and FlashSectorErase().

410 {
411  if(HWREG(NVMNW_BASE + NVMNW_O_STATCMD) & NVMNW_STATCMD_CMDDONE_M)
412  {
413  return(FAPI_STATUS_FSM_READY);
414  }
415  else
416  {
417  return(FAPI_STATUS_FSM_BUSY);
418  }
419 }
#define FAPI_STATUS_FSM_READY
Definition: flash.h:106
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:105

§ FlashDisableSectorsForWrite()

void FlashDisableSectorsForWrite ( void  )

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

This function is depreciated

Returns
None

Referenced by FlashIntClear().

1199 {
1200  // depreciated
1201  return;
1202 }

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

1139 {
1140  bool bStatus;
1141 
1142  // Make sure the clock for the efuse is enabled
1143  HWREG(FLASH_BASE + FLASH_O_CFG) &= ~FLASH_CFG_DIS_EFUSECLK;
1144 
1145  // Set timing for EFUSE read operations.
1146  HWREG(FLASH_BASE + FLASH_O_EFUSEREAD) |= ((5 << FLASH_EFUSEREAD_READCLOCK_S) &
1147  FLASH_EFUSEREAD_READCLOCK_M);
1148 
1149  // Clear status register.
1150  HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) = 0;
1151 
1152  // Select the FuseROM block 0.
1153  HWREG(FLASH_BASE + FLASH_O_EFUSEADDR) = 0x00000000;
1154 
1155  // Start the read operation.
1156  HWREG(FLASH_BASE + FLASH_O_EFUSE) =
1157  (DUMPWORD_INSTR << FLASH_EFUSE_INSTRUCTION_S) |
1158  (ui32RowAddress & FLASH_EFUSE_DUMPWORD_M);
1159 
1160  // Wait for operation to finish.
1161  while(!(HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) & FLASH_EFUSEERROR_DONE))
1162  {
1163  }
1164 
1165  // Check if error reported.
1166  if(HWREG(FLASH_BASE + FLASH_O_EFUSEERROR) & FLASH_EFUSEERROR_CODE_M)
1167  {
1168  // Set error status.
1169  bStatus = 1;
1170 
1171  // Clear data.
1172  *pui32EfuseData = 0;
1173  }
1174  else
1175  {
1176  // Set ok status.
1177  bStatus = 0;
1178 
1179  // No error. Get data from data register.
1180  *pui32EfuseData = HWREG(FLASH_BASE + FLASH_O_DATALOWER);
1181  }
1182 
1183  // Disable the efuse clock to conserve power
1184  HWREG(FLASH_BASE + FLASH_O_CFG) |= FLASH_CFG_DIS_EFUSECLK;
1185 
1186  // Return the data.
1187  return(bStatus);
1188 
1189 }
#define DUMPWORD_INSTR
Definition: flash.h:216

§ 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
577 {
578  HWREG(NVMNW_BASE + NVMNW_O_ICLR) = NVMNW_ICLR_DONE_CLR;
579 }
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
513 {
514  HWREG(NVMNW_BASE + NVMNW_O_IMASK) = NVMNW_IMASK_DONE_DISABLED;
515 }

§ 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
493 {
494  HWREG(NVMNW_BASE + NVMNW_O_IMASK) = NVMNW_IMASK_DONE_ENABLED;
495 }

§ 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.
444 {
445  // Register the interrupt handler.
446  IntRegister(INT_FLASH, pfnHandler);
447 
448  // Enable the flash interrupt.
449  IntEnable(INT_FLASH);
450 }
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().
529 {
530  uint32_t ui32IntFlags;
531 
532  ui32IntFlags = 0;
533  if (HWREG(NVMNW_BASE + NVMNW_O_RIS) & NVMNW_RIS_DONE_M)
534  {
535  ui32IntFlags = NVMNW_RIS_DONE_SET;
536  }
537  else
538  {
539  ui32IntFlags = NVMNW_RIS_DONE_CLR;
540  }
541  return(ui32IntFlags);
542 }

§ 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.
469 {
470  // Disable the interrupts.
471  IntDisable(INT_FLASH);
472 
473  // Unregister the interrupt handler.
474  IntUnregister(INT_FLASH);
475 }
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 is depreciated

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

Referenced by FlashSizeGet().

140 {
141  // depreciated
143 }
#define FAPI_STATUS_NOSUPPORT_ERROR
Definition: flash.h:113

§ FlashPowerModeSet()

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

Set power mode.

This function is depreciated

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

128 {
129  // depreciaed
130  return ;
131 }

§ 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(), FlashProtectionSave(), and FlashSectorErase().

630 {
631  // The below code part constitutes the variant of the FlashProgram() function
632  // that is located in ROM. The source code of this variant is not visible in
633  // internal or external driverlib. The source code is only compiled during a ROM
634  // build.
635  // The two above code parts (seperated by compile switches) constitute wrapper
636  // functions which both call this ROM variant of the function.
637  // The ROM variant is called by referrencing it directly through the ROM API table.
638  uint32_t ui32StartIndex;
639  uint32_t ui32StopIndex;
640  uint8_t ui8BankWidth;
641  uint8_t ui8NoOfBytes;
642  uint32_t ui32ErrorReturn;
643  uint32_t ui32SectorNum;
644  uint32_t ui32BankNum;
645  uint32_t ui32Region;
646  uint32_t bank0Size;
647  uint32_t ui32NoOfSectorsBank0;
648  tFlashStateCommandsType StateMachineCmd;
649  uint32_t sectorSize;
650 
651  sectorSize = FlashSectorSizeGet();
652 
653  // Check the arguments.
654  // onlt main region and non-main CCFG
655  ui32BankNum = 0;
656  if ( (ui32Address + ui32Count) <= (FLASHMEM_BASE + FlashSizeGet()) )
657  {
658  bank0Size = ((HWREG(NVMNW_BASE + NVMNW_O_BANK0INFO0) &
659  NVMNW_BANK0INFO0_MAINSIZE_M) >>
660  NVMNW_BANK0INFO0_MAINSIZE_S) * sectorSize;
661 
662  if (ui32Address >= bank0Size)
663  ui32BankNum = 1;
664 
665  // address is in the main region
666  ui32Region = NVMNW_CMDCTL_REGIONSEL_MAIN ;
667 
668  ui32NoOfSectorsBank0 = (HWREG(NVMNW_BASE + NVMNW_O_BANK0INFO0) &
669  NVMNW_BANK0INFO0_MAINSIZE_M) >>
670  NVMNW_BANK0INFO0_MAINSIZE_S;
671  }
672  else if ( ( ui32Address >= (CCFG_BASE_DEFAULT) ) &&
673  ( (ui32Address + ui32Count) <= (CCFG_BASE_DEFAULT + sectorSize) ) )
674  {
675  // the address is CCFG in non-main region (bank 0)
676  ui32Region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
677  ui32BankNum = 0;
678 
679  }
680  else if ( ( ui32Address >= (FCFG1_BASE) ) &&
681  ( (ui32Address + ui32Count) <= (FCFG1_BASE + sectorSize) ) )
682  {
683  // the address is FCFG1 in non-main region, ( bank 1 )
684  ui32Region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
685  ui32BankNum = 1;
686 
687  }
688  else
689  { // address is wrong
691  }
692 
693  // Set the status to indicate success.
694  ui32ErrorReturn = FAPI_STATUS_SUCCESS;
695 
696  // Find flash bank width in number of bytes.
697  ui8BankWidth = (((HWREG(NVMNW_BASE + NVMNW_O_GBLINFO1) &
698  NVMNW_GBLINFO1_DATAWIDTH_M ) >>
699  NVMNW_GBLINFO1_DATAWIDTH_S) >> 3);
700 
701  // dataIndex =0 for all modes (1X,2X,4X)
702  HWREG(NVMNW_BASE + NVMNW_O_CMDDATAINDEX) = 0x0000;
703 
704  while ( ui32Count)
705  {
706  // Clear the Status register.
708 
709  // set up WEPROT register
710  // based on the flash address to figure out WEPROT register for each state machine command
711  if ( ui32Region == NVMNW_CMDCTL_REGIONSEL_MAIN)
712  { // for main region
713  // based on the flash address, get the sector number on fly
714  ui32SectorNum = (ui32Address - FLASHMEM_BASE) / sectorSize;
715 
716  // for main flash region
717  // Unprotect sector to be erased.
718  // sectorNum = sectorAddr / sectorSize
719  // if sectorNum < 256 (number of sector in bank0)
720  // set bankNum =0
721  // else set bankNum =1
722  //
723  // if sectorNum<32, it is the first 32 sector, it is 2K protect, use the rgister A
724  // registerA = 1<<sectorNum
725  // if sector>=32 and sector<256, select bank0, registerB
726  // registerB = 1<< ( (sectorNum-32)/8 + 4)
727  // if (sector>256)
728  // select Bank=1, registerB = 1<< (sectorNum-256)/8
729  //
730 
731  // set up Dynamic Write/Erase Protect to unprotect mode (clear the bit)
732  if ( ui32SectorNum < 32)
733  {
734  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTA) &= ~(1 << ui32SectorNum);
735  }
736  else if ( ui32SectorNum < ui32NoOfSectorsBank0)
737  {
738  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTB) &= ~( 1 << ((ui32SectorNum-32)/8 + 4));
739  }
740  else
741  {
742  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTB) &= ~( 1 << ((ui32SectorNum - ui32NoOfSectorsBank0)/8));
743  }
744 
745  // set up the command address, translate to Flash word adress
746  // address is relative to each bank, translate to Flash word address
747  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32Address & ( bank0Size -1) )>> 4;
748  }
749  else
750  { // for NON-main region (CCFG) and FCFG1
751  if ( ui32BankNum == 0)
752  {
753  // the address is CCFG in non-main region
754  ui32SectorNum = (ui32Address - CCFG_BASE_DEFAULT) / sectorSize;
755  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTNM) &= ~( 1 << (ui32SectorNum ));
756 
757  // set up the command address, translate to Flash word adress
758  // address is relative to each bank, translate to Flash word address
759  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32Address - CCFG_BASE_DEFAULT )>> 4;
760  }
761  else
762  {
763  // the address is FCFG1 in non-main region
764  ui32SectorNum = (ui32Address - FCFG1_BASE) / sectorSize;
765  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTNM) &= ~( 1 << (ui32SectorNum ));
766 
767  // set up the command address, translate to Flash word adress
768  // address is relative to each bank, translate to Flash word address
769  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32Address - FCFG1_BASE )>> 4;
770 
771  }
772  }
773 
774  // set up NW control register
775  /*
776  21 enable data verification for 1T only
777  19 Stair Step Erase =0
778  18 erase mask disable 0
779  17 Program mask disable (0)
780  16 ECC override (no ECC) 0
781  15 address translate overrid =1
782  14 post verify enable (1)
783  13 preverify enable (1)
784  12:9 regionsel = 1 (main region)/Non-Main
785  8:4 bank selection = 0 or 1
786  3:0 N/A (only for mode change)
787  */
788 
789  HWREG(NVMNW_BASE + NVMNW_O_CMDCTL) = (NVMNW_CMDCTL_BANKSEL_BANK0 <<(ui32BankNum)) |
790  NVMNW_CMDCTL_DATAVEREN |
791  (ui32Region) |
792  NVMNW_CMDCTL_ADDRXLATEOVR_OVERRIDE |
793  NVMNW_CMDCTL_POSTVEREN_ENABLE |
794  NVMNW_CMDCTL_PREVEREN_ENABLE ;
795 
796  // based on the ui32Address alignment and ui32Count to figure oue
797  // 1. if ui32Address is 4X Flashword aligned and ui32Count>=4X flashword
798  // goto 4X program mode
799  // 2. if ui32Address is 2X Flashword aligned and ui32Count>=2X flashword
800  // goto 2X program mode
801  // 3. otherwise
802  // goto 1X program mode (default mode)
803 
804  if ( (( ui32Address & ( FLASHWORDSIZE_FOUR -1 ) ) == 0x00 ) &&
805  ( ui32Count >= FLASHWORDSIZE_FOUR ) )
806  { // 4X program mode
807  ui8NoOfBytes = FlashCopyMultiFlashWordToHW (pui8DataBuffer,ui32Address,FLASHWORDSIZE_FOUR);
808 
809  StateMachineCmd = FAPI_PROGRAM_FOURWORD;
810  }
811  else if ( (( ui32Address & ( FLASHWORDSIZE_TWO -1 ) ) == 0x00 ) &&
812  ( ui32Count >= FLASHWORDSIZE_TWO ) )
813  { // 2X program mode
814  ui8NoOfBytes = FlashCopyMultiFlashWordToHW (pui8DataBuffer,ui32Address,FLASHWORDSIZE_TWO);
815 
816  StateMachineCmd = FAPI_PROGRAM_TWOWORD;
817  }
818  else
819  { // 1X program mode
820 
821  // Setup the start position within the write data registers.
822  ui32StartIndex = ui32Address & (uint32_t)(ui8BankWidth - 1);
823 
824  // setup number of bytes to program
825  ui8NoOfBytes = ui8BankWidth - ui32StartIndex;
826  if(ui8NoOfBytes > ui32Count)
827  {
828  ui8NoOfBytes = ui32Count;
829  }
830 
831  // Setup the stop position within the write data registers.
832  ui32StopIndex = ui32StartIndex + (uint32_t)(ui8NoOfBytes - 1);
833 
834  // Write each byte to the Flash Data registers
835  FlashCopyOneFlashWordToHW(pui8DataBuffer,ui32Address,
836  ui32StartIndex,ui32StopIndex);
837  StateMachineCmd = FAPI_PROGRAM_ONEWORD;
838  }
839 
840  // Issue the Program command to the FSM.
841  IssueFsmCommand(StateMachineCmd);
842 
843  // Wait until the word has been programmed.
845  {
846  }
847 
848  // Exit if an access violation occurred.
849  ui32ErrorReturn = FlashCheckFsmForError();
850  if(ui32ErrorReturn != FAPI_STATUS_SUCCESS)
851  {
852  break;
853  }
854 
855  // Prepare for next data burst.
856  ui32Count -= ui8NoOfBytes;
857  ui32Address += ui8NoOfBytes;
858  pui8DataBuffer += ui8NoOfBytes;
859 
860  // Check if next data burst require change of target bank
861  if( (ui32Region == NVMNW_CMDCTL_REGIONSEL_MAIN) &&
862  (ui32BankNum == 0) && (ui32Address >= bank0Size))
863  {
864  // Change target bank.
865  ui32BankNum = 1;
866  }
867 
868  }
869 
870  // Return status of operation.
871  return(ui32ErrorReturn);
872 }
static uint32_t FlashCopyMultiFlashWordToHW(uint8_t *pBuf, uint32_t FlashAddr, uint32_t numBytes)
Definition: flash.c:587
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
Program 4 Flash Word Mode.
Definition: flash.h:176
#define FLASHWORDSIZE_TWO
Definition: flash.h:166
static uint32_t FlashCheckFsmForReady(void)
Checks if the Flash state machine is ready.
Definition: flash.h:409
Program 1 Flash word mode.
Definition: flash.h:178
#define FAPI_STATUS_SUCCESS
Definition: flash.h:104
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:251
Clear status.
Definition: flash.h:181
tFlashStateCommandsType
Defined values for Flash State Machine commands.
Definition: flash.h:174
#define FLASHWORDSIZE_FOUR
Definition: flash.h:165
Program 4 Flash Word Mode.
Definition: flash.h:177
static uint32_t FlashCopyOneFlashWordToHW(uint8_t *pBuf, uint32_t FlashAddr, uint32_t startIdx, uint32_t endIdx)
Definition: flash.c:542
static uint32_t FlashCheckFsmForError(void)
Checks if the Flash state machine has detected an error.
Definition: flash.h:379
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:105
static void IssueFsmCommand(tFlashStateCommandsType eCommand)
Definition: flash.c:1217
#define FAPI_STATUS_ADDRESS_ERROR
Definition: flash.h:110
Here is the call graph for this function:

§ FlashProgram4X()

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

Referenced by FlashIntClear().

874  {
875  // The below code part constitutes the variant of the FlashProgram() function
876  // that is located in ROM. The source code of this variant is not visible in
877  // internal or external driverlib. The source code is only compiled during a ROM
878  // build.
879  // The two above code parts (seperated by compile switches) constitute wrapper
880  // functions which both call this ROM variant of the function.
881  // The ROM variant is called by referrencing it directly through the ROM API table.
882  uint32_t ui32StartIndex;
883  uint32_t ui32StopIndex;
884  uint8_t ui8BankWidth;
885  uint8_t ui8NoOfBytes;
886  uint32_t ui32ErrorReturn;
887  uint32_t ui32SectorNum;
888  uint32_t ui32BankNum;
889  uint32_t ui32Region;
890  uint32_t bank0Size;
891  uint32_t ui32NoOfSectorsBank0;
892  tFlashStateCommandsType StateMachineCmd;
893  uint32_t sectorSize;
894 
895  sectorSize = FlashSectorSizeGet();
896 
897  // Check the arguments.
898  // onlt main region and non-main CCFG
899  ui32BankNum = 0;
900  if ( (ui32Address + ui32Count) <= (FLASHMEM_BASE + FlashSizeGet()) )
901  { // get bank-0 size
902  bank0Size = ((HWREG(NVMNW_BASE + NVMNW_O_BANK0INFO0) &
903  NVMNW_BANK0INFO0_MAINSIZE_M) >>
904  NVMNW_BANK0INFO0_MAINSIZE_S) * sectorSize;
905 
906  if (ui32Address >= bank0Size)
907  ui32BankNum = 1;
908 
909  // address is in the main region
910  ui32Region = NVMNW_CMDCTL_REGIONSEL_MAIN ;
911 
912  ui32NoOfSectorsBank0 = (HWREG(NVMNW_BASE + NVMNW_O_BANK0INFO0) &
913  NVMNW_BANK0INFO0_MAINSIZE_M) >>
914  NVMNW_BANK0INFO0_MAINSIZE_S;
915  }
916  else if ( ( ui32Address >= (CCFG_BASE_DEFAULT) ) &&
917  ( (ui32Address + ui32Count) <= (CCFG_BASE_DEFAULT + sectorSize ) ) )
918  {
919  // the address is CCFG in non-main region
920  ui32Region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
921  ui32BankNum = 0;
922 
923  }
924  else if ( ( ui32Address >= (FCFG1_BASE) ) &&
925  ( (ui32Address + ui32Count) <= (FCFG1_BASE + sectorSize) ) )
926  {
927  // the address is FCFG1 in non-main region, ( bank 1 )
928  ui32Region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
929  ui32BankNum = 1;
930 
931  }
932  else
933  { // address is wrong
935  }
936 
937  // Set the status to indicate success.
938  ui32ErrorReturn = FAPI_STATUS_SUCCESS;
939 
940  // Find flash bank width in number of bytes.
941  ui8BankWidth = (((HWREG(NVMNW_BASE + NVMNW_O_GBLINFO1) &
942  NVMNW_GBLINFO1_DATAWIDTH_M ) >>
943  NVMNW_GBLINFO1_DATAWIDTH_S) >> 3);
944 
945  // dataIndex =0 for all modes (1X,2X,4X)
946  HWREG(NVMNW_BASE + NVMNW_O_CMDDATAINDEX) = 0x0000;
947 
948  while ( ui32Count)
949  {
950  // Clear the Status register.
952 
953  // set up WEPROT register
954  // based on the flash address to figure out WEPROT register for each state machine command
955  if ( ui32Region == NVMNW_CMDCTL_REGIONSEL_MAIN)
956  { // for main region
957  // based on the flash address, get the sector number on fly
958  ui32SectorNum = (ui32Address - FLASHMEM_BASE) / sectorSize;
959 
960  // for main flash region
961  // Unprotect sector to be erased.
962  // sectorNum = sectorAddr / sectorSize
963  // if sectorNum < 256 (number of sector in bank0)
964  // set bankNum =0
965  // else set bankNum =1
966  //
967  // if sectorNum<32, it is the first 32 sector, it is 2K protect, use the rgister A
968  // registerA = 1<<sectorNum
969  // if sector>=32 and sector<256, select bank0, registerB
970  // registerB = 1<< ( (sectorNum-32)/8 + 4)
971  // if (sector>256)
972  // select Bank=1, registerB = 1<< (sectorNum-256)/8
973  //
974 
975  // set up Dynamic Write/Erase Protect to unprotect mode (clear the bit)
976  if ( ui32SectorNum < 32)
977  {
978  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTA) &= ~(1 << ui32SectorNum);
979  }
980  else if ( ui32SectorNum < ui32NoOfSectorsBank0)
981  {
982  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTB) &= ~( 1 << ((ui32SectorNum-32)/8 + 4));
983  }
984  else
985  {
986  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTB) &= ~( 1 << ((ui32SectorNum - ui32NoOfSectorsBank0)/8));
987  }
988 
989  // set up the command address, translate to Flash word adress
990  // address is relative to each bank, translate to Flash word address
991  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32Address & ( bank0Size -1) )>> 4;
992  }
993  else
994  { // for NON-main region (CCFG)
995  // the address is CCFG in non-main region
996  if ( ui32BankNum ==0 )
997  {
998  ui32SectorNum = (ui32Address - CCFG_BASE_DEFAULT) / sectorSize;
999  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTNM) &= ~( 1 << (ui32SectorNum));
1000 
1001  // set up the command address, translate to Flash word adress
1002  // address is relative to each bank, translate to Flash word address
1003  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32Address - CCFG_BASE_DEFAULT )>> 4;
1004  }
1005  else
1006  {
1007  // the address is FCFG1 in non-main region
1008  ui32SectorNum = (ui32Address - FCFG1_BASE) / sectorSize;
1009  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTNM) &= ~( 1 << (ui32SectorNum ));
1010 
1011  // set up the command address, translate to Flash word adress
1012  // address is relative to each bank, translate to Flash word address
1013  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32Address - FCFG1_BASE )>> 4;
1014 
1015  }
1016  }
1017 
1018  // set up NW control register
1019  /*
1020  21 enable the data verification for 1T only
1021  19 Stair Step Erase =0
1022  18 erase mask disable 0
1023  17 Program mask disable (0)
1024  16 ECC override (no ECC) 0
1025  15 address translate overrid =1
1026  14 post verify enable (1)
1027  13 preverify enable (1)
1028  12:9 regionsel = 1 (main region)/Non-Main
1029  8:4 bank selection = 0 or 1
1030  3:0 N/A (only for mode change)
1031  */
1032 
1033  HWREG(NVMNW_BASE + NVMNW_O_CMDCTL) = (NVMNW_CMDCTL_BANKSEL_BANK0 <<(ui32BankNum)) |
1034  NVMNW_CMDCTL_DATAVEREN |
1035  (ui32Region) |
1036  NVMNW_CMDCTL_ADDRXLATEOVR_OVERRIDE |
1037  NVMNW_CMDCTL_POSTVEREN_ENABLE |
1038  NVMNW_CMDCTL_PREVEREN_ENABLE ;
1039 
1040  // based on the ui32Address alignment and ui32Count to figure oue
1041  // 1. if ui32Address is 4X Flashword aligned and ui32Count>=4X flashword
1042  // goto 4X program mode
1043  // 2. if ui32Address is 2X Flashword aligned and ui32Count>=2X flashword
1044  // goto 2X program mode
1045  // 3. otherwise
1046  // goto 1X program mode (default mode)
1047 
1048  if ( (( ui32Address & ( FLASHWORDSIZE_FOUR -1 ) ) == 0x00 ) &&
1049  ( ui32Count >= FLASHWORDSIZE_FOUR ) )
1050  { // 4X program mode
1051  ui8NoOfBytes = FlashCopyMultiFlashWordToHW (pui8DataBuffer,ui32Address,FLASHWORDSIZE_FOUR);
1052 
1053  StateMachineCmd = FAPI_PROGRAM_FOURWORD;
1054  }
1055  else if ( (( ui32Address & ( FLASHWORDSIZE_TWO -1 ) ) == 0x00 ) &&
1056  ( ui32Count >= FLASHWORDSIZE_TWO ) )
1057  { // 2X program mode
1058  ui8NoOfBytes = FlashCopyMultiFlashWordToHW (pui8DataBuffer,ui32Address,FLASHWORDSIZE_TWO);
1059 
1060  StateMachineCmd = FAPI_PROGRAM_TWOWORD;
1061  }
1062  else
1063  { // 1X program mode
1064 
1065  // Setup the start position within the write data registers.
1066  ui32StartIndex = ui32Address & (uint32_t)(ui8BankWidth - 1);
1067 
1068  // setup number of bytes to program
1069  ui8NoOfBytes = ui8BankWidth - ui32StartIndex;
1070  if(ui8NoOfBytes > ui32Count)
1071  {
1072  ui8NoOfBytes = ui32Count;
1073  }
1074 
1075  // Setup the stop position within the write data registers.
1076  ui32StopIndex = ui32StartIndex + (uint32_t)(ui8NoOfBytes - 1);
1077 
1078  // Write each byte to the Flash Data registers
1079  FlashCopyOneFlashWordToHW(pui8DataBuffer,ui32Address,
1080  ui32StartIndex,ui32StopIndex);
1081  StateMachineCmd = FAPI_PROGRAM_ONEWORD;
1082  }
1083 
1084  // Issue the Program command to the FSM.
1085  IssueFsmCommand(StateMachineCmd);
1086 
1087  // Wait until the word has been programmed.
1089  {
1090  }
1091 
1092  // Exit if an access violation occurred.
1093  ui32ErrorReturn = FlashCheckFsmForError();
1094  if(ui32ErrorReturn != FAPI_STATUS_SUCCESS)
1095  {
1096  break;
1097  }
1098 
1099  // Prepare for next data burst.
1100  ui32Count -= ui8NoOfBytes;
1101  ui32Address += ui8NoOfBytes;
1102  pui8DataBuffer += ui8NoOfBytes;
1103 
1104  // Check if next data burst require change of target bank
1105  if( (ui32Region == NVMNW_CMDCTL_REGIONSEL_MAIN) &&
1106  (ui32BankNum == 0) && (ui32Address >= bank0Size))
1107  {
1108  // Change target bank.
1109  ui32BankNum = 1;
1110  }
1111 
1112  }
1113 
1114  // Return status of operation.
1115  return(ui32ErrorReturn);
1116 }
static uint32_t FlashCopyMultiFlashWordToHW(uint8_t *pBuf, uint32_t FlashAddr, uint32_t numBytes)
Definition: flash.c:587
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
Program 4 Flash Word Mode.
Definition: flash.h:176
#define FLASHWORDSIZE_TWO
Definition: flash.h:166
static uint32_t FlashCheckFsmForReady(void)
Checks if the Flash state machine is ready.
Definition: flash.h:409
Program 1 Flash word mode.
Definition: flash.h:178
#define FAPI_STATUS_SUCCESS
Definition: flash.h:104
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:251
Clear status.
Definition: flash.h:181
tFlashStateCommandsType
Defined values for Flash State Machine commands.
Definition: flash.h:174
#define FLASHWORDSIZE_FOUR
Definition: flash.h:165
Program 4 Flash Word Mode.
Definition: flash.h:177
static uint32_t FlashCopyOneFlashWordToHW(uint8_t *pBuf, uint32_t FlashAddr, uint32_t startIdx, uint32_t endIdx)
Definition: flash.c:542
static uint32_t FlashCheckFsmForError(void)
Checks if the Flash state machine has detected an error.
Definition: flash.h:379
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:105
static void IssueFsmCommand(tFlashStateCommandsType eCommand)
Definition: flash.c:1217
#define FAPI_STATUS_ADDRESS_ERROR
Definition: flash.h:110
Here is the call graph for this function:

§ FlashProgramNowait()

uint32_t FlashProgramNowait ( uint32_t  ui32StartAddress,
uint8_t *  pui8DataBuffer,
uint8_t  ui8NoOfBytes 
)

Starts programming within unprotected main bank flash sector and returns.

This function is depreciated

The pui8DataBuffer pointer can not point to flash.

Parameters
ui32StartAddressis the start address in flash to program.
pui8DataBufferis a pointer to the data to be programmed.
ui8NoOfBytesis the number of bytes to program.
Returns
Returns the status of the flash programming start:

Referenced by FlashIntClear().

1127 {
1128  // Return the function status.
1129  return (FAPI_STATUS_NOSUPPORT_ERROR);
1130 }
#define FAPI_STATUS_NOSUPPORT_ERROR
Definition: flash.h:113

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

221 {
222  uint32_t ui32SectorProtect;
223  uint32_t ui32SectorNumber;
224  uint32_t ui32Mask,ui32result;
225  uint32_t region;
226 
227  // Check the arguments.
228  // only Bank 0 first 32 sectors are protected
229  // for CCFG which is in non-main region
230  // sector address should be aligned on sector size
231  // inverted logic: in CCFG
232 
233  if ((ui32SectorAddress & (FlashSectorSizeGet() - 1)) != 00)
234  {
236  }
237 
238  if (ui32SectorAddress < (FLASHMEM_BASE + FlashSectorSizeGet() * 32))
239  {
240  // address is in the main region
241  // FLASH_O_WEPROT_B0_31_0_BY1 only first 32 sectors are static protected
242  region = NVMNW_CMDCTL_REGIONSEL_MAIN ;
243 
244  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
245  ui32Mask = 1 << (ui32SectorNumber);
246  }
247  else if ( ( ui32SectorAddress >= (CCFG_BASE_DEFAULT) ) &&
248  ( ui32SectorAddress < (CCFG_BASE_DEFAULT + FlashSectorSizeGet() ) ) )
249  {
250  // the address is CCFG in non-main region
251  // non main region only one sector for each region
252  region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
253  ui32Mask = FLASH_WEPROT_AUX_BY1_WEPROT_B0_CCFG_BY1_M;
254  }
255  else
256  { // address is wrong
258  }
259 
260  if (region == NVMNW_CMDCTL_REGIONSEL_MAIN )
261  {
262  ui32result = HWREG(FLASH_BASE + FLASH_O_WEPROT_B0_31_0_BY1) & ui32Mask;
263  }
264  else
265  {
266  ui32result = HWREG(FLASH_BASE + FLASH_O_WEPROT_AUX_BY1) & ui32Mask;
267  }
268 
269  if (ui32result)
270  {
271  ui32SectorProtect = FLASH_WRITE_PROTECT;
272  }
273  else
274  {
275  ui32SectorProtect = FLASH_NO_PROTECT;
276  }
277 
278  return ui32SectorProtect;
279 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
#define FAPI_STATUS_ADDRESS_ALIGN_ERROR
Definition: flash.h:111
#define FLASH_NO_PROTECT
Definition: flash.h:144
#define FLASH_WRITE_PROTECT
Definition: flash.h:145
#define FAPI_STATUS_ADDRESS_ERROR
Definition: flash.h:110
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().

288 {
289  uint32_t ui32SectorProtect;
290  uint32_t ui32SectorNumber;
291  uint32_t ui32Mask;
292  uint32_t ui32ErrorReturn;
293  uint32_t ui32CcfgSectorAddr;
294  uint32_t ccfgVal;
295 
296  // Check the arguments.
297  // only Bank 0 first 32 sectors are protected
298  // for CCFG which is in non-main region
299  // sector address should be aligned on sector size
300 
301  if ((ui32SectorAddress & (FlashSectorSizeGet() - 1)) != 00)
302  {
304  }
305 
306  if (ui32SectorAddress < (FLASHMEM_BASE + FlashSectorSizeGet() * 32))
307  {
308  // address is in the main region
309  // FLASH_O_WEPROT_B0_31_0_BY1 only first 32 sectors are static protected
310 
311  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
312  ui32Mask = 1 << (ui32SectorNumber);
313 
314  ui32CcfgSectorAddr = CCFG_BASE_DEFAULT + CCFG_O_CCFG_WEPROT_31_0_BY2K;
315  }
316  else if ( ( ui32SectorAddress >= (CCFG_BASE_DEFAULT) ) &&
317  ( ui32SectorAddress < (CCFG_BASE_DEFAULT + FlashSectorSizeGet() ) ) )
318  {
319  // the address is CCFG in non-main region
320  // non main region only one sector for each region
321  ui32Mask = CCFG_ERASE_CONF_1_WEPROT_CCFG_N_M;
322 
323  ui32CcfgSectorAddr = CCFG_BASE_DEFAULT + CCFG_O_ERASE_CONF_1;
324  }
325  else
326  { // address is wrong
328  }
329 
330  // read from Flash static protection register
331  ui32SectorProtect = FlashProtectionGet(ui32SectorAddress) ;
332  ui32ErrorReturn = FAPI_STATUS_UNPROTECT_ERROR ;
333  // CCFG change
334  // unprotected (1) ==> protect (0) (allow)
335  // protected (0) ==> protect (0) (no chnage with FlashProgram call)
336  // unprotected (1) ==> unprotect (1) (no action, no FlashProgram call)
337  // protected (0) ==> unprotect (1) (no possible without erase, no Flashprogram Call)
338 
339  if(ui32SectorProtect == FLASH_WRITE_PROTECT)
340  {
341  // Find sector number for specified sector. (conversion)
342  // write 1: unprotected
343  // write 0: protected
344  // from unprotected mode ==> protected mode
345  // from protected mode ==> unprotected mode (need reset ??)
346  //
347  // only change one bit from unprotec (CCFG value=1 ) to protect (CCFG value =0)
348 
349  // read from the CCFG
350  ccfgVal = HWREG(ui32CcfgSectorAddr);
351  // clear the bit to protetc the sector
352  ccfgVal &= (~ui32Mask);
353  ui32SectorProtect = ~ui32Mask;
354 
355  // write the cleared bit back to CCFG
356  // need to reset to take effect
357  ui32ErrorReturn = FlashProgram((uint8_t*)&ccfgVal, ui32CcfgSectorAddr,
359  }
360 
361  // Return status.
362  return(ui32ErrorReturn);
363 }
#define FAPI_STATUS_UNPROTECT_ERROR
Definition: flash.h:115
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
uint32_t FlashProtectionGet(uint32_t ui32SectorAddress)
Get sector protection.
Definition: flash.c:220
#define FAPI_STATUS_ADDRESS_ALIGN_ERROR
Definition: flash.h:111
#define CCFG_SIZE_SECT_PROT
Definition: flash.c:84
#define FLASH_WRITE_PROTECT
Definition: flash.h:145
uint32_t FlashProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected flash sectors in the main bank.
Definition: flash.c:629
#define FAPI_STATUS_ADDRESS_ERROR
Definition: flash.h:110
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().

151 {
152  uint32_t ui32SectorNumber;
153  uint32_t ui32Mask;
154  uint32_t ui32SetMask;
155  uint32_t region;
156 
157  // Check the arguments.
158  // only Bank 0 first 32 sectors are protected
159  // for CCFG which is in non-main region
160  // sector address should be aligned on sector size
161 
162  if ((ui32SectorAddress & (FlashSectorSizeGet() - 1)) != 00)
163  {
164  //return FAPI_STATUS_ADDRESS_ALIGN_ERROR;
165  return;
166  }
167 
168  if (ui32SectorAddress < (FLASHMEM_BASE + FlashSectorSizeGet() * 32))
169  {
170  // address is in the main region
171  // FLASH_O_WEPROT_B0_31_0_BY1 only first 32 sectors are static protected
172  region = NVMNW_CMDCTL_REGIONSEL_MAIN ;
173 
174  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
175  ui32Mask = 1 << (ui32SectorNumber);
176  }
177  else if ( ( ui32SectorAddress >= (CCFG_BASE_DEFAULT) ) &&
178  ( ui32SectorAddress < (CCFG_BASE_DEFAULT + FlashSectorSizeGet() ) ) )
179  {
180  // the address is CCFG in non-main region
181  // non main region only one sector for each region
182  region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
183  ui32Mask = FLASH_WEPROT_AUX_BY1_WEPROT_B0_CCFG_BY1_M;
184  }
185  else
186  { // address is wrong
187  //return FAPI_STATUS_ADDRESS_ERROR;
188  return;
189  }
190 
191  if(ui32ProtectMode == FLASH_WRITE_PROTECT)
192  { // set the corresponding bit
193  ui32SetMask = ui32Mask;
194  }
195  else
196  { // clear the corresponding bit
197  ui32SetMask = 0;
198  }
199 
200  if (region == NVMNW_CMDCTL_REGIONSEL_MAIN )
201  { // clear the bit based on mask and set the bit
202  HWREG(FLASH_BASE + FLASH_O_WEPROT_B0_31_0_BY1) &= ~ui32Mask;
203  HWREG(FLASH_BASE + FLASH_O_WEPROT_B0_31_0_BY1) |= ui32SetMask;
204  }
205  else
206  { // clear the bit based on mask and set the bit
207  HWREG(FLASH_BASE + FLASH_O_WEPROT_AUX_BY1) &= ~ui32Mask;
208  HWREG(FLASH_BASE + FLASH_O_WEPROT_AUX_BY1) |= ui32SetMask;
209  }
210 
211  return;
212 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
#define FLASH_WRITE_PROTECT
Definition: flash.h:145
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().

372 {
373  // The below code part constitutes the variant of the FlashSectorErase()
374  // function that is located in ROM. The source code of this variant is not
375  // visible in internal or external driverlib. The source code is
376  // only compiled during a ROM build.
377  // The two above code parts (seperated by compile switches) constitute wrapper
378  // functions which both call this ROM variant of the function.
379  // The ROM variant is called by referrencing it directly through the ROM API table.
380  uint32_t ui32ErrorReturn;
381  uint32_t ui32SectorNumber;
382  uint32_t ui32NoOfSectorsBank0;
383  uint32_t ui32BankNum;
384  uint32_t ui32Region;
385  uint32_t bank0Size;
386 
387  if ((ui32SectorAddress & (FlashSectorSizeGet() - 1)) != 00)
388  {
390  }
391 
392  if ( ui32SectorAddress < (FLASHMEM_BASE + FlashSizeGet()) )
393  {
394  bank0Size = ((HWREG(NVMNW_BASE + NVMNW_O_BANK0INFO0) &
395  NVMNW_BANK0INFO0_MAINSIZE_M) >>
396  NVMNW_BANK0INFO0_MAINSIZE_S) * FlashSectorSizeGet();
397  // address is in the main region
398  ui32Region = NVMNW_CMDCTL_REGIONSEL_MAIN ;
399 
400  ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet();
401  }
402  else if ( ( ui32SectorAddress >= (CCFG_BASE_DEFAULT) ) &&
403  ( ui32SectorAddress < (CCFG_BASE_DEFAULT + FlashSectorSizeGet() ) ) )
404  {
405  // the address is CCFG in non-main region, bank 0
406  ui32Region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
407  ui32SectorNumber = (ui32SectorAddress - CCFG_BASE_DEFAULT) / FlashSectorSizeGet();
408  ui32BankNum = 0;
409  }
410  else if ( ( ui32SectorAddress >= (FCFG1_BASE) ) &&
411  ( ui32SectorAddress < (FCFG1_BASE + FlashSectorSizeGet() ) ) )
412  {
413  // the address is FCFG1 in non-main region, bank 1
414  ui32Region = NVMNW_CMDCTL_REGIONSEL_NONMAIN ;
415  ui32SectorNumber = (ui32SectorAddress - FCFG1_BASE) / FlashSectorSizeGet();
416  ui32BankNum = 1;
417  }
418  else
419  { // address is wrong
421  }
422 
423  // Clear the Status register.
425 
426  if ( ui32Region == NVMNW_CMDCTL_REGIONSEL_MAIN )
427  {
428  // for main flash region
429  // Unprotect sector to be erased.
430  // sectorNum = sectorAddr / sectorSize
431  // if sectorNum < 256 (number of sector in bank0)
432  // set bankNum =0
433  // else set bankNum =1
434  //
435  // if sectorNum<32, it is the first 32 sector, it is 2K protect, use the rgister A
436  // registerA = 1<<sectorNum
437  // if sector>=32 and sector<256, select bank0, registerB
438  // registerB = 1<< ( (sectorNum-32)/8 + 4)
439  // if (sector>256)
440  // select Bank=1, registerB = 1<< (sectorNum-256)/8
441  //
442  ui32NoOfSectorsBank0 = (HWREG(NVMNW_BASE + NVMNW_O_BANK0INFO0) &
443  NVMNW_BANK0INFO0_MAINSIZE_M) >>
444  NVMNW_BANK0INFO0_MAINSIZE_S;
445 
446  if (ui32SectorNumber < ui32NoOfSectorsBank0)
447  {
448  ui32BankNum = 0;
449  }
450  else
451  {
452  ui32BankNum = 1;
453  }
454 
455  // set up Dynamic Write/Erase Protect to unprotect mode (clear the bit)
456  if ( ui32SectorNumber < 32)
457  {
458  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTA) &= ~(1 << ui32SectorNumber);
459  }
460  else if ( ui32SectorNumber < ui32NoOfSectorsBank0)
461  {
462  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTB) &= ~( 1 << ((ui32SectorNumber-32)/8 + 4));
463  }
464  else
465  {
466  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTB) &= ~( 1 << ((ui32SectorNumber - ui32NoOfSectorsBank0)/8));
467  }
468 
469  // set up the command address, translate to Flash word adress
470  // address is relative to each bank, translate to Flash word address
471  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = ( ( ui32SectorAddress - FLASHMEM_BASE ) & (bank0Size -1) ) >> 4 ;
472  }
473  else
474  {
475  // for NON-MAIN CCFG /FCFG1 region
476  // set up Dynamic Write/Erase Protect to unprotect mode (clear the bit)
477  HWREG(NVMNW_BASE + NVMNW_O_CMDWEPROTNM) &= ~( 1 << (ui32SectorNumber) );
478 
479  // set up the command address, translate to Flash word adress
480  // address is relative to each bank, translate to Flash word address
481  if ( ui32BankNum == 0 )
482  { // CCFG bank 0
483  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32SectorAddress - CCFG_BASE_DEFAULT )>> 4;
484  }
485  else
486  { // FCFG1 bank 1
487  HWREG(NVMNW_BASE + NVMNW_O_CMDADDR ) = (ui32SectorAddress - FCFG1_BASE )>> 4;
488  }
489  }
490 
491  // set up control register
492  /*
493  19 Stair Step Erase =0
494  18 erase mask disable 0
495  17 Program mask disable (0)
496  16 ECC override (no ECC) 0
497  15 address translate overrid = 1
498  14 post verify enable (1)
499  13 preverify enable (1)
500  12:9 regionsel = (main region) /Non-main
501  8:4 bank selection = 0 /1
502  3:0 N/A (only for mode change)
503 
504  */
505  HWREG(NVMNW_BASE + NVMNW_O_CMDCTL) = NVMNW_CMDCTL_BANKSEL_BANK0 <<(ui32BankNum) |
506  ui32Region |
507  NVMNW_CMDCTL_ADDRXLATEOVR_OVERRIDE |
508  NVMNW_CMDCTL_POSTVEREN_ENABLE |
509  NVMNW_CMDCTL_PREVEREN_ENABLE ;
510 
511  // Issue the sector erase command to the FSM.
513 
514  // Wait for erase to finish.
516  {
517  }
518 
519  // Update status.
520  ui32ErrorReturn = FlashCheckFsmForError();
521 
522  // check if the it is CCFG region
523  if ( ( ui32Region == NVMNW_CMDCTL_REGIONSEL_NONMAIN ) &&
524  ( ui32BankNum == 0 ) &&
525  ( ui32ErrorReturn == FAPI_STATUS_SUCCESS ) )
526  {
527  // program security data to default vaues in the customer configuration
528  // are within the flash CCFG sector
529 
530  // Program security data to default values in the customer configuration
531  // area within the flash CCFG.
532  ui32ErrorReturn = FlashProgram((uint8_t *)g_pui8CcfgDefaultSec,
533  (ui32SectorAddress + CCFG_OFFSET_SECURITY),
535 
536  }
537  // Return status of operation.
538  return(ui32ErrorReturn);
539 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
Erase sector.
Definition: flash.h:179
#define CCFG_OFFSET_SECURITY
Definition: flash.c:81
#define FAPI_STATUS_ADDRESS_ALIGN_ERROR
Definition: flash.h:111
static uint32_t FlashCheckFsmForReady(void)
Checks if the Flash state machine is ready.
Definition: flash.h:409
#define CCFG_SIZE_SECURITY
Definition: flash.c:83
#define FAPI_STATUS_SUCCESS
Definition: flash.h:104
static uint32_t FlashSizeGet(void)
Get the size of the flash.
Definition: flash.h:251
Clear status.
Definition: flash.h:181
static uint32_t FlashCheckFsmForError(void)
Checks if the Flash state machine has detected an error.
Definition: flash.h:379
#define FAPI_STATUS_FSM_BUSY
Definition: flash.h:105
uint32_t FlashProgram(uint8_t *pui8DataBuffer, uint32_t ui32Address, uint32_t ui32Count)
Programs unprotected flash sectors in the main bank.
Definition: flash.c:629
const uint8_t g_pui8CcfgDefaultSec[]
Definition: flash.c:99
static void IssueFsmCommand(tFlashStateCommandsType eCommand)
Definition: flash.c:1217
#define FAPI_STATUS_ADDRESS_ERROR
Definition: flash.h:110
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 FlashProgram(), FlashProgram4X(), FlashProtectionGet(), FlashProtectionSave(), FlashProtectionSet(), FlashSectorErase(), and FlashSizeGet().

229 {
230 
231  uint32_t ui32SectorSizeInKbyte;
232 
233  ui32SectorSizeInKbyte = (HWREG(NVMNW_BASE + NVMNW_O_GBLINFO0) &
234  NVMNW_GBLINFO0_SECTORSIZE_M) >>
235  NVMNW_GBLINFO0_SECTORSIZE_S;
236 
237  // Return flash sector size in number of bytes.
238  return (ui32SectorSizeInKbyte);
239 }

§ 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(), FlashProgram4X(), and FlashSectorErase().

252 {
253  uint32_t ui32NoOfSectors;
254 
255  // get the number of sectors from the FLASH:FLASH_SIZE register
256  ui32NoOfSectors = (( HWREG(FLASH_BASE + FLASH_O_FLASH_SIZE) &
257  FLASH_FLASH_SIZE_SECTORS_M ) >>
258  FLASH_FLASH_SIZE_SECTORS_S ) << FLASH_FLASH_SIZE_SECTORS_S;
259 
260  // Return flash size in number of bytes
261  return (ui32NoOfSectors * FlashSectorSizeGet());
262 }
static uint32_t FlashSectorSizeGet(void)
Get size of a flash sector in number of bytes.
Definition: flash.h:228
Here is the call graph for this function:

Macro Definition Documentation

§ DUMPWORD_INSTR

#define DUMPWORD_INSTR   0x04

Referenced by FlashEfuseReadRow().

§ FAPI_STATUS_ADDRESS_ALIGN_ERROR

#define FAPI_STATUS_ADDRESS_ALIGN_ERROR   0x00000006

§ FAPI_STATUS_ADDRESS_ERROR

#define FAPI_STATUS_ADDRESS_ERROR   0x00000005

§ FAPI_STATUS_BANK_NUM_ERROR

#define FAPI_STATUS_BANK_NUM_ERROR   0x00000007

§ FAPI_STATUS_FSM_BUSY

#define FAPI_STATUS_FSM_BUSY   0x00000001

§ 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_NOSUPPORT_ERROR

#define FAPI_STATUS_NOSUPPORT_ERROR   0x00000008

§ FAPI_STATUS_SUCCESS

#define FAPI_STATUS_SUCCESS   0x00000000

§ FAPI_STATUS_UNPROTECT_ERROR

#define FAPI_STATUS_UNPROTECT_ERROR   0x00000009

Referenced by FlashProtectionSave().

§ FBFALLBACK_ACTIVE

#define FBFALLBACK_ACTIVE   3

§ FBFALLBACK_DEEP_STDBY

#define FBFALLBACK_DEEP_STDBY   1

§ FBFALLBACK_SLEEP

#define FBFALLBACK_SLEEP   0

§ FCFG1_OFFSET

#define FCFG1_OFFSET   0x0800

§ FLASH_INT_FSM_DONE

#define FLASH_INT_FSM_DONE   0x00400000

§ FLASH_INT_RV

#define FLASH_INT_RV   0x00010000

§ FLASH_NO_PROTECT

#define FLASH_NO_PROTECT   0x00000000

Referenced by FlashProtectionGet().

§ 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

§ FLASHWORD_MASKBIT

#define FLASHWORD_MASKBIT   (0x03)

§ FLASHWORD_SHIFTBIT

#define FLASHWORD_SHIFTBIT   (2)

§ FLASHWORDSIZE_FOUR

#define FLASHWORDSIZE_FOUR   (0x40)

Referenced by FlashProgram(), and FlashProgram4X().

§ FLASHWORDSIZE_ONE

#define FLASHWORDSIZE_ONE   (0x10)

§ FLASHWORDSIZE_TWO

#define FLASHWORDSIZE_TWO   (0x20)

Referenced by FlashProgram(), and FlashProgram4X().

§ 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

Enumeration Type Documentation

§ tFlashStateCommandsType

Defined values for Flash State Machine commands.

Enumerator
FAPI_PROGRAM_FOURWORD 

Program 4 Flash Word Mode.

FAPI_PROGRAM_TWOWORD 

Program 4 Flash Word Mode.

FAPI_PROGRAM_ONEWORD 

Program 1 Flash word mode.

FAPI_ERASE_SECTOR 

Erase sector.

FAPI_ERASE_BANK 

Erase bank.

FAPI_CLEAR_STATUS 

Clear status.

FAPI_READVERIFY 

Read and Verify.

175 {
176  FAPI_PROGRAM_FOURWORD = 0x0021,
177  FAPI_PROGRAM_TWOWORD = 0x0011,
178  FAPI_PROGRAM_ONEWORD = 0x0001,
179  FAPI_ERASE_SECTOR = 0x0042,
180  FAPI_ERASE_BANK = 0x0052,
181  FAPI_CLEAR_STATUS = 0x0005,
182  FAPI_READVERIFY = 0x0003
183 
Program 4 Flash Word Mode.
Definition: flash.h:176
Erase sector.
Definition: flash.h:179
Program 1 Flash word mode.
Definition: flash.h:178
Clear status.
Definition: flash.h:181
Erase bank.
Definition: flash.h:180
tFlashStateCommandsType
Defined values for Flash State Machine commands.
Definition: flash.h:174
Read and Verify.
Definition: flash.h:182
Program 4 Flash Word Mode.
Definition: flash.h:177