OpenHW CVE2 on ALINX PI-AR035-F1-1 - Episode 06: FreeRTOS minimal system ========================================================================= What it does ------------ The CVE2 core (RV32IM, 50 MHz) is unchanged. The FPGA adds a standard CLINT with a free-running 64-bit mtime and a 64-bit mtimecmp, and reports a timer interrupt. Because CVE2 hardwires mtvec.MODE to 01 (vectored), a 64-entry jump table at 0x100 sends exception entry 0, timer entry 7 and external entry 11 to the single FreeRTOS trap handler, which dispatches on mcause. FreeRTOS Kernel V11.1.0 runs the minimal kernel: tasks, queue, list and heap_4. Timers, event groups and stream buffers are disabled. Six tasks exist (five application tasks plus idle), with priorities 4/3/2/1/1/0. Verified result (2026-11-20) ---------------------------- Two independent JTAG downloads produced identical SUMMARY and STACK lines: 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 Interpretation: - tick 8,000 at 8.000 s proves the 1 kHz timer interrupt and tick path. - sent=recv=81 with qerr=0 proves the 100 ms producer and blocking consumer exchange every sequence number without loss or mismatch. - shared=expected=971 proves the mutex-protected counter had no lost update. producer contributes 81 * 10 = 810 and pulse contributes 161, total 971. - heartbeat=17 and pulse=161 show the 500 ms and 50 ms periodic tasks kept their cadence. - The STACK values are uxTaskGetStackHighWaterMark() results: the historical minimum FREE stack in words, not words used. Peak use is therefore allocation minus the reported value: pulse 256 - 177 = 79 words used, 177 free (708 B) producer 384 - 309 = 75 words used, 309 free (1,236 B) consumer 384 - 309 = 75 words used, 309 free (1,236 B) monitor 512 - 421 = 91 words used, 421 free (1,684 B) Memory map ---------- .text.start 0x0000, 0x40 bytes .trap_vector 0x0100, 0x100 bytes (64 entries) .text 0x0200, 0x58A0 bytes .rodata 0x5AA0, 0x44C bytes .data 0x5EEC, 0x10 bytes .bss 0x5F00, 0x6584 bytes, ends at 0xC484 main stack top 0x10000 (about 15 KiB left below it) xISRStack 0x5FE0, 256 words (ends at 0x63E0) xISRStackTop pointer word at 0x5EE8, value 0x63E0 heap 0x63E0, 24,576 B, grows up; ISR stack grows down Resources / timing ------------------ LUT 4,332 (20.83%), FF 3,815 (9.17%), BRAM 32 / 50 (64.00%), DSP 11 (12.22%), IOB 25 (10.00%). WNS 1.563 ns / WHS 0.032 ns, TNS/THS 0.000, 0 failing endpoints of 11,754. DRC: 0 errors, 76 warning-severity checks (DPIP/DPOP/DPREG/REQP wiring advice). Bitstream 2,192,137 B, SHA-256 02cfb84a5b3cf95096e317c564b753978f64c27f3ef259584ae48399989c406a ELF 139,820 B, SHA-256 9ab648c5d0826fc668dc9ebd634e578524ca0cbc38b48a40e163f1240fffc34d BIN 24,316 B, SHA-256 f8ba7cd63d3bb38e509feccf112b87b0747607f46217a291eb26156bf4b5d913 HEX 54,711 B, 6,079 words, SHA-256 e7f89d1538af4a0b19dbb6fce2b0db54f22193d5c7f4fb48f80e7ee1325f99f8 Build ----- cd sw && make clean && make vivado -mode batch -source build_ep06.tcl python3 cap_serial.py 22 /tmp/ep06.bin & # start capture FIRST vivado -mode batch -source program_ep06.tcl # hw_server TCP:127.0.0.1:3122 The BRAM init path in the RTL is absolute: /media/alinx/nvme4t/fpga-love/pi_ar035_f1_1_cve2_ep06/sw/firmware.hex Change INIT_FILE when the project moves. Pitfalls -------- 1. CLINT address decode must cover 64 KiB, not one 4 KiB page. mtimecmp is at 0x2000_4000 and mtime at 0x2000_BFF8, in different 4 KiB pages. A decode of data_addr[31:12] == 0x20000 faults on the first mtime read; the console stops after the boot banner and looks like a scheduler hang. Use data_addr[31:16] == 0x2000. 2. Do not put .balign 256 inside .trap_vector. It inserts 0xFC bytes of padding, moves vector_table to 0x1FC and overlaps .text at 0x200. Let the linker place the section at 0x100 instead. 3. Start UART capture before programming. The firmware runs immediately after configuration, and the USB-UART bridge holds only about 64 B. Capturing after Vivado exits yields a 64-byte tail that looks like a hang. 4. FreeRTOS V11 defaults INCLUDE_xTaskDelayUntil and INCLUDE_uxTaskGetStackHighWaterMark to 0. Both must be 1 or the link fails with undefined references. 5. CVE2 mtvec.MODE is forced to 01; exceptions and interrupts have different entry addresses. A single handler cannot be installed directly; the 64-entry jump table is required. 6. configISR_STACK_SIZE_WORDS creates the static xISRStack array in port.c. Keep xISRStackTop consistent and ensure it does not overlap the heap. Notes / limits -------------- Verified: single-core CVE2, 1 kHz tick, five-task preemptive scheduling, queue send/receive, mutex-protected counters, stack high-water marks, heap headroom, two repeat downloads. Not verified: timers, event groups, stream buffers, SMP, FPU context save, scheduling jitter with cache or DDR, long-duration soak, temperature/voltage corners, or scheduling-latency comparisons with other RISC-V cores. License ------- FreeRTOS Kernel is MIT licensed; see LICENSE. CVE2 is Apache-2.0.