cancel
Showing results for 
Search instead for 
Did you mean: 

why is ''HAL_SPI_TransmitReceive_DMA'' generated with 8-bit pointers when dma with 16 bit is configured

christophkeiner9
Associate III
Posted on September 19, 2017 at 16:11

I'm using STM32F103RBT6 and try to make an slave SPI-Transfer over DMA using th latest STM32Cube.

The Master sends me 16-Bit Data Packets, i configured the SPI1 to 16 Bit, the DMA channels for Receive and transmit with half word, both circular.

My first Question: the Function 'HAL_SPI_TransmitReceive_DMA' is generated with 8-bit pointers, i cannot pass a 16-bit Array! Why?

->I also use SPI2 with DMA for an external ADC with 8-Bit transfer.

I wondered, that all DMA Interrupts call the same HAL_SPI_TxRxHalfCpltCallback and HAL_SPI_TxRxCpltCallback.

Thanks for helping me!

#spi-over-dma #dma-spi #spi-dma
3 REPLIES 3
Posted on September 19, 2017 at 17:20

Doesn't the callback provide explicit context? The IRQHandler doesn't.

Perhaps void* would be better the SPI can be configured for various widths, the newer STM32 can be aware of width of access also. Use a cast.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 19, 2017 at 21:33

yes, that's the Point. I would expect that the STM32Cube-Functions should use generic pointers, but they use explicit uint8_t.

The Callbacks have the spi-handle as an Argument, so i can see which SPI it is. But i would prefer to have different functions. I think the code would be more modular and easier to understand.

Posted on September 19, 2017 at 22:57

Problem here is a lack of rigour throughout. Some of the code traps on CM0 parts due to arbitrary casting of 8-bit pointer to 16-bit one, with the potential to cause unaligned access.

The HAL requires you to buy into a certain paradigm. Feel free to overload the functionality and let the linker discard the dead code you replace.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..