|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
CANFD0 internal-loopback HIL test for EK-RA8D2. More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_canfd.h"#include "ra8_canfd_regs.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | canfd_demo_const_t : uint32_t { k_canfd_demo_period_ms = 1000U , k_canfd_demo_bitrate = 500000U , k_canfd_demo_id = 0x123U , k_canfd_demo_rx_spin = 200000U } |
| Demo tunables. More... | |
| enum | canfd_demo_layout_t : uint8_t { k_canfd_demo_channel = 0U , k_canfd_demo_dlc = 8U } |
| Channel + payload layout. More... | |
| enum | canfd_demo_payload_t : uint8_t { k_canfd_demo_payload_b1 = 0xA5U , k_canfd_demo_payload_b2 = 0x5AU , k_canfd_demo_payload_b3 = 0xFFU , k_canfd_demo_payload_b4 = 0x00U , k_canfd_demo_payload_b5 = 0xDEU , k_canfd_demo_payload_b6 = 0xADU , k_canfd_demo_payload_b7 = 0xBEU } |
| Constant payload bytes for the heartbeat frame. More... | |
Functions | |
| static void | internal_canfd_demo_panic_halt (void) |
| Park the processor after a fatal CAN-FD loopback failure. | |
| static ra8_err_t | internal_canfd_demo_enable_internal_loopback (uint8_t channel) |
Enable Self-test 1 (internal loopback) on channel. | |
| static void | internal_canfd_demo_setup_or_halt (void) |
| Bring CGC + SysTick + LEDs + CANFD0 up. | |
| static ra8_err_t | internal_canfd_demo_one_round_trip (uint8_t seq) |
| One TX/RX round-trip. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| volatile uint32_t | g_canfd_match = 0U |
| HIL liveness counter – incremented on every successful TX -> internal loopback -> RX round-trip. | |
| volatile uint32_t | g_canfd_mismatch = 0U |
| HIL failure counter – incremented every time TX or RX returned a non-ok status. | |
| volatile uint32_t | g_canfd_init_step = 0U |
| Bring-up step tracker: 1=init ok, 2=set_bitrate ok, 3=loopback ok. | |
| volatile uint32_t | g_canfd_ncfg_after_setbitrate = 0U |
| NCFG readback latched at end of set_bitrate (proves NCFG write). | |
CANFD0 internal-loopback HIL test for EK-RA8D2.
Runs entirely on the bare EK-RA8D2 – no external transceiver required. The demo:
Exits the loop on the first hard HAL error and parks in WFI.
Definition in file main.c.
| enum canfd_demo_const_t : uint32_t |
| enum canfd_demo_layout_t : uint8_t |
| enum canfd_demo_payload_t : uint8_t |
Constant payload bytes for the heartbeat frame.
|
staticnodiscard |
Enable Self-test 1 (internal loopback) on channel.
Forwards to ra8_canfd_set_test_mode which bounces the channel through CH_HALT to land CTME = 1 and CTMS = 11b in CFDC[0].CTR. HUM Ch 41 "CFDCnCTR" p 2710 – CTME / CTMS are only writable in CH_HALT mode.
| [in] | channel | CAN-FD controller channel to place in internal loopback. |
| k_ra8_ok | Bits stamped, channel back in operation. |
| k_ra8_err_invalid_arg | Channel index rejected by the HAL. |
channel. Definition at line 159 of file main.c.
References k_ra8_ctms_self_test_1, and ra8_canfd_set_test_mode().
Referenced by internal_canfd_demo_setup_or_halt().
|
staticnodiscard |
One TX/RX round-trip.
Returns ok on success or first error.
Definition at line 226 of file main.c.
References k_canfd_demo_channel, k_canfd_demo_dlc, k_canfd_demo_id, k_canfd_demo_payload_b1, k_canfd_demo_payload_b2, k_canfd_demo_payload_b3, k_canfd_demo_payload_b4, k_canfd_demo_payload_b5, k_canfd_demo_payload_b6, k_canfd_demo_payload_b7, k_canfd_demo_rx_spin, k_ra8_err_hw_error, k_ra8_err_no_data, k_ra8_ok, ra8_canfd_receive(), ra8_canfd_transmit(), and RA8_INTERNAL.
Referenced by main().
|
static |
Park the processor after a fatal CAN-FD loopback failure.
Retains the controller registers, init-step marker, and HIL counters in a permanent wait-for-interrupt loop for debugger inspection.
Definition at line 128 of file main.c.
References RA8_INTERNAL.
Referenced by internal_canfd_demo_setup_or_halt(), and main().
|
static |
Bring CGC + SysTick + LEDs + CANFD0 up.
Halts on any error.
Initializes the time base and status LEDs, opens CANFD0, applies the nominal and data bit rates, records the NCFG readback, and enables internal loopback. Any failed step enters the permanent panic halt.
Definition at line 181 of file main.c.
References r_canfd_t::CFDC, g_canfd_init_step, g_canfd_ncfg_after_setbitrate, internal_canfd_demo_enable_internal_loopback(), internal_canfd_demo_panic_halt(), k_canfd_demo_bitrate, k_canfd_demo_channel, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, r_canfd_cfdc_t::NCFG, ra8_board_led_init(), ra8_canfd(), ra8_canfd_init(), ra8_canfd_set_bitrate(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, and ra8_time_init().
Referenced by main().
| void main | ( | void | ) |
The application entry point Reset_Handler hands control to.
Returns void, not int. This is a freestanding image: there is no hosted C environment, no process and nothing to report an exit status to. ISO C fixes main at int only for a hosted implementation; for a freestanding one (C23 5.1.2.1) the startup function's name and type are implementation-defined, and this is that definition. Reset_Handler discards no value because there is none to discard, and if main ever does return, startup halts the CPU rather than resuming anything.
The firmware lane is compiled -ffreestanding (see cmake/ra8_add_app.cmake) and the flag and this signature travel together: without it both GCC and clang reject a non-int main (-Wmain / -Wmain-return-type). Do not remove one without the other.
That coupling is why the declaration sits behind __STDC_HOSTED__ == 0, which -ffreestanding sets and a hosted build does not. The guard is not defensive dressing: this header is reachable from host builds (the unit tests compile ra8_core natively), and an unguarded void main(void); makes every hosted translation unit that includes it fail with conflicting types for 'main' against its own ISO int main. The declaration therefore exists exactly where its contract does.
Hosted first-party code – everything under tests/ and tools/ – uses the ISO int main(...) contract instead, because it genuinely does run under an OS that reads the exit status. scripts/checks/check_entry_points.py holds each domain to its own contract (#707).
Declared here, once, for the same reason SystemInit is: every vector_table.c used to restate it as a local extern int32_t main(void);, sixteen copies that no compiler ever compared against the definition – and roughly thirty of them had silently drifted out of agreement with the main they called.
The application entry point Reset_Handler hands control to.
Brings up CGC + BSP audio then plays blocks.
The application entry point Reset_Handler hands control to.
Brings up CGC + GPT triple, runs sweep.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
The application entry point Reset_Handler hands control to.
Brings up LED, console, SDHI pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Profiles power modes once a second.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, SPI, and SD card, then runs the shared ra8_io VFS round-trip over the SD-over-SPI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Initialises logging and the console, brings up the OSPI NOR volume, runs the erase-before-write round-trip, and prints a single PASS/FAIL verdict line over SCI8 before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Both USB controllers' clocks and pins come up before the kernel so the workers only deal with stack bring-up.
The application entry point Reset_Handler hands control to.
Brings up logging and the clock tree, releases the Cortex-M33 (which then blinks LED1 via ra8_pcntr_set_output()), and idles. See the file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the cacheable-SRAM round-trip with the D-cache that SystemInit() enabled through ra8_cache_dcache_enable(), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU + RA8_BOOT_CACHE_VIA_HAL).
The application entry point Reset_Handler hands control to.
Publishes the mailbox, releases the Cortex-M33 into the emitter, yields until it signals done, validates the blob the M33 built, then logs the PASS/FAIL verdict and the chapter count read back from the blob. See the file header for the offload narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Publishes the mailbox, arms the IPC0 wake and configures the LPM block, releases the Cortex-M33 into the reader, waits for the first held page, logs the page-0 verdict, then runs the #150 mode-switch cycle – parking in low-power WFI and waking on the M33's page-turn pokes – before logging the handoff verdict and parking for good. See the file header for the narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the timebase then measures forever.
The application entry point Reset_Handler hands control to.
Arms the RIIC1 target and polls the dispatcher.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the LIN commander then drives frames.
The application entry point Reset_Handler hands control to.
Brings up logging, "renders" page 0 into the shared mailbox, releases the Cortex-M33 into its hold loop, and parks the M85 in low-power WFI sleep. See the file header for the power-saving narrative.
The application entry point Reset_Handler hands control to.
The USB clock, pins, console, and the SD card all come up before the kernel so the worker only deals with USB stack bring-up.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the three-step self-test (MPU enabled, canonical boot map, Device MMIO), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initialises logging + console, brings up the MRAM volume, runs the wear-levelling + power-cycle-survival flow, and prints a single PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Initialises logging + console, brings up the MRAM volume, runs the program/erase round-trip, and prints a single PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, and SDHI bus pins, runs the native SD card identification, fills the payload, then runs the full ra8_io VFS round-trip over the native-SDHI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Brings up the console and both stdio sinks, retargets the engine's stdio to the in-RAM capture sink, runs the two-backend swap, replays the RAM capture out of the UART, and prints a single PASS/FAIL verdict per abstraction before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, and SDHI bus pins, runs the native SD card identification, fills the payload, then writes + reads + compares one raw 512-byte block straight against ra8_sdcard. On success it prints the exact PASS banner; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII + RSIP, then ThreadX.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initializes and arms ADC_B, formats each successful channel sample without variadic I/O, emits the verdict, toggles LED1, and delays.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, releases the Cortex-M33 (which then blinks LED1), and idles. See the file header for the teaching narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See the file header for the full behaviour summary.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the three-step self-test (cacheable SRAM, RO MRAM const, Device MMIO), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches and MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU).
The application entry point Reset_Handler hands control to.
Definition at line 257 of file main.c.
References g_canfd_match, g_canfd_mismatch, internal_canfd_demo_one_round_trip(), internal_canfd_demo_panic_halt(), internal_canfd_demo_setup_or_halt(), k_canfd_demo_period_ms, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_toggle(), ra8_delay_ms(), and ra8_isr_globals_enable().
| volatile uint32_t g_canfd_init_step = 0U |
Bring-up step tracker: 1=init ok, 2=set_bitrate ok, 3=loopback ok.
Definition at line 107 of file main.c.
Referenced by internal_canfd_demo_setup_or_halt().
| volatile uint32_t g_canfd_match = 0U |
HIL liveness counter – incremented on every successful TX -> internal loopback -> RX round-trip.
Read externally by scripts/hil/jlink_memprobe.sh via SWD. The probe asserts this counter advances by >= HIL_PROBE_MIN_ADVANCE over the sample window, proving the CAN_FD peripheral actually moved frames through its internal loopback (the alive-mode check could only prove the chip didn't crash, not that CAN-FD actually worked).
Definition at line 88 of file main.c.
Referenced by main().
| volatile uint32_t g_canfd_mismatch = 0U |
HIL failure counter – incremented every time TX or RX returned a non-ok status.
The memprobe asserts this stays at 0 (or below HIL_PROBE_MAX_FAILURE). Catches the silent-failure mode where the peripheral starts up but TX fails or RX times out – previously invisible because the chip kept iterating the main loop happily.
Definition at line 104 of file main.c.
Referenced by main().
| volatile uint32_t g_canfd_ncfg_after_setbitrate = 0U |
NCFG readback latched at end of set_bitrate (proves NCFG write).
Definition at line 110 of file main.c.
Referenced by internal_canfd_demo_setup_or_halt().