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 on-chip extra-MRAM (data flash) backend (#155/#156). More...

#include <stdint.h>
#include <string.h>
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_board_ek_ra8d2_console_stream.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_flash.h"
#include "ra8_io.h"
#include "ra8_log.h"
#include "ra8_time.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_baud = 115200U ,
  k_demo_mram_base = (uint32_t)k_ra8_flash_extra_start ,
  k_demo_disk_blocks = 24U ,
  k_demo_test_lba = 0U ,
  k_demo_block_count = 1U ,
  k_demo_payload = 512U ,
  k_demo_seed_mul = 5U ,
  k_demo_seed_add = 3U ,
  k_demo_mrcfreq_mhz = 200U ,
  k_demo_mrefreq_mhz = 100U
}
 Console + volume + MRAM knobs (no magic numbers). More...

Functions

static void internal_demo_print (const char *msg)
 Print a NUL-terminated string on the demo's UART stream.
static void internal_demo_setup_or_halt (void)
 Bring up CGC + SysTick + the board console; halt forever on failure.
static ra8_err_t internal_demo_open (void)
 Bring up the MRAM controller and bind the MRAM block device.
static ra8_err_t internal_demo_roundtrip (void)
 Erase a block, program a pattern into it, read it back, and compare.
void main (void)
 Firmware entry point.

Variables

static ra8_io_blockdev_t s_bd
 Block-device handle + its MRAM backend state.
static ra8_io_blockdev_mram_state_t s_mstate
static ra8_io_stream_t s_uart
 Console output stream; the board owns the sink behind it.
static const char *const s_tag = "ra8_io_mram_demo"
 Module log tag.

Detailed Description

ra8_io fabric over on-chip extra-MRAM (data flash) backend (#155/#156).

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

Proves the ra8_io fabric over the RA8D2's on-chip extra MRAM at k_ra8_flash_extra_start (0x02E07600, HUM Ch 59.7.4.5 Table 59.15 p 3592) – programmed through the MACI command sequencer. Same block-device vtable as the other ra8_io demos; only the backend differs (ra8_io_blockdev_mram instead of RAM/SD/OSPI).

Warning
This window is one-time-programmable option-setting / OTP memory, not a rewritable data-flash: the erase + re-program cycle this demo exercises does NOT work on real silicon (there is no erase). ra8_emulator maps the window and so the round-trip passes here, but that is optimistic – a real rewritable-medium home for this demo (OSPI / SD) is tracked by #315.

The demo exercises the backend directly through the ra8_io block-device layer, which is the right level for this special-purpose non-volatile store (the FAT layer is already proven over the RAM / SD / OSPI / SDRAM backends):

  1. ra8_flash_init() brings up the MRAM controller (Phase 1, #156).
  2. ra8_io_blockdev_mram_init() binds a block device over the fenced window.
  3. Erase a 512-byte logical block, program a deterministic pattern into it, read it back, and byte-compare – the full erase + program + read path.
  4. Report on the SCI8 console through a ra8_io UART stream sink; ra8_log is routed into the same stream so any failing step is visible (Phase 2 #157).

ra8_emulator models the MACI program/erase sequence (board_periph_mram.c), so the round-trip runs headless: a successful run prints ra8_io_mram_demo: 512-byte block erase/program/read on extra MRAM PASS.

Definition in file main.c.

Enumeration Type Documentation

◆ demo_const_t

enum demo_const_t : uint32_t

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

Enumerator
k_demo_uart_baud 

Console baud.

k_demo_mram_base 

Extra-MRAM OTP window base.

k_demo_disk_blocks 

12 KiB scratch inside OTP window.

k_demo_test_lba 

Logical block under test.

k_demo_block_count 

Blocks erased/written/read.

k_demo_payload 

One 512-byte block round-tripped.

k_demo_seed_mul 

Test-pattern multiplier.

k_demo_seed_add 

Test-pattern additive bias.

k_demo_mrcfreq_mhz 

Code-MRAM advertised clock (MHz).

k_demo_mrefreq_mhz 

Extra-MRAM advertised clock (MHz).

Definition at line 55 of file main.c.

Function Documentation

◆ internal_demo_open()

ra8_err_t internal_demo_open ( void )
static

Bring up the MRAM controller and bind the MRAM block device.

Initialises the MRAM controller (ra8_flash_init) and binds an erase-before-write block device over the fenced 12 KiB window.

Returns
ra8_err_t Error code.
Return values
k_ra8_okThe MRAM block device s_bd is ready.
(other)The first failing bring-up step's error code.
Precondition
internal_demo_setup_or_halt has run (clocks + console up).
The extra-MRAM region is present and writable.
Postcondition
On success s_bd reads/writes/erases the fenced MRAM window.
On any non-ok return s_bd is left unbound.
Note
Not thread-safe; single-caller boot context.
Since
0.1.0

Definition at line 149 of file main.c.

References k_demo_disk_blocks, k_demo_mram_base, k_demo_mrcfreq_mhz, k_demo_mrefreq_mhz, k_ra8_ok, ra8_flash_init(), RA8_INTERNAL, ra8_io_blockdev_mram_init(), RA8_RETURN_ON_ERROR, s_bd, s_mstate, and s_tag.

Referenced by main().

◆ internal_demo_print()

void internal_demo_print ( const char * msg)
static

Print a NUL-terminated string on the demo's UART stream.

Thin wrapper over ra8_io_stream_puts bound to s_uart.

Parameters
[in]msgNUL-terminated ASCII string (CR/LF supplied by the caller).
Returns
None.
Precondition
s_uart was bound by ra8_board_console_stream.
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 94 of file main.c.

References RA8_INTERNAL, ra8_io_stream_puts(), and s_uart.

◆ internal_demo_roundtrip()

ra8_err_t internal_demo_roundtrip ( void )
static

Erase a block, program a pattern into it, read it back, and compare.

Drives the ra8_io block-device layer directly: erase one 512-byte logical block to 0xFF, program a deterministic pattern, read it back, and verify byte-for-byte – the full MRAM erase + program + read path.

Returns
ra8_err_t Error code.
Return values
k_ra8_okThe block round-tripped intact.
k_ra8_err_checksum_mismatchThe read-back bytes differed.
(other)The first failing block-device call's code.
Precondition
internal_demo_open returned k_ra8_ok; s_bd is bound.
k_demo_test_lba + k_demo_block_count is within the window.
Postcondition
On success block k_demo_test_lba holds the verified pattern.
No resource is leaked on any return path.
Note
Not thread-safe; single-caller boot context.
Since
0.1.0

Definition at line 187 of file main.c.

References k_demo_block_count, k_demo_payload, k_demo_seed_add, k_demo_seed_mul, k_demo_test_lba, k_ra8_err_checksum_mismatch, k_ra8_ok, memcmp(), RA8_INTERNAL, ra8_io_blockdev_erase(), ra8_io_blockdev_read(), ra8_io_blockdev_write(), RA8_RETURN_ON_ERROR, s_bd, and s_tag.

Referenced by internal_demo_run(), and main().

◆ internal_demo_setup_or_halt()

void internal_demo_setup_or_halt ( void )
static

Bring up CGC + SysTick + the board console; halt forever on failure.

Initialises clocks, reads the CPU rate, starts the time base, and hands the console over to the BSP – which owns the channel, the PD02 / PD03 routing and the live-PCLKA bit-rate solve – then binds it as an ra8_io stream.

Returns
None.
Precondition
SystemInit configured VTOR / FPU / priority grouping.
Runs single-threaded during early boot.
Postcondition
On success the console is open at k_demo_uart_baud, bound into s_uart, 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 118 of file main.c.

References k_demo_uart_baud, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_console_stream(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_time_init(), and s_uart.

◆ main()

void main ( void )

Firmware entry point.

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.

Precondition
SystemInit configured VTOR / FPU / priority grouping.
The extra-MRAM region 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 226 of file main.c.

References internal_demo_open(), internal_demo_print(), internal_demo_roundtrip(), internal_demo_setup_or_halt(), k_ra8_ok, ra8_board_uart_console_flush(), ra8_io_log_attach(), ra8_log_init(), and s_uart.

Variable Documentation

◆ s_bd

ra8_io_blockdev_t s_bd
static

Block-device handle + its MRAM backend state.

Definition at line 69 of file main.c.

◆ s_mstate

Definition at line 70 of file main.c.

◆ s_tag

const char* const s_tag = "ra8_io_mram_demo"
static

Module log tag.

Definition at line 75 of file main.c.

◆ s_uart

ra8_io_stream_t s_uart
static

Console output stream; the board owns the sink behind it.

Definition at line 72 of file main.c.