DMA transfer

DMA transfer1. Learning objectivesDMA principle2. Hardware Construction3. Experimental steps1. Open the SYSCONFIG configuration tool2. ADC parameter configuration3. DMA parameter configuration4. Write the program5. Compile4. Program Analysis5. Experimental phenomenon

1. Learning objectives

  1. Understand the basic knowledge of DMA.
  2. Learn the basic use of DMA and display the transmitted ADC data on the serial port assistant.

DMA principle

DMA (Direct Memory Access) is a technology used in computer systems that allows peripherals to directly access memory without having to go through the CPU to complete data transmission. It enables data to be exchanged efficiently between peripherals (such as ADC, DAC, memory, etc.) and memory, reducing the burden on the CPU and improving the overall performance of the system.

Principle:

2. Hardware Construction

The DMA controller of MSPM0G3507 has the following features:

By looking at TI's data sheet, in addition to the common address addressing mode between memory and peripherals, the DMA function also provides two expansion modes: Fill Mode and Table Mode. DMA channels are divided into basic type and full-function type.

0

By looking at the data sheet, only the full-function type DMA channel supports repeated transfers, early interrupts, and extended modes. The basic function DMA channel supports basic data transfers and interrupts, but is sufficient to meet simple data transfer requirements.

The DMA of the MSPM0G3507 supports four transfer modes, and each channel can configure its transfer mode separately. For example, channel 0 can be configured as a single word or single byte transfer mode, while channel 1 is configured as a block transfer mode, and channel 2 uses a repeated block transfer mode. The transfer mode is configured independently of the addressing mode. Any addressing mode can be used with any transfer mode. Three types of data can be transferred, which can be selected by the .srcWidth and .destWidth control bits. The source and destination locations can be byte, short word, or word data. It also supports transfers in byte-to-byte, short word-to-short word, word-to-word, or any combination. As follows:

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

Fixed address to fixed address:

img

Fixed address to block of address :

img

Block of address to fixed address:

img

Block of address to block of address:

img

Fill data to block of address:

img

Data table to specific address:

img

3. Experimental steps

In this case, ADC will be used to collect the voltage of the PA27 pin, and the data collected by ADC will be directly moved to the specified address through DMA.

1. Open the SYSCONFIG configuration tool

Here, the ADC acquisition course is used as a template for introduction. Open the ADC project and open the .syscfg file.

image-20241127152938881

2. ADC parameter configuration

The configuration of ADC here is the same as that of the ADC acquisition case.

Configure the resolution and interrupt of ADC. This case does not use interrupts, so nothing is selected here.

image-20241128180500037

3. DMA parameter configuration

image-20241128180637589

Use the shortcut key Ctrl+S to save the configuration in the .syscfg file.

4. Write the program

In the empty.c file, write the following code

5. Compile

image-20241127155238783

If the compilation is successful, you can download the program to the development board.

4. Program Analysis

image-20241128140214440

The uart0_send_string function sends a string through the UART serial port. The while (*str != 0) loop iterates through each character until the string ends (*str == 0). Before sending each character, DL_UART_isBusy(UART_0_INST) checks whether the UART is busy. Data can only be sent when the UART is idle. Send the current character through DL_UART_Main_transmitData(UART_0_INST, *str++), and let str point to the next character.

image-20241128141038067

This code reads ADC (analog-to-digital converter) data. By triggering ADC conversion and waiting for the conversion to complete, the ADC sampling result is finally obtained and returned.

The function of this code is to collect analog signals and output the results through the serial port by combining ADC (analog-to-digital converter) and DMA (direct memory access). ADC data is directly moved to memory through DMA, without manual reading every time, and ADC sampling values ​​and calculated voltage values ​​are regularly output through the serial port.

5. Experimental phenomenon

After the program is downloaded, configure the serial port assistant as shown below, adjust the potentiometer knob, output voltage to the PA27 pin, and after the ADC loads the data acquisition into the ADC result register 0, the DMA is triggered, and the DMA will move the data to the memory variable ADC_VALUE. The data can be obtained by directly calling ADC_VALUE.

image-20241121194011058