我用的芯片是STM32F407ZGT6,RT Thread版本5.0.2,spi flash挂载在spi1总线,设备号是spi10
int w25qxx_init(void)
{
struct rt_spi_device *spi_device = RT_NULL;
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
if(RT_NULL == spi_device)
{
LOG_E("Failed to malloc the spi device.");
return -RT_ENOMEM;
}
struct stm32_hw_spi_cs cs_pin =
{
.GPIOx = GPIOG,
.GPIO_Pin = GPIO_PIN_6
};
if (RT_EOK != rt_spi_bus_attach_device_cspin(spi_device, "spi10", "spi1",rt_pin_get("PG.6"), &cs_pin))
{
LOG_E("Failed to attach the spi device.");
return -RT_ERROR;
}
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
{
LOG_E("Failed to probe the W25Q128.");
return -RT_ERROR;
};
}
INIT_COMPONENT_EXPORT(w25qxx_init);
通过手动输入sf probe spi10
命令,并用逻辑分析仪观测,发现PG6引脚没有被拉低

这里应该是发送读flash ID命令0x9F