2024-05-31 06:37 AM
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(); }
}
Solved! Go to Solution.
2024-06-06 03:02 AM - edited 2024-06-06 05:41 AM
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"
2024-05-31 06:58 AM
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.
2024-06-04 08:08 AM
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 ?
2024-06-06 02:29 AM
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.
2024-06-06 03:02 AM - edited 2024-06-06 05:41 AM
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"
2024-06-06 05:23 AM
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