- Katılım
- 24 Şubat 2018
- Mesajlar
- 24,139
Bu DMA işini yapay zekaya sordum. Yeni bir sürüm çıkarmışlar, "uses advanced reasoning" (ileri seviyede makuldür)
Önce 24 saniye düşündü. Bu süreyi de yazdı Ve gerçekten çok güzel bir analiz yaptı meret. Bir timer'i harici bir clock ile besle, timer DMA event üretsin, DMA de GPIO data registerini okuyup belleğe yazsın dedi. Ama DMA sadece 16 bit okuyor, o yüzden iki tane DMA kanalı kullan dedi. Yalnız analizi tam bitiremedi, "NVIC configuration" deyip takıldı, ama analiz ettiği kadarı bile baya etkileyici ...
Önce 24 saniye düşündü. Bu süreyi de yazdı Ve gerçekten çok güzel bir analiz yaptı meret. Bir timer'i harici bir clock ile besle, timer DMA event üretsin, DMA de GPIO data registerini okuyup belleğe yazsın dedi. Ama DMA sadece 16 bit okuyor, o yüzden iki tane DMA kanalı kullan dedi. Yalnız analizi tam bitiremedi, "NVIC configuration" deyip takıldı, ama analiz ettiği kadarı bile baya etkileyici ...
Kod:
Short Answer
Yes, on the STM32 platform, it is possible to configure the DMA controller to read data from two GPIO ports (e.g., GPIOx->IDR registers for P0 and P1), triggered by an external clock signal, and place the values into a circular buffer. Additionally, you can set up the DMA to generate an interrupt when half of the circular buffer size has been received.
Detailed Explanation
1. Overview
The STM32 microcontrollers, particularly those based on the ARM Cortex-M4 core, provide flexible DMA controllers capable of transferring data between peripherals and memory without CPU intervention. While DMA transfers are commonly used with peripherals like ADCs, USARTs, and timers, you can configure the DMA to read from GPIO input data registers (IDR) under certain conditions.
2. Reading GPIO Inputs via DMA
Direct DMA from GPIO:
GPIO IDR Accessibility: The GPIO input data registers (GPIOx->IDR) can be read like any memory-mapped register.
DMA Source Address: You can configure the DMA source address to point to the GPIO IDR register.
Considerations:
Atomicity and Synchronization: Ensure that the GPIO inputs are stable during the DMA read operation to prevent data corruption.
Data Width: GPIO IDR registers are 32-bit wide, but only the lower 16 bits are valid (for 16 GPIO pins per port). If you need only specific bits, you might need to process the data after transfer.
3. Triggering DMA Transfers with an External Clock Signal
Using a Timer in External Clock Mode:
Timer Configuration:
External Clock Mode: Configure a timer (e.g., TIMx) to use an external clock signal on one of its input pins (e.g., ETR or TIx).
Counter Increment: The timer's counter increments on each external clock pulse.
DMA Trigger from Timer:
Update Event DMA Request: Configure the timer to generate a DMA request on every update event (overflow), or
Capture/Compare DMA Request: Configure the timer to generate a DMA request on each input capture event tied to the external clock.
Process Flow:
External Clock Signal: The external clock signal drives the timer.
Timer DMA Requests: The timer generates DMA requests synchronized with the external clock.
DMA Transfers: The DMA controller performs a transfer for each request, reading from the GPIO IDR and storing the data into the circular buffer.
4. Configuring DMA to Read from Two GPIO Ports
Single DMA Stream for Multiple Ports:
Not Directly Possible: A single DMA stream cannot read from two non-contiguous memory addresses (e.g., two separate GPIO IDRs) in a single transfer.
Workarounds:
Use Two DMA Streams:
Parallel DMA Streams: Configure two DMA streams, each reading from one GPIO port (P0 and P1) and storing into separate buffers.
Synchronization: Ensure both DMA streams are triggered simultaneously by the same timer event.
Combine GPIO Ports:
Use Adjacent Pins: If possible, map P0 and P1 onto the same GPIO port to read both simultaneously.
Read Combined Data: Configure the DMA to read from a single GPIO IDR, capturing both P0 and P1 in one transfer.
Memory-Mapped Parallel Inputs:
External Hardware: Use external hardware (like a latch or bus) to combine the two ports into a single data bus that can be read in one operation.
5. Circular Buffer and Interrupt Generation
DMA Circular Mode:
Enable Circular Mode: Configure the DMA stream to operate in circular mode, automatically wrapping around the buffer when the end is reached.
Half-Transfer and Transfer Complete Interrupts:
Half-Transfer Interrupt: Enable the half-transfer interrupt (HTIF) to generate an interrupt when half the buffer is filled.
Transfer Complete Interrupt: Enable the transfer complete interrupt (TCIF) for notification when the entire buffer is filled.
Interrupt Configuration Steps:
Enable DMA Interrupts:
Set the HTIE (Half-Transfer Interrupt Enable) and TCIE (Transfer Complete Interrupt Enable) bits in the DMA stream's configuration register.
NVIC Configuration: