68#include "ux_device_class_storage.h"
69#include "ux_device_stack.h"
135typedef enum : uint32_t {
144typedef enum : uint8_t {
152#ifndef RA8_OFF_TARGET
358typedef enum : uint8_t {
420 (void)
memcpy(data_pointer,
544 return _ux_device_stack_initialize((UCHAR*)UX_NULL,
575 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_last_lba =
577 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_block_length =
579 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_type =
580 UX_SLAVE_CLASS_STORAGE_MEDIA_FAT_DISK;
581 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_removable_flag =
582 UX_SLAVE_CLASS_STORAGE_MEDIA_IS_REMOVABLE;
583 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_read_only_flag =
585 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_read =
wlun_msc_read;
586 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_write =
wlun_msc_write;
587 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_status =
611 UX_SLAVE_CLASS_STORAGE_PARAMETER msc_params;
612 (void)
memset(&msc_params, 0,
sizeof(msc_params));
614 msc_params.ux_slave_class_storage_parameter_vendor_id =
s_msc_vendor_id;
617 for (uint32_t idx = 0U; idx < (uint32_t)
k_wlun_count; idx++) {
621 _ux_device_class_storage_entry,
649 if (ux != UX_SUCCESS) {
655 if (ux != UX_SUCCESS) {
702 (void)first_unused_memory;
747 __asm__
volatile(
"wfi");
808 uint32_t cpuclk0_hz = 0U;
856#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 uint8_t s_disk[(size_t) k_demo_disk_blocks *(size_t) k_ra8_io_block_size_bytes]
256 KiB RAM-disk backing buffer (in SRAM .bss) for the "ram" mount.
static void wlun_fill_lun(UX_SLAVE_CLASS_STORAGE_PARAMETER *p, uint32_t idx)
Populate the writable LUN parameter slot with geometry + callbacks.
static void wlun_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
static UINT wlun_class_register(void)
Register the Mass-Storage class with one writable LUN.
static volatile bool s_tx_kernel_up
Set in tx_application_define; gates ThreadX tick delivery.
static const ra8_port_pin_t k_wlun_pin_fs_dp
USBFS D+ (P8_14).
static UCHAR s_msc_product_id[]
static const ra8_port_pin_t k_wlun_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
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 VOID wlun_device_worker(ULONG arg)
Device-side worker: bring the writable RAM-LUN device up, then park.
static UCHAR s_string_framework[]
USBX string descriptor table (vendor / product / serial).
scsi_sense_code_t
SCSI sense triple for an unsupported / out-of-range request.
@ k_scsi_ascq_none
ASCQ: none.
@ k_scsi_asc_write_protected
ASC: WRITE PROTECTED.
@ k_scsi_sense_illegal_request
Sense key: ILLEGAL REQUEST.
@ k_scsi_sense_data_protect
Sense key: DATA PROTECT.
@ k_scsi_asc_lba_out_of_range
ASC: LBA out of range.
static const ra8_port_pin_t k_wlun_pin_fs_dm
USBFS D- (P8_15).
static volatile uint32_t s_dbg_write_blocks
Total 512-B blocks the device media_write callback stored.
static const ra8_port_pin_t k_wlun_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).
static volatile uint32_t s_dbg_write_calls
Device-side media_write invocations (WRITE(10) data received).
static UINT wlun_msc_write(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
Storage media-write callback: store host data into the RAM disk.
static void wlun_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
static const ra8_port_pin_t k_wlun_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
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 UCHAR s_msc_class_name[]
Persistent mutable names retained by USBX and ThreadX.
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 volatile uint32_t s_dbg_read_calls
Device-side media_read invocations.
static volatile uint32_t s_dbg_dev_step
Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach, 5 parked.
static volatile uint32_t s_dbg_dev_err
Device worker first failing return code (0 = none).
static UINT wlun_msc_read(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
Storage media-read callback: synthesize the per-LUN pattern.
static UINT wlun_usbx_stack_up(void)
Bring USBX system + device stack up with the MSC framework.
static UINT wlun_msc_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
Storage media-status callback.
static CHAR s_device_thread_name[]
static const ra8_port_pin_t k_wlun_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
static void wlun_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
wlun_dev_step_t
J-Link probe values marking device-worker bring-up progress.
@ k_wlun_dev_step_dcd
DCD bridge initialized.
@ k_wlun_dev_step_class
MSC class registered.
@ k_wlun_dev_step_attach
Device attached (DPRPU).
@ k_wlun_dev_step_stack
USBX system + device stack up.
@ k_wlun_dev_step_parked
Bring-up done; worker parked.
static UCHAR s_msc_vendor_id[]
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
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+.
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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
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).
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).
Opaque thread stand-in for the host build.
examples/ek_ra8d2/hil_needs_revalidation/usb_selftest_wlun/inc/usb_selftest_wlun_steps....
@ k_wlun_block_size
SCSI logical block size.
@ k_wlun_sectors
512-byte sectors (RAM disk = 32 KiB).
@ k_wlun_count
Logical units exposed (single writable).
VOID wlun_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
@ k_wlun_usbx_pool_bytes
USBX memory pool (bytes).
@ k_wlun_thread_stack
Device worker stack (bytes).
@ k_wlun_baud
J-Link OB CDC log baud.
@ k_wlun_idle_ticks
Parked-loop back-off (ticks).
@ k_wlun_host_priority
Host worker priority (below USBX).
@ k_wlun_host_stack
Host worker stack (bytes).
@ k_wlun_dev_priority
Device bring-up worker priority.
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.