Serial Terminal (original)

Source: Internet
Author: User

---------------------------serial chip, configuration, use---------------
The serial-port chip is integrated into the main chip, the serial-port chip generally includes, receive buffer, send buffer.  This is the hardware buffer. The main chip generally has three serial lines, as if there can be more than one i²c bus.

The corresponding gpio can optionally be configured as a serial port, not every GPIO can be configured as a serial port, from the Gpio configuration table DWS file, you can see whether the Gpio support serial mode.

From the feature phone debug, the serial port can only be used by a module, you may use the SetOwner function to switch which module is used. An NV item will decide which module to use for the serial port.

Each serial port receives the data, will send the serial message, in the feature phone, the message will be assigned to which task.  A task will have a loop to receive the task. The corresponding receive function in the loop receives the message, and if no message comes in, it will block.

Problems encountered in practice:

1. When opening the serial port, originally to open the serial port 1, and opened the serial port 3, the result task loop, has not received the message.

2. When the serial port is configured, the SetOwner is not adjusted, which causes the module to be specified at the open serial port, which is inconsistent with the owner of the serial port, causing the current to change dramatically. One plug-in USB, the computer services process occupies 40%

3. uart_getbytes function of the specified software buffer length size of 0, causing the hardware buffer data is not received, the serial port driver receive flag is not set,
Causes the next serial port to receive the data, does not send the serial message. Change the length to a larger size.

4. The owner switch of the serial port, the default configuration is for the at module. In order to transfer data to 2502, add an AT command to complete the module switchover. The serial port is forwarded by the at module to the custom task module.

5. Task configuration, in Hal_task_config.h configuration, compile however. To configure the app_task_config.h, the tasks do things that should belong to the MMI layer. Corresponding to Linux, should be the serial user space programming.

6. The system hangs because the serial message received is not released, resulting in a No. 600 byte or so.
Let's talk about the general mechanism of the message:
Java, C, C + +, the message schema is all, the Message object will specify the recipient of the message, the recipient of the message, is generally a loop,
There is a function in the loop that waits for the message, and if the message does not come, it will block there, and if the message comes, it will continue to execute.
The MTK task receives the UART message, which is the mechanism used.
The serial port has the data to send, will have a serial port message to send, through to the serial port set owner, namely this task's MoD ID, thus to the message body ID to specify this task. The message sends this task.

The task while loop receives the message, the object that actually receives the message, and the general mechanism is that the receiver is releasing the space that the message requests in memory.

If not released, there is a problem here, due to the continuous leakage of space, to receive more than 600 bytes, the number of message objects increasing, the leakage of memory is increasing, causing the system to hang.

The serial tool is sometimes unresponsive at the command, and the serial tool is turned on again.

------------------CTS RTS Configuration-----------------
Explain the Cts/rts flow control, starting from the receive buffer. What was the problem, and came up with this thing.

Flow control is the problem of data loss in order to receive buffers that are not ready, the sender is still in the problem of sending data.

The solution is to connect a line, the receiver by controlling the high and low level of the line, to tell the sender, the receiving buffer is ready.

Receive buffer If you are not ready, you will pull this line up and pull it down if you are ready.
In terms of terminology, this line is on the RX side, the corresponding PIN is RTS, on the TX side, the pin CTS. When the data is not ready, the RTS pulls low. The default RTS is configured to pull high internally.

Wiring:

Rx to receive each other's TX, TX to receive each other's RX. When adjusting the BLE to 2502 communication, ble is paired with 2502 instead.

RTS is to receive the CTS of each other. The RTS potential is controlled by the receiving side.

By controlling the level, notify the other party:

When the receiver is not ready, the receiver will pull up the RTS, that is, the sender's CTS is pulled high, so that the sender knows that the reception is not ready to send.
When the receiving party is ready, the receiver pulls the RTS down, that is, the sender's CTS is pulled down so that the sender knows that the receive is ready to send the data.

Gpio configuration:

From Datashee can be confirmed, open DWS, you can see the GPIO support hardware flow control. 2,502 only two GPIO supports hardware flow control, which can be confirmed from the GPIO option.

Test whether the hardware works:

For ble with 2502, because 2502 sends the big data to ble, BLE is the receiver, so the RTS signal is controlled by the receiver, which is the BLE support hardware flow control. And 2502 CTS received this signal, can not send data, stating that 2502 also support hardware flow control.

The size of the packet must be limited by the other buffer, and the maximum cannot exceed the receiver buffer.

-----Serial Port Rate---------


Serial port transmission rate, 50K, 20K corresponding to which file.  115200 corresponds to how much. Divide by 8, get 14402, i.e. 15K. Right
There are two ways to express the serial port transmission rate, a bps, such as 115200.  One is kbps, and a typical data account is 8 bits.   So 115200 corresponds to 14.4KBps. Theoretically 14K per second. Whether the transfer rate is restricted by the receiver.

----------coordinate the signal line of serial data transmission----------------

The UART can have 18 signal lines, and the UNIX environment uses only 6.


Gnd-logic Ground Ground, which provides a reference voltage based on this reference voltage, has two voltages, space voltage, Mark voltage.
txd-transmitted Data Send signal line
Rxd-received data receive signal line
Dcd-data Carrier detect means that the other end is connected to the signal line, the space voltage indicates that the other end is connected, Mark voltage indicates not ready
Dtr-data Terminal ready means that the other end is prepared for the signal line, and the space voltage indicates that it is ready.
Cts-clear to send space voltage indicates that the local side can send more data
The rts-request to Send space voltage indicates that the data is ready for transmission locally.

You will not be confused when you see these letters again. These signal lines are to coordinate the data transmission, is to give you a guarantee. There are so many signal lines.

The chip from the serial bus to the data, the data is a byte one byte transfer, you must know the beginning of the byte position, and the end position.
The serial line is the mark voltage when no data is transmitted.
In the change to space voltage, indicating that there is data,
A start bit of space voltage before each byte, indicating the start of the byte
At the end of each byte is a parity check bit, and a stop bit.

The data is generally expressed as 8N1, which represents 8 data bits, no parity bit, and a stop bit.
7E1 represents 7 data bits, even even check bits, and a stop bit.


-------------
Duplex double word, it means bidirectional, receive and send two directions
Full duplex, which is the same time, can receive and send data at the same time, a send line, a receiving line
Half-duplex, at the same moment, can only be sent, or can only be received.

----------------
In order to coordinate serial data flow, there are two methods of software and hardware,
Software is the use of special characters to start or end the flow of data, the special character is: The beginning of the Xon, DC1, the end of the Xoff, DC3.
Hardware, when the receiver is ready, the CTS is placed as a space voltage, and the mark voltage is not ready to be placed.  This way the sender knows that the data can be sent. CLEAR to send, which tells the sender to send.
When the sender is ready, the RTS is placed as a space voltage so that the receiver knows it can receive the data. Request to send, which sends the data to the receiving party.
This is the CTS/RTS notification mechanism.

When data is being transmitted, both the receiving signal line and the sending signal line are kept at the mark voltage. If the transmission passes, from Mark Voltage to space voltage, and lasted 1/4 seconds, indicating the transfer break, then the break condition exists.
Break is generally used to reset the data cable.

---------------Serial Cable-------------
The line of the serial cable must be connected, if only to see the log, then only TX and ground, TX corresponding to the white line. To send the AT command through the serial port, you want TX, RX, ground three wires.

The line of the power supply may burn off, use the multimeter to measure the resistance, the normal will have a value.

2502 the Uart1, which communicates with Bluetooth, receives the AT command sent by Bluetooth, (should be byte), and then 2502 returns the data to Bluetooth via a string.

--------------Serial Port Log--------------------

Serial line send or receive, are based on the name of the board, the serial port data from the board out, is called to send. Serial line Inside, there is a line specifically sent, this line is called the transmission line, the schematic point of the solder is called TX.
T (transmit) means sending, from the board to the computer,
R (receive) receives, from the computer to the Board, receives the computer to send the command.
There is a comment on the schematic, UAR1 for AP Log, and the test's UART point is found on the PCB map corresponding to the schematic diagram.


There is a transmitter in the serial line, the white line is sent, the Green Line is received, and the black lines indicate grounding. Generally look at the serial port log, only send, that is, only white and black lines. If the black line received on the RX, that is, the receiving point, serial log is garbled.

LK passed the Disable_uart parameter determines whether the serial port spit log. If LK behind the stage, such as kernel, recover mode, if not spit log. It is necessary to check this parameter.

Serial port If you want to vomit Android log, you must enter logcat at the command line. Without this command, the serial port will not spit on Android log.

The serial port can see initialization log, Preloader, LK, kernel, serial port log is very need. USB cannot see the initialization log.

PCB generally only choose pads, vias Two items, from the sch corresponding to find the PCB clock test point

Requires a USB to serial port driver software, if the environment variables are modified, the software will fail to install.

Use SECURECRT to see the serial port log output:
From Device Manager, locate the port, here 10
Maximum connection rate, other default
If there is a cursor, it is connected, you can see the serial log.


-------------register the serial port as a terminal------------
TTY_IO.C registering a TTY device

ADB shell
SetProp persist.uartconsole.enable 1

Uart0:ap side Log
Uart1:modem side Log

If the RX is not taken off, there is no problem
A terminal is a window that interacts with the computer externally

------------------------


Pty is a virtual terminal,
PTS, PTMX is the implementation of Pty
With each terminal open, there is a file under/dev/pts/


Let's take a look at the external features.
A serial port (serial ports), is a terminal, corresponding to the/DEV/TTYSN
In the graphical interface, open the terminal is actually open according to the terminal, corresponding to the/dev/pts/below a file, you can open the terminal, look at the PTS directory more than one file.
Use the echo "1" >/dev/pts/n to see the corresponding characters appearing under the terminal.
View current terminal, with TTY, if you can see/DEV/PTS/2
For/dev/console, only in single-user mode can you log in to the console
With WHO, you can see how many virtual terminals are open.
/dev/tty always represents the current terminal, if the current terminal is/DEV/PTS/2, then/dev/tty/represents/DEV/PTS/2
echo "1" >/dev/tty equivalent to echo "1" >/DEV/PTS/2

Ps-aux TTY column, which shows which terminal to run on


Then analyze the implementation from the code:
From the upper to the driving layer:
TTY_IO.C Read
Line layer: TTY_LDISC.C read wait queue mechanism goes to sleep
Drive layer: Take the serial port as an example, it should be serial_core.c


Fs_initcall and Module_initcall, both Define_initcall macro functions, are placed in the init segment specified by the Init_calls macro of the VMLINUX.LDS.S link script, which is defined in Vmlinux.lds.h.

Call procedure: start_kernel-> init-> init thread function calls Do_initcalls to invoke these init functions.

Character device initialization (DRIVERS/CHAR/MEM.C) is mainly the TTY initialization, Chr_dev_init->tty_init, complete the TTY device initialization, finally see the application example of the character device, device initialization will certainly create a device model,

--------------------
Serial line: The white line is TX, which is the sending line. The Green Line is RX. That is, the receive line.

Pick up the RX line, there will be no machine hanging off the problem, the software re-firmware upgrade a bit, to solve the problem of sleep after hanging off,

With Rx, to the machine to send commands, need to machine light screen, you can use the TAB key, the USB cable is not enough, or the USB port is not available, with the RX serial port, the same as see the ADB shell can see the file information, call Otg,usb is occupied, then use the string most appropriate.
If you want to see log, you can display log directly aee-k 6.
When selected, you can directly find

Control+f into debug mode, this mode can see the value of ARM registers, interrupt number information,

Start-up initialization log can only look at the serial port, because the ADB shell is a process of user space after the kernel is fully booted, so the ADB shell does not see the kernel initialization log, which includes the probe initialization log for each driver. The MTK log is built on the file system, so there is no kernel initialization log.

Preloader LK Kernel Initialization log can be seen through the serial port.

In case of garbled characters, it is good to restart the secure UART.

Fundamentals of-----------Serial Bus-------------

The RS-232 is a serial bus standard. The bus is bitwise transmitted.
The serial bus consists of a transmit line TX, a receiving line Rx, and a ground wire.
Send line at the same time, the receiving line can be received, that is, asynchronous communication
The baud rate is the number of bits transmitted per second. Unit is bps. Generally a character has 10 bits and 1 starting bits. 1 End bits, 8 data bits. The number of characters per second (that is, the number of packets, a message containing one character) multiplied by the number of characters, that is, the baud rate.
Data bits, a packet has a start bit, and an end bit. The data bits have 7 bits, some 8 bits. This is to be determined according to the agreement.

The stop bit represents the end of a packet, providing the correct synchronization clock on the one hand

Parity parity check. In case of parity, the number of data 1 is even, and the check bit is 0. It is possible to determine if there is noise interfering with the signal.

UART Connected serial device, I²C-connected parallel device.
The UART is generally used for communication between computers and external devices, such as keyboards. I²c is generally used for internal module communication. Sensor is all about using I²c. GPS, Bluetooth and other RF-related all walk the serial port.

The display also uses the serial port, has the 9-pin serial port, also has the 25-pin serial port.

The so-called protocol, the receiver and the sender determine the meaning of each bit of an information packet representation. The two sides must be consistent in their understanding of this.

Receiving process: Determines the length of time for each bit by the baud rate and the receiving clock.
When the signal line jumps from 1 to 0, it starts receiving.
The reception of a single frame. Within a frame, the clock is used to determine the receive-specific bit.
Every 8 clocks, to receive a bit.

The data is placed in the register, and the data of the register is shifted out under the control of the sending clock.

At the receiving end, at the moment of receiving the rising edge, the data is sampled, the data is placed in the shift register, and the parallel data is taken out.

The baud rate is the number of bits sent in a second. Baud rate factor the number of clocks required to send or receive a data bit.
The display 25-pin serial port has 4 data lines, 11 control lines, the rest of the spare line.

-----------------------------

Serial port can also be synchronous communication, at this time need to more than one clock line, because synchronous communication requires additional hardware support, generally do not synchronize communication.

Ways to access serial device files:
Change the permissions of the serial device file so that the general program can access

Everything is a file, open the serial device, on the open this file, that is
Open ("/dev/ttys0",);

Process open a serial device, by default, the process is the terminal of the serial device, control terminal, the signal on the serial device will affect the process, such as CTRL + C This signal will terminate the process.

If you do not want to receive this serial port signal, so that the process does not become the terminal of the serial port, will not receive the signal of the serial port. With O_noctty.

If the process does not care whether the other end is connected or not, it does not care about the status of the DCD signal, using O_nodelay.

To the serial port can write data, send at command is to write data, call with the write system.

Read data from the serial port, that is, read the data from the serial buffer, if not the data, read will not return.

If you want read to return immediately, you need to set up with Fcntl, Fcntl (FD, F_SETFL, Fndelay);

Close the serial port, close the device file directly, will pull the DTR signal low.

Clocal and Cread Ensure that the program does not become the owner of the port and that the owner must handle various signals.
Options.c_cflag |= (clocal | Cread);

The control option can also set parity.
No parity check:
Options.c_cflag &= ~parenb
Options.c_cflag &= ~CSTOPB
Options.c_cflag &= ~csize;
Options.c_cflag |= CS8;
Odd check:

Options.c_cflag |= Parenb  //enable check bit Options.c_cflag &= ~paroddoptions.c_cflag &= ~cstopboptions.c_cflag &= ~csize;options.c_cflag |= CS7;

The C_cflag is set to 7E1

Even check:
Options.c_cflag |= Parenb
Options.c_cflag |= parodd
Options.c_cflag &= ~CSTOPB
Options.c_cflag &= ~csize;
Options.c_cflag |= CS7;
That is, C_cflag is set to 7o1

Parity is set in the control options, and the odd and even items are stripped at the input option, set to:

Options.c_iflag |= (INPCK | Istrip);

If a parity error occurs, the Del character and the NUL character are emitted along with the characters that are faulted.

If you turn on enable parity, and do some special experiments, such as the occurrence of parity errors, also ignore, release data, available

Options.c_iflag |=ignpar;

Only nul characters are sent out at this time

If Cts/rts is supported on the hardware, it is necessary to set:
Options.c_cflag |= cnew_rtscts
If not supported:
Options.c_cflag &= ~cnew_rtscts;

The old interface does not have a c_ispeed, and c_ospeed two members. So we used the cbaud,b9600 constant, such as the baud rate.

Constant Tcsanow flag All changes must take effect immediately without waiting for the data transfer to end

Tcsetattr can be set to have:
Tcsanow flag All changes must take effect immediately without waiting for the data to end
Tcsadrain wait for transmission to take effect again.

The serial port connects two machines, the baud rate should be two the smaller one.

Set a character size:
Options.c_flag &= ~csize;
Options.c_flag |= CS8; can also be CS8.

--------------------------

------------------------

Serial Terminal (original)

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.