stm32u5 qspi 读写 w25q128 timeout

发布时间 2023-12-28 17:36:29作者: ramlife

http://ramlife.me/posts/solution/embedded/spi/stm32-use-qspi-write-and-read-w25q128-timeout/

背景

使用 STM32U575 主控芯片,使用 QSPI 读写 W25Q128,简单的读写测试没有问题。但是在后面调试中发现,当按照 11 个字节一组进行读写,从 4352 这个地址开始写,写入到 4605 的时候,就超时状态了。

然后我单独从 4605 写入 11 个字节,确实会超时,但是前面写入并没有超时,很奇怪。

然后,我测试了一下,从0开始写,每次写 11 个字节,当从 1023 开始写入 11 个字节会超时。感觉好像是在 256字节的页边界出写入会出问题,但是又不是每个 256 边界都会出问题。

解决

先使用 16个字节为一组进行测试,没有跨界问题。然后又使用了4字节写入,写入了 400多万组,也没有任何问题。 这基本就说明了,是软件或者库的某个层面,因为32位对齐产生的这个 bug.

解决的方法也很简单,我原来写入 11 个字节是对结构体使用了 pragma pack(1) ,只要不用这个字节对齐命令,编译器会自动进行 32位对齐,重新测试,数据就可以正常读写,没有问题了。

参考

https://github.com/zephyrproject-rtos/zephyr/issues/38548
https://shequ.stmicroelectronics.cn/thread-636543-1-1.html
https://www.armbbs.cn/forum.php?mod=viewthread&tid=91603&fromuid=58
https://www.st.com/resource/en/application_note/an4760-quadspi-interface-on-stm32-microcontrollers-and-microprocessors--stmicroelectronics.pdf
https://community.st.com/t5/stm32-mcus-products/hal-qspi-autopolling-fail-when-polling-the-sr-of-nor-flash-in/td-p/216569/page/2
https://community.st.com/t5/stm32-mcus-products/stm32h7-hal-qspi-autpolling-timeout/td-p/112884
https://community.st.com/t5/stm32-mcus-embedded-software/stm32u575rit6-qspi-driver/td-p/595705
https://danieljunho.com/2021/05/09/external_loader.html
https://controllerstech.com/w25q-flash-series-part-8-quadspi-external-loader/