• Non ci sono risultati.

UART3 configuration

STM32H7 configuration

5.1 UART3 configuration

In order to enable the exchange of data between the PC and the board, it is nec-essary to configure the UART.

STM32H7 configuration

A universal asynchronous receiver-transmitter is a computer hardware de-vice for asynchronous serial communication in which the data format and trans-mission speeds are configurable. It sends data bits one by one, from the least significant to the most significant, framed by start and stop bits so that precise timing is handled by the communication channel 1.

5.1.1 UART: Hardware Communication Protocol

As described in the book [11] UART, or universal asynchronous receiver-transmitter, is one of the most used device-to-device communication protocols. The transmit-ting UART is connected to a controlling data bus that sends data in a parallel form. From this, the data will now be transmitted on the transmission line (wire) serially, bit by bit, to the receiving UART. This, in turn, will convert the serial data into parallel for the receiving device.

Figure 5.1: UART packet Data Transmission:

In UART, the mode of transmission is in the form of a packet. The piece that connects the transmitter and receiver includes the creation of serial packets and controls those physical hardware lines. A packet consists of a start bit, data frame, a parity bit, and stop bits.

Start Bit:

The UART data transmission line is normally held at a high voltage level when it’s not transmitting data. To start the transfer of data, the transmitting UART pulls the transmission line from high to low for one clock cycle. When the receiving UART detects the high to low voltage transition, it begins reading the bits in the data frame at the frequency of the baud rate.

Data Frame:

The data frame contains the actual data being transferred. It can be five bits up to eight bits long if a parity bit is used. If no parity bit is used, the data frame can be nine bits long. In most cases, the data is sent with the least significant bit first.

1wikipedia

5.1 – UART3 configuration

Parity:

Parity describes the evenness or oddness of a number. The parity bit is a way for the receiving UART to tell if any data has changed during transmission. Bits can be changed by electromagnetic radiation, mismatched baud rates, or long-distance data transfers. After the receiving UART reads the data frame, it counts the number of bits with a value of 1 and checks if the total is an even or odd number. If the parity bit is a 0 (even parity), the 1 or logic-high bit in the data frame should total to an even number. If the parity bit is a 1 (odd parity), the 1 bit or logic highs in the data frame should total to an odd number. When the parity bit matches the data, the UART knows that the transmission was free of errors. But if the parity bit is a 0, and the total is odd, or the parity bit is a 1, and the total is even, the UART knows that bits in the data frame have changed.

Stop Bits:

To signal the end of the data packet, the sending UART drives the data trans-mission line from a low voltage to a high voltage for one (1) to two (2) bit(s) duration.

Figure 5.2: USART3 & DMA - IDE configuration

In the STM32H7 several pins allow communication via UART, in this case for convenience UART3 has been configured, which refers to the micro-USB port on the board. The figure 5.2 shows the configuration of USART3 and DMA, the complete detailed configuration of the board can be found in the project report.

In this case, in order to have a faster data exchange between PC and board, US-ART3 was set to interrupt, and also DMA was enabled for both input and output data.

The Interrupt Method: Using interrupt signals is a convenient way to

STM32H7 configuration

achieve serial UART data reception. The CPU initializes the UART receive hard-ware so that it fires an interrupt signal whenever a new byte of data is received.

And in the ISR code, we save the received data in a buffer for further processing.

This way of handling the UART data reception is a non-blocking way. As the CPU initiates the receiving process and it resumes executing the main code. Until an interrupt is received, then it freezes the main context and switches to the ISR handler to save the received byte to a buffer and switches back to the main context and resume the main code. Finally, by setting DMA (direct memory access) on UART3 it is able to increase the speed of communication via USB.

The DMA Method: Using the DMA unit in order to direct the received serial UART data from the UART peripheral directly to the memory is considered to be the most efficient way to do such a task. It requires no CPU intervention at all, you’ll have only to set it up and go execute the main application code. The DMA will notify back the CPU upon reception completion and that received data buffer will be in the pre-programmed location.

The DMA can prioritize the channels, decide on the data width, and also the amount of data to be transferred up to 65536 bytes. Which is amazing in fact, and all you’ve got to do is to initialize it like this.

Finally, a crucial parameter that can be changed is the baud rate, which in this case is set to 115200. The baud rate is the speed at which information is transferred to a communication channel. In the context of the serial port, the set baud rate will serve as the maximum number of bits per second to be transferred.

Using STM32CubeIDE, it was possible to configure this peripheral. It was only necessary to set the baud rate and enable DMA, after which the IDE automatically generated the C code containing the configuration made. The configuration of the all board’s peripheral was made via the graphic interface is shown in the Fig. 5.3.

Figure 5.3: Example IDE configuration

Documenti correlati