CC26xx Driver Library
flash.c File Reference
#include "../inc/hw_types.h"
#include "../inc/hw_ccfg.h"
#include "../inc/hw_fcfg2.h"
#include "flash.h"
#include "chipinfo.h"

Macros

#define CCFG_OFFSET_SECURITY   CCFG_O_BL_CONFIG
 
#define CCFG_OFFSET_SECT_PROT   CCFG_O_CCFG_WEPROT_31_0_BY2K
 
#define CCFG_SIZE_SECURITY   0x00000018
 
#define CCFG_SIZE_SECT_PROT   0x00000004
 

Typedefs

typedef uint32_t(* FlashPrgPointer_t) (uint8_t *, uint32_t, uint32_t)
 
typedef uint32_t(* FlashSectorErasePointer_t) (uint32_t)
 

Functions

static void IssueFsmCommand (tFlashStateCommandsType eCommand)
 
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...
 
uint32_t FlashSectorErase (uint32_t ui32SectorAddress)
 Erase a flash sector. More...
 
static uint32_t FlashCopyOneFlashWordToHW (uint8_t *pBuf, uint32_t FlashAddr, uint32_t startIdx, uint32_t endIdx)
 
static uint32_t FlashCopyMultiFlashWordToHW (uint8_t *pBuf, uint32_t FlashAddr, uint32_t numBytes)
 
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...
 

Variables

const uint8_t g_pui8CcfgDefaultSec []
 

Macro Definition Documentation

§ CCFG_OFFSET_SECT_PROT

#define CCFG_OFFSET_SECT_PROT   CCFG_O_CCFG_WEPROT_31_0_BY2K

§ CCFG_OFFSET_SECURITY

#define CCFG_OFFSET_SECURITY   CCFG_O_BL_CONFIG

Referenced by FlashSectorErase().

§ CCFG_SIZE_SECT_PROT

#define CCFG_SIZE_SECT_PROT   0x00000004

Referenced by FlashProtectionSave().

§ CCFG_SIZE_SECURITY

#define CCFG_SIZE_SECURITY   0x00000018

Referenced by FlashSectorErase().

Typedef Documentation

§ FlashPrgPointer_t

typedef uint32_t(* FlashPrgPointer_t) (uint8_t *, uint32_t, uint32_t)

§ FlashSectorErasePointer_t

typedef uint32_t(* FlashSectorErasePointer_t) (uint32_t)

Function Documentation

§ FlashCopyMultiFlashWordToHW()

static uint32_t FlashCopyMultiFlashWordToHW ( uint8_t *  pBuf,
uint32_t  FlashAddr,
uint32_t  numBytes 
)
static

Referenced by FlashProgram(), and FlashProgram4X().

588 {
589  uint32_t wordIdx;
590  uint32_t flashdata=0;
591  uint32_t cmdDataOffset;
592 
593  // double check the Flash address is 32 or 64 byte aligned
594 
595  /* based on the Flash addr to figure the cdata index register
596  1. convert the system byte address to flash word address (>>4)
597  2. based on the flash word address to find command data index (last 2 bit)
598  3. cmddataOffset will be 0,32(0x20), 64 (0x40)
599  */
600  cmdDataOffset = ((FlashAddr >> 4) & 0x3 ) << 4 ;
601 
602  // in 2X/4X program mode, Byte Enable register is required
603  // to set to 0xFFFF
604  HWREG(NVMNW_BASE + NVMNW_O_CMDBYTEN ) = 0xFFFF;
605 
606  // build data buffer from byte address to Flash word address
607  for (wordIdx = 0; wordIdx < (numBytes >> 2); wordIdx++)
608  {
609  flashdata = ( pBuf[3] << 24 ) |
610  ( pBuf[2] << 16 ) |
611  ( pBuf[1] << 8 ) |
612  ( pBuf[0] ) ;
613  HWREG(NVMNW_BASE + NVMNW_O_CMDDATA0 + cmdDataOffset + (4 * wordIdx)) = flashdata ;
614 
615  /* next 4 data byte */
616  pBuf += 4;
617  }
618 
619  return (numBytes);
620 }

§ FlashCopyOneFlashWordToHW()

static uint32_t FlashCopyOneFlashWordToHW ( uint8_t *  pBuf,
uint32_t  FlashAddr,
uint32_t  startIdx,
uint32_t  endIdx 
)
static

Referenced by FlashProgram(), and FlashProgram4X().

543 {
544  uint32_t dataBuf[FLASHWORDSIZE_ONE/4];
545  uint32_t i,wordIdx,byteIdx;
546  uint32_t byteEnableVal =0;
547  uint32_t cmdDataOffset;
548 
549  // init the dataBuf to zero
550  for (i = 0; i < (FLASHWORDSIZE_ONE/4); i++)
551  {
552  dataBuf[i] = 0x00000000;
553  }
554 
555  // build data buffer from byte address to Flash word address
556  // build the byte enable value
557  for (i = startIdx; i <= endIdx; i++)
558  {
559  byteEnableVal |= 1 << i ;
560  wordIdx = i >> FLASHWORD_SHIFTBIT ;
561  byteIdx = i & FLASHWORD_MASKBIT ;
562 
563  dataBuf[wordIdx] |= (*pBuf) << ( 8 * byteIdx );
564  /* next data byte */
565  pBuf++;
566  }
567 
568  /* based on the Flash addr to figure the cdata index register
569  1. convert the system byte address to flash word address (>>4)
570  2. based on the flash word address to find command data index (last 2 bit)
571  3. cmddataOffset will be 0,16(0x10),32(0x20),48(0x30)
572  */
573  cmdDataOffset = ((FlashAddr >> 4) & 0x3 ) << 4 ;
574 
575  /* write the data buffer to Flash Command data buffer */
576  HWREG(NVMNW_BASE + NVMNW_O_CMDDATA0 + cmdDataOffset ) = dataBuf[0];
577  HWREG(NVMNW_BASE + NVMNW_O_CMDDATA1 + cmdDataOffset ) = dataBuf[1];
578  HWREG(NVMNW_BASE + NVMNW_O_CMDDATA2 + cmdDataOffset ) = dataBuf[2];
579  HWREG(NVMNW_BASE + NVMNW_O_CMDDATA3 + cmdDataOffset ) = dataBuf[3];
580 
581  /* update the byte enable register (mask) */
582  HWREG(NVMNW_BASE + NVMNW_O_CMDBYTEN ) = byteEnableVal;
583 
584  return (endIdx - startIdx + 1);
585 }
#define FLASHWORD_SHIFTBIT
Definition: flash.h:162
#define FLASHWORD_MASKBIT
Definition: flash.h:163
#define FLASHWORDSIZE_ONE
Definition: flash.h:167

§ IssueFsmCommand()

static void IssueFsmCommand ( tFlashStateCommandsType  eCommand)
static

Issues a command to the Flash State Machine.

Parameters
eCommandspecifies the FSM command.

Issues a command to the Flash State Machine.

Returns
None

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

1218 {
1219  // Check the arguments.
1220  ASSERT(
1221  eCommand == FAPI_ERASE_SECTOR || eCommand == FAPI_ERASE_BANK ||
1222  eCommand == FAPI_PROGRAM_FOURWORD || eCommand == FAPI_CLEAR_STATUS ||
1223  eCommand == FAPI_PROGRAM_ONEWORD || eCommand == FAPI_PROGRAM_TWOWORD ||
1224  eCommand == FAPI_READVERIFY );
1225 
1226  // write to NW COMMAND Type register
1227  HWREG(NVMNW_BASE + NVMNW_O_CMDTYPE) = eCommand;
1228 
1229  // write to NW Execute register
1230  HWREG(NVMNW_BASE + NVMNW_O_CMDEXEC) = NVMNW_CMDEXEC_VAL_EXECUTE;
1231 
1232 }
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
#define ASSERT(expr)
Definition: debug.h:71
Erase bank.
Definition: flash.h:180
Read and Verify.
Definition: flash.h:182
Program 4 Flash Word Mode.
Definition: flash.h:177

Variable Documentation

§ g_pui8CcfgDefaultSec

const uint8_t g_pui8CcfgDefaultSec[]
Initial value:
= {0xFF, 0xFF, 0xFF, 0xC5,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xC5, 0xC5, 0xC5, 0xFF,
0xC5, 0xC5, 0xC5, 0xFF,
0xC5, 0xC5, 0xC5, 0xFF
}

Referenced by FlashSectorErase().