Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UART echo test. #16

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions uart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
UART Echo Test
==============

This is a trivial UART loopback program for the Sonata board. It configures the
pinmux to conect uart1 to PMOD0 pins 2 (TX) and 3 (RX) and then enters a loop
reading from the UART and echoing back any characters received. The baud rate is
set to 9600.

The PMOD connector is the 15 x 2 right angled connector with holes. It is
labelled PMOD0 on the left side (when facing the holes) and PMOD1 on the other.
The pins used for the UART can be found like so:

```
P +--------------------------------------
M | 3V | GD | 4 | RX | TX | 1 | ...
O +--------------------------------------
D | 3V | GD | 8 | 7 | 6 | 5 | ...
0 +--------------------------------------
```
28 changes: 28 additions & 0 deletions uart/uart.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Microsoft and CHERIoT Contributors.
// SPDX-License-Identifier: MIT

#include "compartment-macros.h"
#include "platform/sunburst/platform-pinmux.hh"
#include <compartment.h>
#include <debug.hh>

/// Expose debugging features unconditionally for this compartment.
using Debug = ConditionalDebug<true, "uart">;

/// Thread entry point.
void __cheri_compartment("uart") uart_entry()
{
Debug::log("Configuring pinmux");
auto pinSinks = MMIO_CAPABILITY(SonataPinmux::PinSinks, pinmux_pins_sinks);
pinSinks->get(SonataPinmux::PinSink::pmod0_2).select(4); // uart1 tx -> pmod0_2
auto blockSinks = MMIO_CAPABILITY(SonataPinmux::BlockSinks, pinmux_block_sinks);
blockSinks->get(SonataPinmux::BlockSink::uart_1_rx).select(5); // pmod0_3 -> uart1 rx

auto uart1 = MMIO_CAPABILITY(Uart, uart1);
uart1->init(9600);
while(true) {
char c = uart1->blocking_read();
Debug::log("read {}", c);
uart1->blocking_write(c);
}
}
31 changes: 31 additions & 0 deletions uart/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Copyright Microsoft and CHERIoT Contributors.
-- SPDX-License-Identifier: MIT

set_project("CHERIoT UART demo")
sdkdir = "../cheriot-rtos/sdk"
includes(sdkdir)
set_toolchains("cheriot-clang")

option("board")
set_default("sonata-1.1")

compartment("uart")
-- memcpy
add_deps("freestanding", "debug")
add_files("uart.cc")

-- Firmware image for the example.
firmware("uart-demo")
add_deps("uart")
on_load(function(target)
target:values_set("board", "$(board)")
target:values_set("threads", {
{
compartment = "uart",
priority = 1,
entry_point = "uart_entry",
stack_size = 0x800,
trusted_stack_frames = 4
}
}, {expand = false})
end)