ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
38
39#include <stdint.h>
40#include <string.h>
41
42#include "ra8_attributes.h"
43#include "ra8_board_ek_ra8d2.h"
45#include "ra8_boot_entry.h"
46#include "ra8_cgc.h"
47#include "ra8_check.h"
48#include "ra8_err.h"
49#include "ra8_flash.h"
50#include "ra8_io.h"
51#include "ra8_log.h"
52#include "ra8_time.h"
53
67
73
75static const char* const s_tag = "ra8_io_mram_demo";
76
94RA8_INTERNAL static void internal_demo_print(const char* msg)
95{
96 (void)ra8_io_stream_puts(&s_uart, msg);
97}
98
119{
120 uint32_t cpuclk0_hz = 0U;
121 if ((ra8_cgc_init() != k_ra8_ok) ||
123 (ra8_time_init(cpuclk0_hz) != k_ra8_ok) ||
126 while (true) {
127 }
128 }
129}
130
150{
151 const ra8_flash_cfg_t fcfg = {.mrcfreq_mhz = (uint16_t)k_demo_mrcfreq_mhz,
152 .mrefreq_mhz = (uint8_t)k_demo_mrefreq_mhz,
153 .prefetch_en = true,
154 .ecc_encoder_enable = true,
155 .ecc_decoder_enable = true};
156 RA8_RETURN_ON_ERROR(ra8_flash_init(&fcfg), s_tag, "flash init");
158 &s_mstate,
159 (uintptr_t)k_demo_mram_base,
160 (uint32_t)k_demo_disk_blocks,
161 false),
162 s_tag,
163 "mram blockdev init");
164 return k_ra8_ok;
165}
166
188{
189 uint8_t data[(size_t)k_demo_payload];
190 for (uint32_t i = 0; i < (uint32_t)k_demo_payload; ++i) {
191 data[i] = (uint8_t)((i * (uint32_t)k_demo_seed_mul) + (uint32_t)k_demo_seed_add);
192 }
195 s_tag,
196 "erase");
198 ra8_io_blockdev_write(&s_bd, (uint32_t)k_demo_test_lba, (uint32_t)k_demo_block_count, data),
199 s_tag,
200 "write");
201 uint8_t got[(size_t)k_demo_payload] = {};
203 ra8_io_blockdev_read(&s_bd, (uint32_t)k_demo_test_lba, (uint32_t)k_demo_block_count, got),
204 s_tag,
205 "read");
206 if (memcmp(got, data, sizeof(data)) != 0) {
208 }
209 return k_ra8_ok;
210}
211
226void main(void)
227{
228 ra8_log_init();
230 (void)ra8_io_log_attach(&s_uart); /* route ra8_log into the console stream too */
231 internal_demo_print("ra8_io_mram_demo: boot\r\n");
232
234 if (e == k_ra8_ok) {
236 }
237 if (e == k_ra8_ok) {
239 "ra8_io_mram_demo: 512-byte block erase/program/read on extra MRAM PASS\r\n");
240 } else {
241 internal_demo_print("ra8_io_mram_demo: FAIL\r\n");
242 }
244 while (true) {
245 }
246}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void internal_demo_print(const char *s)
Convenience wrapper to write a NUL-terminated string to SCI8.
Definition main.c:326
static void internal_demo_setup_or_halt(void)
Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up.
Definition main.c:285
demo_const_t
Console + volume + payload knobs (no magic numbers).
Definition main.c:56
@ k_demo_payload
Source bytes (compressible).
Definition main.c:60
@ k_demo_disk_blocks
256 KiB per volume (FAT12).
Definition main.c:59
@ k_demo_uart_baud
Console baud.
Definition main.c:58
@ k_demo_seed_mul
Test-pattern multiplier.
Definition main.c:63
static ra8_io_stream_t s_uart
UART output stream + its sink state.
Definition main.c:88
static ra8_io_blockdev_t s_bd
Block-device handle + its RAM backend state.
Definition main.c:52
static ra8_io_blockdev_mram_state_t s_mstate
Definition main.c:97
@ k_demo_mram_base
Extra-MRAM OTP window base (0x02E07600).
Definition main.c:65
@ k_demo_mrefreq_mhz
Extra-MRAM advertised clock (MHz).
Definition main.c:82
@ k_demo_mrcfreq_mhz
Code-MRAM advertised clock (MHz).
Definition main.c:81
static ra8_err_t internal_demo_open(void)
Bring up the MRAM controller and bind the MRAM block device.
Definition main.c:149
@ k_demo_seed_add
Test-pattern additive bias.
Definition main.c:63
@ k_demo_block_count
Blocks erased/written/read.
Definition main.c:60
@ k_demo_test_lba
Logical block under test.
Definition main.c:59
static ra8_err_t internal_demo_roundtrip(void)
Erase a block, program a pattern into it, read it back, and compare.
Definition main.c:187
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
EK-RA8D2 debug console as an ra8_io_stream byte sink.
ra8_err_t ra8_board_console_stream(ra8_io_stream_t *out)
Bind the J-Link OB VCOM console into a caller-owned stream handle.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
ra8_err_t ra8_board_uart_console_flush(void)
Block until every byte queued on the J-Link OB VCOM console has finished clocking out on the wire.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Definition ra8_check.h:184
Error Code Definitions for ra8-firmware.
@ k_ra8_err_checksum_mismatch
Stored / transmitted checksum does not match computed value.
Definition ra8_err.h:465
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Code MRAM + Extra MRAM + Option-Setting driver – DANGEROUS, brick-capable.
ra8_err_t ra8_flash_init(const ra8_flash_cfg_t *cfg)
Initialise the MRAM controller for safe read access.
Definition ra8_flash.c:386
@ k_ra8_flash_extra_start
First legal Program target (FSBL setting).
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
ra8_io – unified peripheral-agnostic I/O fabric (umbrella header).
ra8_err_t ra8_io_blockdev_read(const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count, uint8_t *buf)
Read count logical blocks starting at lba into buf.
ra8_err_t ra8_io_blockdev_write(const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count, const uint8_t *buf)
Write count logical blocks from buf starting at lba.
ra8_err_t ra8_io_blockdev_erase(const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count)
Erase count blocks starting at lba to the medium's erase value.
ra8_err_t ra8_io_blockdev_mram_init(ra8_io_blockdev_t *bd, ra8_io_blockdev_mram_state_t *state, uintptr_t base_addr, uint32_t block_count, bool read_only)
Bind a hard-fenced MRAM block-device backend into a caller handle.
ra8_err_t ra8_io_log_attach(ra8_io_stream_t *s)
Route ra8_log output to a bound ra8_io stream.
Definition ra8_io_log.c:61
ra8_err_t ra8_io_stream_puts(ra8_io_stream_t *s, const char *str)
Write a NUL-terminated string (without the NUL) to the bound sink.
Lightweight Logging Interface for ra8-firmware.
void ra8_log_init(void)
Initialise the logging backend.
Definition ra8_log.c:379
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
Initialisation descriptor for ra8_flash_init.
Caller-owned private state for an MRAM block device.
Caller-allocated block-device handle binding a backend to its context.
Caller-allocated byte-stream handle binding a sink to its context.