Episode 06 still leaves the CVE2 CPU core untouched. The RTL gains a standard CLINT (mtime / mtimecmp) and a 64-entry interrupt vector table, and FreeRTOS Kernel V11.1.0 runs as a five-task system at a 1 kHz tick: pulse, producer, consumer, monitor and heartbeat, plus idle. Queue delivery, mutex-protected counters, stack high-water marks and heap headroom are all checked from the serial console, with a PASS verdict at 8 seconds.
What this proves is that the scheduler really runs, not that the code compiles. At 8.000 s: tick=8000, queue 81 sent / 81 received, qerr=0, mutex-protected shared=expected=971, and all four measured task stacks report a high-water mark. Two independent downloads produce byte-identical SUMMARY and STACK lines.
After the JTAG download, the console prints from the boot banner through the 8-second verdict. Key lines from the raw log (the complete file is in the project files):
EP06 FreeRTOS minimal system on CVE2
configCPU_CLOCK_HZ=50000000 configTICK_RATE_HZ=1000
tasks created, starting scheduler
[mon] tick=0 heap=15280 idle=0 pulse=1 hb=0 q=1/1 sh=11/11
[pulse] n=20 tick=950
[mon] tick=1000 heap=15280 idle=2739634 pulse=21 hb=2 q=11/11 sh=131/131
[hb] n=4 tick=1501
[prod] sent=20 tick=1900
[cons] recv=20 tick=1902
...
[mon] tick=7000 heap=15280 idle=19102201 pulse=141 hb=14 q=71/71 sh=851/851
[hb] n=16 tick=7501
[prod] sent=80 tick=7900
[cons] recv=80 tick=7902
[pulse] n=160 tick=7950
[mon] tick=8000 heap=15280 idle=21820112 pulse=161 hb=16 q=81/81 sh=971/971
[mon] tick=8000 heap=15280 idle=21820112 pulse=161 hb=17 q=81/81 sh=971/971
EP06 SUMMARY tick=8000 heap_free=15280 idle=21820112 pulse=161 heartbeat=17 sent=81 recv=81 qerr=0 shared=971 expected=971
EP06 STACK pulse=177 producer=309 consumer=309 monitor=421 words
EP06 RESULT: PASS
A second download reproduces the SUMMARY and STACK lines character for character: tick=8000, heap_free=15280, idle=21820112, pulse=161, heartbeat=17, sent=recv=81, qerr=0, shared=expected=971. This is not a one-off pass; it is the same firmware, same board and the same counters, repeated.
mtime increments every clk; read +0xBFF8 for the low word and +0xBFFC for the high word. mtimecmp resets to all ones and is read/written at +0x4000 / +0x4004. mtime >= mtimecmp drives CVE2's irq_timer_i directly.mtvec.MODE to 01 (vectored). Exceptions always jump to base + 0x00; interrupts jump to base + 4 × irq_id. FreeRTOS's single entry cannot be written into mtvec directly, so 0x100 holds 64 j freertos_risc_v_trap_handler entries. Exception entry 0, timer entry 7 and external entry 11 all reach the same handler, which dispatches on mcause..text.start begins at 0x0000, the vector table occupies 0x100–0x1FF, and .text starts at 0x200. The 64 KiB RAM holds code, rodata, bss, the 24 KiB heap and the main stack.configUSE_TIMERS=0, configUSE_EVENT_GROUPS=0, configUSE_STREAM_BUFFERS=0. Unverified modules are not counted as part of this “minimal system”.| Task | Priority | Period / trigger | Stack words | Work |
|---|---|---|---|---|
| pulse | 4 | 50 ms | 256 | Toggle LED0, shared counter +1 |
| producer | 3 | 100 ms | 384 | Queue a sequence number, shared counter +10 |
| consumer | 2 | blocks on queue | 384 | Receive and check sequence continuity |
| monitor | 1 | 1000 ms | 512 | Print watermarks; at 8 s print summary and verdict |
| heartbeat | 1 | 500 ms | 256 | Toggle LED1 |
| idle | 0 | idle | 256 | Idle hook increments the spin counter |
The verdict is not “there is output”; every counter has to reconcile:
| Counter | Value at 8.000 s | Verdict |
|---|---|---|
| FreeRTOS tick | 8,000 | 1 kHz timer interrupt is stable; tick tracks real time |
| Queue sent / received | 81 / 81 | 100 ms period, first send at t=0, 81 sends in 8 s |
| Queue errors | 0 | No send failure, no sequence mismatch |
| Shared / expected | 971 / 971 | producer 81×10 + pulse 161 = 971; mutex lost no update |
| pulse / heartbeat | 161 / 17 | 50 ms and 500 ms periodic tasks both keep their cadence |
| Idle spin count | 21,820,112 | When no task is runnable, idle really consumes the CPU |
| Heap left | 15,280 B | 9,296 B used of the 24 KiB heap (37.8%) |
The key is that shared and expected advance together. producer and pulse both take g_shared_mtx before modifying the shared counter, and inside that critical section they execute g_shared++ and g_expected++. If the mutex failed, the critical section were preempted, or an update were lost, the two would diverge. They remain exactly equal after 8 seconds, so the mstatus.MIE save/restore path of the mutex works on this core.
configCHECK_FOR_STACK_OVERFLOW=2 is enabled. uxTaskGetStackHighWaterMark returns the historical minimum free space in words (4 B). A larger number means more headroom:
| Task | Allocated words | Peak used words | Min free words | Free bytes |
|---|---|---|---|---|
| pulse | 256 | 79 | 177 | 708 B |
| producer | 384 | 75 | 309 | 1,236 B |
| consumer | 384 | 75 | 309 | 1,236 B |
| monitor | 512 | 91 | 421 | 1,684 B |
The smallest absolute margin is pulse (177 words / 708 B), although it only uses 79 words. monitor uses the most stack (91 words) because it has to assemble several log_printf varargs and multiple 32-bit counters; the 512-word allocation still leaves it 421 words. That sets the budget for the next episode: adding formatted output or floating point means raising monitor from 512 to 640 words, or splitting the print.
The ISR stack is a separate static 256-word (1 KiB) array in .bss. Its boundary with the 24 KiB heap is exactly at 0x63E0: the ISR stack grows down, the heap grows up from 0x63E0, and the two directions do not overlap. This layout was confirmed with nm after linking, not estimated.
| Item | EP05 | EP06 | Change |
|---|---|---|---|
| Slice LUTs | 4,266 | 4,332 | +66 |
| Slice Registers | 3,687 | 3,815 | +128 |
| Block RAM Tile | 32 / 50 | 32 / 50 | unchanged (64.0%) |
| DSPs | 11 | 11 | unchanged |
| Bonded IOB | 25 | 25 | unchanged |
| WNS / WHS | 1.239 / 0.053 ns | 1.563 / 0.032 ns | 0 failing endpoints |
| bitstream | 2,192,137 B | 2,192,137 B | same device, same layout footprint |
The new CLINT is a 64-bit counter plus a 64-bit comparator, and the vector table is 64 4-byte instructions. The cost is only +66 LUT / +128 FF, with no extra BRAM. Timing is actually better than EP05 (WNS 1.563 ns); the added logic is not on the critical path, and this is normal place-and-route variation, not evidence that “FreeRTOS is faster than CoreMark”.
The bitstream is exactly the same size as EP05 (2,192,137 B) because both use the same XC7A35T and the same 64 KiB dual-RAM configuration; only the BRAM contents and a small amount of control logic differ, not the fixed bitstream overhead. SHA-256: 02cfb84a5b3cf95096e317c564b753978f64c27f3ef259584ae48399989c406a.
data_addr[31:12] == 0x20000, covering only 0x2000_0000–0x2000_0FFF. But mtimecmp is at 0x2000_4000 and mtime at 0x2000_BFF8, both outside that page. The first mtime read raised a load access fault and the console stopped after the banner, which looked like “FreeRTOS hangs”. Changing to the 64 KiB range data_addr[31:16] == 0x2000 made the very next board run reach PASS. This is the most expensive lesson of the episode: decode by the peripheral's real span, not by one register address..balign 256 inside .trap_vector made the assembler insert 0xFC bytes of padding, so vector_table landed at 0x1FC and its 64 entries ran to 0x2FC, overlapping .text at 0x200; the linker reported an LMA overlap. Removing the in-section .balign and letting the linker place the whole section at 0x100 fixed it; objdump confirms entries start at 0x100, 64 in total, the last at 0x1FC.cap_serial.py catches the last 64 B and looks like “printing stops halfway”. The correct order is start capture, then program; split the capture at the EP06 FreeRTOS minimal system marker so bytes left over from the previous bitstream are not counted.xTaskDelayUntil and uxTaskGetStackHighWaterMark are gated by INCLUDE_xTaskDelayUntil and INCLUDE_uxTaskGetStackHighWaterMark in V11.1.0. Without setting them to 1 you get an undefined reference at link time, not compile time, which is easy to misread as a missing kernel feature.[31:8] of mtvec and forces the low 8 bits to 01; exceptions and interrupts have different entry addresses. A 64-entry table is mandatory, and exception entry 0, timer entry 7 and external entry 11 must all reach the same handler, otherwise the tick and exceptions take two different paths.configISR_STACK_SIZE_WORDS=256 makes port.c emit the static xISRStack array and export xISRStackTop. Without that symbol, portASM.S fails to link at load_x sp, xISRStackTop; with a symbol that overlaps the heap, the first interrupt corrupts the heap.riscv-nuclei-elf-gcc 10.2, JTAG and a USB serial cable; serial is /dev/ttyUSB1, 115200 8N1.cd sw && make clean && make; confirm firmware.hex (6,079 words).vivado -mode batch -source build_ep06.tcl. The script runs synth_1, impl_1, phys_opt_design -hold_fix and route_design, then writes final timing/util/drc reports and the bitstream.python3 cap_serial.py 22 /tmp/ep06.bin &, then vivado -mode batch -source program_ep06.tcl.EP06 RESULT: PASS. Split the log at the boot banner and compare it with metrics/ep06_metrics.json.cd sw && make clean && make
cd ..
vivado -mode batch -source build_ep06.tcl
python3 cap_serial.py 22 /tmp/ep06.bin & # start before programming
vivado -mode batch -source program_ep06.tcl
/media/alinx/nvme4t/fpga-love/pi_ar035_f1_1_cve2_ep06/sw/firmware.hex. On another machine or directory, update INIT_FILE in the RTL too, otherwise synthesis “succeeds” with an all-zero RAM.The files below are taken directly from this verified project. FreeRTOS kernel sources are provided under the MIT licence; this page includes the port and project files, and the complete kernel should be taken from FreeRTOS upstream.
Daily Briefing · Weekly Digest · Monthly Deep Dive