小学生
最后登录1970-1-1
在线时间 小时
注册时间2019-5-9
|
同样的读写算法,同样的Flash,在QSPI下可以任意地址读写任意长度,在SPI接口就不行。SPI每次发送256个字节,QSPI是一次全部发送。
1.可能写入数据时超过了SPI的缓冲区?
2.写入地址大小超出SPI函数限制?
3.单次读取不能超过一个block也就是64K?
另外SPI写入时出现了基于Block的写入偏移,写入地址每大于一个Block,单次写入256字节时就在末尾有一个自己写入失败。。[mw_shl_code=c,true]int SendDatTo_Mx25_spi4(uint32_t add, uint32_t len)
{
uint32_t block_erase_num;
uint32_t pp_offset, pp_add, pp_len, pp_end, src_add;
pp_len = 0;
pp_add = add;
pp_end = add + len;
src_add = 0;
/*Total num of Erase block*/
block_erase_num = (pp_end - 1)/ QSPI_BLOCK_SIZE - add / QSPI_BLOCK_SIZE + 1;
/*Erase block slected*/
for(uint32_t n = 0; n < block_erase_num; n++)
{
/*Write System Reg*/
Mx25_Write_Enable_spi4();
while( WELMASK != (Mx25_Read_State_spi4() & WELMASK));
Mx25_Write_StateRegister_spi4(); // Disable WP
while(Mx25_Read_State_spi4() & WIPMASK);
Mx25_Write_Enable_spi4();
while( WELMASK != (Mx25_Read_State_spi4() & WELMASK));
Mx25_Erase_Sector_spi4((add / QSPI_BLOCK_SIZE + n) * QSPI_BLOCK_SIZE);
while(Mx25_Read_State_spi4() & WIPMASK);
}
#if 1
/*check erase*/
check_erase(add);
#endif
/*Page program*/
for(;pp_add != pp_end;)
{
pp_offset = pp_add % QSPI_PAGE_SIZE;
pp_len = (pp_offset + pp_end - pp_add) < QSPI_PAGE_SIZE ? (pp_end - pp_add) : (QSPI_PAGE_SIZE - pp_offset);
if(0 != write_to_mx25_spi4(DateTestBuf + src_add, pp_add, pp_len))
{
printf("write error, add: 0x&x\r\n", src_add);
}
#if 1
/*compare Recv data to Datetest*/
Mx25_FastRead_1_line_spi4(fw_readback_buff + src_add, pp_add, pp_len);
compar_falsh_dat(fw_readback_buff + src_add, DateTestBuf + src_add, pp_len);
#endif
pp_add += pp_len;
src_add += pp_len;
}
[/mw_shl_code][mw_shl_code=c,true]int write_to_mx25_spi4( uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite )
{
uint8_t command = FLASH_CMD_PP; //1线写指令
Mx25_Write_Enable_spi4();
while( WELMASK != (Mx25_Read_State_spi4() & WELMASK));
HAL_GPIO_WritePin(GPIOE ,GPIO_PIN_11 ,GPIO_PIN_RESET);
HAL_SPI_Transmit(&SPI4_Handle, &command, 1, 5000);
HAL_SPI_Transmit(&SPI4_Handle, (void *)&WriteAddr, 3, 5000);
HAL_SPI_Transmit(&SPI4_Handle, pBuffer, NumByteToWrite, 5000);
HAL_GPIO_WritePin(GPIOE ,GPIO_PIN_11 ,GPIO_PIN_SET);
while(WIPMASK == (Mx25_Read_State_spi4() & WIPMASK));
return 0;
}
void Mx25_FastRead_1_line_spi4(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead)
{
uint32_t index = 0;
uint8_t command = 0x0b; //指令
HAL_GPIO_WritePin(GPIOE ,GPIO_PIN_11 ,GPIO_PIN_RESET);
HAL_SPI_Transmit(&SPI4_Handle, &command, 1, 5000);
HAL_SPI_Transmit(&SPI4_Handle, (void *)&ReadAddr, 3, 5000);
command = 0x55;
HAL_SPI_Transmit(&SPI4_Handle, &command, 1, 5000);
for(; index < NumByteToRead; index++)
{
HAL_SPI_Receive(&SPI4_Handle, pBuffer + index, 1, 5000);
}
HAL_GPIO_WritePin(GPIOE ,GPIO_PIN_11 ,GPIO_PIN_SET);
}[/mw_shl_code]
|
|