|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Format + mount + file-ops HIL demo across every FAT type ra8_fs writes. 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_fs.h"#include "ra8_gpio_constants.h"#include "ra8_isr.h"#include "ra8_log.h"#include "ra8_port_utils.h"#include "ra8_sci_spi.h"#include "ra8_sdmmc_spi.h"#include "ra8_spi.h"#include "ra8_time.h"Go to the source code of this file.
Macros | |
| #define | FS_FMT_PUTS(lit) |
| Emit a NUL-terminated literal (length via strlen at compile sites). | |
Enumerations | |
| enum | fs_fmt_config_t : uint32_t { k_fs_fmt_uart_baud = 115200U , k_fs_fmt_spi_channel = 0U , k_fs_fmt_decimal_base = 10U , k_fs_fmt_payload_bytes = 1300U , k_fs_fmt_prng_seed = 0xA5F00DadUL , k_fs_fmt_prng_mul = 1664525UL , k_fs_fmt_prng_add = 1013904223UL , k_fs_fmt_prng_byte_shift = 16U , k_fs_fmt_byte_mask = 0xFFU } |
| Compile-time settings for the format/mount HIL demo. More... | |
| enum | fs_fmt_type_idx_t : uint8_t { k_fs_fmt_idx_fat12 = 0U , k_fs_fmt_idx_fat16 = 1U , k_fs_fmt_idx_fat32 = 2U , k_fs_fmt_idx_count = 3U } |
| Index into the per-run FAT-type table. More... | |
Functions | |
| static void | fs_fmt_print (const uint8_t *msg, uint32_t len) |
| Write a byte run on the SCI8 console. | |
| static void | fs_fmt_panic_halt (void) |
| Halt forever in WFI – panic stop on irrecoverable failure. | |
| static const uint8_t * | fs_fmt_label (ra8_fs_type_t type, uint32_t *out_len) |
| Return the printable label bytes for a FAT type. | |
| static void | fs_fmt_print_line (ra8_fs_type_t type, const uint8_t *suffix, uint32_t suflen) |
| Print "fsfmt: FS <TYPE><suffix>" for a pass/fail line. | |
| static ra8_err_t | fs_fmt_spi_set_clock (void *ctx, uint32_t hz) |
| static ra8_err_t | fs_fmt_spi_cs (void *ctx, bool asserted) |
| ra8_sdmmc_spi_transport_t::cs over ra8_gpio (CS active-low). | |
| static ra8_err_t | fs_fmt_spi_xfer (void *ctx, const uint8_t *tx, uint8_t *rx, uint32_t len) |
| ra8_sdmmc_spi_transport_t::xfer over ra8_sci_spi_xfer. | |
| static ra8_err_t | fs_fmt_spi_pins_init (void) |
| Route Pmod2 SPI pins and claim CS as a GPIO output (idle high). | |
| static void | fs_fmt_setup_or_halt (uint32_t *out_pclka_hz) |
| Bring up CGC + SysTick + console SCI + SPI + CS GPIO; panic on fail. | |
| static void | fs_fmt_init_card_or_halt (uint32_t *pclka_hz) |
| Init the SD driver, panic-halt with a diagnostic on failure. | |
| static void | fs_fmt_fill_payload (void) |
| Fill the payload buffer with a deterministic LCG byte sequence. | |
| static ra8_err_t | fs_fmt_create_and_verify (ra8_fs_mount_t *mount, const char *path) |
| Create + write the payload, read it back, and byte-compare. | |
| static ra8_err_t | fs_fmt_rename_and_verify (ra8_fs_mount_t *mount, const char *from, const char *to) |
Rename from to to and confirm the new name reads back intact. | |
| static ra8_err_t | fs_fmt_write_cycle (ra8_fs_mount_t *mount, ra8_fs_type_t type) |
| Run the create -> write -> read-back -> rename -> unlink cycle on a mounted volume, printing the specific FAIL line on the failing step. | |
| static ra8_err_t | fs_fmt_run_one_type (ra8_fs_type_t type) |
Format the card as type, mount, run the full file cycle, unmount. | |
| static void | fs_fmt_count_cb (const char *name, uint8_t attr, uint64_t size, void *ctx) |
| ra8_fs_listdir callback: tally visible entries for the exFAT trial. | |
| static ra8_err_t | fs_fmt_assert_empty_root (ra8_fs_mount_t *mount, ra8_fs_type_t type) |
| Assert a mounted volume's root directory lists exactly zero files. | |
| static ra8_err_t | fs_fmt_run_exfat (void) |
| Format the card as exFAT, mount, and run the full file-mutation cycle. | |
| void | main (void) |
| App entry: bring up the bus + card, then format/mount/file-cycle each FAT type and print the overall PASS banner. | |
Variables | |
| static const ra8_port_pin_t | k_fs_fmt_pin_sck = (ra8_port_pin_t)k_ra8_board_pmod2_spi_sck |
| Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO. | |
| static const ra8_port_pin_t | k_fs_fmt_pin_cipo = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cipo |
| static const ra8_port_pin_t | k_fs_fmt_pin_copi = (ra8_port_pin_t)k_ra8_board_pmod2_spi_copi |
| static const ra8_port_pin_t | k_fs_fmt_pin_cs = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cs |
| static const uint8_t | k_msg_boot [] = "fsfmt: boot\r\n" |
| static const uint8_t | k_msg_card_ok [] = "fsfmt: card ready\r\n" |
| static const uint8_t | k_msg_init_fail [] = "fsfmt: FAIL init\r\n" |
| static const uint8_t | k_msg_eol [] = "\r\n" |
| static const uint8_t | k_msg_fat12 [] = "FAT12" |
| static const uint8_t | k_msg_fat16 [] = "FAT16" |
| static const uint8_t | k_msg_fat32 [] = "FAT32" |
| static const uint8_t | k_msg_exfat [] = "EXFAT" |
| static const uint8_t | k_msg_pass_pre [] = "fsfmt: FS " |
| static const uint8_t | k_msg_pass_suf [] = " FORMAT+MOUNT PASS\r\n" |
| static const uint8_t | k_msg_all_pass [] = "fsfmt: FS FORMAT+MOUNT ALL PASS\r\n" |
| static const uint8_t | k_msg_fail_fmt [] = " FAIL format\r\n" |
| static const uint8_t | k_msg_fail_mount [] = " FAIL mount\r\n" |
| static const uint8_t | k_msg_fail_type [] = " FAIL type-mismatch\r\n" |
| static const uint8_t | k_msg_fail_write [] = " FAIL write\r\n" |
| static const uint8_t | k_msg_fail_rename [] = " FAIL rename\r\n" |
| static const uint8_t | k_msg_fail_unlink [] = " FAIL unlink\r\n" |
| static const uint8_t | k_msg_skip_size [] = " SKIP: capacity out of range for this type\r\n" |
| static const char | k_name_a [] = "FMTTEST.BIN" |
| Test file names (8.3, root level). | |
| static const char | k_name_b [] = "FMTDONE.BIN" |
| static uint8_t | s_payload [k_fs_fmt_payload_bytes] |
| Static payload + read-back buffers (no heap; NASA Rule 3). | |
| static uint8_t | s_readback [k_fs_fmt_payload_bytes] |
| static uint32_t | s_exfat_listed = 0U |
| Root-directory entry tally for the exFAT trial. | |
Format + mount + file-ops HIL demo across every FAT type ra8_fs writes.
Standalone EVM-tier app that exercises the new ra8_fs_format() mkfs path end to end on real removable storage. It drives a microSD card over the ra8_sdmmc_spi SPI-mode driver (the same Pmod2 / SCI0 Simple-SPI transport adapter as tz_secure_only_sd) and, for each FAT variant ra8_fs can write:
it runs this cycle on the card:
It then runs the identical cycle on an exFAT volume: format + mount + assert type + confirm an empty root, then create + write + read-back + rename + unlink, and re-confirm an empty root afterwards.
On a clean pass for a type it prints ... FS <TYPE> FORMAT+MOUNT PASS; after all of them it prints FS FORMAT+MOUNT ALL PASS. The HIL runner (and the ra8_emulator smoke gate) scrape for that banner. Any failure prints a FAIL ... diagnostic and parks the CPU.
The flow re-formats the card several times, so the card's initial contents are irrelevant – on the bench insert any microSD; under ra8_emulator attach a blank card with --sd-new <MiB> (e.g. --sd-new 64:fat32). A 64 MiB card is large enough that the auto cluster-size sweep lands every type in its valid band.
Required external hardware (on-bench): Digilent PMOD MicroSD (part 410-380) in Pmod2 (J25) with any microSD card inserted. THIS APP ERASES THE CARD.
Definition in file main.c.
| #define FS_FMT_PUTS | ( | lit | ) |
Emit a NUL-terminated literal (length via strlen at compile sites).
Definition at line 163 of file main.c.
Referenced by fs_fmt_init_card_or_halt(), and main().
| enum fs_fmt_config_t : uint32_t |
Compile-time settings for the format/mount HIL demo.
| enum fs_fmt_type_idx_t : uint8_t |
|
staticnodiscard |
Assert a mounted volume's root directory lists exactly zero files.
Re-zeroes s_exfat_listed, walks the root via ra8_fs_listdir, and fails if the walk errors or any user-visible entry surfaces. Used by the exFAT trial both right after format (the bitmap / up-case / volume-label system entries must stay hidden) and again after the create/rename/unlink cycle (proving the unlink fully reclaimed the directory set, not merely returned success).
| [in] | mount | Mounted, type-validated volume. |
| [in] | type | Filesystem type, for the per-step diagnostic line. |
| k_ra8_ok | Root listed zero entries. |
| k_ra8_err_validation_failed | Root was non-empty. |
| k_ra8_err_* | ra8_fs_listdir failed (its code). |
mount is mounted. Definition at line 606 of file main.c.
References fs_fmt_count_cb(), fs_fmt_print_line(), k_msg_fail_mount, k_ra8_err_validation_failed, k_ra8_ok, ra8_fs_listdir(), and s_exfat_listed.
Referenced by fs_fmt_run_exfat().
|
static |
ra8_fs_listdir callback: tally visible entries for the exFAT trial.
Definition at line 576 of file main.c.
References s_exfat_listed.
Referenced by fs_fmt_assert_empty_root().
|
staticnodiscard |
Create + write the payload, read it back, and byte-compare.
| [in] | mount | Mounted volume. |
| [in] | path | File name to create. |
| k_ra8_ok | Round-trip verified. |
| k_ra8_err_validation_failed | Length or content mismatch on read-back. |
| k_ra8_err_* | ra8_fs create/read failure. |
mount is mounted; s_payload is filled. path does not already exist. path holds s_payload. Definition at line 399 of file main.c.
References k_fs_fmt_payload_bytes, k_ra8_err_validation_failed, k_ra8_fs_mode_read, k_ra8_ok, memcmp(), memset(), ra8_fs_close(), ra8_fs_open(), ra8_fs_read(), ra8_fs_write_file(), s_payload, and s_readback.
Referenced by fs_fmt_write_cycle().
|
static |
Fill the payload buffer with a deterministic LCG byte sequence.
Definition at line 375 of file main.c.
References k_fs_fmt_byte_mask, k_fs_fmt_payload_bytes, k_fs_fmt_prng_add, k_fs_fmt_prng_byte_shift, k_fs_fmt_prng_mul, k_fs_fmt_prng_seed, and s_payload.
Referenced by main().
|
static |
Init the SD driver, panic-halt with a diagnostic on failure.
| [in] | pclka_hz | Cached PCLKA (Hz) bound into the transport ctx. |
Definition at line 344 of file main.c.
References fs_fmt_panic_halt(), FS_FMT_PUTS, fs_fmt_spi_cs(), fs_fmt_spi_set_clock(), fs_fmt_spi_xfer(), k_msg_card_ok, k_msg_init_fail, k_ra8_ok, and ra8_sdmmc_spi_init().
Referenced by main().
|
static |
Return the printable label bytes for a FAT type.
| [in] | type | FAT variant under test. |
| [out] | out_len | Receives the label length. |
| k_msg_fat12 | / _fat16 / _fat32 per type. |
out_len is non-NULL. type is FAT12/FAT16/FAT32. Definition at line 194 of file main.c.
References k_msg_exfat, k_msg_fat12, k_msg_fat16, k_msg_fat32, k_ra8_fs_type_exfat, k_ra8_fs_type_fat12, and k_ra8_fs_type_fat16.
Referenced by fs_fmt_print_line().
|
static |
Halt forever in WFI – panic stop on irrecoverable failure.
Definition at line 172 of file main.c.
Referenced by fs_fmt_init_card_or_halt(), fs_fmt_setup_or_halt(), and main().
|
static |
Write a byte run on the SCI8 console.
| [in] | msg | Bytes to emit. |
| [in] | len | Byte count. |
Definition at line 157 of file main.c.
References ra8_board_uart_console_write().
Referenced by fs_fmt_print_line(), and main().
|
static |
Print "fsfmt: FS <TYPE><suffix>" for a pass/fail line.
| [in] | type | FAT variant the line is about. |
| [in] | suffix | NUL-trimmed suffix bytes (e.g. " FAIL mount\r\n"). |
| [in] | suflen | Suffix length. |
suffix is non-NULL. Definition at line 224 of file main.c.
References fs_fmt_label(), fs_fmt_print(), and k_msg_pass_pre.
Referenced by fs_fmt_assert_empty_root(), fs_fmt_run_exfat(), fs_fmt_run_one_type(), fs_fmt_write_cycle(), and main().
|
staticnodiscard |
Rename from to to and confirm the new name reads back intact.
| [in] | mount | Mounted volume. |
| [in] | from | Existing file name. |
| [in] | to | Replacement name (must not exist). |
| k_ra8_ok | Renamed; old gone, new reads back. |
| k_ra8_err_invalid_state | Old name still resolves after rename. |
| k_ra8_err_* | ra8_fs rename/read failure. |
from exists and holds s_payload. to holds the data and from is gone. Definition at line 442 of file main.c.
References k_fs_fmt_payload_bytes, k_ra8_err_invalid_state, k_ra8_err_validation_failed, k_ra8_fs_mode_read, k_ra8_ok, memcmp(), memset(), ra8_fs_close(), ra8_fs_open(), ra8_fs_read(), ra8_fs_rename(), s_payload, and s_readback.
Referenced by fs_fmt_write_cycle().
|
staticnodiscard |
Format the card as exFAT, mount, and run the full file-mutation cycle.
Mirrors fs_fmt_run_one_type for exFAT now that ra8_fs writes the format: it formats the volume, mounts it, asserts the detected type is exFAT, confirms a freshly-formatted root lists zero files (the allocation bitmap / up-case / volume-label system entries must stay hidden), runs the shared create -> write -> read-back -> rename -> unlink cycle, then re-asserts an empty root to prove the unlink fully reclaimed the directory set. The image the formatter writes is independently fsck.exfat-clean.
| k_ra8_ok | Format + mount + full file cycle all passed. |
| k_ra8_err_invalid_size | Card capacity cannot hold an exFAT volume (SKIP). |
| k_ra8_err_* | The first failing step's code. |
Definition at line 638 of file main.c.
References fs_fmt_assert_empty_root(), fs_fmt_print_line(), fs_fmt_write_cycle(), k_msg_fail_fmt, k_msg_fail_mount, k_msg_fail_type, k_msg_pass_suf, k_ra8_err_hw_error, k_ra8_err_invalid_size, k_ra8_err_validation_failed, k_ra8_fs_type_exfat, k_ra8_ok, ra8_fs_format_opts_t::label, ra8_fs_format(), ra8_fs_mount(), ra8_fs_unmount(), ra8_sdmmc_spi_bind_fs_backend(), ra8_fs_format_opts_t::type, and ra8_fs_mount_t::type.
Referenced by main().
|
staticnodiscard |
Format the card as type, mount, run the full file cycle, unmount.
Emits a per-step FAIL ... diagnostic and returns the failing code on any error, or prints the FS <TYPE> FORMAT+MOUNT PASS line and returns k_ra8_ok on success.
| [in] | type | FAT variant to format + exercise. |
| k_ra8_ok | The whole cycle passed for type. |
| k_ra8_err_* | The first failing step's code. |
type with the test file removed. Definition at line 527 of file main.c.
References fs_fmt_print_line(), fs_fmt_write_cycle(), k_msg_fail_fmt, k_msg_fail_mount, k_msg_fail_type, k_msg_pass_suf, k_ra8_err_hw_error, k_ra8_err_invalid_size, k_ra8_err_validation_failed, k_ra8_ok, ra8_fs_format_opts_t::label, ra8_fs_format(), ra8_fs_mount(), ra8_fs_unmount(), ra8_sdmmc_spi_bind_fs_backend(), ra8_fs_format_opts_t::type, and ra8_fs_mount_t::type.
Referenced by main().
|
static |
Bring up CGC + SysTick + console SCI + SPI + CS GPIO; panic on fail.
| [out] | out_pclka_hz | Cached PCLKA rate (Hz) for the SPI clock shim. |
Definition at line 301 of file main.c.
References fs_fmt_panic_halt(), fs_fmt_spi_pins_init(), k_fs_fmt_spi_channel, k_fs_fmt_uart_baud, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_ra8_sdmmc_spi_clock_init_hz, k_ra8_spi_mode_0, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_sci_spi_init(), and ra8_time_init().
Referenced by main().
|
static |
ra8_sdmmc_spi_transport_t::cs over ra8_gpio (CS active-low).
Definition at line 246 of file main.c.
References k_fs_fmt_pin_cs, k_ra8_level_high, k_ra8_level_low, and ra8_gpio_write().
Referenced by fs_fmt_init_card_or_halt().
|
staticnodiscard |
Route Pmod2 SPI pins and claim CS as a GPIO output (idle high).
| k_ra8_ok | SPI pins routed, CS driven high. |
| k_ra8_err_* | Routing failure. |
Definition at line 274 of file main.c.
References k_fs_fmt_pin_cipo, k_fs_fmt_pin_copi, k_fs_fmt_pin_cs, k_fs_fmt_pin_sck, k_ra8_level_high, k_ra8_ok, k_ra8_psel_sci_async, ra8_gpio_output_init(), and ra8_pfs_route_peripheral().
Referenced by fs_fmt_setup_or_halt().
|
static |
Definition at line 239 of file main.c.
References k_fs_fmt_spi_channel, and ra8_sci_spi_set_clock().
Referenced by fs_fmt_init_card_or_halt().
|
static |
ra8_sdmmc_spi_transport_t::xfer over ra8_sci_spi_xfer.
Definition at line 253 of file main.c.
References k_fs_fmt_spi_channel, and ra8_sci_spi_xfer().
Referenced by fs_fmt_init_card_or_halt().
|
staticnodiscard |
Run the create -> write -> read-back -> rename -> unlink cycle on a mounted volume, printing the specific FAIL line on the failing step.
Shared by fs_fmt_run_one_type (FAT12/16/32) and fs_fmt_run_exfat so every writable filesystem proves the identical mutation path. The caller owns the mount and unmounts after this returns.
| [in] | mount | Mounted, type-validated volume. |
| [in] | type | Filesystem type, for the per-step diagnostic line. |
| k_ra8_ok | create + rename + unlink all verified. |
| k_ra8_err_* | The first failing step's code (its FAIL line is printed). |
mount no longer holds the test file. Definition at line 491 of file main.c.
References fs_fmt_create_and_verify(), fs_fmt_print_line(), fs_fmt_rename_and_verify(), k_msg_fail_rename, k_msg_fail_unlink, k_msg_fail_write, k_name_a, k_name_b, k_ra8_ok, and ra8_fs_unlink().
Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().
| void main | ( | void | ) |
App entry: bring up the bus + card, then format/mount/file-cycle each FAT type and print the overall PASS banner.
The application entry point Reset_Handler hands control to.
Definition at line 703 of file main.c.
References fs_fmt_fill_payload(), fs_fmt_init_card_or_halt(), fs_fmt_panic_halt(), fs_fmt_print(), fs_fmt_print_line(), FS_FMT_PUTS, fs_fmt_run_exfat(), fs_fmt_run_one_type(), fs_fmt_setup_or_halt(), k_fs_fmt_idx_count, k_msg_all_pass, k_msg_boot, k_msg_eol, k_msg_skip_size, k_ra8_err_invalid_size, k_ra8_fs_type_exfat, k_ra8_fs_type_fat12, k_ra8_fs_type_fat16, k_ra8_fs_type_fat32, k_ra8_ok, ra8_isr_globals_enable(), and ra8_log_init().
|
static |
Definition at line 105 of file main.c.
Referenced by fs_fmt_spi_pins_init().
|
static |
Definition at line 106 of file main.c.
Referenced by fs_fmt_spi_pins_init().
|
static |
Definition at line 107 of file main.c.
Referenced by fs_fmt_spi_cs(), and fs_fmt_spi_pins_init().
|
static |
Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO.
Definition at line 104 of file main.c.
Referenced by fs_fmt_spi_pins_init().
|
static |
|
static |
|
static |
Definition at line 122 of file main.c.
Referenced by fs_fmt_label().
|
static |
Definition at line 127 of file main.c.
Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().
|
static |
Definition at line 128 of file main.c.
Referenced by fs_fmt_assert_empty_root(), fs_fmt_run_exfat(), and fs_fmt_run_one_type().
|
static |
Definition at line 131 of file main.c.
Referenced by fs_fmt_write_cycle().
|
static |
Definition at line 129 of file main.c.
Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().
|
static |
Definition at line 132 of file main.c.
Referenced by fs_fmt_write_cycle().
|
static |
Definition at line 130 of file main.c.
Referenced by fs_fmt_write_cycle().
|
static |
Definition at line 119 of file main.c.
Referenced by fs_fmt_label().
|
static |
Definition at line 120 of file main.c.
Referenced by fs_fmt_label().
|
static |
Definition at line 121 of file main.c.
Referenced by fs_fmt_label().
|
static |
|
static |
Definition at line 124 of file main.c.
Referenced by fs_fmt_print_line().
|
static |
Definition at line 125 of file main.c.
Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().
|
static |
|
static |
Test file names (8.3, root level).
Definition at line 139 of file main.c.
Referenced by fs_fmt_write_cycle().
|
static |
Definition at line 140 of file main.c.
Referenced by fs_fmt_write_cycle().
|
static |
Root-directory entry tally for the exFAT trial.
Definition at line 573 of file main.c.
Referenced by fs_fmt_assert_empty_root(), and fs_fmt_count_cb().
|
static |
|
static |