STM32C0116-DK: Problem with SPI + DMA at 24MBits/s
Hello!
I am interfacing an ADS131M02 ADC to the STM32C0116-DK board using SPI for a project I am developing on live streamings. I am able to read SPI Data using the HAL polling functions (HAL_SPI_TransmitReceive), however that created unwanted delay between bytes and I tried swithing to DMA to improve performance.
Configuration:
- All clock to max (48MHz)
- SPI: Full-Duplex Master, 8bits, Mode 01, DMA Tx + DMA Rx
- Prescaler 2: BaudRate 24 MBits/s -> FAIL
- Prescaler 4-Max: SUCCESS
This is the result with prescaler set to 4 (12 Mbits/s). (Pink: MISO, Blue: SCK), the data is correct.

With the Prescaler set to 2 (24MBits/s) (Pink: MISO, Blue: SCK). The clock does not even try (the pulse is 3us)

The Pseudocode I am using:
/** Simplified code **/
uint8_t newData = 0;
// This is never called if the SPI prescaler is set to:SPI_BAUDRATEPRESCALER_2
// With SPI_BAUDRATEPRESCALER_4 works.
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef* hspi) {
newData = 1;
}
void main(void)
{
// All CubeMX initializations
// Clock configured to 48 MHz.
HAL_SPI_Receive_DMA(...);
while(1)
{
if(newData){
newData = 0;
HAL_SPI_Receive_DMA(...);
}
// Mandatory othwerwise wont work in Release:
__asm__("nop");
}
}
Debuging the problem, I found out that the DMA interrupt for the TX channel is triggered, however the DMA for the RX channel is never triggered. I tried moving the RX DMA from Ch3 o Ch1 with no luck. I would say there is something messing up with the DMA interrupts and the SPI.
Am I missing something?
