|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Octo-SPI flash journal demo for EK-RA8D2. More...
#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_time.h"#include "ra8_xspi.h"Go to the source code of this file.
Enumerations | |
| enum | flash_journal_const_t : uint32_t { k_journal_period_ms = 1000U , k_journal_record_bytes = 16U , k_journal_record_addr = 0x0U , k_journal_xspi_instance = 0U , k_journal_counter_bytes = 4U , k_journal_byte_mask = 0xFFU , k_journal_byte_shift = 8U } |
| Demo tunables. More... | |
| enum | fj_step_t : uint32_t { k_fj_step_init = 0U , k_fj_step_erase_ok = 1U , k_fj_step_program_ok = 2U , k_fj_step_read_ok = 3U , k_fj_step_compare_ok = 4U , k_fj_step_erase_failed = 5U , k_fj_step_program_failed = 6U , k_fj_step_read_failed = 7U , k_fj_step_compare_mismatch = 8U } |
| Step codes for g_fj_last_step (erase/program/read/compare chain). More... | |
| enum | fj_err_sentinel_t : uint32_t { k_fj_err_none = 0xFFFFFFFFU } |
| Sentinel for g_fj_expander_err meaning "no error captured yet". More... | |
Functions | |
| static void | flash_journal_panic_halt (void) |
| Park the CPU after a fatal init failure. | |
| static void | flash_journal_pack (uint32_t counter, uint8_t *rec) |
| Pack a counter into a 16-byte record (little-endian + padding). | |
| static uint32_t | flash_journal_unpack (const uint8_t *rec) |
| Decode the counter from a 16-byte record. | |
| static ra8_err_t | flash_journal_round_trip (uint32_t counter, uint32_t *echoed) |
| Erase + program + read-back round-trip of one record. | |
| static void | flash_journal_setup_or_halt (void) |
| Run all init-time bring-up that must complete before the loop. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| volatile uint32_t | g_fj_match = 0U |
| HIL liveness counter – incremented on every successful erase -> program -> read-back -> compare round-trip. | |
| volatile uint32_t | g_fj_mismatch = 0U |
| HIL failure counter – incremented on any erase, program, or read failure, or when the read-back bytes don't match what was just written. | |
| volatile uint32_t | g_fj_last_step = k_fj_step_init |
| Last round-trip step value (J-Link memprobe diagnostic). | |
| volatile uint32_t | g_fj_last_counter = 0U |
| Last counter the firmware tried to write. | |
| volatile uint32_t | g_fj_last_echoed = 0U |
| Last counter value read back from flash. | |
| volatile uint32_t | g_fj_jedec_id = 0U |
| One-shot JEDEC ID read at boot (memprobe diagnostic). | |
| volatile uint32_t | g_fj_expander_err = k_fj_err_none |
| Return code from the best-effort U15 Octo-SPI-active override. | |
Octo-SPI flash journal demo for EK-RA8D2.
Treats the on-board 64 MB Octo-SPI flash as a tiny append-only journal of 16-byte records. Each boot:
No filesystem layer (LevelX, FileX) is used – this exercises ra8_xspi_flash_* directly.
Definition in file main.c.
| enum fj_err_sentinel_t : uint32_t |
Sentinel for g_fj_expander_err meaning "no error captured yet".
| Enumerator | |
|---|---|
| k_fj_err_none | Fj error none. |
| enum fj_step_t : uint32_t |
Step codes for g_fj_last_step (erase/program/read/compare chain).
Low codes are success milestones, high codes are the matching failure points; read via J-Link memprobe.
| enum flash_journal_const_t : uint32_t |
Demo tunables.
|
static |
Pack a counter into a 16-byte record (little-endian + padding).
| [in] | counter | Value to encode. |
| [out] | rec | 16-byte buffer to populate. |
Definition at line 200 of file main.c.
References k_journal_byte_mask, k_journal_byte_shift, k_journal_counter_bytes, and k_journal_record_bytes.
Referenced by flash_journal_round_trip().
|
static |
Park the CPU after a fatal init failure.
Definition at line 187 of file main.c.
Referenced by flash_journal_setup_or_halt(), and main().
|
staticnodiscard |
Erase + program + read-back round-trip of one record.
| [in] | counter | Sequence number to encode in the record. |
| [out] | echoed | Counter actually read back from flash. |
| k_ra8_ok | Round-trip succeeded. |
| k_ra8_err_hw_error | Any of the three flash ops failed. |
Definition at line 242 of file main.c.
References flash_journal_pack(), flash_journal_unpack(), g_fj_last_counter, g_fj_last_echoed, g_fj_last_step, k_fj_step_erase_failed, k_fj_step_erase_ok, k_fj_step_program_failed, k_fj_step_program_ok, k_fj_step_read_failed, k_fj_step_read_ok, k_journal_record_addr, k_journal_record_bytes, k_journal_xspi_instance, k_ra8_err_hw_error, k_ra8_ok, ra8_xspi_flash_erase_sector(), ra8_xspi_flash_program(), and ra8_xspi_flash_read().
Referenced by main().
|
static |
Run all init-time bring-up that must complete before the loop.
Brings CGC, SysTick, LEDs, OCTA pins, and OSPI controller up, then does a one-shot JEDEC ID read so a memprobe can confirm the bus is electrically alive. Panics on any failure other than the JEDEC read (which is best-effort – a floating bus returns 0x00FFFFFF and the loop will surface the same fact via g_fj_last_step = 5).
Definition at line 289 of file main.c.
References flash_journal_panic_halt(), g_fj_expander_err, g_fj_jedec_id, k_journal_xspi_instance, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, k_ra8_xspi_lio_1s1s1s, ra8_board_io_expander_set_octospi_active(), ra8_board_led_init(), ra8_board_xspi_pins_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_time_init(), ra8_xspi_flash_read_id(), and ra8_xspi_init().
Referenced by main().
|
static |
Decode the counter from a 16-byte record.
| [in] | rec | 16-byte buffer. |
Definition at line 217 of file main.c.
References k_journal_byte_shift, and k_journal_counter_bytes.
Referenced by flash_journal_round_trip().
| 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.
The application entry point Reset_Handler hands control to.
Lights HOCO + PLL, then runs a 1 Hz blink.
The application entry point Reset_Handler hands control to.
See file header for behaviour summary.
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 the demo, executes one comparison per period, increments the exported match or mismatch counter, and toggles the matching LED.
The application entry point Reset_Handler hands control to.
Brings up the clock tree, MSTP, ISR/ELC, and the VCOM console, programs a software-triggered DTC block copy, runs it with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU), 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.
Brings up logging, zeros the shared control block, releases the Cortex-M33, waits for its boot signature, then yields while the M33 counts autonomously to k_bg_target_count. After the M33 sets done, the M85 reads the counter and logs the PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Brings up logging, releases the Cortex-M33, confirms it booted, runs k_m85_demo_rounds narrated mailbox rounds, then drops into the idle heartbeat. See the file header for the teaching narrative.
The application entry point Reset_Handler hands control to.
Fires ELC software events once a second.
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.
Definition at line 333 of file main.c.
References flash_journal_panic_halt(), flash_journal_round_trip(), flash_journal_setup_or_halt(), g_fj_last_step, g_fj_match, g_fj_mismatch, k_fj_step_compare_mismatch, k_fj_step_compare_ok, k_journal_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_fj_expander_err = k_fj_err_none |
Return code from the best-effort U15 Octo-SPI-active override.
0 (k_ra8_ok) means the U15 I/O expander ACKed the SW4 override write. Note this does NOT mean the flash is connected: a firmware sweep of the entire U15 output space (all 256 values, released-inputs, Hi-Z, per-bit) proved the expander's GPIOs do NOT gate the OSPI bus at all – the IS25LX512M is connected only through the hardware-only SW4-3 analog mux. So this write is inert with respect to flash reachability and kept only as a no-op courtesy. Non-zero means the expander did not respond on RIIC1. Read externally by J-Link (see docs/HARDWARE_BRINGUP.md).
Definition at line 184 of file main.c.
Referenced by flash_journal_setup_or_halt().
| volatile uint32_t g_fj_jedec_id = 0U |
One-shot JEDEC ID read at boot (memprobe diagnostic).
Stamped once by main right after ra8_xspi_init returns. Lets a memprobe confirm the OSPI controller actually clocks the bus by reading the on-board flash's JEDEC ID. The EK-RA8D2 ships an ISSI IS25LX512M-JHLE (manufacturer 0x9D; UM Table 29, p 35), so a correct 1S RDID on a connected part returns 0x9D. A value of 0x000000 means no ID returned; 0xFFFFFF means the bus floated to the board pull-ups (no CIPO drive) – the on-board flash is reached only through the SW4-3 analog mux, which is hardware-only and cannot be moved from firmware (the U15 expander override does NOT gate the OSPI bus; see issue #44 and docs/HARDWARE_BRINGUP.md), NOT a dead chip.
Definition at line 160 of file main.c.
Referenced by flash_journal_setup_or_halt().
| volatile uint32_t g_fj_last_counter = 0U |
Last counter the firmware tried to write.
Lets a memprobe compare against g_fj_last_echoed when g_fj_last_step lands at 8 (compare mismatch).
Definition at line 127 of file main.c.
Referenced by flash_journal_round_trip().
| volatile uint32_t g_fj_last_echoed = 0U |
Last counter value read back from flash.
Holds the result of flash_journal_unpack on the read-back record.
Definition at line 139 of file main.c.
Referenced by flash_journal_round_trip().
| volatile uint32_t g_fj_last_step = k_fj_step_init |
Last round-trip step value (J-Link memprobe diagnostic).
Encodes which step of the erase / program / read / compare chain the firmware completed last. 0 = pre-loop init, 1 = erase ok, 2 = program ok, 3 = read ok, 4 = match, 5 = erase err, 6 = program err, 7 = read err, 8 = compare mismatch (echoed != counter). Lets a memprobe pinpoint which OSPI op fails without UART.
Definition at line 114 of file main.c.
Referenced by flash_journal_round_trip(), and main().
| volatile uint32_t g_fj_match = 0U |
HIL liveness counter – incremented on every successful erase -> program -> read-back -> compare 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 Octo-SPI flash peripheral actually wrote and read back matching bytes (the alive-mode check could only prove the chip didn't crash, not that flash actually round-tripped data).
Definition at line 62 of file main.c.
Referenced by main().
| volatile uint32_t g_fj_mismatch = 0U |
HIL failure counter – incremented on any erase, program, or read failure, or when the read-back bytes don't match what was just written.
The memprobe asserts this stays at 0 (or below HIL_PROBE_MAX_FAILURE). Catches the silent-failure mode where the peripheral starts up but writes silently drop, reads return stale data, or the compare miscompares – previously invisible because the chip kept iterating the main loop happily.
Definition at line 80 of file main.c.
Referenced by main().