Space hardware bring-up · 2019

Checking a GR712RC,
one test at a time

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
GR712RC2× LEON3FT
2boards
11test programs
5MCAL drivers
C++11bare metal
BCC 2+ GRMON2

Why these tests

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.

Small and independent

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.

Run from on-chip RAM

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.

Results you can measure

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.

Two boards, one code base

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 test bench

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.

Test bench: host PC with BCC 2 and GRMON2, GR712RC board, and the instruments that read each result Host PC BCC 2 sparc-gaisler-elf-g++ test.cpp → test.elf GRMON2 load test.elf run mem 0x40000000 Serial terminal screen, 9600 baud uart_periph, spw_periph GR712RC board (commercial or ed31) 2 × LEON3FT SPARC V8, fault tolerant debug support unit On-chip RAM the test program runs here linkcmds-ahbram AMBA AHB / APB buses FTMCTRLmemory ctrl GRGPIOport 1 APBUARTUART 0 GRSPWlink 0 SDRAM under test 0x40000000 … 64 MB / 256 MiB GPIO25 / GPIO26 → J23 pins 11, 13 UART 0 → serial adapter SpaceWire link 0 → remote node debug link exit code, memory dump UART 0 Oscilloscope square wave on GPIO26 gpio_config, gpio_inout Logic analyser clock GPIO25, data GPIO26 memory_count_gpio SpaceWire node link reaches Run, receives packets Teal: program load and results read by GRMON2. Amber: signals measured outside the board.

Software architecture

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.

Software layers: test programs, MCAL with one board folder selected at build time, register access templates and GR712RC registers APPLICATION memory_config single_access memory_run run_bucle persistence run_gpio, count_gpio gpio_config gpio_inout uart_periph spw_periph src/app/unit_test · one main() each mcal::init(), port_pin<…>, uart_communication<…> MCAL mcal.h / mcal.cpp mcal::init() → cpu::init(), mem::init(): disable SRAM, enable SDRAM, EDAC off gr712rc_comercial/ cpu · mem · port · uart · spw SDRAM 64 MB, UART 0–5, GRSPW 0–5 Gaisler development board gr712rc_ed31/ cpu · mem · port · uart · gpt · irq · wdt SDRAM 256 MiB, timers, interrupts IAA board for PLATO one board folder on the include path: -Isrc/mcal/gr712rc_comercial or -Isrc/mcal/gr712rc_ed31 REGISTER ACCESS mcal::reg::access<addr_type, reg_type, address, value>::reg_set() / reg_or() / reg_and() / reg_get() FTMCTRL 0x80000000GRGPIO1 0x80000900UART0 0x80000100GRSPW0 0x80100800SDRAM src/util from real-time-cpp · STL subset for baremetal (array, cstdint…) · memory, safety andutility helpers · no exceptions,no RTTI, no heap Boost Software License 1.0 BCC 2 BSP start-up code linker script -qbsp=gr712rc -mfix-gr712rc

A pin is a type

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.

mcal::port::port_pin<std::uint32_t, std::uint32_t, mcal::reg::grgpio1_base_address, // 0x80000900 UINT32_C(26)> gpio26_pin; gpio26_pin.set_direction_output(); while (1) gpio26_pin.toggle_pin(); // ~1.6 µs period

Configuration as constants

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.

// Disable SRAM, enable SDRAM mcal::reg::access<std::uint32_t, std::uint32_t, mcal::reg::mem_config_register_2, mcal::reg::mem_cfg2_value>::reg_set(); // mem_cfg2_value = 0x8a206000UL

The eleven tests

Seven tests exercise the SDRAM through the memory controller; four check the peripherals that later carry the instrument data.

memory_config

Writes MCFG1–3 and copies what the controller reports back to the first three SDRAM words.

result: 0x40000000–08
memory_single_access

Writes 0xA5A5A5A5 to one word, flushes the cache and reads it back, forever.

result: exit code
memory_run

Fills the whole SDRAM with 0xABABABAB, then checks every word.

result: exit code
memory_run_bucle

The same fill and check with 0xA5A5A5A5, repeated without end.

result: exit code
memory_persistence

Fills once and checks forever, counting full passes: catches refresh problems.

result: counter at 0x40000000
memory_run_gpio

Like memory_run, toggling GPIO26 to time the write and read phases.

result: oscilloscope
memory_count_gpio

Each word holds its own address, which is also shifted out on two GPIO pins.

result: logic analyser
gpio_config

Drives GPIO26 as fast as possible to check the pin and the switch matrix.

result: square wave, J23-13
gpio_inout

Oscillates GPIO26 only while GPIO25 is held low.

result: input J23-11
uart_periph

APBUART 0 at 9600 baud: banner, a stream of T and an echo of what it receives.

result: serial terminal
spw_periph

Reports the GRSPW link state and, in Run, sends a counter and a 20-word packet.

result: UART + remote node

What each memory test leaves in the SDRAM

Memory patterns written by each memory test, word by word from address 0x40000000 0x40000000…04…08…0C… end of SDRAM memory_configsingle_accessmemory_runrun_buclepersistencecount_gpio MCFG1 MCFG2 MCFG3 untouched A5A5A5A5 untouched ABABABABABABABABABABABABABABABAB… ABABABAB A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5… A5A5A5A5 pass n ABABABABABABABABABABABAB… ABABABAB 4000000040000004400000084000000C… own address read back write, flush,read: forever fill, thencheck once fill and check,forever fill once,check forever streamed onGPIO25/26
status written by the test pattern 0xABABABAB pattern 0xA5A5A5A5 address as data not written

Both 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.

Reading an address off two pins

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.

Timing of memory_count_gpio: GPIO25 toggles as clock while GPIO26 carries the address bits, most significant first GPIO25 clock GPIO26 data 01000000… address 0x40000004 = 0100 0000 … 0100, bit 31 first one bit per clock pulse, then a short delay and the next word
GRSPW link states from Error-reset to Run; spw_periph sends packets only in Run 0 · Error-resetlink down 1 · Error-waittimeout 2 · Readywaiting to start 3 · Startedsending NULLs 4 · ConnectingNULLs received 5 · Runpackets sent state = (status >> 21) & 0x7; errors = status & 0xF both are printed as digits on UART 0 in every loop

SpaceWire: wait for Run, then send

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.

Ideas taken from Real-Time C++

SpringerReal-Time C++Christopher Kormanyos

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.

Register access templates

Address and value as template parameters, so each register access compiles to one instruction. Used by every driver here.

The MCAL

A thin layer with one namespace per peripheral and a single mcal::init(); the application never touches a register directly.

Static peripheral objects

Pins, UARTs and SpaceWire links are template classes with static members: no heap, no virtual calls.

A standard library for bare metal

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.

Build and run

1 · Choose the board

Put one MCAL folder on the include path.

-Isrc/mcal/gr712rc_ed31
2 · Compile

BCC 2 for LEON3 with the GR712RC errata fixes, linked to on-chip RAM.

-qbsp=gr712rc -mfix-gr712rc
3 · Load and run

GRMON2 loads the ELF through the debug link and starts it.

load test.elf · run
4 · Read the result

Exit code, SDRAM words, GPIO on the scope or the serial terminal.

mem 0x40000000 16
sparc-gaisler-elf-g++ -std=c++11 -O2 -g -qbsp=gr712rc -mcpu=leon3 -mfix-gr712rc -msoft-float -mflat \ -fno-exceptions -Isrc -Isrc/mcal/gr712rc_comercial -Isrc/util/STL \ src/mcal/mcal.cpp src/mcal/gr712rc_comercial/*.cpp src/app/unit_test/memory_run.cpp \ -T linkcmds-ahbram -o memory_run.elf

Reconstructed 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.

API reference

Doxygen documentation of the tests and the MCAL, generated from the sources.

Open the API reference →

Source code

The repository is private. Its README has the full test table, the memory map and these build notes.

References