[feat][sf] add 2 line flash program support

This commit is contained in:
jzlv 2021-07-16 16:09:37 +08:00
parent 21e2591a25
commit 147df677b1
8 changed files with 868 additions and 340 deletions

View file

@ -205,7 +205,7 @@ typedef struct {
uint32_t parity : 1; /*!< Parity of capcode */ uint32_t parity : 1; /*!< Parity of capcode */
uint32_t en : 1; /*!< Enable status */ uint32_t en : 1; /*!< Enable status */
uint32_t rsvd : 26; /*!< Reserved */ uint32_t rsvd : 26; /*!< Reserved */
}Efuse_Ldo11VoutSelTrim_Info_Type; } Efuse_Ldo11VoutSelTrim_Info_Type;
/** /**
* @brief Efuse Tx Power definition * @brief Efuse Tx Power definition
@ -215,7 +215,7 @@ typedef struct {
uint32_t parity : 1; /*!< Parity of capcode */ uint32_t parity : 1; /*!< Parity of capcode */
uint32_t en : 1; /*!< Enable status */ uint32_t en : 1; /*!< Enable status */
uint32_t rsvd : 25; /*!< Reserved */ uint32_t rsvd : 25; /*!< Reserved */
}Efuse_TxPower_Info_Type; } Efuse_TxPower_Info_Type;
/*@} end of group EF_CTRL_Public_Types */ /*@} end of group EF_CTRL_Public_Types */

View file

@ -469,6 +469,7 @@ BL_Err_Type Sec_Eng_Trng_Enable(void);
void Sec_Eng_Trng_Int_Enable(void); void Sec_Eng_Trng_Int_Enable(void);
void Sec_Eng_Trng_Int_Disable(void); void Sec_Eng_Trng_Int_Disable(void);
BL_Err_Type Sec_Eng_Trng_Read(uint8_t data[32]); BL_Err_Type Sec_Eng_Trng_Read(uint8_t data[32]);
BL_Err_Type Sec_Eng_Trng_Get_Random(uint8_t *data, uint32_t len);
void Sec_Eng_Trng_Int_Read_Trigger(void); void Sec_Eng_Trng_Int_Read_Trigger(void);
void Sec_Eng_Trng_Int_Read(uint8_t data[32]); void Sec_Eng_Trng_Int_Read(uint8_t data[32]);
void Sec_Eng_Trng_Disable(void); void Sec_Eng_Trng_Disable(void);

View file

@ -38,15 +38,14 @@
#include "bl602_common.h" #include "bl602_common.h"
#include "bl602_sflash.h" #include "bl602_sflash.h"
#include "bl602_sflash_ext.h"
#include "bl602_xip_sflash.h" #include "bl602_xip_sflash.h"
#include "bl602_sf_cfg.h"
#include "bl602_sf_cfg_ext.h"
/** @addtogroup BL602_Peripheral_Driver /** @addtogroup BL602_Peripheral_Driver
* @{ * @{
*/ */
/** @addtogroup XIP_SFLASH /** @addtogroup XIP_SFLASH_EXT
* @{ * @{
*/ */
@ -71,7 +70,23 @@
/** @defgroup XIP_SFLASH_EXT_Public_Functions /** @defgroup XIP_SFLASH_EXT_Public_Functions
* @{ * @{
*/ */
BL_Err_Type XIP_SFlash_State_Restore_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t offset);
BL_Err_Type XIP_SFlash_Erase_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t startaddr,
uint32_t endaddr);
BL_Err_Type XIP_SFlash_Write_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr,uint8_t *data,
uint32_t len);
BL_Err_Type XIP_SFlash_Read_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr,uint8_t *data,
uint32_t len);
BL_Err_Type XIP_SFlash_GetJedecId_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint8_t *data);
BL_Err_Type XIP_SFlash_GetDeviceId_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint8_t *data);
BL_Err_Type XIP_SFlash_GetUniqueId_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint8_t *data,
uint8_t idLen);
BL_Err_Type XIP_SFlash_RCV_Enable_Need_Lock(SPI_Flash_Cfg_Type *pFlashCfg, uint8_t rCmd, uint8_t wCmd,
uint8_t bitPos);
int XIP_SFlash_Read_With_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr, uint8_t *dst, int len);
int XIP_SFlash_Write_With_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr, uint8_t *src, int len);
int XIP_SFlash_Erase_With_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr, int len);
int XIP_SFlash_RCV_Enable_With_Lock(SPI_Flash_Cfg_Type *pFlashCfg, uint8_t rCmd, uint8_t wCmd, uint8_t bitPos);
BL_Err_Type XIP_SFlash_Init(SPI_Flash_Cfg_Type *pFlashCfg); BL_Err_Type XIP_SFlash_Init(SPI_Flash_Cfg_Type *pFlashCfg);
int XIP_SFlash_Read(uint32_t addr, uint8_t *dst, int len); int XIP_SFlash_Read(uint32_t addr, uint8_t *dst, int len);
int XIP_SFlash_Write(uint32_t addr, uint8_t *src, int len); int XIP_SFlash_Write(uint32_t addr, uint8_t *src, int len);
@ -79,7 +94,7 @@ int XIP_SFlash_Erase(uint32_t addr, int len);
/*@} end of group XIP_SFLASH_EXT_Public_Functions */ /*@} end of group XIP_SFLASH_EXT_Public_Functions */
/*@} end of group XIP_SFLASH */ /*@} end of group XIP_SFLASH_EXT */
/*@} end of group BL602_Peripheral_Driver */ /*@} end of group BL602_Peripheral_Driver */

View file

@ -27,7 +27,7 @@ void main(void)
static BL_Err_Type PtTable_Flash_Read(uint32_t addr, uint8_t *data, uint32_t len) static BL_Err_Type PtTable_Flash_Read(uint32_t addr, uint8_t *data, uint32_t len)
{ {
XIP_SFlash_Read_Need_Lock(pFlashCfg, addr, data, len); XIP_SFlash_Read_Need_Lock_Ext(pFlashCfg, addr, data, len);
return SUCCESS; return SUCCESS;
} }
@ -68,14 +68,14 @@ static int8_t mfg_flash_program(void)
mfg_print("mfg_flash_write\r\n"); mfg_print("mfg_flash_write\r\n");
ret = XIP_SFlash_Erase_Need_Lock(pFlashCfg, rf_para_addr, rf_para_addr + 15); ret = XIP_SFlash_Erase_Need_Lock_Ext(pFlashCfg, rf_para_addr, rf_para_addr + 15);
if (ret != SUCCESS) { if (ret != SUCCESS) {
mfg_print("Flash erase error\r\n"); mfg_print("Flash erase error\r\n");
return -1; return -1;
} }
ret = XIP_SFlash_Write_Need_Lock(pFlashCfg, rf_para_addr, (uint8_t *)&rf_para, sizeof(rf_para)); ret = XIP_SFlash_Write_Need_Lock_Ext(pFlashCfg, rf_para_addr, (uint8_t *)&rf_para, sizeof(rf_para));
if (ret != SUCCESS) { if (ret != SUCCESS) {
mfg_print("Flash write error\r\n"); mfg_print("Flash write error\r\n");
@ -91,7 +91,7 @@ static int8_t mfg_flash_read(void)
mfg_print("mfg_flash_read\r\n"); mfg_print("mfg_flash_read\r\n");
ret = XIP_SFlash_Read_Need_Lock(pFlashCfg, rf_para_addr, (uint8_t *)&rf_para, sizeof(rf_para)); ret = XIP_SFlash_Read_Need_Lock_Ext(pFlashCfg, rf_para_addr, (uint8_t *)&rf_para, sizeof(rf_para));
if (ret != SUCCESS) { if (ret != SUCCESS) {
mfg_print("Flash write error\r\n"); mfg_print("Flash write error\r\n");

View file

@ -1529,6 +1529,43 @@ BL_Err_Type Sec_Eng_Trng_Read(uint8_t data[32])
return SUCCESS; return SUCCESS;
} }
/****************************************************************************/ /**
* @brief TRNG get random data out
*
* @param data: TRNG output data buffer
*
* @param len: total length to get in bytes
*
* @return SUCCESS
*
*******************************************************************************/
BL_Err_Type Sec_Eng_Trng_Get_Random(uint8_t *data, uint32_t len)
{
uint8_t tmpBuf[32];
uint32_t readLen = 0;
uint32_t i = 0, cnt = 0;
while (readLen < len) {
if (Sec_Eng_Trng_Read(tmpBuf) != SUCCESS) {
return -1;
}
cnt = len - readLen;
if (cnt > sizeof(tmpBuf)) {
cnt = sizeof(tmpBuf);
}
for (i = 0; i < cnt; i++) {
data[readLen + i] = tmpBuf[i];
}
readLen += cnt;
}
return 0;
}
/****************************************************************************/ /** /****************************************************************************/ /**
* @brief TRNG Interrupt Read Trigger * @brief TRNG Interrupt Read Trigger
* *

View file

@ -58,342 +58,474 @@
/** @defgroup SF_CFG_EXT_Private_Types /** @defgroup SF_CFG_EXT_Private_Types
* @{ * @{
*/ */
typedef struct typedef struct {
{
uint32_t jedecID; uint32_t jedecID;
char *name; char *name;
const SPI_Flash_Cfg_Type *cfg; const SPI_Flash_Cfg_Type *cfg;
} Flash_Info_t; }Flash_Info_t;
/*@} end of group SF_CFG_EXT_Private_Types */ /*@} end of group SF_CFG_EXT_Private_Types */
/** @defgroup SF_CFG_EXT_Private_Variables /** @defgroup SF_CFG_EXT_Private_Variables
* @{ * @{
*/ */
static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_FM_25Q08 = { static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_FM_25Q08={
.resetCreadCmd = 0xff, .resetCreadCmd=0xff,
.resetCreadCmdSize = 3, .resetCreadCmdSize=3,
.mid = 0xc8, .mid=0xc8,
.deBurstWrapCmd = 0x77, .deBurstWrapCmd=0x77,
.deBurstWrapCmdDmyClk = 0x3, .deBurstWrapCmdDmyClk=0x3,
.deBurstWrapDataMode = SF_CTRL_DATA_4_LINES, .deBurstWrapDataMode=SF_CTRL_DATA_4_LINES,
.deBurstWrapData = 0xF0, .deBurstWrapData=0xF0,
/*reg*/ /*reg*/
.writeEnableCmd = 0x06, .writeEnableCmd=0x06,
.wrEnableIndex = 0x00, .wrEnableIndex=0x00,
.wrEnableBit = 0x01, .wrEnableBit=0x01,
.wrEnableReadRegLen = 0x01, .wrEnableReadRegLen=0x01,
.qeIndex = 1, .qeIndex=1,
.qeBit = 0x01, .qeBit=0x01,
.qeWriteRegLen = 0x02, .qeWriteRegLen=0x02,
.qeReadRegLen = 0x1, .qeReadRegLen=0x1,
.busyIndex = 0, .busyIndex=0,
.busyBit = 0x00, .busyBit=0x00,
.busyReadRegLen = 0x1, .busyReadRegLen=0x1,
.releasePowerDown = 0xab, .releasePowerDown=0xab,
.readRegCmd[0] = 0x05, .readRegCmd[0]=0x05,
.readRegCmd[1] = 0x35, .readRegCmd[1]=0x35,
.writeRegCmd[0] = 0x01, .writeRegCmd[0]=0x01,
.writeRegCmd[1] = 0x01, .writeRegCmd[1]=0x01,
.fastReadQioCmd = 0xeb, .fastReadQioCmd=0xeb,
.frQioDmyClk = 16 / 8, .frQioDmyClk=16/8,
.cReadSupport = 1, .cReadSupport=1,
.cReadMode = 0x20, .cReadMode=0xa0,
.burstWrapCmd = 0x77, .burstWrapCmd=0x77,
.burstWrapCmdDmyClk = 0x3, .burstWrapCmdDmyClk=0x3,
.burstWrapDataMode = SF_CTRL_DATA_4_LINES, .burstWrapDataMode=SF_CTRL_DATA_4_LINES,
.burstWrapData = 0x40, .burstWrapData=0x40,
/*erase*/ /*erase*/
.chipEraseCmd = 0xc7, .chipEraseCmd=0xc7,
.sectorEraseCmd = 0x20, .sectorEraseCmd=0x20,
.blk32EraseCmd = 0x52, .blk32EraseCmd=0x52,
.blk64EraseCmd = 0xd8, .blk64EraseCmd=0xd8,
/*write*/ /*write*/
.pageProgramCmd = 0x02, .pageProgramCmd=0x02,
.qpageProgramCmd = 0x32, .qpageProgramCmd=0x32,
.qppAddrMode = SF_CTRL_ADDR_1_LINE, .qppAddrMode=SF_CTRL_ADDR_1_LINE,
.ioMode = SF_CTRL_QIO_MODE, .ioMode=SF_CTRL_QIO_MODE,
.clkDelay = 1, .clkDelay=1,
.clkInvert = 0x3f, .clkInvert=0x3f,
.resetEnCmd = 0x66, .resetEnCmd=0x66,
.resetCmd = 0x99, .resetCmd=0x99,
.cRExit = 0xff, .cRExit=0xff,
.wrEnableWriteRegLen = 0x00, .wrEnableWriteRegLen=0x00,
/*id*/ /*id*/
.jedecIdCmd = 0x9f, .jedecIdCmd=0x9f,
.jedecIdCmdDmyClk = 0, .jedecIdCmdDmyClk=0,
.qpiJedecIdCmd = 0x9f, .qpiJedecIdCmd=0x9f,
.qpiJedecIdCmdDmyClk = 0x00, .qpiJedecIdCmdDmyClk=0x00,
.sectorSize = 4, .sectorSize=4,
.pageSize = 256, .pageSize=256,
/*read*/ /*read*/
.fastReadCmd = 0x0b, .fastReadCmd=0x0b,
.frDmyClk = 8 / 8, .frDmyClk=8/8,
.qpiFastReadCmd = 0x0b, .qpiFastReadCmd =0x0b,
.qpiFrDmyClk = 8 / 8, .qpiFrDmyClk=8/8,
.fastReadDoCmd = 0x3b, .fastReadDoCmd=0x3b,
.frDoDmyClk = 8 / 8, .frDoDmyClk=8/8,
.fastReadDioCmd = 0xbb, .fastReadDioCmd=0xbb,
.frDioDmyClk = 0, .frDioDmyClk=0,
.fastReadQoCmd = 0x6b, .fastReadQoCmd=0x6b,
.frQoDmyClk = 8 / 8, .frQoDmyClk=8/8,
.qpiFastReadQioCmd = 0xeb, .qpiFastReadQioCmd=0xeb,
.qpiFrQioDmyClk = 16 / 8, .qpiFrQioDmyClk=16/8,
.qpiPageProgramCmd = 0x02, .qpiPageProgramCmd=0x02,
.writeVregEnableCmd = 0x50, .writeVregEnableCmd=0x50,
/* qpi mode */ /* qpi mode */
.enterQpi = 0x38, .enterQpi=0x38,
.exitQpi = 0xff, .exitQpi=0xff,
/*AC*/ /*AC*/
.timeEsector = 300, .timeEsector=300,
.timeE32k = 1200, .timeE32k=1200,
.timeE64k = 1200, .timeE64k=1200,
.timePagePgm = 5, .timePagePgm=5,
.timeCe = 20 * 1000, .timeCe=20*1000,
.pdDelay = 20, .pdDelay=20,
.qeData = 0, .qeData=0,
}; };
static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_Gd_Md_40D = { static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_Gd_Md_40D={
.resetCreadCmd = 0xff, .resetCreadCmd=0xff,
.resetCreadCmdSize = 3, .resetCreadCmdSize=3,
.mid = 0x51, .mid=0x51,
.deBurstWrapCmd = 0x77, .deBurstWrapCmd=0x77,
.deBurstWrapCmdDmyClk = 0x3, .deBurstWrapCmdDmyClk=0x3,
.deBurstWrapDataMode = SF_CTRL_DATA_4_LINES, .deBurstWrapDataMode=SF_CTRL_DATA_4_LINES,
.deBurstWrapData = 0xF0, .deBurstWrapData=0xF0,
/*reg*/ /*reg*/
.writeEnableCmd = 0x06, .writeEnableCmd=0x06,
.wrEnableIndex = 0x00, .wrEnableIndex=0x00,
.wrEnableBit = 0x01, .wrEnableBit=0x01,
.wrEnableReadRegLen = 0x01, .wrEnableReadRegLen=0x01,
.qeIndex = 1, .qeIndex=1,
.qeBit = 0x01, .qeBit=0x01,
.qeWriteRegLen = 0x02, .qeWriteRegLen=0x02,
.qeReadRegLen = 0x1, .qeReadRegLen=0x1,
.busyIndex = 0, .busyIndex=0,
.busyBit = 0x00, .busyBit=0x00,
.busyReadRegLen = 0x1, .busyReadRegLen=0x1,
.releasePowerDown = 0xab, .releasePowerDown=0xab,
.readRegCmd[0] = 0x05, .readRegCmd[0]=0x05,
.readRegCmd[1] = 0x35, .readRegCmd[1]=0x35,
.writeRegCmd[0] = 0x01, .writeRegCmd[0]=0x01,
.writeRegCmd[1] = 0x01, .writeRegCmd[1]=0x01,
.fastReadQioCmd = 0xeb, .fastReadQioCmd=0xeb,
.frQioDmyClk = 16 / 8, .frQioDmyClk=16/8,
.cReadSupport = 0, .cReadSupport=0,
.cReadMode = 0xA0, .cReadMode=0xA0,
.burstWrapCmd = 0x77, .burstWrapCmd=0x77,
.burstWrapCmdDmyClk = 0x3, .burstWrapCmdDmyClk=0x3,
.burstWrapDataMode = SF_CTRL_DATA_4_LINES, .burstWrapDataMode=SF_CTRL_DATA_4_LINES,
.burstWrapData = 0x40, .burstWrapData=0x40,
/*erase*/ /*erase*/
.chipEraseCmd = 0xc7, .chipEraseCmd=0xc7,
.sectorEraseCmd = 0x20, .sectorEraseCmd=0x20,
.blk32EraseCmd = 0x52, .blk32EraseCmd=0x52,
.blk64EraseCmd = 0xd8, .blk64EraseCmd=0xd8,
/*write*/ /*write*/
.pageProgramCmd = 0x02, .pageProgramCmd=0x02,
.qpageProgramCmd = 0x32, .qpageProgramCmd=0x32,
.qppAddrMode = SF_CTRL_ADDR_1_LINE, .qppAddrMode=SF_CTRL_ADDR_1_LINE,
.ioMode = SF_CTRL_DO_MODE, .ioMode=SF_CTRL_DO_MODE,
.clkDelay = 1, .clkDelay=1,
.clkInvert = 0x3f, .clkInvert=0x3f,
.resetEnCmd = 0x66, .resetEnCmd=0x66,
.resetCmd = 0x99, .resetCmd=0x99,
.cRExit = 0xff, .cRExit=0xff,
.wrEnableWriteRegLen = 0x00, .wrEnableWriteRegLen=0x00,
/*id*/ /*id*/
.jedecIdCmd = 0x9f, .jedecIdCmd=0x9f,
.jedecIdCmdDmyClk = 0, .jedecIdCmdDmyClk=0,
.qpiJedecIdCmd = 0x9f, .qpiJedecIdCmd=0x9f,
.qpiJedecIdCmdDmyClk = 0x00, .qpiJedecIdCmdDmyClk=0x00,
.sectorSize = 4, .sectorSize=4,
.pageSize = 256, .pageSize=256,
/*read*/ /*read*/
.fastReadCmd = 0x0b, .fastReadCmd=0x0b,
.frDmyClk = 8 / 8, .frDmyClk=8/8,
.qpiFastReadCmd = 0x0b, .qpiFastReadCmd =0x0b,
.qpiFrDmyClk = 8 / 8, .qpiFrDmyClk=8/8,
.fastReadDoCmd = 0x3b, .fastReadDoCmd=0x3b,
.frDoDmyClk = 8 / 8, .frDoDmyClk=8/8,
.fastReadDioCmd = 0xbb, .fastReadDioCmd=0xbb,
.frDioDmyClk = 0, .frDioDmyClk=0,
.fastReadQoCmd = 0x6b, .fastReadQoCmd=0x6b,
.frQoDmyClk = 8 / 8, .frQoDmyClk=8/8,
.qpiFastReadQioCmd = 0xeb, .qpiFastReadQioCmd=0xeb,
.qpiFrQioDmyClk = 16 / 8, .qpiFrQioDmyClk=16/8,
.qpiPageProgramCmd = 0x02, .qpiPageProgramCmd=0x02,
.writeVregEnableCmd = 0x50, .writeVregEnableCmd=0x50,
/* qpi mode */ /* qpi mode */
.enterQpi = 0x38, .enterQpi=0x38,
.exitQpi = 0xff, .exitQpi=0xff,
/*AC*/ /*AC*/
.timeEsector = 300, .timeEsector=300,
.timeE32k = 1200, .timeE32k=1200,
.timeE64k = 1200, .timeE64k=1200,
.timePagePgm = 5, .timePagePgm=5,
.timeCe = 20 * 1000, .timeCe=20*1000,
.pdDelay = 20, .pdDelay=20,
.qeData = 0, .qeData=0,
}; };
static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_XM25QH16 = { static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_XM25QH16={
.resetCreadCmd = 0xff, .resetCreadCmd=0xff,
.resetCreadCmdSize = 3, .resetCreadCmdSize=3,
.mid = 0x20, .mid=0x20,
.deBurstWrapCmd = 0x77, .deBurstWrapCmd=0x77,
.deBurstWrapCmdDmyClk = 0x3, .deBurstWrapCmdDmyClk=0x3,
.deBurstWrapDataMode = SF_CTRL_DATA_4_LINES, .deBurstWrapDataMode=SF_CTRL_DATA_4_LINES,
.deBurstWrapData = 0xF0, .deBurstWrapData=0xF0,
/*reg*/ /*reg*/
.writeEnableCmd = 0x06, .writeEnableCmd=0x06,
.wrEnableIndex = 0x00, .wrEnableIndex=0x00,
.wrEnableBit = 0x01, .wrEnableBit=0x01,
.wrEnableReadRegLen = 0x01, .wrEnableReadRegLen=0x01,
.qeIndex = 1, .qeIndex=1,
.qeBit = 0x01, .qeBit=0x01,
.qeWriteRegLen = 0x01, .qeWriteRegLen=0x01,
.qeReadRegLen = 0x1, .qeReadRegLen=0x1,
.busyIndex = 0, .busyIndex=0,
.busyBit = 0x00, .busyBit=0x00,
.busyReadRegLen = 0x1, .busyReadRegLen=0x1,
.releasePowerDown = 0xab, .releasePowerDown=0xab,
.readRegCmd[0] = 0x05, .readRegCmd[0]=0x05,
.readRegCmd[1] = 0x35, .readRegCmd[1]=0x35,
.writeRegCmd[0] = 0x01, .writeRegCmd[0]=0x01,
.writeRegCmd[1] = 0x31, .writeRegCmd[1]=0x31,
.fastReadQioCmd = 0xeb, .fastReadQioCmd=0xeb,
.frQioDmyClk = 16 / 8, .frQioDmyClk=16/8,
.cReadSupport = 1, .cReadSupport=1,
.cReadMode = 0x20, .cReadMode=0x20,
.burstWrapCmd = 0x77, .burstWrapCmd=0x77,
.burstWrapCmdDmyClk = 0x3, .burstWrapCmdDmyClk=0x3,
.burstWrapDataMode = SF_CTRL_DATA_4_LINES, .burstWrapDataMode=SF_CTRL_DATA_4_LINES,
.burstWrapData = 0x40, .burstWrapData=0x40,
/*erase*/ /*erase*/
.chipEraseCmd = 0xc7, .chipEraseCmd=0xc7,
.sectorEraseCmd = 0x20, .sectorEraseCmd=0x20,
.blk32EraseCmd = 0x52, .blk32EraseCmd=0x52,
.blk64EraseCmd = 0xd8, .blk64EraseCmd=0xd8,
/*write*/ /*write*/
.pageProgramCmd = 0x02, .pageProgramCmd=0x02,
.qpageProgramCmd = 0x32, .qpageProgramCmd=0x32,
.qppAddrMode = SF_CTRL_ADDR_1_LINE, .qppAddrMode=SF_CTRL_ADDR_1_LINE,
.ioMode = SF_CTRL_QIO_MODE, .ioMode=SF_CTRL_QIO_MODE,
.clkDelay = 1, .clkDelay=1,
.clkInvert = 0x3f, .clkInvert=0x3f,
.resetEnCmd = 0x66, .resetEnCmd=0x66,
.resetCmd = 0x99, .resetCmd=0x99,
.cRExit = 0xff, .cRExit=0xff,
.wrEnableWriteRegLen = 0x00, .wrEnableWriteRegLen=0x00,
/*id*/ /*id*/
.jedecIdCmd = 0x9f, .jedecIdCmd=0x9f,
.jedecIdCmdDmyClk = 0, .jedecIdCmdDmyClk=0,
.qpiJedecIdCmd = 0x9f, .qpiJedecIdCmd=0x9f,
.qpiJedecIdCmdDmyClk = 0x00, .qpiJedecIdCmdDmyClk=0x00,
.sectorSize = 4, .sectorSize=4,
.pageSize = 256, .pageSize=256,
/*read*/ /*read*/
.fastReadCmd = 0x0b, .fastReadCmd=0x0b,
.frDmyClk = 8 / 8, .frDmyClk=8/8,
.qpiFastReadCmd = 0x0b, .qpiFastReadCmd =0x0b,
.qpiFrDmyClk = 8 / 8, .qpiFrDmyClk=8/8,
.fastReadDoCmd = 0x3b, .fastReadDoCmd=0x3b,
.frDoDmyClk = 8 / 8, .frDoDmyClk=8/8,
.fastReadDioCmd = 0xbb, .fastReadDioCmd=0xbb,
.frDioDmyClk = 0, .frDioDmyClk=0,
.fastReadQoCmd = 0x6b, .fastReadQoCmd=0x6b,
.frQoDmyClk = 8 / 8, .frQoDmyClk=8/8,
.qpiFastReadQioCmd = 0xeb, .qpiFastReadQioCmd=0xeb,
.qpiFrQioDmyClk = 16 / 8, .qpiFrQioDmyClk=16/8,
.qpiPageProgramCmd = 0x02, .qpiPageProgramCmd=0x02,
.writeVregEnableCmd = 0x50, .writeVregEnableCmd=0x50,
/* qpi mode */ /* qpi mode */
.enterQpi = 0x38, .enterQpi=0x38,
.exitQpi = 0xff, .exitQpi=0xff,
/*AC*/ /*AC*/
.timeEsector = 400, .timeEsector=400,
.timeE32k = 1600, .timeE32k=1600,
.timeE64k = 2000, .timeE64k=2000,
.timePagePgm = 5, .timePagePgm=5,
.timeCe = 20 * 1000, .timeCe=20*1000,
.pdDelay = 3, .pdDelay=3,
.qeData = 0, .qeData=0,
}; };
static const ATTR_TCM_CONST_SECTION Flash_Info_t flashInfos[] = { static const ATTR_TCM_CONST_SECTION SPI_Flash_Cfg_Type flashCfg_MX_KH25={
.resetCreadCmd=0xff,
.resetCreadCmdSize=3,
.mid=0xc2,
.deBurstWrapCmd=0x77,
.deBurstWrapCmdDmyClk=0x3,
.deBurstWrapDataMode=SF_CTRL_DATA_4_LINES,
.deBurstWrapData=0xF0,
/*reg*/
.writeEnableCmd=0x06,
.wrEnableIndex=0x00,
.wrEnableBit=0x01,
.wrEnableReadRegLen=0x01,
.qeIndex=1,
.qeBit=0x01,
.qeWriteRegLen=0x01,
.qeReadRegLen=0x1,
.busyIndex=0,
.busyBit=0x00,
.busyReadRegLen=0x1,
.releasePowerDown=0xab,
.readRegCmd[0]=0x05,
.readRegCmd[1]=0x00,
.writeRegCmd[0]=0x01,
.writeRegCmd[1]=0x00,
.fastReadQioCmd=0xeb,
.frQioDmyClk=16/8,
.cReadSupport=0,
.cReadMode=0x20,
.burstWrapCmd=0x77,
.burstWrapCmdDmyClk=0x3,
.burstWrapDataMode=SF_CTRL_DATA_4_LINES,
.burstWrapData=0x40,
/*erase*/
.chipEraseCmd=0xc7,
.sectorEraseCmd=0x20,
.blk32EraseCmd=0x52,
.blk64EraseCmd=0xd8,
/*write*/
.pageProgramCmd=0x02,
.qpageProgramCmd=0x32,
.qppAddrMode=SF_CTRL_ADDR_1_LINE,
.ioMode=0x11,
.clkDelay=1,
.clkInvert=0x3f,
.resetEnCmd=0x66,
.resetCmd=0x99,
.cRExit=0xff,
.wrEnableWriteRegLen=0x00,
/*id*/
.jedecIdCmd=0x9f,
.jedecIdCmdDmyClk=0,
.qpiJedecIdCmd=0x9f,
.qpiJedecIdCmdDmyClk=0x00,
.sectorSize=4,
.pageSize=256,
/*read*/
.fastReadCmd=0x0b,
.frDmyClk=8/8,
.qpiFastReadCmd =0x0b,
.qpiFrDmyClk=8/8,
.fastReadDoCmd=0x3b,
.frDoDmyClk=8/8,
.fastReadDioCmd=0xbb,
.frDioDmyClk=0,
.fastReadQoCmd=0x6b,
.frQoDmyClk=8/8,
.qpiFastReadQioCmd=0xeb,
.qpiFrQioDmyClk=16/8,
.qpiPageProgramCmd=0x02,
.writeVregEnableCmd=0x50,
/* qpi mode */
.enterQpi=0x38,
.exitQpi=0xff,
/*AC*/
.timeEsector=300,
.timeE32k=1200,
.timeE64k=1200,
.timePagePgm=5,
.timeCe=20*1000,
.pdDelay=20,
.qeData=0,
};
static const ATTR_TCM_CONST_SECTION Flash_Info_t flashInfos[]={
{ {
.jedecID = 0x1440A1, .jedecID=0x1440A1,
//.name="FM_25Q08", //.name="FM_25Q08",
.cfg = &flashCfg_FM_25Q08, .cfg=&flashCfg_FM_25Q08,
}, },
{ {
.jedecID = 0x134051, .jedecID=0x134051,
//.name="GD_MD04D_04_33", //.name="GD_MD04D_04_33",
.cfg = &flashCfg_Gd_Md_40D, .cfg=&flashCfg_Gd_Md_40D,
}, },
{ {
.jedecID = 0x144020, .jedecID=0x144020,
//.name="XM_25QH80_80_33", //.name="XM_25QH80_80_33",
.cfg = &flashCfg_XM25QH16, .cfg=&flashCfg_XM25QH16,
}, },
{ {
.jedecID = 0x154020, .jedecID=0x154020,
//.name="XM_25QH16_16_33", //.name="XM_25QH16_16_33",
.cfg = &flashCfg_XM25QH16, .cfg=&flashCfg_XM25QH16,
}, },
{ {
.jedecID = 0x164020, .jedecID=0x164020,
//.name="XM_25QH32_32_33", //.name="XM_25QH32_32_33",
.cfg = &flashCfg_XM25QH16, .cfg=&flashCfg_XM25QH16,
}, },
{ {
.jedecID = 0x15605E, .jedecID=0x1320C2,
//.name="MX_KH40_04_33",
.cfg=&flashCfg_MX_KH25,
},
{
.jedecID=0x1420C2,
//.name="MX_KH80_08_33",
.cfg=&flashCfg_MX_KH25,
},
{
.jedecID=0x1520C2,
//.name="MX_KH16_16_33",
.cfg=&flashCfg_MX_KH25,
},
{
.jedecID=0x13325E,
//.name="ZB_D40B_80_33",
.cfg=&flashCfg_MX_KH25,
},
{
.jedecID=0x14325E,
//.name="ZB_D80B_80_33",
.cfg=&flashCfg_MX_KH25,
},
{
.jedecID=0x15605E,
//.name="ZB_25VQ16_16_33", //.name="ZB_25VQ16_16_33",
.cfg = &flashCfg_XM25QH16, .cfg=&flashCfg_XM25QH16,
},
{
.jedecID=0x15345E,
//.name="ZB_25WQ16_16_33",
.cfg=&flashCfg_XM25QH16,
},
{
.jedecID=0x1560EB,
//.name="TH_25Q16",
.cfg=&flashCfg_FM_25Q08,
}, },
}; };
@ -415,7 +547,7 @@ static const ATTR_TCM_CONST_SECTION Flash_Info_t flashInfos[] = {
* @{ * @{
*/ */
/****************************************************************************/ /** /****************************************************************************//**
* @brief Get flash config according to flash ID * @brief Get flash config according to flash ID
* *
* @param flashID: Flash ID * @param flashID: Flash ID
@ -424,32 +556,29 @@ static const ATTR_TCM_CONST_SECTION Flash_Info_t flashInfos[] = {
* @return SUCCESS or ERROR * @return SUCCESS or ERROR
* *
*******************************************************************************/ *******************************************************************************/
BL_Err_Type ATTR_TCM_SECTION SF_Cfg_Get_Flash_Cfg_Need_Lock_Ext(uint32_t flashID, SPI_Flash_Cfg_Type *pFlashCfg) BL_Err_Type ATTR_TCM_SECTION SF_Cfg_Get_Flash_Cfg_Need_Lock_Ext(uint32_t flashID,SPI_Flash_Cfg_Type * pFlashCfg)
{ {
uint32_t i; uint32_t i;
uint8_t buf[sizeof(SPI_Flash_Cfg_Type) + 8]; uint8_t buf[sizeof(SPI_Flash_Cfg_Type)+8];
uint32_t crc, *pCrc; uint32_t crc,*pCrc;
if (flashID == 0) { if(flashID==0){
XIP_SFlash_Read_Via_Cache_Need_Lock(8 + BL602_FLASH_XIP_BASE, buf, sizeof(SPI_Flash_Cfg_Type) + 8); XIP_SFlash_Read_Via_Cache_Need_Lock(8+BL602_FLASH_XIP_BASE,buf,sizeof(SPI_Flash_Cfg_Type)+8);
if(BL602_MemCmp(buf,BFLB_FLASH_CFG_MAGIC,4)==0){
if (BL602_MemCmp(buf, BFLB_FLASH_CFG_MAGIC, 4) == 0) { crc=BFLB_Soft_CRC32((uint8_t *)buf+4,sizeof(SPI_Flash_Cfg_Type));
crc = BFLB_Soft_CRC32((uint8_t *)buf + 4, sizeof(SPI_Flash_Cfg_Type)); pCrc=(uint32_t *)(buf+4+sizeof(SPI_Flash_Cfg_Type));
pCrc = (uint32_t *)(buf + 4 + sizeof(SPI_Flash_Cfg_Type)); if(*pCrc==crc){
BL602_MemCpy_Fast(pFlashCfg,(uint8_t *)buf+4,sizeof(SPI_Flash_Cfg_Type));
if (*pCrc == crc) { return SUCCESS ;
BL602_MemCpy_Fast(pFlashCfg, (uint8_t *)buf + 4, sizeof(SPI_Flash_Cfg_Type)); }
}
}else{
if(SF_Cfg_Get_Flash_Cfg_Need_Lock(flashID, pFlashCfg) == SUCCESS){
return SUCCESS; return SUCCESS;
} }
} for(i=0;i<sizeof(flashInfos)/sizeof(flashInfos[0]);i++){
} else { if(flashInfos[i].jedecID==flashID){
if (SF_Cfg_Get_Flash_Cfg_Need_Lock(flashID, pFlashCfg)) { BL602_MemCpy_Fast(pFlashCfg,flashInfos[i].cfg,sizeof(SPI_Flash_Cfg_Type));
return SUCCESS;
}
for (i = 0; i < sizeof(flashInfos) / sizeof(flashInfos[0]); i++) {
if (flashInfos[i].jedecID == flashID) {
BL602_MemCpy_Fast(pFlashCfg, flashInfos[i].cfg, sizeof(SPI_Flash_Cfg_Type));
return SUCCESS; return SUCCESS;
} }
} }
@ -458,7 +587,7 @@ BL_Err_Type ATTR_TCM_SECTION SF_Cfg_Get_Flash_Cfg_Need_Lock_Ext(uint32_t flashID
return ERROR; return ERROR;
} }
/****************************************************************************/ /** /****************************************************************************//**
* @brief Identify one flash * @brief Identify one flash
* *
* @param callFromFlash: code run at flash or ram * @param callFromFlash: code run at flash or ram
@ -471,31 +600,31 @@ BL_Err_Type ATTR_TCM_SECTION SF_Cfg_Get_Flash_Cfg_Need_Lock_Ext(uint32_t flashID
* *
*******************************************************************************/ *******************************************************************************/
uint32_t ATTR_TCM_SECTION SF_Cfg_Flash_Identify_Ext(uint8_t callFromFlash, uint32_t ATTR_TCM_SECTION SF_Cfg_Flash_Identify_Ext(uint8_t callFromFlash,
uint32_t autoScan, uint32_t flashPinCfg, uint8_t restoreDefault, SPI_Flash_Cfg_Type *pFlashCfg) uint32_t autoScan,uint32_t flashPinCfg,uint8_t restoreDefault,SPI_Flash_Cfg_Type * pFlashCfg)
{ {
uint32_t jdecId = 0; uint32_t jdecId=0;
uint32_t i = 0; uint32_t i=0;
uint32_t ret = 0; uint32_t ret=0;
ret = SF_Cfg_Flash_Identify(callFromFlash, autoScan, flashPinCfg, restoreDefault, pFlashCfg); ret=SF_Cfg_Flash_Identify(callFromFlash,autoScan,flashPinCfg,restoreDefault,pFlashCfg);
if(callFromFlash){
if ((ret & BFLB_FLASH_ID_VALID_FLAG) != 0) { SFlash_Set_IDbus_Cfg(pFlashCfg,pFlashCfg->ioMode&0xf,1,0,32);
}
if((ret&BFLB_FLASH_ID_VALID_FLAG)!=0){
return ret; return ret;
} }
jdecId = (ret & 0xffffff); jdecId=(ret&0xffffff);
for(i=0;i<sizeof(flashInfos)/sizeof(flashInfos[0]);i++){
for (i = 0; i < sizeof(flashInfos) / sizeof(flashInfos[0]); i++) { if(flashInfos[i].jedecID==jdecId){
if (flashInfos[i].jedecID == jdecId) { BL602_MemCpy_Fast(pFlashCfg,flashInfos[i].cfg,sizeof(SPI_Flash_Cfg_Type));
BL602_MemCpy_Fast(pFlashCfg, flashInfos[i].cfg, sizeof(SPI_Flash_Cfg_Type));
break; break;
} }
} }
if(i==sizeof(flashInfos)/sizeof(flashInfos[0])){
if (i == sizeof(flashInfos) / sizeof(flashInfos[0])) {
return jdecId; return jdecId;
} else { }else{
return (jdecId | BFLB_FLASH_ID_VALID_FLAG); return (jdecId|BFLB_FLASH_ID_VALID_FLAG);
} }
} }

View file

@ -399,12 +399,45 @@ BL_Err_Type TIMER_Init(TIMER_CFG_Type *timerCfg)
if (timerCfg->countMode == TIMER_COUNT_PRELOAD) { if (timerCfg->countMode == TIMER_COUNT_PRELOAD) {
/* Configure timer preload value */ /* Configure timer preload value */
TIMER_SetPreloadValue(timerCh, timerCfg->preLoadVal); TIMER_SetPreloadValue(timerCh, timerCfg->preLoadVal);
}
/* Configure match compare values */ /* Configure match compare values */
if (timerCfg->matchVal0 > 1 + timerCfg->preLoadVal) {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0 - 2);
} else {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0); TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0);
}
if (timerCfg->matchVal1 > 1 + timerCfg->preLoadVal) {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1 - 2);
} else {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1); TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1);
}
if (timerCfg->matchVal2 > 1 + timerCfg->preLoadVal) {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2 - 2);
} else {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2); TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2);
}
} else {
/* Configure match compare values */
if (timerCfg->matchVal0 > 1) {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0 - 2);
} else {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_0, timerCfg->matchVal0);
}
if (timerCfg->matchVal1 > 1) {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1 - 2);
} else {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_1, timerCfg->matchVal1);
}
if (timerCfg->matchVal2 > 1) {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2 - 2);
} else {
TIMER_SetCompValue(timerCh, TIMER_COMP_ID_2, timerCfg->matchVal2);
}
}
#ifndef BFLB_USE_HAL_DRIVER #ifndef BFLB_USE_HAL_DRIVER
Interrupt_Handler_Register(TIMER_CH0_IRQn, TIMER_CH0_IRQHandler); Interrupt_Handler_Register(TIMER_CH0_IRQn, TIMER_CH0_IRQHandler);

View file

@ -35,13 +35,16 @@
*/ */
#include "string.h" #include "string.h"
#include "bl602_sf_cfg.h"
#include "bl602_sf_cfg_ext.h"
#include "bl602_xip_sflash.h"
#include "bl602_xip_sflash_ext.h" #include "bl602_xip_sflash_ext.h"
/** @addtogroup BL602_Peripheral_Driver /** @addtogroup BL602_Peripheral_Driver
* @{ * @{
*/ */
/** @addtogroup XIP_SFLASH /** @addtogroup XIP_SFLASH_EXT
* @{ * @{
*/ */
@ -82,7 +85,319 @@ static uint8_t aesEnable;
* @{ * @{
*/ */
/****************************************************************************/ /** /*@} end of group XIP_SFLASH_EXT_Private_Functions */
/** @defgroup XIP_SFLASH_EXT_Public_Functions
* @{
*/
/****************************************************************************//**
* @brief Restore flash controller state
*
* @param pFlashCfg: Flash config pointer
* @param offset: CPU XIP flash offset
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_State_Restore_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t offset)
{
uint32_t tmp[1];
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
SF_Ctrl_Set_Flash_Image_Offset(offset);
SFlash_SetBurstWrap(pFlashCfg);
SFlash_Read(pFlashCfg,ioMode,1,0x0,(uint8_t *)tmp, sizeof(tmp));
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
return SUCCESS;
}
/*@} end of group XIP_SFLASH_EXT_Public_Functions */
/** @defgroup XIP_SFLASH_EXT_Public_Functions
* @{
*/
/****************************************************************************//**
* @brief Erase flash one region
*
* @param pFlashCfg: Flash config pointer
* @param startaddr: start address to erase
* @param endaddr: end address(include this address) to erase
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_Erase_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t startaddr,uint32_t endaddr)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
stat=SFlash_Erase(pFlashCfg,startaddr,endaddr);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return stat;
}
/****************************************************************************//**
* @brief Program flash one region
*
* @param pFlashCfg: Flash config pointer
* @param addr: start address to be programed
* @param data: data pointer to be programed
* @param len: data length to be programed
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_Write_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr,uint8_t *data, uint32_t len)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
stat= SFlash_Program(pFlashCfg,ioMode,addr,data,len);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return stat;
}
/****************************************************************************//**
* @brief Read data from flash
*
* @param pFlashCfg: Flash config pointer
* @param addr: flash read start address
* @param data: data pointer to store data read from flash
* @param len: data length to read
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_Read_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr,uint8_t *data, uint32_t len)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
stat=SFlash_Read(pFlashCfg,ioMode,0,addr, data,len);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return stat;
}
/****************************************************************************//**
* @brief Get Flash Jedec ID
*
* @param pFlashCfg: Flash config pointer
* @param data: data pointer to store Jedec ID Read from flash
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_GetJedecId_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint8_t *data)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
SFlash_GetJedecId(pFlashCfg,data);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return SUCCESS;
}
/****************************************************************************//**
* @brief Get Flash Device ID
*
* @param pFlashCfg: Flash config pointer
* @param data: data pointer to store Device ID Read from flash
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_GetDeviceId_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint8_t *data)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
SFlash_GetDeviceId(data);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return SUCCESS;
}
/****************************************************************************//**
* @brief Get Flash Unique ID
*
* @param pFlashCfg: Flash config pointer
* @param data: data pointer to store Device ID Read from flash
* @param idLen: Unique id len
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_GetUniqueId_Need_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint8_t *data,uint8_t idLen)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
SFlash_GetUniqueId(data,idLen);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return SUCCESS;
}
/****************************************************************************//**
* @brief Sflash enable RCV mode to recovery for erase while power drop need lock
*
* @param pFlashCfg: Flash config pointer
* @param rCmd: Read RCV register cmd
* @param wCmd: Write RCV register cmd
* @param bitPos: RCV register bit pos
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
__WEAK
BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_RCV_Enable_Need_Lock(SPI_Flash_Cfg_Type *pFlashCfg, uint8_t rCmd, uint8_t wCmd, uint8_t bitPos)
{
BL_Err_Type stat;
uint32_t offset;
SF_Ctrl_IO_Type ioMode = (SF_Ctrl_IO_Type)pFlashCfg->ioMode&0xf;
stat=XIP_SFlash_State_Save(pFlashCfg,&offset);
if(stat!=SUCCESS){
SFlash_Set_IDbus_Cfg(pFlashCfg,ioMode,1,0,32);
}else{
stat=SFlash_RCV_Enable(pFlashCfg, rCmd, wCmd, bitPos);
XIP_SFlash_State_Restore_Ext(pFlashCfg,offset);
}
return stat;
}
/****************************************************************************//**
* @brief Read data from flash with lock
*
* @param pFlashCfg: Flash config pointer
* @param addr: flash read start address
* @param dst: data pointer to store data read from flash
* @param len: data length to read
*
* @return 0
*
*******************************************************************************/
__WEAK
int ATTR_TCM_SECTION XIP_SFlash_Read_With_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr, uint8_t *dst, int len)
{
__disable_irq();
XIP_SFlash_Read_Need_Lock_Ext(pFlashCfg, addr, dst, len);
__enable_irq();
return 0;
}
/****************************************************************************//**
* @brief Program flash one region with lock
*
* @param pFlashCfg: Flash config pointer
* @param addr: Start address to be programed
* @param src: Data pointer to be programed
* @param len: Data length to be programed
*
* @return 0
*
*******************************************************************************/
__WEAK
int ATTR_TCM_SECTION XIP_SFlash_Write_With_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr, uint8_t *src, int len)
{
__disable_irq();
XIP_SFlash_Write_Need_Lock_Ext(pFlashCfg, addr, src, len);
__enable_irq();
return 0;
}
/****************************************************************************//**
* @brief Erase flash one region with lock
*
* @param pFlashCfg: Flash config pointer
* @param addr: Start address to be erased
* @param len: Data length to be erased
*
* @return 0
*
*******************************************************************************/
__WEAK
int ATTR_TCM_SECTION XIP_SFlash_Erase_With_Lock_Ext(SPI_Flash_Cfg_Type *pFlashCfg,uint32_t addr, int len)
{
__disable_irq();
XIP_SFlash_Erase_Need_Lock_Ext(pFlashCfg, addr, addr + len - 1);
__enable_irq();
return 0;
}
/****************************************************************************//**
* @brief Sflash enable RCV mode to recovery for erase while power drop with lock
*
* @param pFlashCfg: Flash config pointer
* @param rCmd: Read RCV register cmd
* @param wCmd: Write RCV register cmd
* @param bitPos: RCV register bit pos
*
* @return 0
*
*******************************************************************************/
__WEAK
int ATTR_TCM_SECTION XIP_SFlash_RCV_Enable_With_Lock(SPI_Flash_Cfg_Type *pFlashCfg, uint8_t rCmd, uint8_t wCmd, uint8_t bitPos)
{
__disable_irq();
XIP_SFlash_RCV_Enable_Need_Lock(pFlashCfg, rCmd, wCmd, bitPos);
__enable_irq();
return 0;
}
/****************************************************************************//**
* @brief Read data from flash with lock * @brief Read data from flash with lock
* *
* @param pFlashCfg:Flash config pointer * @param pFlashCfg:Flash config pointer
@ -95,23 +410,22 @@ BL_Err_Type ATTR_TCM_SECTION XIP_SFlash_Init(SPI_Flash_Cfg_Type *pFlashCfg)
{ {
uint32_t ret; uint32_t ret;
if (pFlashCfg == NULL) { if(pFlashCfg==NULL){
/* Get flash config identify */ /* Get flash config identify */
XIP_SFlash_Opt_Enter(&aesEnable); XIP_SFlash_Opt_Enter(&aesEnable);
ret = SF_Cfg_Flash_Identify_Ext(1, 1, 0, 0, &flashCfg); ret=SF_Cfg_Flash_Identify_Ext(1,1,0,0,&flashCfg);
XIP_SFlash_Opt_Exit(aesEnable); XIP_SFlash_Opt_Exit(aesEnable);
if((ret&BFLB_FLASH_ID_VALID_FLAG)==0){
if ((ret & BFLB_FLASH_ID_VALID_FLAG) == 0) {
return ERROR; return ERROR;
} }
} else { }else{
memcpy(&flashCfg, pFlashCfg, sizeof(flashCfg)); memcpy(&flashCfg,pFlashCfg,sizeof(flashCfg));
} }
return SUCCESS; return SUCCESS;
} }
/****************************************************************************/ /** /****************************************************************************//**
* @brief Read data from flash with lock * @brief Read data from flash with lock
* *
* @param addr: flash read start address * @param addr: flash read start address
@ -126,13 +440,13 @@ int ATTR_TCM_SECTION XIP_SFlash_Read(uint32_t addr, uint8_t *dst, int len)
{ {
__disable_irq(); __disable_irq();
XIP_SFlash_Opt_Enter(&aesEnable); XIP_SFlash_Opt_Enter(&aesEnable);
XIP_SFlash_Read_Need_Lock(&flashCfg, addr, dst, len); XIP_SFlash_Read_Need_Lock_Ext(&flashCfg, addr, dst, len);
XIP_SFlash_Opt_Exit(aesEnable); XIP_SFlash_Opt_Exit(aesEnable);
__enable_irq(); __enable_irq();
return 0; return 0;
} }
/****************************************************************************/ /** /****************************************************************************//**
* @brief Program flash one region with lock * @brief Program flash one region with lock
* *
* @param addr: Start address to be programed * @param addr: Start address to be programed
@ -147,13 +461,13 @@ int ATTR_TCM_SECTION XIP_SFlash_Write(uint32_t addr, uint8_t *src, int len)
{ {
__disable_irq(); __disable_irq();
XIP_SFlash_Opt_Enter(&aesEnable); XIP_SFlash_Opt_Enter(&aesEnable);
XIP_SFlash_Write_Need_Lock(&flashCfg, addr, src, len); XIP_SFlash_Write_Need_Lock_Ext(&flashCfg, addr, src, len);
XIP_SFlash_Opt_Exit(aesEnable); XIP_SFlash_Opt_Exit(aesEnable);
__enable_irq(); __enable_irq();
return 0; return 0;
} }
/****************************************************************************/ /** /****************************************************************************//**
* @brief Erase flash one region with lock * @brief Erase flash one region with lock
* *
* @param addr: Start address to be erased * @param addr: Start address to be erased
@ -167,12 +481,11 @@ int ATTR_TCM_SECTION XIP_SFlash_Erase(uint32_t addr, int len)
{ {
__disable_irq(); __disable_irq();
XIP_SFlash_Opt_Enter(&aesEnable); XIP_SFlash_Opt_Enter(&aesEnable);
XIP_SFlash_Erase_Need_Lock(&flashCfg, addr, addr + len - 1); XIP_SFlash_Erase_Need_Lock_Ext(&flashCfg, addr, addr + len - 1);
XIP_SFlash_Opt_Exit(aesEnable); XIP_SFlash_Opt_Exit(aesEnable);
__enable_irq(); __enable_irq();
return 0; return 0;
} }
/*@} end of group XIP_SFLASH_EXT_Public_Functions */ /*@} end of group XIP_SFLASH_EXT_Public_Functions */
/*@} end of group XIP_SFLASH_EXT */ /*@} end of group XIP_SFLASH_EXT */