2020-10-31 08:57 PM
I'm trying to run SPI2 (Master Receive Only) such that it continuously DMAs data from the slave.
The problem is, it only works when I step over the HAL_SPI_Receive_DMA line... at which point I see SCLK, and it will run forever, until I "resume" the debugger, then SCLK will stop immediately. Similarly, if I just run after reset, (without stepping) there is no SCLK activity.. and if I pause, SCLK remains INactive.
HAL_SPI_Receive_DMA(&hspi2, (uint8_t*)(&data_rcv), 1);
while ( 1 )
{
}
I've tried setting the number of elements to > 1, but it doesn't seem to matter.. the only way I get SCLK activity is if the processor is never allowed to "RUN" after starting the DMA.
I don't have any interrupts and the only initialization is for the SPI2/DMA.. yet something is either causing an SPI/DMA error, or something is stopping the DMA, but I don't have any other code!
Any suggestions what to look at to see what's causing the halt?
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
hspi2.Init.DataSize = SPI_DATASIZE_13BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 0x0;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_15CYCLE;
hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
HAL_SPI_Init(&hspi2):
hdma_spi2_rx.Instance = DMA1_Stream7;
hdma_spi2_rx.Init.Request = DMA_REQUEST_SPI2_RX;
hdma_spi2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi2_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_spi2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_spi2_rx.Init.Mode = DMA_CIRCULAR;
hdma_spi2_rx.Init.Priority = DMA_PRIORITY_LOW;
hdma_spi2_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
HAL_DMA_Init(&hdma_spi2_rx);
2020-11-01 02:49 AM
2020-11-01 04:20 PM
@Community member I believe he's saying that when run mode, SCLK has no pulses, not that it has too many.
Doesn't really make sense that you're not seeing any pulses though, if you see them in debug mode. Maybe try non-circular mode.
2020-11-01 05:04 PM
> SCLK has no pulses
Ah, I see.
Which STM32?
What's the content of SPI, DMA, relevant GPIO registers?
JW
2020-11-02 01:33 PM
I've been trying various different DMA/SPI settings, but no luck, something stops the DMA. Not sure if it's related but *VERY* frequently, whenever I'd restart the debugger, the CPU would hang on:
SystemClock_Config():
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
I ended up commenting out the while loop, and haven't noticed anything unusual (aside of course from the SPI/DMA issue).
The image shows a capture of the registers while SCLK is active, which only works when I step over the HAL_SPI_Receive_DMA call..
as well as a register capture taken immediately after (Resume+Pause). The SCLK stops as soon as I resume.
BTW, this is an STM32H745
2020-11-02 02:12 PM
There's transfer error set in the status word of DMA, and suspicious value of NDTR.
Make sure the used memory is accessible by the DMA and used address is properly aligned.
I don't use the 'H7.
JW