cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 read from PIN to DMA

gevmar
Associate III

Hello everyone, I have a board.STM32F429I DISCO1, I want to read, say, two bytes of parallel data from port A{15:0}, into the DMA buffer, every time a rising edge of some signal comes to the microcontroller from the outside.

How exactly can this be implemented ?

Can I , Configure DMA to transfer data from the GPIO port to a memory buffer ?

because I dont see that , in CubeMX may support direct GPIO to memory transfer for this use case ?

but can I manually handle this , ? for example

 

#define BUFFER_SIZE 1

uint16_t dma_buffer[BUFFER_SIZE];

void MX_DMA_Init(void) {

....................................................

DMA_HandleTypeDef hdma;

hdma.Instance = DMA1_Stream0;

hdma.Init.Channel = DMA_CHANNEL_0;

hdma.Init.Direction = DMA_PERIPH_TO_MEMORY;   ????????????????????????

hdma.Init.PeriphInc = DMA_PINC_DISABLE;

hdma.Init.MemInc = DMA_MINC_ENABLE;

hdma.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

..................................................................

}

.................................................................................

HAL_DMA_Start(&hdma, (uint32_t)&GPIOA->IDR, (uint32_t)dma_buffer, BUFFER_SIZE);

.........................................................................................................

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {

if (GPIO_Pin == GPIO_PIN_0) { // Assuming PB0 is the EXTI line

Start_DMA(); }

}

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

The direction needs to be: hdma.Init.Direction = DMA_MEMORY_TO_MEMORY; as there is no peripheral request connection between GPIO and DMA and need to use DMA2 and not DMA1.

 

"every time a rising edge of some signal comes to the microcontroller from the outside."

You can use a GP Timer in PWM mode clocked by your external signal which triggers a transfer of the DMA each time a rising clock appears on the Timer clock input. The DMA requests will be generated by the timer, on each PWM data clock rising edge. So no need for EXTI usage as it introduces a considerable latency and you may face some timing issues and lose data.

You can refer to the AN4666 "Parallel synchronous transmission using GPIO and DMA" 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

5 REPLIES 5
Uwe Bonnes
Principal III

On F4 and most older families, you can not trigger one step of a multi item  DMA   from  EXTI. So with EXTI here, DMA is not needed and you can read the word direct in the IRQ. This will only work up to a not so high rate. If you can process blocks of read data, set up a timer compare event to trigger the GPIO->IDR readout to a block double the size you want to handle, and process the block data in the half/full transfer interrupt.

gevmar
Associate III

If instead of STM32F429 I take STM32H730, can this microcontroller solve this problem (Configure DMA to transfer data from the GPIO port for example A{15:0} to a memory buffer)? , and how many clock cycles will it take for the data from the pin to be written to the DMA buffer, and begin to take the next couple of bytes ? 

H730 has a DMAMUX with more capabilities. I short look at RM0468 did not help me to judge if a EXTI triggered GPIO D<A transfer is possible. Maybe others can help and better you work with thr refermece manual too. Otherwise timing is very variable as several buses and their synchronization and bus load needs to be considered. But  DMA on F7/H7 can join bytes and halfwords to words, so memory is only accessed once.

SofLit
ST Employee

Hello,

The direction needs to be: hdma.Init.Direction = DMA_MEMORY_TO_MEMORY; as there is no peripheral request connection between GPIO and DMA and need to use DMA2 and not DMA1.

 

"every time a rising edge of some signal comes to the microcontroller from the outside."

You can use a GP Timer in PWM mode clocked by your external signal which triggers a transfer of the DMA each time a rising clock appears on the Timer clock input. The DMA requests will be generated by the timer, on each PWM data clock rising edge. So no need for EXTI usage as it introduces a considerable latency and you may face some timing issues and lose data.

You can refer to the AN4666 "Parallel synchronous transmission using GPIO and DMA" 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

F4 will need to use DMA2 to read from GPIO to memory, basically a memory-to-memory transfer (ie two stage)

TIM based triggers will need to be TIM on APB2

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..