Lab 8
UART and a driver
Link your board to a PC over a UART and see what a wrong baud rate does to the bytes. Then write a driver for the MCP3008 ADC twice over: as a tested userspace library, and by binding the kernel's own driver and comparing the two. As a stretch, build and load a kernel module of your own.
Modules this lab uses
What you need
- Your station's board, booted to Linux, reachable over SSH
- Your station's USB-to-UART adapter and the bench PC with a serial terminal
- The MCP3008 ADC wired as in lab 7
- The bench logic analyser
Before you start
Read the rules that keep the board alive. The UART link follows the same rules as the console: three wires, crossed, and never the adapter's power pin.
Which UART
Das Frite's serial console is on header pins 3 and 5. Enable a second UART on the header, as the guide How to enable UART A on S805X boards describes, and find its pins in the GPIO pinout. If your station has one USB-to-UART adapter, move it from the console to the new UART with the board unplugged, and work over SSH.
Which UART
Solitude's serial console is on its own 3-pin header. Find a UART on the 40-pin header in the GPIO pinout and enable it with the wiring tool's overlay. If your station has one USB-to-UART adapter, move it from the console to the header UART with the board unplugged, and work over SSH.
Steps: UART
- With the board shut down and unplugged, clip a logic analyser channel to the board's transmit pin on the header UART and its ground to a ground pin, then boot. If you enabled the UART with a live overlay, enable it again: a live overlay does not survive a reboot.
- Find the UART's device under
/dev/tty*on the board. - Set the board's end with
sudo stty -F <device> 115200 raw -echo, and the same rate in the serial terminal on the bench PC. Over SSH, watch the board's end withsudo cat <device>in one session and send from another withecho hello | sudo tee <device>; type in the bench PC's terminal to send the other way. - Repeat at a second baud rate, changing both ends.
- Set the two ends to different baud rates, send a known message with
echo, and capture it on the logic analyser. Set the analyser's UART decoder to the receiving end's rate (the bench PC terminal's), then to the board's, and explain the framing errors you see at the receiver's rate from what it decoded.
Steps: a driver
- Enable the
spidevdevice again withsudo ldto enable H40P_SPI_0_1CS_DEV(a live overlay does not survive a reboot), and check that it appears in/dev. - Write a userspace library for the MCP3008 with a clean API, unit tests that run against a mocked SPI bus, and a small command-line tool that uses it.
- Take the
spidevdevice off withsudo ldto disable H40P_SPI_0_1CS_DEVand enable the bare bus withsudo ldto enable H40P_SPI_0_1CS. Apply your own overlay that binds the kernel's MCP3008 driver to chip select 0. Its node needs the driver'scompatiblestring and avref-supply(both in the kernel's devicetree binding documentation; point the supply at a 3.3 V regulator node),reg = <0>for chip select 0, andspi-max-frequencyat or below 1000000, lab 7's limit for the part at 3.3 V; read the same channel through its files under/sys/bus/iio/devices/, and compare the two readings. - Write down what the kernel driver gives that your library does not, and when you would choose each.
- Stretch: build and load a minimal kernel module that registers a character device reporting a counter. Read the counter, unload the module, and read its messages with
dmesg.
What to measure
- What arrives at each baud rate, and what arrives when the two ends disagree.
- The same ADC channel read through your library and through the kernel's driver.
What you hand in
- A UART capture with its framing errors explained.
- Your library, its tests and the tool.
- The same channel read through your library and through the kernel's driver, and when you would choose each.
- Stretch: the module's source and the
dmesglines from loading and unloading it. - Your own short report: what you did, what you measured, and one problem you met and how you solved it.
If it goes wrong
If the module will not build, tell your TA: it needs kernel headers that match the image your board runs. If you moved the adapter off the console and the board stops answering over SSH, move the adapter back and read the console. If it will not boot, work down when it will not boot on your bench page.