ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

ra8_io fabric over OSPI NOR flash (epic #155, #156) on the EK-RA8D2. More...

#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io.h"
#include "ra8_io_roundtrip.h"
#include "ra8_log.h"
#include "ra8_port_constants.h"
#include "ra8_port_utils.h"
#include "ra8_sci.h"
#include "ra8_time.h"
#include "ra8_xspi.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  demo_const_t : uint32_t {
  k_demo_uart_chan = 8U ,
  k_demo_uart_baud = 115200U ,
  k_demo_xspi_inst = 0U ,
  k_demo_xspi_base = 0U ,
  k_demo_disk_blocks = 512U ,
  k_demo_payload = 256U ,
  k_demo_pin_shift = 8U
}
 Console + volume + OSPI knobs (no magic numbers). More...

Functions

static void demo_print (const char *msg)
 Print a NUL-terminated string on the UART stream.
static void demo_setup_or_halt (void)
 Bring up CGC + SysTick + the SCI8 console; halt on any failure.
static ra8_err_t demo_run (void)
 Bring up the OSPI block device, then run the shared FAT round-trip.
void main (void)
 Firmware entry point.

Variables

static const ra8_port_pin_t k_demo_txd
 SCI8 console TXD = PD02.
static const ra8_port_pin_t k_demo_rxd
 SCI8 console RXD = PD03.
static ra8_io_blockdev_t s_bd
 Block-device handle + its OSPI NOR backend state.
static ra8_io_blockdev_xspi_state_t s_xstate
static ra8_fs_backend_t s_be
 ra8_fs backend bridged onto the OSPI block device.
static ra8_io_stream_t s_uart
 UART output stream + its sink state.
static ra8_io_stream_uart_state_t s_ust
static const char *const s_tag = "ra8_io_xspi_demo"
 Module log tag.
static const ra8_io_roundtrip_params_t s_params
 Shared round-trip parameters for this OSPI-backed FAT12 volume.

Detailed Description

ra8_io fabric over OSPI NOR flash (epic #155, #156) on the EK-RA8D2.

Tag
[Ring 6 / APP] {World: S}

The third storage tier for the ra8_io fabric. Where ra8_io_demo proves the fabric over RAM and ra8_io_sd_demo over an SD card, this app proves it over the on-board Octo-SPI (OSPI / xSPI) NOR flash – an erase-before-write medium. NOR can only clear bits (1 -> 0) on a program, so a 4 KiB sector must be erased back to all-ones before any byte in it is re-written. The xSPI block-device backend hides this behind the block vtable: an arbitrary 512-byte block write triggers a whole-4-KiB-sector read-modify-write inside the backend. The ra8_fs + VFS layers above are identical to the other FAT demos and shared through ra8_io_roundtrip.{h,c} (a self-contained local copy); this app differs only by the OSPI controller bring-up (ra8_xspi_init) plus the ONE backend bind line (ra8_io_blockdev_xspi_init) and its own PASS banner.

The window and payload are deliberately small (512 blocks = 256 KiB volume, 256-byte payload) because every 512-byte write drives a 4 KiB erase + reprogram RMW that is slow in ra8_emulator; a large volume would blow the run budget. ra8_emulator models the 2 MiB OSPI NOR array internally, so the run is headless and observable: a successful run prints ra8_io_xspi_demo: xs:/CFG/SET.BIN 256 bytes PASS.

Definition in file main.c.

Enumeration Type Documentation

◆ demo_const_t

enum demo_const_t : uint32_t

Console + volume + OSPI knobs (no magic numbers).

Enumerator
k_demo_uart_chan 

SCI8 J-Link OB console.

k_demo_uart_baud 

Console baud.

k_demo_xspi_inst 

xSPI controller instance index.

k_demo_xspi_base 

Flash byte offset of logical blk 0.

k_demo_disk_blocks 

256 KiB OSPI window (FAT12).

k_demo_payload 

Bytes written + read back.

k_demo_pin_shift 

Port byte position in ra8_port_pin_t.

Definition at line 49 of file main.c.

Function Documentation

◆ demo_print()

void demo_print ( const char * msg)
static

Print a NUL-terminated string on the UART stream.

Thin wrapper over ra8_io_stream_puts that fixes the demo's UART stream sink, so callers do not repeat the sink handle.

Parameters
[in]msgNUL-terminated ASCII string (CR/LF included by the caller).
Returns
None.
Precondition
s_uart was initialised by ra8_io_stream_uart_init.
msg is non-NULL and NUL-terminated.
Postcondition
The bytes of msg are queued on the UART stream.
No other state changes.
Note
Blocking polled TX; not interrupt-safe.
Since
0.1.0

Definition at line 110 of file main.c.

References ra8_io_stream_puts(), and s_uart.

◆ demo_run()

ra8_err_t demo_run ( void )
static

Bring up the OSPI block device, then run the shared FAT round-trip.

Initialises the xSPI controller in 1S-1S-1S link mode, binds an erase-before-write block device over a 256 KiB flash window (the two per-demo bring-up lines), mounts the FAT12 volume through the shared helper, then runs the shared mkdir + nested round-trip into xs:/CFG/SET.BIN. The first failing step short-circuits with its code.

Returns
ra8_err_t Error code.
Return values
k_ra8_okThe "xs" volume mounted and the payload round-tripped.
k_ra8_err_*The first failing bring-up / mount / round-trip step's code.
Precondition
demo_setup_or_halt has run (clocks + console up).
s_bd / s_xstate / s_be out-live every call through the device.
Postcondition
On success xs:/CFG/SET.BIN holds the verified payload.
No file handle is left open on any return path.
Note
Not thread-safe; single-caller boot context.
Since
0.1.0

Definition at line 178 of file main.c.

References k_demo_disk_blocks, k_demo_xspi_base, k_demo_xspi_inst, k_ra8_xspi_lio_1s1s1s, ra8_board_xspi_pins_init(), ra8_io_blockdev_xspi_init(), ra8_io_roundtrip_mount(), ra8_io_roundtrip_subdir_file(), RA8_RETURN_ON_ERROR, ra8_xspi_init(), s_bd, s_be, s_params, s_tag, and s_xstate.

Referenced by main().

◆ demo_setup_or_halt()

void demo_setup_or_halt ( void )
static

Bring up CGC + SysTick + the SCI8 console; halt on any failure.

Initialises the clock-generation circuit, reads the CPU and PCLKA rates, starts the millisecond time base, routes the SCI8 console pins, and opens the SCI8 UART. Any failure spins forever so a debugger can inspect the halt; there is no console yet to report on.

Returns
None.
Precondition
SystemInit has configured VTOR / FPU / priority grouping.
Runs single-threaded during early boot with no other driver active.
Postcondition
On success SCI8 is open at k_demo_uart_baud and the time base runs.
On any failure the function never returns (infinite halt loop).
Note
Not thread-safe; boot-context only.
Since
0.1.0

Definition at line 133 of file main.c.

References k_demo_rxd, k_demo_txd, k_demo_uart_baud, k_demo_uart_chan, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_ra8_psel_sci_async, k_ra8_sci_data_8, k_ra8_sci_parity_none, k_ra8_sci_stop_1, ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_pfs_route_peripheral(), ra8_sci_init(), and ra8_time_init().

◆ main()

void main ( void )

Firmware entry point.

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.

Precondition
SystemInit configured VTOR / FPU / priority grouping.
The OSPI NOR array is present (modelled in ra8_emulator, real on silicon).
Postcondition
Exactly one PASS or FAIL verdict line has been queued on SCI8.
Control parks in an infinite loop; the function never returns.
Note
Single-threaded; runs to the park loop on the main stack.
Since
0.1.0

Definition at line 218 of file main.c.

References demo_print(), demo_run(), demo_setup_or_halt(), k_demo_uart_chan, k_ra8_ok, ra8_io_log_attach(), ra8_io_stream_uart_init(), ra8_log_init(), ra8_sci_flush(), s_uart, and s_ust.

Variable Documentation

◆ k_demo_rxd

const ra8_port_pin_t k_demo_rxd
static
Initial value:
=
(ra8_port_pin_t)(((uint16_t)k_ra8_port_13 << (uint16_t)k_demo_pin_shift) | (uint16_t)k_ra8_pin_3)
@ k_demo_pin_shift
Port byte position in ra8_port_pin_t.
Definition main.c:62
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_port_13
RA8 port 13.
@ k_ra8_pin_3
RA8 pin 3.

SCI8 console RXD = PD03.

Definition at line 63 of file main.c.

◆ k_demo_txd

const ra8_port_pin_t k_demo_txd
static
Initial value:
=
(ra8_port_pin_t)(((uint16_t)k_ra8_port_13 << (uint16_t)k_demo_pin_shift) | (uint16_t)k_ra8_pin_2)
@ k_ra8_pin_2
RA8 pin 2.

SCI8 console TXD = PD02.

Definition at line 60 of file main.c.

◆ s_bd

ra8_io_blockdev_t s_bd
static

Block-device handle + its OSPI NOR backend state.

Definition at line 67 of file main.c.

◆ s_be

ra8_fs_backend_t s_be
static

ra8_fs backend bridged onto the OSPI block device.

Definition at line 70 of file main.c.

◆ s_params

const ra8_io_roundtrip_params_t s_params
static
Initial value:
= {
.vfs_prefix = "xs",
.fat_type = k_ra8_fs_type_fat12,
.volume_label = "RAIOXS",
.log_tag = s_tag,
.root_file = "",
.root_path = "",
.root_bytes = 0U,
.subdir_path = "xs:/CFG",
.subdir_file = "xs:/CFG/SET.BIN",
.subdir_bytes = (uint32_t)k_demo_payload,
}
@ k_demo_payload
Source bytes (compressible).
Definition main.c:60
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
@ k_ra8_fs_type_fat12
count_of_clusters < 4085.

Shared round-trip parameters for this OSPI-backed FAT12 volume.

Definition at line 79 of file main.c.

◆ s_tag

const char* const s_tag = "ra8_io_xspi_demo"
static

Module log tag.

Definition at line 76 of file main.c.

◆ s_uart

ra8_io_stream_t s_uart
static

UART output stream + its sink state.

Definition at line 72 of file main.c.

◆ s_ust

Definition at line 73 of file main.c.

◆ s_xstate

Definition at line 68 of file main.c.

Referenced by demo_run().