Small bare-metal C++ programs that test the SDRAM, GPIO, UART and SpaceWire of a GR712RC board, the dual-core fault-tolerant LEON3FT processor used in many space missions.
Written at IAA-CSIC for the PLATO mission, to validate the Frontgrade Gaisler commercial board and the IAA ed31 board before running flight software on them.
// simplified from src/app/unit_test/memory_run.cpp constexpr std::uint32_t def_pattern = 0xABABABABUL; mcal::init(nullptr); // SDRAM on, EDAC off auto* p = reinterpret_cast<volatile std::uint32_t*> (mcal::reg::mem_base_addr); // 0x40000000 auto* end = reinterpret_cast<volatile std::uint32_t*> (mcal::reg::mem_end_addr); for (auto* q = p; q < end; ++q) *q = def_pattern; // write for (auto* q = p; q < end; ++q) if (*q != def_pattern) return 1; // check return 0; // exit code seen in GRMON2
Before any flight software runs on a new board, someone has to prove that the processor sees its memory and its peripherals as the schematics say. These programs do exactly that, one peripheral at a time, with as little software in between as possible.
Each test is a single main() of a few dozen lines. If one fails, there is only one thing to look at: no operating system, no shared framework state, no dependencies between tests.
The programs are linked to the GR712RC internal RAM (linkcmds-ahbram). The SDRAM under test is never used by the test itself, so a memory fault cannot corrupt the program that is looking for it.
A test answers through its exit code, through words it leaves at the start of the SDRAM (read back with GRMON2), through GPIO pins for the oscilloscope, or through the serial port.
The same tests build for the Gaisler GR712RC commercial board and for the IAA ed31 board. Only the board folder of the MCAL changes: memory size, memory map and available drivers.
The host compiles a test with BCC 2 and loads it through the debug link with GRMON2. The test runs from on-chip RAM and talks to the outside world through four paths.
The code uses the layered design of Christopher Kormanyos' Real-Time C++: test programs on top, a microcontroller abstraction layer (MCAL) below, and register access written as templates that the compiler resolves to single load and store instructions.
A GPIO pin is declared as a template with its port address and bit number. Every method is static and every argument is a compile-time constant, so toggle_pin() becomes a read-modify-write of one register, with nothing stored in RAM.
The memory controller settings live in mcal_reg.h as constexpr values, next to the address map. mcal::mem::init() writes them with the same templates, so moving to another board means editing one header.
Seven tests exercise the SDRAM through the memory controller; four check the peripherals that later carry the instrument data.
Writes MCFG1–3 and copies what the controller reports back to the first three SDRAM words.
result: 0x40000000–08Writes 0xA5A5A5A5 to one word, flushes the cache and reads it back, forever.
Fills the whole SDRAM with 0xABABABAB, then checks every word.
The same fill and check with 0xA5A5A5A5, repeated without end.
Fills once and checks forever, counting full passes: catches refresh problems.
result: counter at 0x40000000Like memory_run, toggling GPIO26 to time the write and read phases.
result: oscilloscopeEach word holds its own address, which is also shifted out on two GPIO pins.
result: logic analyserDrives GPIO26 as fast as possible to check the pin and the switch matrix.
result: square wave, J23-13Oscillates GPIO26 only while GPIO25 is held low.
result: input J23-11APBUART 0 at 9600 baud: banner, a stream of T and an echo of what it receives.
Reports the GRSPW link state and, in Run, sends a counter and a 20-word packet.
result: UART + remote nodeBoth patterns put ones next to zeros on neighbouring data lines (0xAB = 1010 1011, 0xA5 = 1010 0101), which helps reveal lines that are stuck or shorted together. Writing each word's own address detects address lines that are stuck or shorted, because two locations would then overwrite each other. On an error, persistence stores 0x12000000 | n at the first word.
memory_count_gpio turns GPIO25 and GPIO26 into a home-made serial bus. For every word it sends the 32 bits of the address, most significant bit first: GPIO26 carries the bit and GPIO25 toggles around it as a clock. A logic analyser on J23 shows which address is being written or checked, and where it stops if a comparison fails.
spw_periph polls the GRSPW status register, prints the link state and the error bits on the UART, and only when the link reaches Run fills a DMA descriptor and sends a counter word (0x55555500 | n) followed by a 20-word packet. With a second node at the other end, the counter shows whether packets arrive in order.
The driver sets up the receive and transmit descriptor tables, the maximum packet length and the node address with the same register templates as the rest of the MCAL.
Kormanyos' book shows how to write microcontroller software in modern C++ that is as small and fast as C. This project applies its recipes to a SPARC space processor instead of the 8-bit and ARM targets of the book.
Address and value as template parameters, so each register access compiles to one instruction. Used by every driver here.
A thin layer with one namespace per peripheral and a single mcal::init(); the application never touches a register directly.
Pins, UARTs and SpaceWire links are template classes with static members: no heap, no virtual calls.
The util folder brings std::array and the other pieces the code needs, without exceptions or RTTI.
The book has several editions (Springer, 3rd edition 2018, 4th edition 2021) and its examples live at github.com/ckormanyos/real-time-cpp. The same architecture, on AVR and ARM, is in my real-time-cpp-practice and Embedded_Software_Collection repositories.
Put one MCAL folder on the include path.
-Isrc/mcal/gr712rc_ed31BCC 2 for LEON3 with the GR712RC errata fixes, linked to on-chip RAM.
-qbsp=gr712rc -mfix-gr712rcGRMON2 loads the ELF through the debug link and starts it.
load test.elf · runExit code, SDRAM words, GPIO on the scope or the serial terminal.
mem 0x40000000 16Reconstructed from the 2018 makefile of Embedded_Software_Collection; each test was compiled on its own. On the commercial board the GPIO tests need the JP29 switch matrix in position A.
Doxygen documentation of the tests and the MCAL, generated from the sources.
The repository is private. Its README has the full test table, the memory map and these build notes.