Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


SPI Rx DMA with variable length data

I am using an STM32G474. I am setup as an SPI slave and have the DMA setup with the SPI to receive data. The SPI master will be sending a variable length of data. I would like the DMA to finish and call the callback function when the CS pin goes high. However, the callback function is only called when I receive the amount of data I asked for or a timeout occurs. I don’t know how much data will be coming, so I can’t rely on that, and a finding an appropriate timeout value doesn’t seem possible. (Data is coming every 5ms. If I set the timeout to short, I will cut off data in middle of the packet, and if I make the timeout too long, I will start to get the next packet before the timeout ends.)
Is there a way to setup the SPI Rx to generate a callback when the CS pin goes high?

thanks in advance,
Brent

Well, I believe I found a way to implement this...
I changed changed by CS pin to act as an external interrupt that triggers on the rising edge. I call my SPI DMA setup function as usual. Then when I receive the callback for this interrupt (ie CS has gone high), I call HAL_DMA_Stop(). The buffer I provided the DMA when setting it up now has my data in it.
I’m surprised no one else has had to deal with this before and that I couldn’t find any forums talking about it. I’ve tested it out with various sized buffers and everything appears to be working how I want. If anyone reading this, knows of a “gotcha” that I haven’t found yet, please let me know.


 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs