|
@ -574,13 +574,12 @@ FError FQspiFlashReadDataConfig(FQspiCtrl *pctrl, u8 command) |
|
|
* @name: FQspiFlashWriteData |
|
|
* @name: FQspiFlashWriteData |
|
|
* @msg: write flash data |
|
|
* @msg: write flash data |
|
|
* @param {FQspiCtrl} *pctrl, instance of FQSPI controller |
|
|
* @param {FQspiCtrl} *pctrl, instance of FQSPI controller |
|
|
* @param {u8} command, command to write flash,see the Flash manual for details |
|
|
|
|
|
* @param {u32} chip_addr, The start address of the chip to write |
|
|
* @param {u32} chip_addr, The start address of the chip to write |
|
|
* @param {u8} *buf, write buffer |
|
|
* @param {u8} *buf, write buffer |
|
|
* @param {size_t} len, write length |
|
|
* @param {size_t} len, write length |
|
|
* @return {FError} err code information, FQSPI_SUCCESS indicates success,others indicates failed 表示写入成功,其它返回值表示写入失败 |
|
|
* @return {FError} err code information, FQSPI_SUCCESS indicates success,others indicates failed 表示写入成功,其它返回值表示写入失败 |
|
|
*/ |
|
|
*/ |
|
|
FError FQspiFlashWriteData(FQspiCtrl *pctrl, u8 command, u32 chip_addr, const u8 *buf, size_t len) |
|
|
FError FQspiFlashWriteData(FQspiCtrl *pctrl, u32 chip_addr, const u8 *buf, size_t len) |
|
|
{ |
|
|
{ |
|
|
FASSERT(pctrl && buf); |
|
|
FASSERT(pctrl && buf); |
|
|
FError ret = FQSPI_SUCCESS; |
|
|
FError ret = FQSPI_SUCCESS; |
|
@ -589,7 +588,6 @@ FError FQspiFlashWriteData(FQspiCtrl *pctrl, u8 command, u32 chip_addr, const u8 |
|
|
u32 reg_val = 0; |
|
|
u32 reg_val = 0; |
|
|
u32 val = 0; |
|
|
u32 val = 0; |
|
|
u32 aligned_bit = 0; |
|
|
u32 aligned_bit = 0; |
|
|
|
|
|
|
|
|
u8 tmp[FQSPI_ALIGNED_BYTE] = {0xff, 0xff, 0xff, 0xff}; |
|
|
u8 tmp[FQSPI_ALIGNED_BYTE] = {0xff, 0xff, 0xff, 0xff}; |
|
|
uintptr addr = pctrl->config.mem_start + pctrl->config.channel * pctrl->flash_size + chip_addr; |
|
|
uintptr addr = pctrl->config.mem_start + pctrl->config.channel * pctrl->flash_size + chip_addr; |
|
|
uintptr base_addr = pctrl->config.base_addr; |
|
|
uintptr base_addr = pctrl->config.base_addr; |
|
@ -608,40 +606,6 @@ FError FQspiFlashWriteData(FQspiCtrl *pctrl, u8 command, u32 chip_addr, const u8 |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
memset(&pctrl->wr_cfg, 0, sizeof(pctrl->wr_cfg)); |
|
|
|
|
|
/* set cmd region, command */ |
|
|
|
|
|
pctrl->wr_cfg.wr_cmd = command; |
|
|
|
|
|
pctrl->wr_cfg.wr_wait = FQSPI_WAIT_ENABLE; |
|
|
|
|
|
/* clear addr select bit */ |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = 0; |
|
|
|
|
|
/* set wr mode, use buffer */ |
|
|
|
|
|
pctrl->wr_cfg.wr_mode = FQSPI_USE_BUFFER_ENABLE; |
|
|
|
|
|
/* set sck_sel region, clk_div */ |
|
|
|
|
|
pctrl->wr_cfg.wr_sck_sel = FQSPI_SCK_DIV_128; |
|
|
|
|
|
|
|
|
|
|
|
/* set addr_sel region, FQSPI_ADDR_SEL_3 or FQSPI_ADDR_SEL_4 */ |
|
|
|
|
|
switch (command) |
|
|
|
|
|
{ |
|
|
|
|
|
case FQSPI_FLASH_CMD_PP: |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = FQSPI_ADDR_SEL_3; |
|
|
|
|
|
break; |
|
|
|
|
|
case FQSPI_FLASH_CMD_QPP: |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = FQSPI_ADDR_SEL_3; |
|
|
|
|
|
pctrl->wr_cfg.wr_transfer = FQSPI_TRANSFER_1_1_4; |
|
|
|
|
|
break; |
|
|
|
|
|
case FQSPI_FLASH_CMD_4PP: |
|
|
|
|
|
case FQSPI_FLASH_CMD_4QPP: |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = FQSPI_ADDR_SEL_4; |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
ret |= FQSPI_NOT_SUPPORT; |
|
|
|
|
|
return ret; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*write wr_cfg to Write config register 0x08 */ |
|
|
|
|
|
FQspiWrCfgConfig(pctrl); |
|
|
|
|
|
|
|
|
|
|
|
if (IS_ALIGNED(addr, FQSPI_ALIGNED_BYTE)) /* if copy src is aligned by 4 bytes */ |
|
|
if (IS_ALIGNED(addr, FQSPI_ALIGNED_BYTE)) /* if copy src is aligned by 4 bytes */ |
|
|
{ |
|
|
{ |
|
|
/* write alligned data into memory space */ |
|
|
/* write alligned data into memory space */ |
|
@ -702,6 +666,54 @@ FError FQspiFlashWriteData(FQspiCtrl *pctrl, u8 command, u32 chip_addr, const u8 |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @name: FQspiFlashWriteDataConfig |
|
|
|
|
|
* @msg: write flash data configuration |
|
|
|
|
|
* @param {FQspiCtrl} *pctrl, instance of FQSPI controller |
|
|
|
|
|
* @param {u8} command, command to write flash,see the Flash manual for details |
|
|
|
|
|
* @return {FError} err code information, FQSPI_SUCCESS indicates success,others indicates failed 表示配置成功,其它返回值表示配置失败 |
|
|
|
|
|
*/ |
|
|
|
|
|
FError FQspiFlashWriteDataConfig(FQspiCtrl *pctrl, u8 command) |
|
|
|
|
|
{ |
|
|
|
|
|
FASSERT(pctrl); |
|
|
|
|
|
FError ret = FQSPI_SUCCESS; |
|
|
|
|
|
memset(&pctrl->wr_cfg, 0, sizeof(pctrl->wr_cfg)); |
|
|
|
|
|
/* set cmd region, command */ |
|
|
|
|
|
pctrl->wr_cfg.wr_cmd = command; |
|
|
|
|
|
pctrl->wr_cfg.wr_wait = FQSPI_WAIT_ENABLE; |
|
|
|
|
|
/* clear addr select bit */ |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = 0; |
|
|
|
|
|
/* set wr mode, use buffer */ |
|
|
|
|
|
pctrl->wr_cfg.wr_mode = FQSPI_USE_BUFFER_ENABLE; |
|
|
|
|
|
/* set sck_sel region, clk_div */ |
|
|
|
|
|
pctrl->wr_cfg.wr_sck_sel = FQSPI_SCK_DIV_128; |
|
|
|
|
|
|
|
|
|
|
|
/* set addr_sel region, FQSPI_ADDR_SEL_3 or FQSPI_ADDR_SEL_4 */ |
|
|
|
|
|
switch (command) |
|
|
|
|
|
{ |
|
|
|
|
|
case FQSPI_FLASH_CMD_PP: |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = FQSPI_ADDR_SEL_3; |
|
|
|
|
|
break; |
|
|
|
|
|
case FQSPI_FLASH_CMD_QPP: |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = FQSPI_ADDR_SEL_3; |
|
|
|
|
|
pctrl->wr_cfg.wr_transfer = FQSPI_TRANSFER_1_1_4; |
|
|
|
|
|
break; |
|
|
|
|
|
case FQSPI_FLASH_CMD_4PP: |
|
|
|
|
|
case FQSPI_FLASH_CMD_4QPP: |
|
|
|
|
|
pctrl->wr_cfg.wr_addr_sel = FQSPI_ADDR_SEL_4; |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
ret |= FQSPI_NOT_SUPPORT; |
|
|
|
|
|
return ret; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*write wr_cfg to Write config register 0x08 */ |
|
|
|
|
|
FQspiWrCfgConfig(pctrl); |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* @name: FQspiFlashPortReadData |
|
|
* @name: FQspiFlashPortReadData |
|
|
* @msg: read flash data use register port |
|
|
* @msg: read flash data use register port |
|
|