yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0 Smart Robot Car📖
1.Quick Start Guide
  • 1. Assembly Videos
  • 2. Quick Start Videos
  • 3. Battery charging
  • 4. Notes
2.Introduction to the MSPM0 Car
  • 1.About MSPM0
  • 2.Development board interface description
3.Development environment setup and usage
  • 1.CCS Theia development
  • 2.MDK Arm development
  • 3.Uniflash burning
  • 4.External crystal oscillator configuration
  • 5.Project Migration
4.MSPM0 basic course
  • 1. LED light control (GPIO)
  • 2. Buzzer Control (GPIO)
  • 3. Button Control (EXTI)
  • 4. Serial Port (UART)
  • 5. Voltage Detection (ADC)
  • 6. Temperature Detection (ADC)
  • 7. Independent Watchdog (WWDG)
  • 8. Window Watchdog (WWDG)
  • 9. Timer (TIM)
  • 10. Breathing LED (PWM)
  • 11. I2C Communication (I2C)
  • 12. External Flash (SPI)
  • 13. Internal Flash (Flash)
  • 14. DMA
  • 15. FreeRTOS
5.Sensor basic course
  • 1.Servo control
  • 2.Ultrasonic servo PTZ basic use
  • 3.Motor PID control
  • 4.OLED display photosensitive value
  • 5.Infrared avoid sensor
  • 6.1 Infrared line tracking sensor-8 channel infrared tracking sensor module
  • 6.2 Infrared line tracking sensor-4 channel infrared tracking sensor module
  • 7.Infrared remote control
  • 8.Ultrasonic ranging
  • 9.RGB light drive
  • 10.MPU6050 raw data acquisition
  • 11.MPU6050 data fusion
  • 12.K210 vision recognition module
  • 13.K230 vision recognition module
6.Smart car course
  • 1.1 Car line tracking-8 channel infrared tracking sensor module
  • 1.2 Car line tracking-4 channel infrared tracking sensor module
  • 2.1 Drawing a circle-8 channel infrared tracking sensor module
  • 2.2 Drawing a circle-4 channel infrared tracking sensor module
  • 3.Ultrasonic following
  • 4.Ultrasonic avoid
  • 5.Ultrasonic avoid(Servo PTZ)
  • 6.Infrared sensor avoid
  • 7.Light following
  • 8.Gyroscope calibration straight-line walk
  • 9.Infrared remote control
  • 10.Autonomous driving car
7.Vision application course
  • 1.K210 autonomous driving
  • 2.K210 color tracking
  • 3.K210 handwritten digit action
  • 4.K210 color response
  • 5.K210 road sign indication action
  • 6.K210 following machine code
  • 7.K210 QR code command
  • 8.K230 vision line tracking
  • 9.K230 color tracking
  • 10.K230 machine code tracking
  • 11.K230 QR code command
  • 12.K230 autonomous avoid
  • 13.K230 license plate tracking
  • 14.K230 face tracking
  • 15.K230 gaze direction tracking
  • 16.K230 palm tracking
  • 17.K230 target tracking
  • 18.K230 human body tracking
  • 19.K230 OCR character recognition
8.Extended application course (Sold separately)
  • 1.Voice interaction module communication
  • 2.Voice interaction control
  • 3.K230 road sign indication action(Voice)
  • 4.K230 color response(Voice)
  • 5.K230 gesture control(Voice)
  • 6.K230 rock-paper-scissors(Voice)
  • 7.8-channel grayscale color line tracking
  • 8.Bluetooth remote control
  • 9.K210 Scenario-based autonomous driving
  • 10.K230 Scenario-based autonomous driving
Download
  • Code
  • SCH
  • 3D Model File
  • MSPM0 Data Sheet
  • Voice firmware
  • Hardware interface manual
Download ZIP

Welcome to MSPM0 Smart Robot Car repository

14. DMA

DMA

DMAI. Learning ObjectivesII. DMA IntroductionIII. Hardware SetupIV. Experiment StepsV. Code AnalysisVI. Experiment Phenomenon

 

I. Learning Objectives

  1. Understand basic DMA knowledge.
  2. Learn basic DMA usage, implement variable-length data reception through serial port DMA sending data.

II. DMA Introduction

DMA (Direct Memory Access) is a technology used in computer systems that enables peripherals to directly access memory without requiring CPU involvement for data transfer. It allows efficient data exchange between peripherals (such as ADC, DAC, memory, etc.) and memory, reducing CPU burden and improving overall system performance.

Principle:

  • Trigger data transfer: DMA operations are typically triggered by external devices (such as ADC, sensors) or internal events (such as timer overflow).
  • Initialize DMA controller: CPU configures parameters to the DMA controller such as source address, destination address, transfer data size, transfer direction, etc.
  • Direct data transfer: Once the DMA controller is activated, it can directly transfer data from the source address (peripheral's output buffer or memory) to the destination address (memory or peripheral) without CPU intervention.
  • Notify CPU after transfer completion: After DMA completes data transfer, it can send an interrupt request to the CPU, telling the CPU that data is ready or the transfer has been successfully completed.

The MSPM0G3507 DMA controller has the following features:

  • 7 independent transfer channels;
  • Configurable DMA channel priority;
  • Supports 8-bit (byte), 16-bit (short word), 32-bit (word) and 64-bit (long word) or mixed size (byte and word) transfers;
  • Supports data block transfers of up to 64K arbitrary data types;
  • Configurable DMA transfer trigger sources;
  • 6 flexible addressing modes;
  • Single or block transfer modes; It has a total of 7 DMA channels, each channel can be independently configured, and various data transfer modes can adapt to the data transfer needs of different application scenarios.

By checking TI's data manual, in addition to common address addressing methods between memory and peripherals, the DMA function also provides two extended modes: Fill Mode and Table Mode. DMA channels are divided into two types: basic type and full-featured type.

0

By checking the data manual, only full-featured type DMA channels support repeated transfers, early interrupts, and extended modes. Basic function DMA channels support basic data transfer and interrupts, but are sufficient to meet simple data transfer requirements.

MSPM0G3507's DMA supports four transfer modes, each channel can be individually configured for its transfer mode. For example, channel 0 can be configured for single word or single byte transfer mode, while channel 1 is configured for block transfer mode, and channel 2 uses repeated block transfer mode. Transfer modes are configured independently of addressing modes. Any addressing mode can be used with any transfer mode. Three types of data can be transferred, which can be selected through .srcWidth and .destWidth control bits. Source and destination locations can be byte, short word, or word data. It also supports transmission in byte-to-byte, short word-to-short word, word-to-word, or any combination. As follows:

  • Single word or single byte transfer: Each transfer requires a separate trigger. DMA will be automatically disabled when DMAxSZ transfers have been generated.
  • Block transfer: An entire block will be transferred after one trigger. DMA will be automatically disabled at the end of block transfer.
  • Repeated single word or single byte transfer: Each transfer requires a separate trigger, DMA remains enabled.
  • Repeated block transfer: An entire block will be transferred after one trigger, DMA remains enabled.

Based on these three modes, MSPM0G3507 provides 6 addressing methods,

Fixed address to fixed address:

img

Fixed address to address block:

img

Address block to fixed address:

img

Address block to address block:

img

Fill data to address block:

img

Data table to specified address:

img

Since the development board has a built-in CH340 serial port circuit, it can be directly implemented through USB cable

III. Hardware Setup

Serial communication, no external USB to TTL module required.

Serial port schematic diagram

image-20251013103759170

IV. Experiment Steps

This lesson uses the UART0 peripheral on pins PA10 and PA11, combined with the development board's onboard CH340 USB-to-serial chip, to achieve receiving serial port data sent by the host computer, and then sending the data back to the host computer through the serial port sending function.

  1. Open SYSCONFIG configuration tool

This course is based on migrating previous serial communication code parts. Peripheral configuration modifications are as follows. Parameter definitions can refer to the previous serial communication section introduction.

image-20251027210957620

image-20251027211113394

DMA configuration part is as follows

Channel ID: DMA channel, default channel 0

Address Mode: Address mode, we set it to from block address to fixed address

Source Address Direction: Source address direction, set to address increment

Source Length: Source transfer size, the source transfer size determines the size of data transfer from source to destination, as well as the increment per transfer (if configured as block).

Uneven transfer sizes can be configured. If source is larger than destination, only the lower half of the short word is transferred, ignoring the upper half. If destination is larger, the upper half of source will be zero-padded to fill the entire segment.

Destination Length: Destination transfer size, the destination transfer size determines the size of data transfer from source to destination, as well as the increment per transfer (if configured as block).

Uneven transfer sizes can be configured. If source is larger than destination, only the lower half of the short word is transferred, ignoring the upper half. If destination is larger, the upper half of source will be zero-padded to fill the entire segment.

image-20251027211807964

RX Timeout Interrupt Counts: Set the timeout time for receive timeout interrupt. To make the timeout function effective, the RTOUT interrupt needs to be set.

In the interrupt settings, we add DMA transmit interrupt and receive timeout interrupt based on the original receive interrupt. Priority can be set to default.

image-20251027211322027

Then we save and generate code

V. Code Analysis

xxxxxxxxxx
 * @brief DMA方式发送字符串
 * @brief Send string via DMA
 * 
 * @param str 要发送的字符串指针 / Pointer to string to send
 * @param len 字符串长度 / String length
 * @return uint8_t 1=发送成功, 0=发送失败 / 1=success, 0=failure
 */
uint8_t UART0_sendStrDMA(const char* str, uint16_t len) {
    // Check send conditions: DMA idle, length valid, pointer valid
​
    if (!UART0TxDMADone || len == 0 || str == NULL) {
        return 0; // Send failed 
    }
    
    // Set DMA transfer parameters
​
    UART0TxDMADone = 0; // Mark DMA as busy 
    // Set source address 
    DL_DMA_setSrcAddr(DMA, UART0_TX_CHAN_ID, (uint32_t)str);
    // Set destination address 
    DL_DMA_setDestAddr(DMA, UART0_TX_CHAN_ID, (uint32_t)(&UART_0_INST->TXDATA));
     // Set DMA send data size 
    DL_DMA_setTransferSize(DMA, UART0_TX_CHAN_ID, len);
     // Enable DMA channel 
    DL_DMA_enableChannel(DMA, UART0_TX_CHAN_ID);
    
    return 1; // Send success 
}
xxxxxxxxxx
void UART0_IRQHandler(void) {
    uint8_t receivedData = 0;
    // Get interrupt source
    switch (DL_UART_getPendingInterrupt(UART_0_INST)) {
        // DMA send complete interrupt 
        case DL_UART_IIDX_DMA_DONE_TX:
            UART0_DMADoneTxCallback();
            break;
            
        // Receive timeout interrupt (frame end) 
        case DL_UART_MAIN_IIDX_RX_TIMEOUT_ERROR:
            // Clear remaining data in RX FIFO 
            while (!DL_UART_Main_isRXFIFOEmpty(UART_0_INST)) {
                uint8_t data_from_fifo = DL_UART_Main_receiveData(UART_0_INST);
                
                // Store in buffer (check overflow) 
                if (recv0_length < (RE_0_BUFF_LEN_MAX - 1)) {
                    recv0_buff[recv0_length++] = data_from_fifo;
                } else {
                    // Reset when buffer is full 
                    recv0_length = 0;
                }
            }
            // Add terminator and mark reception complete 
            recv0_buff[recv0_length] = '\0';
            UART0RxDone = 1;
            break;
            
        // Regular receive interrupt
        case DL_UART_IIDX_RX:
            receivedData = DL_UART_Main_receiveData(UART_0_INST);
            
            // Check buffer space 
            if (recv0_length < RE_0_BUFF_LEN_MAX - 1) {
                // Store in receive buffer 
                recv0_buff[recv0_length++] = receivedData;
                
                // Detect line end character (newline) 
                if (receivedData == '\n') {
                    // Add terminator
                    recv0_buff[recv0_length] = '\0';
                     // Mark reception complete 
                    UART0RxDone = 1;                
                }
            } else {
                // Buffer overflow handling 
                recv0_length = 0;    
                recv0_buff[0] = '\0'; 
            }
            break;
​
        // Other unhandled interrupts 
        default:
            break;
    }
}

VI. Experiment Phenomenon

After the program is flashed, connect the Type-C to the car, then configure the serial port as follows. After receiving data each time, we will copy a copy of the received data to the buffer and send it back, then start receiving again. We can send "Hello,Yahboom", the program processes and echoes data through timeout interrupt, or manually add a line break after "Hello,Yahboom", as shown in the figure below, to process data in specified format.

image-20251027214237558

Internal Flash (Flash)
FreeRTOS

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文