2018-03-07 04:01 AM
EDIT: 14/03/2018
https://community.st.com/people/Schwaninger.Hannes
found that we need to use RAM_D1 and not DTCMRAM of the memory area. This is not made by default when we use STM32CubeMx to set SPI and DMA together. Hello, I am working on a full duplex SPI communication through DMA using STM32H7. So, I have bought 2 NUCLEO-H743ZI, one to be the master, the other to be the slave. I have downloaded, built and flashed SPI_FullDuplex_ComDMA example via TrueStudio. As there is no ''TrueStudio format'' example, I have generated the project with STM32CubeMx and replace Inc and Src generated files with SPI_FullDuplex_ComDMAfiles. And tadada! ... It is not working correctly....... Only a few bytes are sent and Rxbuffer is never filled.I have made connexion wires as short as possible and I have increased spi clock prescaler to get ''slow, nice and smooth'' signals. Electronic not seems to be the problem. I have modified the example to run it without DMA by replacing :
HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)�?�?�?�?�?�?�?�?�?�?
With :
HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE,5000)�?�?�?�?�?�?�?�?�?�?
And now it's working! But not with the DMA .... This test shows that SPI is set and works correctly. aRxBuffer is filled with the good values.
Back in my code, I am trying now to send data through DMA with master and read them with slave:
// Master
HAL_SPI_Transmit_DMA(&SpiHandle, (uint8_t*)aTxBuffer, BUFFERSIZE)
// Slave
HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000)�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
It's working! Master sends DATA through DMA and my aRxBuffer is correctly filled on slave.
However, I have never been able to read DATA on master or slave with one of these functions:
HAL_SPI_TransmitReceive_DMA(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE)
HAL_SPI_Receive_DMA(&SpiHandle, (uint8_t *)aRxBuffer, BUFFERSIZE)�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
I have tried to set DMA and SPI with STM32CubeMx but the problem remains the same.
HAL_SPI_TransmitReceive_DMA always returns
HAL_OK but code quickly falls into
HAL_SPI_ErrorCallback. That only happens with DMA, never wih SPI only...
I do not think that I am doing something wrong as I have not modified the SPI_FullDuplex_ComDMA''example'' Src and Inc files...
EDIT: 13/03/2018
I have tried HAL_SPI_TransmitReceive_DMA and HAL_SPI_Receive_DMA on a STM32F7 to be sure that there is no technological problem on Cortex-M7. All DMA functions are working perfectly with F7.
EDIT: 14/03/2018
https://community.st.com/people/Schwaninger.Hannes
has tested SPI_FullDuplex_ComDMA example with Keil and it seems to work. However, he can't make it work with same configuration files if he creates a new project.For me there is a problem with files generated by STM32CubeMX.
Does anyone have already made a full duplex spi communication with dma on a stm32h7 with a new STM32CubeMx project?
Thanks for your help!
#dma #spi #nucleo-h743zi #stm32h7 #halSolved! Go to Solution.
2018-03-14 08:43 AM
This is exactly my problem. As there is no 'TrueStudio format' example for
SPI_FullDuplex_ComDMA
, I have generated the libraries with STM32CubeMX and copy/paste src and inc from the example. So the problem is probably coming from files generated by STM32CubeMX... but it seems to work for you with Keil... This is starting to make me crazy2018-03-14 08:51 AM
Oh, i did not know that you have create your project with CubeMX. In this case we have the same problem... ;)
2018-03-14 08:56 AM
You are right, I will edit my first post with all this new information.
2018-03-14 11:03 AM
I've just found the difference between the HAL Nucelo example projects and the CubeMX generated projects.The problem for the DMA transfer error is that we use the false RAM!!
I have changed the settings in MDK-ARM from IRAM1 (default setting from CubeMX) to IRAM2 (same is in the example projects) and now the SPI DMA transfer runs without error. I've found out, that with this memory address IRAM1 is the DTCM-RAM and IRAM2 is the AXI SRAM D1.
enjolras.g
please check also in your project with TrueStudio and if it works, please share also the correct settings. 2018-03-14 01:29 PM
Schwaninger.Hannes
You have just saved my day! It is a little bit more tricky on TrueStudio ( maybe there is an easiest way but I have not found it): I had to open STM32H743ZI_FLASH.ld file. In this file I had to change every DTCMRAM to RAM_D1 in SECTIONS and ONLY in SECTIONS. LED is now blue! I have not found any option in STM32CubeMx nor in TrueStudio to do that. Heap and Stack can be changed but memory area cannot be selected. Anyway, thanks a lot for your help and your time!2018-03-15 02:09 AM
I'm glad that it works also by you and we both could now work normaly with the H7. ;)
2018-04-18 09:34 AM
Hi,
Thanks HS for sharing the correct answer, actually for all application using DMA you have to do the same workaround.
Currently, a new interface is under dev in STM32CubeMX to handle the memory assignment and it will be delivered in a later release.
Thanks for the interest in STM32CubeMX, enjoy using the tool.
2018-05-24 05:00 AM
Hi All,
I am using STM32 AC6 Workbench and STM32CubeMX 4.25. I am doing SPI DMA Transfer ( Memory to Peripheral) and have selected RAM_D1 (0x24008000) but i didn't see any output on MOSI line. I used GPIO as CS and did following thing:
uint8_t txBuf[3];
txBuf[0]=0x1;
txBuf[1]=0x2;
txBuf[2]=0x3
HAL_GPIO_WritePin(GPIOE, AD9913_SPI4_CS_DDS_Pin, GPIO_PIN_RESET);// chip-select low
errorcode = HAL_SPI_Transmit_DMA(&hspi4, &txBuf[0], 3);
HAL_GPIO_WritePin(GPIOE, AD9913_SPI4_CS_DDS_Pin, GPIO_PIN_SET);// chip-select high
I debugged it on STM32 AC6 and i didn't see any data on TXDR register which is quite confusing. Although, when i did same thing without DMA operation then everything works fine but no data is watched on TXDR when i debugged it on STM32AC6.
I do get 'Complete Xfer Callback' when all the data are transfered but i don't see any data on MOSI line. Is it BUG ?
So two things bring out here:
1. Why don't SPI DMA (MEM 2 PER ) works ?
2. Why don't see data on TXDR while checking through STM32 AC6 Workbench ?
Regards,
Manish
2018-05-24 08:22 AM
This are less informations for other people to help you ...
I would suggest, that you are starting with a working example project from the HAL repository folder (e.g. Nucleo \ Examples \ SPI_FullDuplex_ComDMA). If this code run on your board, then change the code like your desires.
2018-05-31 05:28 AM
Thanks. I am able to perform SPI DMA Transmit with some notable changes.
Observation 1:
I was using global buffer ( uint8_t txBuf[5] ; ) and I enabled (using STM32CubeMx) D-Cache inside main() then to perform DMA, I need to call SCB_CleanDCache_by_Addr((uint32_t*)&txBuf[0], 5) before HAL_SPI_Transmit_DMA(&hspi4, txBuf, 5) otherwise DMA doesn't work OR need to configure MPU_Config() for the DMA to work.
Observation 2:
I was using global buffer ( uint8_t txBuf[10] ; ) and I didn't enable (using STM32CubeMx) D-Cache inside main() then to perform DMA , I don't need to call SCB_CleanDCache_by_Addr((uint32_t*)&txBuf[0], 5) before HAL_SPI_Transmit_DMA(&hspi4, txBuf, 5) and DMA works fine.
I am confused with the results and i checked it 10-20 times. I am unable to reach to conclusion as i am new to it. Kindly help.
Regards,
Manish