野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11485|回复: 1

H7上使用SPI读写MX25L6433F

[复制链接]
发表于 2019-5-9 18:07:48 | 显示全部楼层 |阅读模式
同样的读写算法,同样的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]



回复

使用道具 举报

 楼主| 发表于 2019-5-9 18:09:08 | 显示全部楼层
请熟悉这个Flash的大佬看看
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-22 14:56 , Processed in 0.027312 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表