|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Prove the ra8_io fabric's swappable backend (#155/#156) over a microSD. More...
#include <stdint.h>#include "ra8_attributes.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_isr.h"#include "ra8_log.h"#include "ra8_port_utils.h"#include "ra8_sdmmc_spi.h"#include "ra8_time.h"Go to the source code of this file.
Macros | |
| #define | SD_DEMO_PUTS(lit) |
| Emit a NUL-terminated literal (length via sizeof at the call site). | |
Enumerations | |
| enum | sd_demo_config_t : uint32_t { k_sd_demo_uart_baud = 115200U , k_sd_demo_spi_channel = 0U , k_sd_demo_payload_bytes = 512U } |
| Compile-time settings for the ra8_io SD-backend demo. More... | |
Functions | |
| static void | internal_sd_demo_print (const uint8_t *msg, uint32_t len) |
| Write a byte run on the SCI8 console. | |
| static void | internal_sd_demo_panic_halt (void) |
| Halt forever in WFI – panic stop on irrecoverable failure. | |
| static void | internal_sd_demo_setup_or_halt (uint32_t *out_pclka_hz) |
| Bring up CGC + SysTick + console SCI; panic on fail. | |
| static void | internal_sd_demo_init_card_or_halt (uint32_t pclka_hz) |
| Build the SCI-SPI transport, init the SD driver, panic-halt on failure. | |
| static ra8_err_t | internal_sd_demo_roundtrip (void) |
| Bind the SD-SPI block device and run the shared ra8_io round-trip. | |
| void | main (void) |
| App entry: bring up the bus + card, run the ra8_io round-trip, print PASS. | |
Variables | |
| static const ra8_port_pin_t | s_sd_demo_pin_sck = (ra8_port_pin_t)k_ra8_board_pmod2_spi_sck |
| Pmod2 SCI0 clock pin used by the SD-SPI transport. | |
| static const ra8_port_pin_t | s_sd_demo_pin_cipo = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cipo |
| Pmod2 SCI0 controller-input pin used by the SD-SPI transport. | |
| static const ra8_port_pin_t | s_sd_demo_pin_copi = (ra8_port_pin_t)k_ra8_board_pmod2_spi_copi |
| Pmod2 SCI0 controller-output pin used by the SD-SPI transport. | |
| static const ra8_port_pin_t | s_sd_demo_pin_cs = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cs |
| Pmod2 GPIO chip-select pin used by the SD-SPI transport. | |
| static const uint8_t | s_msg_boot [] = "ra8_io_sd_demo: boot\r\n" |
| HIL banner emitted before SD initialization starts. | |
| static const uint8_t | s_msg_card_ok [] = "ra8_io_sd_demo: card ready\r\n" |
| HIL banner emitted after the SD card enters SPI mode. | |
| static const uint8_t | s_msg_init_fail [] = "ra8_io_sd_demo: FAIL init\r\n" |
| Diagnostic emitted when transport or card initialization fails. | |
| static const uint8_t | s_msg_pass [] = "ra8_io_sd_demo: sd:/LOGS/A.TXT 512 bytes PASS\r\n" |
| HIL success banner emitted after the verified file round-trip. | |
| static const uint8_t | s_msg_fail [] = "ra8_io_sd_demo: FAIL\r\n" |
| Diagnostic emitted when the VFS round-trip fails. | |
| static const char *const | s_tag = "ra8_io_sd_demo" |
| Module log tag. | |
| static ra8_io_blockdev_t | s_bd |
| ra8_io block device + ra8_fs backend bridged onto the SD card. | |
| static ra8_fs_backend_t | s_be |
| static const ra8_io_roundtrip_params_t | s_params |
| Shared round-trip parameters for this SD-backed FAT32 volume. | |
Prove the ra8_io fabric's swappable backend (#155/#156) over a microSD.
Companion to ra8_io_demo, which runs the ra8_io VFS over a RAM disk. This app runs the IDENTICAL ra8_io VFS API over a real micro-SD card by swapping only the block-device backend: instead of the RAM backend it binds the ra8_io SD-over-SPI block device (ra8_io_blockdev_sdspi_init) on top of the ra8_sdmmc_spi driver. The Pmod2 / SCI0 Simple-SPI bus comes up in one library call – ra8_sdmmc_spi_transport_sci routes the four pins, claims CS, brings up SCI0 Simple-SPI, and fills the transport vtable – matching the SDHI demo's one-line ra8_sdcard_init ergonomics. The data path above the block device is this app's self-contained ra8_io_roundtrip.{h,c} helper (the SDRAM / OSPI / SD demos under hw_pending carry their own copy) – this app differs only by the SD-SPI transport factory call plus the ONE backend bind line and its own PASS banner.
On a clean round-trip it prints exactly ra8_io_sd_demo: sd:/LOGS/A.TXT 512 bytes PASS; any failed step prints ra8_io_sd_demo: FAIL and parks the CPU. The HIL runner and the ra8_emulator smoke gate scrape for that PASS line.
Required external hardware (on-bench): Digilent PMOD MicroSD (part 410-380) in Pmod2 (J25) with any microSD card inserted. THIS APP ERASES THE CARD: it self-formats a fresh FAT32 volume, so any blank card works (FAT32 handles the multi-GB cards a real SD slot sees – FAT16's 2 GB ceiling does not). Under ra8_emulator attach a blank card with --sd-new 64:fat16 (the firmware reformats it FAT32 regardless of the seed type; only the capacity matters).
Definition in file main.c.
| #define SD_DEMO_PUTS | ( | lit | ) |
Emit a NUL-terminated literal (length via sizeof at the call site).
Definition at line 158 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt(), and main().
| enum sd_demo_config_t : uint32_t |
|
static |
Build the SCI-SPI transport, init the SD driver, panic-halt on failure.
The whole SD-SPI bring-up now collapses to two library calls: the ra8_sdmmc_spi SCI transport factory routes the four Pmod2 pins, claims CS, brings up SCI0 Simple-SPI, and fills the transport vtable; ra8_sdmmc_spi_init then runs the SD identification sequence. Prints card ready on success or a FAIL init diagnostic before parking.
| [in] | pclka_hz | Live PCLKA rate (Hz) feeding the SCI baud divider. |
pclka_hz is the live PCLKA rate. Definition at line 256 of file main.c.
References internal_sd_demo_panic_halt(), k_ra8_ok, k_sd_demo_spi_channel, RA8_INTERNAL, ra8_sdmmc_spi_init(), ra8_sdmmc_spi_transport_sci(), s_msg_card_ok, s_msg_init_fail, s_sd_demo_pin_cipo, s_sd_demo_pin_copi, s_sd_demo_pin_cs, s_sd_demo_pin_sck, and SD_DEMO_PUTS.
Referenced by main().
|
static |
Halt forever in WFI – panic stop on irrecoverable failure.
Used after a fatal bring-up or round-trip error has already been reported on the console; it parks the core so a debugger or the HIL runner can observe the final state.
Definition at line 177 of file main.c.
References RA8_INTERNAL.
Referenced by internal_sd_demo_init_card_or_halt(), internal_sd_demo_setup_or_halt(), and main().
|
static |
Write a byte run on the SCI8 console.
Thin wrapper over ra8_board_uart_console_write so the demo's print sites stay terse; the return value is intentionally discarded because a diagnostic-print failure has no useful recovery on a panic path.
| [in] | msg | Bytes to emit (non-NULL, length len). |
| [in] | len | Byte count to emit. |
msg points to at least len readable bytes. Definition at line 152 of file main.c.
References ra8_board_uart_console_write(), and RA8_INTERNAL.
|
staticnodiscard |
Bind the SD-SPI block device and run the shared ra8_io round-trip.
This is the "swappable backend" core: the only difference from the RAM / SDRAM / OSPI demos is that the block device bound here is the SD-over-SPI backend. After binding, the shared helper formats + mounts a FAT32 volume under "sd" and runs the mkdir + nested round-trip into sd:/LOGS/A.TXT. The VFS is initialised first because this app does not rely on an earlier mount having done so.
| k_ra8_ok | Backend bound, FAT32 formatted + mounted, round-trip passed. |
| k_ra8_err_* | The first failing fabric step's code. |
Definition at line 304 of file main.c.
References RA8_INTERNAL, ra8_io_blockdev_sdspi_init(), ra8_io_roundtrip_mount(), ra8_io_roundtrip_subdir_file(), ra8_io_vfs_init(), RA8_RETURN_ON_ERROR, s_bd, s_be, s_params, and s_tag.
Referenced by main().
|
static |
Bring up CGC + SysTick + console SCI; panic on fail.
Initialises the clock generator, caches CPUCLK0 and PCLKA, starts the SysTick time base, and brings up the SCI8 J-Link console via the board-support package (ra8_board_uart_console_init), which routes PD02 TXD / PD03 RXD and configures SCI8 async at the given baud. The Pmod2 SD SPI bus is brought up later by the ra8_sdmmc_spi SCI transport factory, so this routine only owns the clocks + console. Any failing step panic-halts so a misconfigured console never reaches the SD bring-up.
| [out] | out_pclka_hz | Cached PCLKA rate (Hz) handed to the transport factory. |
out_pclka_hz is writable. Definition at line 213 of file main.c.
References internal_sd_demo_panic_halt(), k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_sd_demo_uart_baud, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, and ra8_time_init().
Referenced by main().
| void main | ( | void | ) |
App entry: bring up the bus + card, run the ra8_io round-trip, print PASS.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, SPI, and SD card, then runs the shared ra8_io VFS round-trip over the SD-over-SPI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
Definition at line 334 of file main.c.
References internal_sd_demo_init_card_or_halt(), internal_sd_demo_panic_halt(), internal_sd_demo_roundtrip(), internal_sd_demo_setup_or_halt(), k_ra8_ok, ra8_board_uart_console_flush(), ra8_isr_globals_enable(), ra8_log_init(), s_msg_boot, s_msg_fail, s_msg_pass, and SD_DEMO_PUTS.
|
static |
|
static |
|
static |
|
static |
HIL banner emitted after the SD card enters SPI mode.
Definition at line 95 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt().
|
static |
Diagnostic emitted when the VFS round-trip fails.
Definition at line 104 of file main.c.
Referenced by internal_rc_setup_or_halt(), internal_setup_or_halt(), internal_td_setup_or_halt(), and main().
|
static |
Diagnostic emitted when transport or card initialization fails.
Definition at line 98 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt().
|
static |
|
static |
Shared round-trip parameters for this SD-backed FAT32 volume.
|
static |
Pmod2 SCI0 controller-input pin used by the SD-SPI transport.
Definition at line 78 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt().
|
static |
Pmod2 SCI0 controller-output pin used by the SD-SPI transport.
Definition at line 81 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt().
|
static |
Pmod2 GPIO chip-select pin used by the SD-SPI transport.
Definition at line 84 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt().
|
static |
Pmod2 SCI0 clock pin used by the SD-SPI transport.
Definition at line 75 of file main.c.
Referenced by internal_sd_demo_init_card_or_halt().