cancel
Showing results for 
Search instead for 
Did you mean: 

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?

Takeshi
Associate II
// 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);

1 ACCEPTED SOLUTION

Accepted Solutions

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

JW

View solution in original post

4 REPLIES 4

>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
Associate II

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 ...

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

JW

Takeshi
Associate II

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.