外挂W25Q128 easyflash初始化错误

发布于 2020-03-17 16:18:45    浏览:797
芯片是stm32f103,基本是按照这篇帖子操作的:https://www.rt-thread.org/qa/forum.php?mod=viewthread&tid=423771&highlight=sfud
之后有一个很奇怪的现象
程序第一次启动之后会打印这条log:
[Flash] Warning: Sector header check failed. Format this sector (0x00000000).
但是芯片reset之后再启动会打印这条log,然后在读flash时死机:
[Flash] Warning: Sector header check failed. Format this sector (0x00000800).
之后每次reset会在这两种情况中循环,一次0x00000000,0x00000800。
这是spi初始化代码,其中PA4是NSS,PC4是nRST,PC5是nWP:
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct = { 0 };
if (hspi->Instance == SPI1)
{
__HAL_RCC_SPI1_CLK_ENABLE()
;

__HAL_RCC_GPIOA_CLK_ENABLE()
;
__HAL_RCC_GPIOC_CLK_ENABLE()
;
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/*Configure GPIO pins : PC4 PC5 */
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

/*Configure GPIO pins : PC4 PC5 */
GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4 | GPIO_PIN_5, GPIO_PIN_SET);
}

}
这是flash初始化代码:
int ef_init(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE()
;
rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_4);
if (RT_NULL == rt_sfud_flash_probe(FAL_USING_NOR_FLASH_DEV_NAME, "spi10"))
{
return -RT_ERROR;
};

fal_init();
if (easyflash_init() == EF_NO_ERR)
{
return RT_EOK;
}
else
{
return RT_ERROR;
}
}

INIT_DEVICE_EXPORT(ef_init);
这是分区表:
#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_

#include
#include

#define NOR_FLASH_DEV_NAME "norflash0"

/* ===================== Flash device Configuration ========================= */
extern const struct fal_flash_dev stm32_onchip_flash;
extern struct fal_flash_dev nor_flash0;

/* flash device table */
#define FAL_FLASH_DEV_TABLE \
{ \
&stm32_onchip_flash, \
&nor_flash0, \
}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE \
{ \
{FAL_PART_MAGIC_WORD, "app", "onchip_flash", 0, 256*1024, 0}, \
{FAL_PART_MAGIC_WORD, "easyflash", NOR_FLASH_DEV_NAME, 0, 1024*1024, 0}, \
}
#endif /* FAL_PART_HAS_TABLE_CFG */

#endif /* _FAL_CFG_H_ */


查看更多

2 个回答
zhao_gx
zhao_gx 2020-03-17
This guy hasn't written anything yet
经测试,在第一种情况下读写flash都是正常的。
但是reset两次,再回到第一种情况的时候,就读不出来上次写入的数据了。
zhao_gx
zhao_gx 2020-03-17
This guy hasn't written anything yet
把分区表改成这样之后好了:
{FAL_PART_MAGIC_WORD, "app", "onchip_flash", 0, 256*1024, 0}, \
{FAL_PART_MAGIC_WORD, "easyflash", NOR_FLASH_DEV_NAME, 2 * 1024, 1024*1024, 0}, \

希望哪位大神解释下原理

撰写答案

请登录后再发布答案,点击登录
关注者
0
被浏览
797

发布
问题

分享
好友

手机
浏览

扫码手机浏览