野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10023|回复: 4

求助!!!FLAH扇区擦除不成功!旧版例程里的代码

[复制链接]
发表于 2017-6-29 15:42:19 | 显示全部楼层 |阅读模式
  1. 无论是扇区擦除还是页擦除,都不成功,读ID正常。FLASH的0x00~0x46里的内容都不是0xFF,0x46之后的内容就是0xFF。请各位大大指点!!!
复制代码
  1. /**********************************************************************************
  2. * 文件名  :spi_flash.c
  3. * 描述    :spi 底层应用函数库         
  4. * 实验平台:野火STM32开发板
  5. * 硬件连接 ----------------------------
  6. *         | PA4-SPI1-NSS  : W25X16-CS  |
  7. *         | PA5-SPI1-SCK  : W25X16-CLK |
  8. *         | PA6-SPI1-MISO : W25X16-DO  |
  9. *         | PA7-SPI1-MOSI : W25X16-DIO |
  10. *          ----------------------------
  11. * 库版本  :ST3.5.0
  12. * 作者    :保留
  13. * 论坛    :http://www.amobbs.com/forum-1008-1.html
  14. * 淘宝    :http://firestm32.taobao.com
  15. **********************************************************************************/
  16. #include "spi_flash.h"



  17. /* Private typedef -----------------------------------------------------------*/
  18. //#define SPI_FLASH_PageSize      4096
  19. #define SPI_FLASH_PageSize      256
  20. #define SPI_FLASH_PerWritePageSize      256

  21. /* Private define ------------------------------------------------------------*/
  22. #define W25X_WriteEnable                      0x06
  23. #define W25X_WriteDisable                      0x04
  24. #define W25X_ReadStatusReg                    0x05
  25. #define W25X_WriteStatusReg                    0x01
  26. #define W25X_ReadData                                0x03
  27. #define W25X_FastReadData                      0x0B
  28. #define W25X_FastReadDual                      0x3B
  29. #define W25X_PageProgram                      0x02
  30. #define W25X_BlockErase                              0xD8
  31. #define W25X_SectorErase                      0x20
  32. #define W25X_ChipErase                              0xC7
  33. #define W25X_PowerDown                              0xB9
  34. #define W25X_ReleasePowerDown            0xAB
  35. #define W25X_DeviceID                                0xAB
  36. #define W25X_ManufactDeviceID           0x90
  37. #define W25X_JedecDeviceID                    0x9F

  38. #define WIP_Flag                  0x01  /* Write In Progress (WIP) flag */

  39. #define Dummy_Byte                0xFF

  40. /*******************************************************************************
  41. * Function Name  : SPI_FLASH_Init
  42. * Description    : Initializes the peripherals used by the SPI FLASH driver.
  43. * Input          : None
  44. * Output         : None
  45. * Return         : None
  46. *******************************************************************************/
  47. void SPI_FLASH_Init(void)
  48. {
  49.   SPI_InitTypeDef  SPI_InitStructure;
  50.   GPIO_InitTypeDef GPIO_InitStructure;
  51.   
  52.   /* Enable SPI1 and GPIO clocks */
  53.   /*!< SPI_FLASH_SPI_CS_GPIO, SPI_FLASH_SPI_MOSI_GPIO,
  54.        SPI_FLASH_SPI_MISO_GPIO, SPI_FLASH_SPI_DETECT_GPIO
  55.        and SPI_FLASH_SPI_SCK_GPIO Periph clock enable */
  56.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD, ENABLE);

  57.   /*!< SPI_FLASH_SPI Periph clock enable */
  58.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

  59.   
  60.   /*!< Configure SPI_FLASH_SPI pins: SCK */
  61.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  62.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  63.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  64.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  65.   /*!< Configure SPI_FLASH_SPI pins: MISO */
  66.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  67.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  68.   /*!< Configure SPI_FLASH_SPI pins: MOSI */
  69.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  70.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  71.   /*!< Configure SPI_FLASH_SPI_CS_PIN pin: SPI_FLASH Card CS pin */
  72.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  73.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  74.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  75.   /* Deselect the FLASH: Chip Select high */
  76.   SPI_FLASH_CS_HIGH();

  77.   /* SPI1 configuration */
  78.   // W25X16: data input on the DIO pin is sampled on the rising edge of the CLK.
  79.   // Data on the DO and DIO pins are clocked out on the falling edge of CLK.
  80.   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  81.   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  82.   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  83.   SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  84.   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  85.   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  86.   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  87.   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  88.   SPI_InitStructure.SPI_CRCPolynomial = 7;
  89.   SPI_Init(SPI1, &SPI_InitStructure);

  90.   /* Enable SPI1  */
  91.   SPI_Cmd(SPI1, ENABLE);
  92. }
  93. /*******************************************************************************
  94. * Function Name  : SPI_FLASH_SectorErase
  95. * Description    : Erases the specified FLASH sector.
  96. * Input          : SectorAddr: address of the sector to erase.
  97. * Output         : None
  98. * Return         : None
  99. *******************************************************************************/
  100. void SPI_FLASH_SectorErase(u32 SectorAddr)
  101. {
  102.   /* Send write enable instruction */
  103.   SPI_FLASH_WriteEnable();
  104.   SPI_FLASH_WaitForWriteEnd();
  105.   /* Sector Erase */
  106.   /* Select the FLASH: Chip Select low */
  107.   SPI_FLASH_CS_LOW();
  108.   /* Send Sector Erase instruction */
  109.   SPI_FLASH_SendByte(W25X_SectorErase);
  110.   /* Send SectorAddr high nibble address byte */
  111.   SPI_FLASH_SendByte((SectorAddr & 0xFF0000) >> 16);
  112.   /* Send SectorAddr medium nibble address byte */
  113.   SPI_FLASH_SendByte((SectorAddr & 0xFF00) >> 8);
  114.   /* Send SectorAddr low nibble address byte */
  115.   SPI_FLASH_SendByte(SectorAddr & 0xFF);
  116.   /* Deselect the FLASH: Chip Select high */
  117.   SPI_FLASH_CS_HIGH();
  118.   /* Wait the end of Flash writing */
  119.   SPI_FLASH_WaitForWriteEnd();
  120. }

  121. /*******************************************************************************
  122. * Function Name  : SPI_FLASH_BulkErase
  123. * Description    : Erases the entire FLASH.
  124. * Input          : None
  125. * Output         : None
  126. * Return         : None
  127. *******************************************************************************/
  128. void SPI_FLASH_BulkErase(void)
  129. {
  130.   /* Send write enable instruction */
  131.   SPI_FLASH_WriteEnable();

  132.   /* Bulk Erase */
  133.   /* Select the FLASH: Chip Select low */
  134.   SPI_FLASH_CS_LOW();
  135.   /* Send Bulk Erase instruction  */
  136.   SPI_FLASH_SendByte(W25X_ChipErase);
  137.   /* Deselect the FLASH: Chip Select high */
  138.   SPI_FLASH_CS_HIGH();

  139.   /* Wait the end of Flash writing */
  140.   SPI_FLASH_WaitForWriteEnd();
  141. }

  142. /*******************************************************************************
  143. * Function Name  : SPI_FLASH_PageWrite
  144. * Description    : Writes more than one byte to the FLASH with a single WRITE
  145. *                  cycle(Page WRITE sequence). The number of byte can't exceed
  146. *                  the FLASH page size.
  147. * Input          : - pBuffer : pointer to the buffer  containing the data to be
  148. *                    written to the FLASH.
  149. *                  - WriteAddr : FLASH's internal address to write to.
  150. *                  - NumByteToWrite : number of bytes to write to the FLASH,
  151. *                    must be equal or less than "SPI_FLASH_PageSize" value.
  152. * Output         : None
  153. * Return         : None
  154. *******************************************************************************/
  155. void SPI_FLASH_PageWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite)
  156. {
  157.   /* Enable the write access to the FLASH */
  158.   SPI_FLASH_WriteEnable();

  159.   /* Select the FLASH: Chip Select low */
  160.   SPI_FLASH_CS_LOW();
  161.   /* Send "Write to Memory " instruction */
  162.   SPI_FLASH_SendByte(W25X_PageProgram);
  163.   /* Send WriteAddr high nibble address byte to write to */
  164.   SPI_FLASH_SendByte((WriteAddr & 0xFF0000) >> 16);
  165.   /* Send WriteAddr medium nibble address byte to write to */
  166.   SPI_FLASH_SendByte((WriteAddr & 0xFF00) >> 8);
  167.   /* Send WriteAddr low nibble address byte to write to */
  168.   SPI_FLASH_SendByte(WriteAddr & 0xFF);

  169.   if(NumByteToWrite > SPI_FLASH_PerWritePageSize)
  170.   {
  171.      NumByteToWrite = SPI_FLASH_PerWritePageSize;
  172.      //printf("\n\r Err: SPI_FLASH_PageWrite too large!");
  173.   }

  174.   /* while there is data to be written on the FLASH */
  175.   while (NumByteToWrite--)
  176.   {
  177.     /* Send the current byte */
  178.     SPI_FLASH_SendByte(*pBuffer);
  179.     /* Point on the next byte to be written */
  180.     pBuffer++;
  181.   }

  182.   /* Deselect the FLASH: Chip Select high */
  183.   SPI_FLASH_CS_HIGH();

  184.   /* Wait the end of Flash writing */
  185.   SPI_FLASH_WaitForWriteEnd();
  186. }

  187. /*******************************************************************************
  188. * Function Name  : SPI_FLASH_BufferWrite
  189. * Description    : Writes block of data to the FLASH. In this function, the
  190. *                  number of WRITE cycles are reduced, using Page WRITE sequence.
  191. * Input          : - pBuffer : pointer to the buffer  containing the data to be
  192. *                    written to the FLASH.
  193. *                  - WriteAddr : FLASH's internal address to write to.
  194. *                  - NumByteToWrite : number of bytes to write to the FLASH.
  195. * Output         : None
  196. * Return         : None
  197. *******************************************************************************/
  198. void SPI_FLASH_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite)
  199. {
  200.   u8 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;

  201.   Addr = WriteAddr % SPI_FLASH_PageSize;
  202.   count = SPI_FLASH_PageSize - Addr;
  203.   NumOfPage =  NumByteToWrite / SPI_FLASH_PageSize;
  204.   NumOfSingle = NumByteToWrite % SPI_FLASH_PageSize;

  205.   if (Addr == 0) /* WriteAddr is SPI_FLASH_PageSize aligned  */
  206.   {
  207.     if (NumOfPage == 0) /* NumByteToWrite < SPI_FLASH_PageSize */
  208.     {
  209.       SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumByteToWrite);
  210.     }
  211.     else /* NumByteToWrite > SPI_FLASH_PageSize */
  212.     {
  213.       while (NumOfPage--)
  214.       {
  215.         SPI_FLASH_PageWrite(pBuffer, WriteAddr, SPI_FLASH_PageSize);
  216.         WriteAddr +=  SPI_FLASH_PageSize;
  217.         pBuffer += SPI_FLASH_PageSize;
  218.       }

  219.       SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumOfSingle);
  220.     }
  221.   }
  222.   else /* WriteAddr is not SPI_FLASH_PageSize aligned  */
  223.   {
  224.     if (NumOfPage == 0) /* NumByteToWrite < SPI_FLASH_PageSize */
  225.     {
  226.       if (NumOfSingle > count) /* (NumByteToWrite + WriteAddr) > SPI_FLASH_PageSize */
  227.       {
  228.         temp = NumOfSingle - count;

  229.         SPI_FLASH_PageWrite(pBuffer, WriteAddr, count);
  230.         WriteAddr +=  count;
  231.         pBuffer += count;

  232.         SPI_FLASH_PageWrite(pBuffer, WriteAddr, temp);
  233.       }
  234.       else
  235.       {
  236.         SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumByteToWrite);
  237.       }
  238.     }
  239.     else /* NumByteToWrite > SPI_FLASH_PageSize */
  240.     {
  241.       NumByteToWrite -= count;
  242.       NumOfPage =  NumByteToWrite / SPI_FLASH_PageSize;
  243.       NumOfSingle = NumByteToWrite % SPI_FLASH_PageSize;

  244.       SPI_FLASH_PageWrite(pBuffer, WriteAddr, count);
  245.       WriteAddr +=  count;
  246.       pBuffer += count;

  247.       while (NumOfPage--)
  248.       {
  249.         SPI_FLASH_PageWrite(pBuffer, WriteAddr, SPI_FLASH_PageSize);
  250.         WriteAddr +=  SPI_FLASH_PageSize;
  251.         pBuffer += SPI_FLASH_PageSize;
  252.       }

  253.       if (NumOfSingle != 0)
  254.       {
  255.         SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumOfSingle);
  256.       }
  257.     }
  258.   }
  259. }

  260. /*******************************************************************************
  261. * Function Name  : SPI_FLASH_BufferRead
  262. * Description    : Reads a block of data from the FLASH.
  263. * Input          : - pBuffer : pointer to the buffer that receives the data read
  264. *                    from the FLASH.
  265. *                  - ReadAddr : FLASH's internal address to read from.
  266. *                  - NumByteToRead : number of bytes to read from the FLASH.
  267. * Output         : None
  268. * Return         : None
  269. *******************************************************************************/
  270. void SPI_FLASH_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)
  271. {
  272.   /* Select the FLASH: Chip Select low */
  273.   SPI_FLASH_CS_LOW();

  274.   /* Send "Read from Memory " instruction */
  275.   SPI_FLASH_SendByte(W25X_ReadData);

  276.   /* Send ReadAddr high nibble address byte to read from */
  277.   SPI_FLASH_SendByte((ReadAddr & 0xFF0000) >> 16);
  278.   /* Send ReadAddr medium nibble address byte to read from */
  279.   SPI_FLASH_SendByte((ReadAddr& 0xFF00) >> 8);
  280.   /* Send ReadAddr low nibble address byte to read from */
  281.   SPI_FLASH_SendByte(ReadAddr & 0xFF);

  282.   while (NumByteToRead--) /* while there is data to be read */
  283.   {
  284.     /* Read a byte from the FLASH */
  285.     *pBuffer = SPI_FLASH_SendByte(Dummy_Byte);
  286.     /* Point to the next location where the byte read will be saved */
  287.     pBuffer++;
  288.   }

  289.   /* Deselect the FLASH: Chip Select high */
  290.   SPI_FLASH_CS_HIGH();
  291. }

  292. /*******************************************************************************
  293. * Function Name  : SPI_FLASH_ReadID
  294. * Description    : Reads FLASH identification.
  295. * Input          : None
  296. * Output         : None
  297. * Return         : FLASH identification
  298. *******************************************************************************/
  299. u32 SPI_FLASH_ReadID(void)
  300. {
  301.   u32 Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;

  302.   /* Select the FLASH: Chip Select low */
  303.   SPI_FLASH_CS_LOW();

  304.   /* Send "RDID " instruction */
  305.   SPI_FLASH_SendByte(W25X_JedecDeviceID);

  306.   /* Read a byte from the FLASH */
  307.   Temp0 = SPI_FLASH_SendByte(Dummy_Byte);

  308.   /* Read a byte from the FLASH */
  309.   Temp1 = SPI_FLASH_SendByte(Dummy_Byte);

  310.   /* Read a byte from the FLASH */
  311.   Temp2 = SPI_FLASH_SendByte(Dummy_Byte);

  312.   /* Deselect the FLASH: Chip Select high */
  313.   SPI_FLASH_CS_HIGH();

  314.   Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;

  315.   return Temp;
  316. }
  317. /*******************************************************************************
  318. * Function Name  : SPI_FLASH_ReadID
  319. * Description    : Reads FLASH identification.
  320. * Input          : None
  321. * Output         : None
  322. * Return         : FLASH identification
  323. *******************************************************************************/
  324. u32 SPI_FLASH_ReadDeviceID(void)
  325. {
  326.   u32 Temp = 0;

  327.   /* Select the FLASH: Chip Select low */
  328.   SPI_FLASH_CS_LOW();

  329.   /* Send "RDID " instruction */
  330.   SPI_FLASH_SendByte(W25X_DeviceID);
  331.   SPI_FLASH_SendByte(Dummy_Byte);
  332.   SPI_FLASH_SendByte(Dummy_Byte);
  333.   SPI_FLASH_SendByte(Dummy_Byte);
  334.   
  335.   /* Read a byte from the FLASH */
  336.   Temp = SPI_FLASH_SendByte(Dummy_Byte);

  337.   /* Deselect the FLASH: Chip Select high */
  338.   SPI_FLASH_CS_HIGH();

  339.   return Temp;
  340. }
  341. /*******************************************************************************
  342. * Function Name  : SPI_FLASH_StartReadSequence
  343. * Description    : Initiates a read data byte (READ) sequence from the Flash.
  344. *                  This is done by driving the /CS line low to select the device,
  345. *                  then the READ instruction is transmitted followed by 3 bytes
  346. *                  address. This function exit and keep the /CS line low, so the
  347. *                  Flash still being selected. With this technique the whole
  348. *                  content of the Flash is read with a single READ instruction.
  349. * Input          : - ReadAddr : FLASH's internal address to read from.
  350. * Output         : None
  351. * Return         : None
  352. *******************************************************************************/
  353. void SPI_FLASH_StartReadSequence(u32 ReadAddr)
  354. {
  355.   /* Select the FLASH: Chip Select low */
  356.   SPI_FLASH_CS_LOW();

  357.   /* Send "Read from Memory " instruction */
  358.   SPI_FLASH_SendByte(W25X_ReadData);

  359.   /* Send the 24-bit address of the address to read from -----------------------*/
  360.   /* Send ReadAddr high nibble address byte */
  361.   SPI_FLASH_SendByte((ReadAddr & 0xFF0000) >> 16);
  362.   /* Send ReadAddr medium nibble address byte */
  363.   SPI_FLASH_SendByte((ReadAddr& 0xFF00) >> 8);
  364.   /* Send ReadAddr low nibble address byte */
  365.   SPI_FLASH_SendByte(ReadAddr & 0xFF);
  366. }

  367. /*******************************************************************************
  368. * Function Name  : SPI_FLASH_ReadByte
  369. * Description    : Reads a byte from the SPI Flash.
  370. *                  This function must be used only if the Start_Read_Sequence
  371. *                  function has been previously called.
  372. * Input          : None
  373. * Output         : None
  374. * Return         : Byte Read from the SPI Flash.
  375. *******************************************************************************/
  376. u8 SPI_FLASH_ReadByte(void)
  377. {
  378.   return (SPI_FLASH_SendByte(Dummy_Byte));
  379. }

  380. /*******************************************************************************
  381. * Function Name  : SPI_FLASH_SendByte
  382. * Description    : Sends a byte through the SPI interface and return the byte
  383. *                  received from the SPI bus.
  384. * Input          : byte : byte to send.
  385. * Output         : None
  386. * Return         : The value of the received byte.
  387. *******************************************************************************/
  388. u8 SPI_FLASH_SendByte(u8 byte)
  389. {
  390.   /* Loop while DR register in not emplty */
  391.   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

  392.   /* Send byte through the SPI1 peripheral */
  393.   SPI_I2S_SendData(SPI1, byte);

  394.   /* Wait to receive a byte */
  395.   //while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  396.   while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);

  397.   /* Return the byte read from the SPI bus */
  398.   return SPI_I2S_ReceiveData(SPI1);
  399. }

  400. /*******************************************************************************
  401. * Function Name  : SPI_FLASH_SendHalfWord
  402. * Description    : Sends a Half Word through the SPI interface and return the
  403. *                  Half Word received from the SPI bus.
  404. * Input          : Half Word : Half Word to send.
  405. * Output         : None
  406. * Return         : The value of the received Half Word.
  407. *******************************************************************************/
  408. u16 SPI_FLASH_SendHalfWord(u16 HalfWord)
  409. {
  410.   /* Loop while DR register in not emplty */
  411.   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

  412.   /* Send Half Word through the SPI1 peripheral */
  413.   SPI_I2S_SendData(SPI1, HalfWord);

  414.   /* Wait to receive a Half Word */
  415.   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);

  416.   /* Return the Half Word read from the SPI bus */
  417.   return SPI_I2S_ReceiveData(SPI1);
  418. }

  419. /*******************************************************************************
  420. * Function Name  : SPI_FLASH_WriteEnable
  421. * Description    : Enables the write access to the FLASH.
  422. * Input          : None
  423. * Output         : None
  424. * Return         : None
  425. *******************************************************************************/
  426. void SPI_FLASH_WriteEnable(void)
  427. {
  428.   /* Select the FLASH: Chip Select low */
  429.   SPI_FLASH_CS_LOW();

  430.   /* Send "Write Enable" instruction */
  431.   SPI_FLASH_SendByte(W25X_WriteEnable);

  432.   /* Deselect the FLASH: Chip Select high */
  433.   SPI_FLASH_CS_HIGH();
  434. }

  435. /*******************************************************************************
  436. * Function Name  : SPI_FLASH_WaitForWriteEnd
  437. * Description    : Polls the status of the Write In Progress (WIP) flag in the
  438. *                  FLASH's status  register  and  loop  until write  opertaion
  439. *                  has completed.
  440. * Input          : None
  441. * Output         : None
  442. * Return         : None
  443. *******************************************************************************/
  444. void SPI_FLASH_WaitForWriteEnd(void)
  445. {
  446.   u8 FLASH_Status = 0;

  447.   /* Select the FLASH: Chip Select low */
  448.   SPI_FLASH_CS_LOW();

  449.   /* Send "Read Status Register" instruction */
  450.   SPI_FLASH_SendByte(W25X_ReadStatusReg);

  451.   /* Loop as long as the memory is busy with a write cycle */
  452.   do
  453.   {
  454.     /* Send a dummy byte to generate the clock needed by the FLASH
  455.     and put the value of the status register in FLASH_Status variable */
  456.     FLASH_Status = SPI_FLASH_SendByte(Dummy_Byte);         
  457.   }
  458.   while ((FLASH_Status & WIP_Flag) == SET); /* Write in progress */

  459.   /* Deselect the FLASH: Chip Select high */
  460.   SPI_FLASH_CS_HIGH();
  461. }


  462. //进入掉电模式
  463. void SPI_Flash_PowerDown(void)   
  464. {
  465.   /* Select the FLASH: Chip Select low */
  466.   SPI_FLASH_CS_LOW();

  467.   /* Send "Power Down" instruction */
  468.   SPI_FLASH_SendByte(W25X_PowerDown);

  469.   /* Deselect the FLASH: Chip Select high */
  470.   SPI_FLASH_CS_HIGH();
  471. }   

  472. //唤醒
  473. void SPI_Flash_WAKEUP(void)   
  474. {
  475.   /* Select the FLASH: Chip Select low */
  476.   SPI_FLASH_CS_LOW();

  477.   /* Send "Power Down" instruction */
  478.   SPI_FLASH_SendByte(W25X_ReleasePowerDown);

  479.   /* Deselect the FLASH: Chip Select high */
  480.   SPI_FLASH_CS_HIGH();                   //等待TRES1
  481. }   

  482. /******************************END OF FILE*****************************/
复制代码


回复

使用道具 举报

发表于 2017-6-29 15:52:14 | 显示全部楼层
旧版是什么板子,到这个帖子下载配套的例程,每一项下面有板子的图片,对照来找找
【资料】野火产品资料合集(所有产品资料链接都在此处)-点击名称后下拉浏览器滚动条~
http://www.firebbs.cn/forum.php? ... 2686&fromuid=64
(出处: 野火论坛)


回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-29 15:57:58 | 显示全部楼层
flyleaf 发表于 2017-6-29 15:52
旧版是什么板子,到这个帖子下载配套的例程,每一项下面有板子的图片,对照来找找
【资料】野火产品资料合 ...

芯片是F103VET6的,好久之前买的了,能否看看代码有没有问题?查了好久都不知道什么问题。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-29 15:59:33 | 显示全部楼层
flyleaf 发表于 2017-6-29 15:52
旧版是什么板子,到这个帖子下载配套的例程,每一项下面有板子的图片,对照来找找
【资料】野火产品资料合 ...

野火M3的开发板
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-7-14 17:05:56 | 显示全部楼层
已找到问题,FLASH的扇区保护了,查询FLASH的寄存器标志可知道,S2,S3,S4,S5的值都为1,把这几位置0则关闭保护,擦除成功。不知道是什么时候被保护的,搞了好久才弄明白,血的教训,以后用什么器件都要老老实实的看DataSheet啦。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-24 02:16 , Processed in 0.033836 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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