DMA-based UART communication for 44b0

Source: Internet
Author: User

This article first introduces the shortcomings of query receiving mode and interrupt receiving mode commonly used in UART communication, and introduces the method and key code for receiving data through UART port and dma in the b0x processor, the advantages of DMA compared with interrupt mode and query mode are analyzed. Experiments show that the DMA-based UART communication further reduces the burden on the CPU and improves the communication reliability.

 

 

 

High Efficiency UART Communication Based on DMA controller in ARM processor and Its Application

Abstract: Compared with polling and interrupt mode used in UART communication, giving the disadvantage of them. The paper introduced the uart and DMA controller on the s3c2444b0x processor, and give the method of processing ing
Data by communication based on uart and DMA. analyzing the benefit of DMA method compared with the interrupt and polling method. the experiment give the proof that UART base on DMA saving much time for CPU and further increasing the communication efficiency.

 

 

1. Introduction

UART serial port is widely used in traditional 8-bit and 16-bit processors and 32-bit processors. In traditional UART-based data communication, two methods are generally used: Query and interruption. In the query mode, the CPU workload is heavy, which wastes the processor capability and cannot handle other events. In the interrupt mode, information is received or data needs to be sent is interrupted, receives and sends data in the interrupted service program. Compared with the query method, the CPU usage of the interrupt method is high. In a system with a simple CPU task, interruption is indeed a good method. However, in complex systems, such as mobile robots, processors need to process serial port communication, data collection and processing of multiple sensors, and real-time track generation, tasks such as trajectory interpolation and closed-loop location control involve priority allocation of multiple interruptions. In order to ensure the reliability of data transmission and receiving, the UART interrupt priority needs to be designed to be relatively high, but the system may have other interruptions that require higher priority, and must ensure its timing accuracy, in this way, the interruption of serial communication may fail to respond in a timely manner, resulting in data loss. For this reason, when designing a mobile robot controller using b0x, in order to ensure timely and reliable receipt of serial communication data, while taking into account other tasks, UART Serial Communication Based on DMA and interrupt modes is adopted. DMA is direct
Memory Access, short for "direct access to memory", is a high-speed data transmission operation that allows you to directly read/write data between external devices and memory, that is, no CPU intervention is required. The entire data transmission operation is performed under the control of a DMA controller. In addition to processing data at the beginning and end of data transmission, the CPU can perform other work during the transmission process. In this way, the CPU and input/output devices are in parallel operation most of the time. For more information about the basic principles, see the textbooks. Here, we will only introduce the DMA controller of v44c0x.

 

2. Features of DMA controller and UART in b0x

The b0x uses the ARM7TDMI core, has a 4-channel DMA controller, and should have 4 interruptions. Two DMA channels are called zdma (General DMA), connected to SSB (System Bus), and the other two DMA channels are called bdma (Bridge DMA), connected to SSB and SPB (Peripheral Bus) interface layer. The zdma controller connected to SSB can be used to transmit data from memory to memory, from memory to fixed target I/O memory, and from I/O devices to memory. The other two bdma controllers are mainly used to transmit data between external memory and internal peripherals. The I internal peripherals include SiO2, IIS, timer, and UART. Bdma and zdma can be started through software or hardware. In this design, we use uart0 and the corresponding DMA channel is bdma0. The Controller Block 1 is shown in.

The UART unit of b0x provides two independent asynchronous serial I/O Ports. Each port can work in the interrupt mode or DMA mode, that is, the UART can generate internal interrupt requests or DMA requests, transmits data between the serial I/O Ports of the CPU and supports transmission rates up to 115.2kbps. Each UART channel contains two 16-bit FIFO channels for sending and receiving respectively.

 

Figure 1 DMA controller block diagram of b0x

 

3. hardware circuit design

Because b0x comes with a DMA controller that supports UART, you do not need to do anything about the DMA hardware. The I/O port voltage of 44b0x is 3.3 V, while the serial port at one end of the PC uses RS232 level, so the center must undergo level conversion, and the sp3232e chip is used here. Connection Circuit 2.

Figure 2 UART level conversion circuit

 

4. Design of Communication Software Based on DMA and fault combination

Three DC motors are driven by a three-way PWM timer in a mobile robot with b0x as the core. The universal gpio port and A/D port are connected to external infrared, ultrasonic, and laser sensors, uart0 is used to exchange data with the host computer (PC). The data is unidirectional (sent from the host computer to the cloud44b0x), mainly the Command Information sent from the host computer to the robot controller, however, the sending time of command information is irregular, that is, the interval is not fixed. To fully utilize the CPU and reduce the risk of data loss, we use the uart dma mode to receive data. The software mainly initializes the DMA controller and UART for specific applications. UART Initialization is relatively simple, mainly the communication data format, baud rate and other settings, these are the same as other controllers, as long as you set the relevant registers. Note that uart0 is set to DMA mode instead of interrupt mode when UART is set to no automatic traffic control or infrared transmission mode, use a 16-byte receiving buffer). In this way, when the receiving buffer is full, a DMA request is generated instead of an interrupt request. The specific register definition and the initialization of the serial port are not described in detail. For details, refer to [1] [2].

The initialization of the DMA controller is also relatively simple, mainly the settings of related registers. The registers and definitions related to bdma0 used in this system are shown in Table 1. For details about the Register name definition and physical address, see references [1] [2].

Table 1 Definitions of bdma-related registers of b0x

Bdma0 control register bdcon0

Bit [], DMA channel status, 00 = ready; 01 = No termination count; 10 = termination count; 11 = N/

Bit [3: 2] disable/enable external/internal DMA requests, 00 = Enable; others = Disable

Digit [0-1] software command 00: no command, the CMD bit of other numeric values will be automatically cleared 0; 01: retained; 10: retained; 11: cancel the DMA Operation

Source Address bdisrc0,

Bit [31: 30], data transmission size, 00 = byte 01 = half word; 10 = word 11 = Unused

Bit [29:28], loading address direction 00 = N/A 01 = increase; 10 = decrease 11 = internal peripherals (fixed address)

Bit [27:0], bdma initialization Source Address

The target address bdides0 during bdma0 Initialization

Bit [31: 30], transmission direction: 00 = reserved; 01 = m2io (from external memory to internal device); 10 = io2m (from internal device to external memory ); 11 = io2io (from internal devices to internal devices)

Bit [29:28], save the direction of the address

00 = N/A 01 = increase

10 = decrease by 11 = internal peripherals (fixed address)

Bits [27:0], bdman's initialization target address

 

Counter register bdicnt0 during bdma0 Initialization

Bit [31: 30], select 00 = N/A 01 = IIS; 10 = uartn; 11 = SiO

Bit [], interrupt mode settings: 00 = rotation Detection Mode 01 = N/A; 10 = interrupted during transmission; 11 = interrupted during termination count.

When the DMA counter reaches 0, whether it is automatically reloaded and automatically started. 0 = disabled; 1 = Enable

Bit [20], hardware enabling/disabling of DMA. 0 = Disable DMA; 1 = Enable DMA

Bit [], bdma0 transmission counter

                 

 

During initialization, you must correctly set the first address of the target (buffer zone), the direction of data transmission, the first address of the source register, whether the address pointer is incremented, the increment direction, and the DMA counter. The related code and comments are as follows:

# Define ram_address 0xc200000 // defines the buffer for receiving data, depending on the hardware. The expanded SDRAM storage space in our system ranges from 0x0c00000 ~ 0x0c7fffff, which occupies the Bank 6 of b0x.

# Define size 16 // defines the DMA counter. You can set the options as needed: 4, 8, 2, and 16.

Char * Buf;

Buf = (unsigned char *) ram_address; // The Pointer Points to the starting address.

Bdisrc0 = (11 <28) + (INT) (rurxh0);/* transmitted in bytes; because the DMA Operation places the data in the UART Register into the preset buffer, the source Register address should be fixed; The UART receiving and storing register rurxh0, at the same time, it should be set to 0b11 at [29:28. */

Bdides0 = (10 <30) + (01 <28) + BUF);/* the transmission direction mode is set from the internal device (UART port) to the external memory (SDRAM ), the target memory (SDRAM) uses the address increment direction to place data in the buffer sequentially */

Bdicnt0 = (10 <30) + (1 <26) + (3 <22) + (1 <21) + (0 <20) + size; /* Set uart0 to use the bdma0 channel. When the DMA count reaches 0, it is automatically reloaded and started automatically. When the Count ends, interruption occurs,Each DMA Operation moves 16 bytes of data to the set buffer zone (the buffer zone needs to be opened up separately, instead of the bdma destination address, so that the time for bus release will not be occupied all the time ).*/If non-continuous data is sent, automatic reinstallation can be disabled because receiving FIFO (or receiving buffer) does not trigger DMA, and the bus is not occupied. For continuous data, you need to consider the occupation of the bus.

Bdicnt0 | = (1 <20); // enables DMA

Bdcon0 = 0x0 <2; // allow external DMA requests

Data Receiving: The initialized DMA controller relies on hardware. When receiving data is not scheduled, the receiving buffer for initialization uart0 is 16 bytes. When the receiving buffer is full, a DMA request is generated, and then under the control of the DMA controller, transfer the 16-byte data in the UART receiving FIFO to the specified buffer zone (SRAM). After the data transfer is completed (the DMA count is 0), do the following: one is automatic reload and automatic start, that is, the first address and Source Address (UART receiving register) of the target (buffer zone) and the DMA counter are automatically reset to prepare the next DMA request. In addition, the DMA interrupt is generated. The work done by the DMA interrupt service program is very simple. As long as the receive_flag is set to the global flag, it notifies the main program that new commands need to be processed. In this way, the main program can directly process data in ram without the need to spend time reading the UART receiving buffer.

Data Processing: when the main program queries the global flag receive_flag, if it is 1, it will know that there is a new command, and it can directly read the command buffer and clear the receive_flag. Then parse the received data according to certain algorithms. This part of content is not discussed in detail.

 

5. Test and conclusion

In order to verify the effectiveness of DMA-based communication, the author makes a comparative test. The scheduled interruption priority for trajectory interpolation is designed to be the highest (the interruption interval is 50 milliseconds, and the interruption service program execution time is about 30 milliseconds ), then, one robot uses the interrupt method to receive 100 sets of commands continuously sent by the upper computer, and the other uses the DMA-based method to receive 100 sets of commands continuously sent by the upper computer. Then, in the robot's main program, an error is identified by reading the UART Status Register (mainly because the data overflow error occurs, that is, the buffer zone receives the data but does not read it in time and is overwritten by the new data) the number of times. The software is compiled and debugged in C language and ads1.2. The test results are shown in table 2. The experiment proves the effectiveness of the second method.

Table 2: Comparison of test results

Test

1st groups

2nd groups

3rd groups

Number of robot data overflow errors that receive commands in DMA mode

0

0

0

Number of robot data overflow errors that receive commands in the interrupt mode

6

4

6

 

The author's innovation in this article is: In UART communication, the data received by UART is directly transferred to the set Ram zone by using the DMA method, and then the corresponding global flag is set, notify the master program that data is available. Developers do not need to read data in the UART buffer, so they can directly read Ram. Compared with the serial port communication mode that uses the interrupt mode or query mode, it not only saves the time used for receiving data during CPU communication, but also prevents the loss of data received by UART because it is not read in time, this improves the reliability of communication.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.