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

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"
Include dependency graph for main.c:

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.

Detailed Description

Format + mount + file-ops HIL demo across every FAT type ra8_fs writes.

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

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:

  • FAT12, FAT16, FAT32,

it runs this cycle on the card:

  1. ra8_fs_format the volume as the target type (auto cluster size);
  2. ra8_fs_mount it and assert the detected ra8_fs_type matches;
  3. create + write a known payload to a test file;
  4. read it back and byte-compare;
  5. rename the file and confirm the new name reads back intact and the old name is gone;
  6. unlink the file and confirm listdir no longer shows it;
  7. unmount.

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.

Since
0.1.0

Definition in file main.c.

Macro Definition Documentation

◆ FS_FMT_PUTS

#define FS_FMT_PUTS ( lit)
Value:
fs_fmt_print((lit), (uint32_t)sizeof(lit) - 1U)
static void fs_fmt_print(const uint8_t *msg, uint32_t len)
Write a byte run on the SCI8 console.
Definition main.c:157

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().

Enumeration Type Documentation

◆ fs_fmt_config_t

enum fs_fmt_config_t : uint32_t

Compile-time settings for the format/mount HIL demo.

Enumerator
k_fs_fmt_uart_baud 

J-Link OB CDC console baud.

k_fs_fmt_spi_channel 

Pmod2 / J25 SCI0 Simple-SPI.

k_fs_fmt_decimal_base 

Radix for integer-to-ASCII.

k_fs_fmt_payload_bytes 

Multi-cluster test payload (> 1 KiB).

k_fs_fmt_prng_seed 

Deterministic payload seed.

k_fs_fmt_prng_mul 

Numerical Recipes LCG multiplier.

k_fs_fmt_prng_add 

Numerical Recipes LCG increment.

k_fs_fmt_prng_byte_shift 

Bit shift selecting the PRNG byte.

k_fs_fmt_byte_mask 

Low-byte mask.

Definition at line 75 of file main.c.

◆ fs_fmt_type_idx_t

enum fs_fmt_type_idx_t : uint8_t

Index into the per-run FAT-type table.

Enumerator
k_fs_fmt_idx_fat12 

FAT12 trial slot.

k_fs_fmt_idx_fat16 

FAT16 trial slot.

k_fs_fmt_idx_fat32 

FAT32 trial slot.

k_fs_fmt_idx_count 

Number of trials.

Definition at line 91 of file main.c.

Function Documentation

◆ fs_fmt_assert_empty_root()

ra8_err_t fs_fmt_assert_empty_root ( ra8_fs_mount_t * mount,
ra8_fs_type_t type )
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).

Parameters
[in]mountMounted, type-validated volume.
[in]typeFilesystem type, for the per-step diagnostic line.
Returns
ra8_err_t
Return values
k_ra8_okRoot listed zero entries.
k_ra8_err_validation_failedRoot was non-empty.
k_ra8_err_*ra8_fs_listdir failed (its code).
Precondition
mount is mounted.
Postcondition
s_exfat_listed holds the entry count seen on this call.
Since
0.1.0

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().

◆ fs_fmt_count_cb()

void fs_fmt_count_cb ( const char * name,
uint8_t attr,
uint64_t size,
void * ctx )
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().

◆ fs_fmt_create_and_verify()

ra8_err_t fs_fmt_create_and_verify ( ra8_fs_mount_t * mount,
const char * path )
staticnodiscard

Create + write the payload, read it back, and byte-compare.

Parameters
[in]mountMounted volume.
[in]pathFile name to create.
Returns
ra8_err_t
Return values
k_ra8_okRound-trip verified.
k_ra8_err_validation_failedLength or content mismatch on read-back.
k_ra8_err_*ra8_fs create/read failure.
Precondition
mount is mounted; s_payload is filled.
path does not already exist.
Postcondition
On success path holds s_payload.
Since
0.1.0

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().

◆ fs_fmt_fill_payload()

void fs_fmt_fill_payload ( void )
static

Fill the payload buffer with a deterministic LCG byte sequence.

Precondition
None.
Postcondition
s_payload holds a reproducible byte pattern.
Since
0.1.0

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().

◆ fs_fmt_init_card_or_halt()

void fs_fmt_init_card_or_halt ( uint32_t * pclka_hz)
static

Init the SD driver, panic-halt with a diagnostic on failure.

Parameters
[in]pclka_hzCached PCLKA (Hz) bound into the transport ctx.
Precondition
SCI0 Simple-SPI + CS GPIO are configured.
Postcondition
On success the SD card is in SPI mode at default speed.
Since
0.1.0

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().

◆ fs_fmt_label()

const uint8_t * fs_fmt_label ( ra8_fs_type_t type,
uint32_t * out_len )
static

Return the printable label bytes for a FAT type.

Parameters
[in]typeFAT variant under test.
[out]out_lenReceives the label length.
Returns
Pointer to the (static) label bytes.
Return values
k_msg_fat12/ _fat16 / _fat32 per type.
Precondition
out_len is non-NULL.
type is FAT12/FAT16/FAT32.
Postcondition
*out_len holds the label length.
No state modified beyond *out_len.
Since
0.1.0

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().

◆ fs_fmt_panic_halt()

void fs_fmt_panic_halt ( void )
static

Halt forever in WFI – panic stop on irrecoverable failure.

Precondition
Called only after a fatal error has been reported.
Postcondition
CPU is parked.
Since
0.1.0

Definition at line 172 of file main.c.

Referenced by fs_fmt_init_card_or_halt(), fs_fmt_setup_or_halt(), and main().

◆ fs_fmt_print()

void fs_fmt_print ( const uint8_t * msg,
uint32_t len )
static

Write a byte run on the SCI8 console.

Parameters
[in]msgBytes to emit.
[in]lenByte count.
Precondition
The BSP console is initialised.
Postcondition
The bytes are queued to the console.
Since
0.1.0

Definition at line 157 of file main.c.

References ra8_board_uart_console_write().

Referenced by fs_fmt_print_line(), and main().

◆ fs_fmt_print_line()

void fs_fmt_print_line ( ra8_fs_type_t type,
const uint8_t * suffix,
uint32_t suflen )
static

Print "fsfmt: FS <TYPE><suffix>" for a pass/fail line.

Parameters
[in]typeFAT variant the line is about.
[in]suffixNUL-trimmed suffix bytes (e.g. " FAIL mount\r\n").
[in]suflenSuffix length.
Precondition
SCI8 is initialised.
suffix is non-NULL.
Postcondition
The composed line is queued to the console.
Since
0.1.0

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().

◆ fs_fmt_rename_and_verify()

ra8_err_t fs_fmt_rename_and_verify ( ra8_fs_mount_t * mount,
const char * from,
const char * to )
staticnodiscard

Rename from to to and confirm the new name reads back intact.

Parameters
[in]mountMounted volume.
[in]fromExisting file name.
[in]toReplacement name (must not exist).
Returns
ra8_err_t
Return values
k_ra8_okRenamed; old gone, new reads back.
k_ra8_err_invalid_stateOld name still resolves after rename.
k_ra8_err_*ra8_fs rename/read failure.
Precondition
from exists and holds s_payload.
Postcondition
On success to holds the data and from is gone.
Since
0.1.0

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().

◆ fs_fmt_run_exfat()

ra8_err_t fs_fmt_run_exfat ( void )
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.

Returns
ra8_err_t
Return values
k_ra8_okFormat + mount + full file cycle all passed.
k_ra8_err_invalid_sizeCard capacity cannot hold an exFAT volume (SKIP).
k_ra8_err_*The first failing step's code.
Precondition
The SD card is initialised and s_payload is filled.
Postcondition
The card is left formatted as exFAT with the test file removed.
Since
0.1.0

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().

◆ fs_fmt_run_one_type()

ra8_err_t fs_fmt_run_one_type ( ra8_fs_type_t type)
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.

Parameters
[in]typeFAT variant to format + exercise.
Returns
ra8_err_t
Return values
k_ra8_okThe whole cycle passed for type.
k_ra8_err_*The first failing step's code.
Precondition
The SD card is initialised and s_payload is filled.
Postcondition
The card is left formatted as type with the test file removed.
Since
0.1.0

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().

◆ fs_fmt_setup_or_halt()

void fs_fmt_setup_or_halt ( uint32_t * out_pclka_hz)
static

Bring up CGC + SysTick + console SCI + SPI + CS GPIO; panic on fail.

Parameters
[out]out_pclka_hzCached PCLKA rate (Hz) for the SPI clock shim.
Precondition
Reset_Handler initialised .data/.bss.
Postcondition
On success the console prints and SCI0 Simple-SPI is configured at the SD init clock, CS deasserted.
Since
0.1.0

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().

◆ fs_fmt_spi_cs()

ra8_err_t fs_fmt_spi_cs ( void * ctx,
bool asserted )
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().

◆ fs_fmt_spi_pins_init()

ra8_err_t fs_fmt_spi_pins_init ( void )
staticnodiscard

Route Pmod2 SPI pins and claim CS as a GPIO output (idle high).

Returns
ra8_err_t from the routing calls.
Return values
k_ra8_okSPI pins routed, CS driven high.
k_ra8_err_*Routing failure.
Precondition
IOPORT is reachable.
Postcondition
P601/P602/P603 are SCI0 Simple-SPI; P604 is a GPIO output high.
Since
0.1.0

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().

◆ fs_fmt_spi_set_clock()

ra8_err_t fs_fmt_spi_set_clock ( void * ctx,
uint32_t hz )
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().

◆ fs_fmt_spi_xfer()

ra8_err_t fs_fmt_spi_xfer ( void * ctx,
const uint8_t * tx,
uint8_t * rx,
uint32_t len )
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().

◆ fs_fmt_write_cycle()

ra8_err_t fs_fmt_write_cycle ( ra8_fs_mount_t * mount,
ra8_fs_type_t type )
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.

Parameters
[in]mountMounted, type-validated volume.
[in]typeFilesystem type, for the per-step diagnostic line.
Returns
ra8_err_t
Return values
k_ra8_okcreate + rename + unlink all verified.
k_ra8_err_*The first failing step's code (its FAIL line is printed).
Precondition
mount is mounted; s_payload is filled.
k_name_a does not already exist on mount.
Postcondition
On success mount no longer holds the test file.
Since
0.1.0

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().

◆ main()

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.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, FPU, and priority grouping.
Postcondition
On a clean run the CPU loops forever after the ALL PASS banner.
On any failure the function halts in WFI after a FAIL diagnostic.
Since
0.1.0

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().

Variable Documentation

◆ k_fs_fmt_pin_cipo

const ra8_port_pin_t k_fs_fmt_pin_cipo = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cipo
static

Definition at line 105 of file main.c.

Referenced by fs_fmt_spi_pins_init().

◆ k_fs_fmt_pin_copi

const ra8_port_pin_t k_fs_fmt_pin_copi = (ra8_port_pin_t)k_ra8_board_pmod2_spi_copi
static

Definition at line 106 of file main.c.

Referenced by fs_fmt_spi_pins_init().

◆ k_fs_fmt_pin_cs

const ra8_port_pin_t k_fs_fmt_pin_cs = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cs
static

Definition at line 107 of file main.c.

Referenced by fs_fmt_spi_cs(), and fs_fmt_spi_pins_init().

◆ k_fs_fmt_pin_sck

const ra8_port_pin_t k_fs_fmt_pin_sck = (ra8_port_pin_t)k_ra8_board_pmod2_spi_sck
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().

◆ k_msg_all_pass

const uint8_t k_msg_all_pass[] = "fsfmt: FS FORMAT+MOUNT ALL PASS\r\n"
static

Definition at line 126 of file main.c.

Referenced by main().

◆ k_msg_boot

const uint8_t k_msg_boot[] = "fsfmt: boot\r\n"
static

Definition at line 114 of file main.c.

◆ k_msg_card_ok

const uint8_t k_msg_card_ok[] = "fsfmt: card ready\r\n"
static

Definition at line 115 of file main.c.

◆ k_msg_eol

const uint8_t k_msg_eol[] = "\r\n"
static

Definition at line 117 of file main.c.

◆ k_msg_exfat

const uint8_t k_msg_exfat[] = "EXFAT"
static

Definition at line 122 of file main.c.

Referenced by fs_fmt_label().

◆ k_msg_fail_fmt

const uint8_t k_msg_fail_fmt[] = " FAIL format\r\n"
static

Definition at line 127 of file main.c.

Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().

◆ k_msg_fail_mount

const uint8_t k_msg_fail_mount[] = " FAIL mount\r\n"
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().

◆ k_msg_fail_rename

const uint8_t k_msg_fail_rename[] = " FAIL rename\r\n"
static

Definition at line 131 of file main.c.

Referenced by fs_fmt_write_cycle().

◆ k_msg_fail_type

const uint8_t k_msg_fail_type[] = " FAIL type-mismatch\r\n"
static

Definition at line 129 of file main.c.

Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().

◆ k_msg_fail_unlink

const uint8_t k_msg_fail_unlink[] = " FAIL unlink\r\n"
static

Definition at line 132 of file main.c.

Referenced by fs_fmt_write_cycle().

◆ k_msg_fail_write

const uint8_t k_msg_fail_write[] = " FAIL write\r\n"
static

Definition at line 130 of file main.c.

Referenced by fs_fmt_write_cycle().

◆ k_msg_fat12

const uint8_t k_msg_fat12[] = "FAT12"
static

Definition at line 119 of file main.c.

Referenced by fs_fmt_label().

◆ k_msg_fat16

const uint8_t k_msg_fat16[] = "FAT16"
static

Definition at line 120 of file main.c.

Referenced by fs_fmt_label().

◆ k_msg_fat32

const uint8_t k_msg_fat32[] = "FAT32"
static

Definition at line 121 of file main.c.

Referenced by fs_fmt_label().

◆ k_msg_init_fail

const uint8_t k_msg_init_fail[] = "fsfmt: FAIL init\r\n"
static

Definition at line 116 of file main.c.

◆ k_msg_pass_pre

const uint8_t k_msg_pass_pre[] = "fsfmt: FS "
static

Definition at line 124 of file main.c.

Referenced by fs_fmt_print_line().

◆ k_msg_pass_suf

const uint8_t k_msg_pass_suf[] = " FORMAT+MOUNT PASS\r\n"
static

Definition at line 125 of file main.c.

Referenced by fs_fmt_run_exfat(), and fs_fmt_run_one_type().

◆ k_msg_skip_size

const uint8_t k_msg_skip_size[] = " SKIP: capacity out of range for this type\r\n"
static

Definition at line 136 of file main.c.

Referenced by main().

◆ k_name_a

const char k_name_a[] = "FMTTEST.BIN"
static

Test file names (8.3, root level).

Definition at line 139 of file main.c.

Referenced by fs_fmt_write_cycle().

◆ k_name_b

const char k_name_b[] = "FMTDONE.BIN"
static

Definition at line 140 of file main.c.

Referenced by fs_fmt_write_cycle().

◆ s_exfat_listed

uint32_t s_exfat_listed = 0U
static

Root-directory entry tally for the exFAT trial.

Note
File-scope; reset before each ra8_fs_listdir call.
Since
0.1.0

Definition at line 573 of file main.c.

Referenced by fs_fmt_assert_empty_root(), and fs_fmt_count_cb().

◆ s_payload

uint8_t s_payload[k_fs_fmt_payload_bytes]
static

Static payload + read-back buffers (no heap; NASA Rule 3).

Definition at line 365 of file main.c.

◆ s_readback

uint8_t s_readback[k_fs_fmt_payload_bytes]
static

Definition at line 366 of file main.c.