41#include "ux_device_class_storage.h"
42#include "ux_device_stack.h"
267 (void)
memcpy(data_pointer,
373 return _ux_device_stack_initialize((UCHAR*)UX_NULL,
404 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_last_lba =
406 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_block_length =
408 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_type =
409 UX_SLAVE_CLASS_STORAGE_MEDIA_FAT_DISK;
410 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_removable_flag =
411 UX_SLAVE_CLASS_STORAGE_MEDIA_IS_REMOVABLE;
412 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_read_only_flag =
414 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_read =
microsd_msc_read;
415 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_write =
417 p->ux_slave_class_storage_parameter_lun[idx].ux_slave_class_storage_media_status =
441 UX_SLAVE_CLASS_STORAGE_PARAMETER msc_params;
442 (void)
memset(&msc_params, 0,
sizeof(msc_params));
444 msc_params.ux_slave_class_storage_parameter_vendor_id =
s_msc_vendor_id;
450 static UCHAR s_class_name[] =
"ux_slave_class_storage";
452 return _ux_device_stack_class_register(s_class_name,
453 _ux_device_class_storage_entry,
464 if (ux != UX_SUCCESS) {
470 if (ux != UX_SUCCESS) {
525 uint32_t block_count = 0U;
526 uint32_t block_size = 0U;
584 return microsd_print(
" OK (64 sectors, SD vs snapshot)\r\n");
690 err =
microsd_print(
"ra8d2 microsd: USB SELFTEST MICROSD PASS\r\n");
static UCHAR s_msc_product_id[]
static UCHAR s_string_framework[]
USBX string descriptor table (vendor / product / serial).
@ 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 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_device_framework_fs[]
static UCHAR s_msc_product_rev[]
static UCHAR s_language_id_framework[]
USBX language-id table – US English.
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 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_on(ra8_board_led_id_t led)
Drive led HIGH (light it).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
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.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
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_hs
High-Speed controller (USBHS @ 0x40351000).
@ k_ra8_usb_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
Native USB host-side MSC (Mass Storage Class) class layer.
ra8_err_t ra8_usb_hmsc_read_capacity(uint8_t target_lun, uint32_t *block_count, uint32_t *block_size)
Issue a SCSI READ CAPACITY(10) (opcode 0x25) over BBB.
ra8_err_t ra8_usb_hmsc_read10(uint8_t target_lun, uint32_t lba, uint16_t block_count, uint8_t *out_buf)
Issue a SCSI READ(10) (opcode 0x28) over BBB.
ra8_err_t ra8_usb_hmsc_enumerate(ra8_usb_hmsc_device_t *out_device)
Enumerate the attached MSC device end to end (polled).
ra8_err_t ra8_usb_hmsc_close(void)
Tear down the host-MSC driver and release the controller.
ra8_err_t ra8_usb_hmsc_init(ra8_usb_speed_t speed)
Bring up the host-MSC driver on a chosen USB controller.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Snapshot of the attached MSC device, passed to the attach callback.
uint8_t max_lun
Get-Max-LUN response (0..15).
uint16_t product_id
idProduct from device descriptor.
static ra8_err_t microsd_verify_one(uint32_t lun)
Read + verify the LUN's sectors against the SD snapshot.
static UINT microsd_msc_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
Storage media-status callback.
static UINT microsd_usbx_stack_up(void)
Bring USBX system + device stack up with the MSC framework.
static ra8_err_t microsd_host_enumerate(ra8_usb_hmsc_device_t *device)
Enumerate the looped device and print its PID + GET_MAX_LUN.
static ra8_err_t microsd_host_pass(void)
One full host-side pass: enumerate, verify the SD snapshot.
static UINT microsd_class_register(void)
Register the Mass-Storage class with one read-only LUN.
static UINT microsd_msc_read(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
Storage media-read callback: serve the boot-time SD snapshot.
VOID microsd_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
static void microsd_fill_lun(UX_SLAVE_CLASS_STORAGE_PARAMETER *p, uint32_t idx)
Populate the LUN parameter slot with geometry + callbacks.
static UINT microsd_msc_write(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
Storage media-write callback: reject (all LUNs are read-only).
static ra8_err_t microsd_print_lun_ok(uint32_t lun)
Print "LUN n OK (256 sectors)" for a verified logical unit.
VOID microsd_device_worker(ULONG arg)
Device-side worker: bring the read-only SD FS device up, then park.
examples/ek_ra8d2/hw_validated/hil/usb_selftest_microsd/inc/usb_selftest_microsd_steps....
ra8_err_t microsd_print_fail(const char *what, ra8_err_t err)
Print "FAIL <what> err=0xNNNNNNNN" on its own console line.
ra8_err_t microsd_print_dec(uint32_t value)
Print a uint32_t as ASCII decimal over the SCI8 console.
@ k_microsd_hex_chars_u16
16-bit value -> "ABCD".
ra8_err_t microsd_print(const char *text)
Print a NUL-terminated ASCII string over the SCI8 console.
unsigned char s_usb_selftest_microsd_sd_snapshot[(uint32_t) k_microsd_snap_bytes]
Read-only RAM snapshot of SD LBA 0..63, taken once at boot.
@ k_microsd_boot_wait_ticks
Host start delay (1 ms ticks).
@ k_microsd_idle_ticks
Parked-loop back-off (ticks).
@ k_microsd_usbx_pool_bytes
USBX memory pool (bytes).
@ k_microsd_retry_ticks
Pause between ladder retries.
@ k_microsd_phase_pass
All LUNs verified.
@ k_microsd_phase_init
ra8_usb_hmsc_init issued.
@ k_microsd_phase_verify
Reading + checking LUNs.
@ k_microsd_phase_enum
Enumerating.
@ k_microsd_block_size
SCSI logical block size.
@ k_microsd_no_mismatch
Probe: no mismatch.
@ k_microsd_burst_blocks
Blocks per READ(10) burst.
@ k_microsd_sectors
Exposed sectors (LBA 0..63).
@ k_microsd_count
Single read-only logical unit.
@ k_microsd_burst_bytes
8 x 512 B burst buffer.
@ k_microsd_dev_step_stack
USBX system + device stack up.
@ k_microsd_dev_step_attach
Device attached (DPRPU).
@ k_microsd_dev_step_class
MSC class registered.
@ k_microsd_dev_step_dcd
DCD bridge initialized.
@ k_microsd_dev_step_parked
Bring-up done; worker parked.
ra8_err_t microsd_print_hex(uint32_t value, uint8_t digits)
Print a value as fixed-width uppercase hex over the SCI8 console.
volatile uint32_t s_usb_selftest_microsd_dbg_bootsig
1 = LBA0 carries the 0x55AA FAT/exFAT boot signature.
static volatile uint32_t s_dbg_phase
Host-ladder phase marker (wlun_phase_t).
static volatile uint32_t s_dbg_luns_ok
Sectors that read back correctly after the write pass.
static volatile uint32_t s_dbg_pass_count
Completed full passes (sticky success counter).
static volatile uint32_t s_dbg_mismatch
First mismatching sector, or k_wlun_no_mismatch.
static volatile uint32_t s_dbg_max_lun
Device-reported GET_MAX_LUN value (expect 0, single LUN).
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.