Skip to main content
Takeshi
Associate
February 4, 2020
Solved

I ran the following code to reconfigure the SPI running on an STM32F103, but the DMA settings do not seem to be updated. Is there any solution?

  • February 4, 2020
  • 4 replies
  • 973 views
// SPI_HandleTypeDef *hspi
// DMA_HandleTypeDef *hdmatx
 
hspi->Init.DataSize = SPI_DATASIZE_16BIT;
hdmatx->Init.MemInc = DMA_MINC_DISABLE;
hdmatx->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdmatx->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 
while( hspi->State != HAL_SPI_STATE_READY );
 
HAL_DMA_DeInit(hdmatx);
HAL_DMA_Init(hdmatx);
HAL_SPI_DeInit(hspi);
HAL_SPI_Init(hspi);

This topic has been closed for replies.
Best answer by waclawek.jan

Read out and compare/post content of both SPI and DMA registers, before and after the change.

JW

4 replies

waclawek.jan
Super User
February 4, 2020

>DMA settings do not seem to be updated

How do you know? Did you read out content of DMA registers before and b after and compared them and checked against the expected content?

JW

Takeshi
TakeshiAuthor
Associate
February 4, 2020

When I checked the TX data by logic analyzer, it changed as follows.

data: [0x00,0xF8,0x00,0xF8,...]

// SPI_DATASIZE_8BIT, DMA_MDATAALIGN_BYTE, DMA_PDATAALIGN_BYTE, DMA_MINC_ENABLE

... 00 F8 00 F8 00 F8 00 F8 ...

// SPI_DATASIZE_16BIT, DMA_MDATAALIGN_HALFWORD, DMA_PDATAALIGN_HALFWORD, DMA_MINC_ENABLE

... 00 F8 F8 00 F8 F8 00 F8 ...

waclawek.jan
waclawek.janBest answer
Super User
February 4, 2020

Read out and compare/post content of both SPI and DMA registers, before and after the change.

JW

Takeshi
TakeshiAuthor
Associate
February 5, 2020

Following your advice, I checked the DMA registers and found that they were not set to the intended values. After the HAL_SPI_Init () function, the contents of hspi-> hdmatx were rewritten. Changing the order of the code worked fine. Thanks for the advice.