73#include "ux_device_class_storage.h"
74#include "ux_device_stack.h"
129#ifndef RA8_OFF_TARGET
317typedef enum : uint8_t {
355 return _ux_device_stack_initialize((UCHAR*)UX_NULL,
385 UX_SLAVE_CLASS_STORAGE_PARAMETER msc_params;
386 (void)
memset(&msc_params, 0,
sizeof(msc_params));
387 msc_params.ux_slave_class_storage_parameter_number_lun = 1UL;
388 msc_params.ux_slave_class_storage_parameter_vendor_id =
s_msc_vendor_id;
392 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_last_lba =
394 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_block_length =
396 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_type =
397 UX_SLAVE_CLASS_STORAGE_MEDIA_FAT_DISK;
398 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_removable_flag =
399 UX_SLAVE_CLASS_STORAGE_MEDIA_IS_REMOVABLE;
400 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_read_only_flag =
402 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_read =
404 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_write =
406 msc_params.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_status =
409 static UCHAR s_class_name[] =
"ux_slave_class_storage";
411 return _ux_device_stack_class_register(s_class_name,
412 _ux_device_class_storage_entry,
449 for (uint32_t s = 0U; s < sec_per_erase; s++) {
603 (void)first_unused_memory;
648 __asm__
volatile(
"wfi");
716 uint32_t cpuclk0_hz = 0U;
764#ifndef RA8_OFF_TARGET
void main(void)
Secure fallback main entry point.
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
void _tx_timer_interrupt(void)
void SysTick_Handler(void)
SysTick exception handler – tail-calls the ThreadX timer.
static volatile bool s_tx_kernel_up
Set in tx_application_define; gates ThreadX tick delivery.
static UCHAR s_msc_product_id[]
static UCHAR s_host_stack[k_wlun_host_stack]
Stack backing storage for s_host_thread.
static TX_THREAD s_device_thread
ThreadX TCB for the USBX device-side worker thread.
static UCHAR s_string_framework[]
USBX string descriptor table (vendor / product / serial).
static UCHAR s_usbx_pool[k_wlun_usbx_pool_bytes]
USBX memory pool (USBX uses tx_byte_pool internally).
@ k_usb_langid_en_us_lo
LANGID 0x0409 low byte.
@ k_usb_langid_en_us_hi
LANGID 0x0409 high byte.
static CHAR s_host_thread_name[]
static TX_THREAD s_host_thread
ThreadX TCB for the host-side worker thread.
static UCHAR s_device_framework_fs[]
static UCHAR s_msc_product_rev[]
static UCHAR s_language_id_framework[]
USBX language-id table – US English.
static UCHAR s_device_stack[k_wlun_thread_stack]
Stack backing storage for s_device_thread.
static CHAR s_device_thread_name[]
static UCHAR s_msc_vendor_id[]
static const ra8_port_pin_t k_selftest_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
static VOID selftest_device_worker(ULONG arg)
Device-side worker: bring the FS device stack up, then park.
static const ra8_port_pin_t k_selftest_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
static VOID selftest_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
static void selftest_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
static void selftest_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
static const ra8_port_pin_t k_selftest_pin_fs_dm
USBFS D- (P8_15).
static const ra8_port_pin_t k_selftest_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).
static const ra8_port_pin_t k_selftest_pin_fs_dp
USBFS D+ (P8_14).
static void selftest_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
static UINT selftest_usbx_stack_up(void)
Brings USBX system + FS device stack up.
static UINT selftest_msc_class_register(void)
Registers the Mass-Storage class with the read-only MRAM LUN.
static const ra8_port_pin_t k_selftest_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
static ra8_err_t selftest_ospi_provision(void)
Bring the OSPI flash up and provision the test pattern.
static ra8_err_t selftest_ospi_write_pattern(void)
Erase the OSPI window and program the deterministic pattern.
static volatile uint32_t s_dbg_ospi_prov
OSPI provisioning result (sentinel = pending, 0 = done, else err).
static volatile uint32_t s_dbg_ospi_id
OSPI JEDEC id read at boot (IS25LX512M = 0x009D5A1A).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_io_expander_set_usbhs_host_mode(void)
Drive the U15 I/O expander to select USB-HS HOST mode.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
@ k_ra8_board_usbhs_pin_pwr
PD07 J7 host-power switch (HIGH = U18 drives 5 V VBUS).
@ k_ra8_board_usbhs_pin_vbus
P4_08 USBHS_VBUS sense.
@ k_ra8_board_usbfs_pin_dm
P8_15 D-.
@ k_ra8_board_usbfs_pin_vbusen
P5_00 VBUSEN GPIO.
@ k_ra8_board_usbfs_pin_vbus
P4_07 VBUS sense.
@ k_ra8_board_usbfs_pin_dp
P8_14 D+.
ra8_err_t ra8_board_io_expander_set_octospi_active(void)
Program the U15 I/O expander to request the Octo-SPI SW4 layout.
ra8_err_t ra8_board_xspi_pins_init(void)
Route the 12 OCTA bus pins to the xSPI peripheral and pulse RESET_L.
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.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
ra8_err_t ra8_cgc_usbfs_clock_enable(void)
Bring up the USB-FS module clock (USBCKCR / USBCKDIVCR).
ra8_err_t ra8_cgc_usbhs_pll_enable(void)
Bring up the USBHS PHY reference clock + module clock.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
PSEL codes for peripheral pin routing on the RA8D2.
@ k_ra8_psel_usb_fs
10011b: USB Full-Speed.
@ k_ra8_psel_usb_hs
10100b: USB High-Speed (e.g.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
@ k_ra8_xspi_lio_1s1s1s
1S-1S-1S extended SPI.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_level_high
Drive or read 1.
@ k_ra8_level_low
Drive or read 0.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_gpio_output_init(ra8_port_pin_t pin, ra8_level_t init_level)
Configure a pin as a digital output and drive it to an initial level.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
void ux_dcd_ra8_usb_irq_reenable(void)
Storm-guard recovery: zero the run counter and re-enable the USB IRQ.
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.
void ra8_time_on_tick(void)
SysTick IRQ handler – called from the vector table.
Native USB controller driver public API (device + host modes).
ra8_err_t ra8_usb_device_attach(ra8_usb_speed_t speed, bool attached)
Raise / drop the D+ pull-up to advertise the device to the host.
@ k_ra8_usb_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
Native USB host-side MSC (Mass Storage Class) class layer.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
char CHAR
ThreadX-compatible CHAR (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
xSPI / Octo-SPI driver (flash read/program/erase + ID/status)
ra8_err_t ra8_xspi_flash_program(uint8_t instance, uint32_t flash_addr, const uint8_t *data, uint32_t len)
Program (write) len bytes at flash_addr.
ra8_err_t ra8_xspi_init(uint8_t instance, ra8_xspi_lio_mode_t mode)
Initialise an xSPI instance in the chosen link-layer IO mode.
ra8_err_t ra8_xspi_flash_erase_sector(uint8_t instance, uint32_t flash_addr)
Erase the 4 KiB sector containing flash_addr.
ra8_err_t ra8_xspi_flash_read_id(uint8_t instance, uint32_t *out_id)
Read the JEDEC ID (opcode 0x9F), returning 24 bits in a uint32_t.
Opaque thread stand-in for the host build.
@ k_selftest_no_mismatch
Probe: no mismatch found.
UINT selftest_msc_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
Storage media-status callback.
ra8_err_t selftest_host_pass(void)
One full host-side pass: enumerate, mount, browse, verify, WP.
@ k_fat_total_sectors
1 + 17 + 32 + 4096.
UINT selftest_msc_read(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
Storage media-read callback: synthesize sectors over MRAM.
UINT selftest_msc_write(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
Storage media-write callback: always rejects (write-protected).
@ k_selftest_boot_wait_ticks
Host start delay (1 ms ticks).
@ k_selftest_thread_stack
Device worker stack (bytes).
@ k_selftest_block_size
SCSI logical block size (bytes).
@ k_selftest_idle_ticks
Parked-loop back-off (ticks).
@ k_selftest_retry_ticks
Pause between ladder retries.
@ k_selftest_usbx_pool_bytes
USBX memory pool (bytes).
@ k_selftest_host_priority
Host worker: BELOW the USBX storage class thread (UX_THREAD_PRIORITY_CLASS = 20).
@ k_selftest_dev_priority
Device bring-up worker priority.
@ k_selftest_host_stack
Host worker stack (bytes).
@ k_selftest_baud
J-Link OB CDC log baud.
Shared constants + step prototypes for the OSPI USB self-loop app.
void selftest_pattern_fill(uint32_t win_sector, UCHAR *out)
Compute the deterministic pattern for one window data sector.
@ k_ospi_erase_count
1 MiB / 4 KiB = 256 erases.
@ k_ospi_test_offset
1 MiB into the chip (scratch).
@ k_ospi_erase_sector
IS25LX512M 4 KiB erase sector.
@ k_ospi_instance
xSPI controller instance.
USBX device-controller-driver (DCD) bridge to ra8_usb.
ra8_err_t ux_dcd_ra8_usb_initialize(ra8_usb_speed_t speed)
Register the ra8_usb bridge as the active USBX DCD.