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

USB self-loop: HS host WRITE(10)s + reads back a RAM-backed device. 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_gpio_constants.h"
#include "ra8_isr.h"
#include "ra8_port_constants.h"
#include "ra8_port_utils.h"
#include "ra8_time.h"
#include "ra8_usb.h"
#include "ra8_usb_hmsc.h"
#include "usb_selftest_wlun_steps.h"
#include "tx_api.h"
#include "ux_api.h"
#include "ux_dcd_ra8_usb.h"
#include "ux_device_class_storage.h"
#include "ux_device_stack.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  wlun_dev_step_t : uint32_t {
  k_wlun_dev_step_stack = 1U ,
  k_wlun_dev_step_class = 2U ,
  k_wlun_dev_step_dcd = 3U ,
  k_wlun_dev_step_attach = 4U ,
  k_wlun_dev_step_parked = 5U
}
 J-Link probe values marking device-worker bring-up progress. More...
enum  scsi_sense_code_t : uint8_t {
  k_scsi_sense_illegal_request = 0x05U ,
  k_scsi_asc_lba_out_of_range = 0x21U ,
  k_scsi_ascq_none = 0x00U ,
  k_scsi_sense_data_protect = 0x07U ,
  k_scsi_asc_write_protected = 0x27U
}
 SCSI sense triple for an unsupported / out-of-range request. More...
enum  usb_langid_byte_t : uint8_t {
  k_usb_langid_en_us_lo = 0x09U ,
  k_usb_langid_en_us_hi = 0x04U
}

Functions

void _tx_timer_interrupt (void)
void SysTick_Handler (void)
 Service the SysTick exception selected by the linked application.
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_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 UINT wlun_msc_status (VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
 Storage media-status callback.
static UINT wlun_usbx_stack_up (void)
 Bring USBX system + device stack up with the MSC framework.
static void wlun_fill_lun (UX_SLAVE_CLASS_STORAGE_PARAMETER *p, uint32_t idx)
 Populate the writable LUN parameter slot with geometry + callbacks.
static UINT wlun_class_register (void)
 Register the Mass-Storage class with one writable LUN.
static VOID wlun_device_worker (ULONG arg)
 Device-side worker: bring the writable RAM-LUN device up, then park.
VOID tx_application_define (VOID *first_unused_memory)
 ThreadX application-define hook.
static void wlun_panic_halt (void)
 Halt forever in WFI – panic stop on init failure.
static void wlun_route_usb_or_halt (void)
 Route both ports' pins: FS as device, HS as host.
static void wlun_setup_or_halt (void)
 Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
void main (void)
 Application entry: bring the board up, then hand off to ThreadX.

Variables

static volatile bool s_tx_kernel_up = false
 Set in tx_application_define; gates ThreadX tick delivery.
static const ra8_port_pin_t k_wlun_pin_fs_vbus = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbus
 USBFS VBUS sense pin (P4_07, PSEL = 0x13).
static const ra8_port_pin_t k_wlun_pin_fs_vbusen = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbusen
 USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
static const ra8_port_pin_t k_wlun_pin_fs_dp = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dp
 USBFS D+ (P8_14).
static const ra8_port_pin_t k_wlun_pin_fs_dm = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dm
 USBFS D- (P8_15).
static const ra8_port_pin_t k_wlun_pin_hs_vbus = (ra8_port_pin_t)k_ra8_board_usbhs_pin_vbus
 USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
static const ra8_port_pin_t k_wlun_pin_hs_pwr = (ra8_port_pin_t)k_ra8_board_usbhs_pin_pwr
 J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).
static TX_THREAD s_device_thread
 ThreadX TCB for the USBX device-side worker thread.
static UCHAR s_device_stack [k_wlun_thread_stack]
 Stack backing storage for s_device_thread.
static TX_THREAD s_host_thread
 ThreadX TCB for the host-side worker thread.
static UCHAR s_host_stack [k_wlun_host_stack]
 Stack backing storage for s_host_thread.
static UCHAR s_usbx_pool [k_wlun_usbx_pool_bytes]
 USBX memory pool (USBX uses tx_byte_pool internally).
static UCHAR s_msc_vendor_id [] = "RA8D2 "
static UCHAR s_msc_product_id [] = "WRITABLE-RAM RW "
static UCHAR s_msc_product_rev [] = "0001"
static UCHAR s_msc_class_name [] = "ux_slave_class_storage"
 Persistent mutable names retained by USBX and ThreadX.
static CHAR s_device_thread_name [] = "wlun_device"
static CHAR s_host_thread_name [] = "wlun_host"
static volatile uint32_t s_dbg_read_calls
 Device-side media_read invocations.
static volatile uint32_t s_dbg_write_calls
 Device-side media_write invocations (WRITE(10) data received).
static volatile uint32_t s_dbg_write_blocks
 Total 512-B blocks the device media_write callback stored.
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_disk [(size_t) k_wlun_sectors *(size_t) k_wlun_block_size]
 Writable RAM-backed disk: the device LUN's backing store.
static UCHAR s_device_framework_fs []
static UCHAR s_string_framework []
 USBX string descriptor table (vendor / product / serial).
static UCHAR s_language_id_framework [] = {k_usb_langid_en_us_lo, k_usb_langid_en_us_hi}
 USBX language-id table – US English.

Detailed Description

USB self-loop: HS host WRITE(10)s + reads back a RAM-backed device.

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

The WRITABLE MSC self-loop – it exercises the host->device bulk-OUT data path (SCSI WRITE(10)). The two USB ports are cabled to EACH OTHER and one firmware image runs both USB stacks:

  • USBFS (J11) = DEVICE: a ThreadX + USBX Mass-Storage class that exposes one WRITABLE logical unit (GET_MAX_LUN = 0) backed by a 64-sector (32 KiB) RAM disk. media_write copies host data into the RAM disk; media_read serves it back. IRQ-driven through the port/usbx/ux_dcd_ra8_usb bridge.
  • USBHS (J7) = HOST: the first-party polled host MSC stack (ra8_usb_hmsc). It enumerates the device, WRITE(10)s a deterministic per-LBA pattern across the whole disk, then READ(10)s it back and byte-checks every sector – proving the device bulk-OUT WRITE data phase round-trips intact, end to end on chip.

No filesystem is involved (raw SCSI WRITE(10)/READ(10)); this is the write-path counterpart to the read-only MSC self-loops, and the on-bench validation for the device bulk-OUT WRITE(10) driver fix.

The link runs at 12 Mbps (FS device ceiling; HS host serves an FS downstream device).

Verdicts stream over SCI8 (J-Link OB CDC console, 115200) and are mirrored in J-Link-readable probes (s_dbg_*).

Pinout

FS device: P4_07 VBUS sense, P5_00 VBUSEN GPIO LOW (device role), P8_14 D+, P8_15 D- (PSEL usb_fs). HS host: SW4-8 to Host via the U15 expander, PD07 HIGH (U18 supplies J7 VBUS), P4_08 USBHS_VBUS (PSEL usb_hs). Console: PD_02/PD_03 SCI8 (PSEL sci_async).

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ scsi_sense_code_t

enum scsi_sense_code_t : uint8_t

SCSI sense triple for an unsupported / out-of-range request.

Enumerator
k_scsi_sense_illegal_request 

Sense key: ILLEGAL REQUEST.

k_scsi_asc_lba_out_of_range 

ASC: LBA out of range.

k_scsi_ascq_none 

ASCQ: none.

k_scsi_sense_data_protect 

Sense key: DATA PROTECT.

k_scsi_asc_write_protected 

ASC: WRITE PROTECTED.

Definition at line 144 of file main.c.

◆ usb_langid_byte_t

enum usb_langid_byte_t : uint8_t
Enumerator
k_usb_langid_en_us_lo 

LANGID 0x0409 low byte.

k_usb_langid_en_us_hi 

LANGID 0x0409 high byte.

Definition at line 358 of file main.c.

◆ wlun_dev_step_t

enum wlun_dev_step_t : uint32_t

J-Link probe values marking device-worker bring-up progress.

Enumerator
k_wlun_dev_step_stack 

USBX system + device stack up.

k_wlun_dev_step_class 

MSC class registered.

k_wlun_dev_step_dcd 

DCD bridge initialized.

k_wlun_dev_step_attach 

Device attached (DPRPU).

k_wlun_dev_step_parked 

Bring-up done; worker parked.

Definition at line 135 of file main.c.

Function Documentation

◆ _tx_timer_interrupt()

void _tx_timer_interrupt ( void )
extern

◆ main()

void main ( void )

Application entry: bring the board up, then hand off to ThreadX.

The application entry point Reset_Handler hands control to.

Both USB controllers' clocks and pins come up before the kernel so the workers only deal with stack bring-up.

Precondition
Reset_Handler copied .data and zeroed .bss.
SystemInit set VTOR, FPU, priority grouping.
Postcondition
On clean entry the CPU stays in tx_kernel_enter forever.
On any HAL init failure the function halts in WFI.
Note
Single entry point; not re-entrant.
Since
0.1.0

Definition at line 850 of file main.c.

References ra8_isr_globals_enable(), wlun_panic_halt(), and wlun_setup_or_halt().

◆ SysTick_Handler()

void SysTick_Handler ( void )

Service the SysTick exception selected by the linked application.

Service one SysTick event for the core timebase.

Service one SysTick event for the core timebase.

Resolves to the weak core timebase handler unless a strong RTOS or application handler overrides it. The vector table references the selected implementation without owning its subsystem policy.

Precondition
Entered for a SysTick exception with a valid exception frame.
The selected handler's timebase or scheduler state is initialised.
Postcondition
The selected implementation has processed one SysTick event.
The vector table itself remains unchanged.
Note
Runs in handler mode; thread-safety follows the selected implementation.
Since
0.1.0

The weak firmware implementation advances the millisecond counter, then services linked ThreadX and USB hooks when their weak symbols and readiness state permit. The host-test implementation advances only the counter. An application may replace either weak definition with a strong handler.

Precondition
The handler is entered for one SysTick event or a host-test equivalent.
On target, ra8_time_init() configured the SysTick period.
Postcondition
s_tick_ms has advanced by exactly one.
Optional subsystem hooks run only when linked and ready.
Note
IRQ-safe; the weak symbol may be overridden by an application handler.
Since
0.1.0

Service the SysTick exception selected by the linked application.

The weak firmware implementation advances the millisecond counter, then services linked ThreadX and USB hooks when their weak symbols and readiness state permit. The host-test implementation advances only the counter. An application may replace either weak definition with a strong handler.

Precondition
The handler is entered for one SysTick event or a host-test equivalent.
On target, ra8_time_init() configured the SysTick period.
Postcondition
s_tick_ms has advanced by exactly one.
Optional subsystem hooks run only when linked and ready.
Note
IRQ-safe; the weak symbol may be overridden by an application handler.
Since
0.1.0

Service the SysTick exception selected by the linked application.

Precondition
Called from exception context (IPSR == 15).
_tx_initialize_low_level has programmed SysTick.
Postcondition
One ThreadX tick elapsed; PendSV may be pending.

Definition at line 89 of file main.c.

References _tx_timer_interrupt(), ra8_time_on_tick(), s_tx_kernel_up, and ux_dcd_ra8_usb_irq_reenable().

◆ tx_application_define()

VOID tx_application_define ( VOID * first_unused_memory)

ThreadX application-define hook.

Spawns both workers.

Device worker at priority 8, host worker at 24 (below the USBX class threads). Sets s_tx_kernel_up so SysTick may feed ThreadX from here on.

Parameters
[in]first_unused_memorySentinel (unused; static stacks).
Precondition
Called from tx_kernel_enter after scheduler init.
Static stacks are reserved at file scope.
Postcondition
Two auto-start worker threads are queued.
s_tx_kernel_up is true.
Note
Called once at boot; not thread-safe.
Since
0.1.0

Definition at line 700 of file main.c.

References k_wlun_dev_priority, k_wlun_host_priority, k_wlun_host_stack, k_wlun_thread_stack, s_device_stack, s_device_thread, s_device_thread_name, s_host_stack, s_host_thread, s_host_thread_name, s_tx_kernel_up, TX_AUTO_START, TX_NO_TIME_SLICE, tx_thread_create, wlun_device_worker(), and wlun_host_worker().

◆ wlun_class_register()

UINT wlun_class_register ( void )
static

Register the Mass-Storage class with one writable LUN.

Sets number_lun = 1 and fills the LUN slot via wlun_fill_lun, so the host's GET_MAX_LUN returns 0. One is the single writable unit this self-loop exercises.

Returns
UINT UX_SUCCESS on success.
Return values
UX_SUCCESSClass registered.
Precondition
wlun_usbx_stack_up has succeeded.
Media callbacks are defined.
Postcondition
MSC class bound to configuration 1, interface 0, with 1 LUN.
GET_MAX_LUN will report 0.
Note
Not re-entrant.
Since
0.1.0

Definition at line 609 of file main.c.

References k_wlun_count, memset(), s_msc_class_name, s_msc_product_id, s_msc_product_rev, s_msc_vendor_id, and wlun_fill_lun().

Referenced by wlun_device_worker().

◆ wlun_device_worker()

VOID wlun_device_worker ( ULONG arg)
static

Device-side worker: bring the writable RAM-LUN device up, then park.

USBX system + device stack + writable MSC class + DCD bridge on the USBFS controller, then DPRPU attach. USBX runs the SCSI/BBB state machine on its own class threads after this.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread.
USB-FS pins + 48 MHz clock are up (main did both).
Postcondition
The FS device is attached and serviceable on its writable LUN.
On any bring-up failure the thread exits.
Note
Runs once; loops forever on success.
Since
0.1.0

Definition at line 644 of file main.c.

References k_ra8_ok, k_ra8_usb_speed_fs, k_wlun_dev_step_attach, k_wlun_dev_step_class, k_wlun_dev_step_dcd, k_wlun_dev_step_parked, k_wlun_dev_step_stack, k_wlun_idle_ticks, ra8_usb_device_attach(), s_dbg_dev_err, s_dbg_dev_step, tx_thread_sleep, ux_dcd_ra8_usb_initialize(), wlun_class_register(), and wlun_usbx_stack_up().

Referenced by tx_application_define().

◆ wlun_fill_lun()

void wlun_fill_lun ( UX_SLAVE_CLASS_STORAGE_PARAMETER * p,
uint32_t idx )
static

Populate the writable LUN parameter slot with geometry + callbacks.

The LUN is a writable FAT-disk-typed, removable, 64-sector RAM-backed volume whose media callbacks store and serve the RAM disk.

Parameters
[in,out]pThe class parameter block.
[in]idxLUN slot index (0..1).
Precondition
p is zeroed and being filled before class register.
idx is below k_wlun_count.
Postcondition
Slot idx carries the geometry + media callbacks.
No other slot is touched.
Note
Helper to keep the register function within the size cap.
Since
0.1.0

Definition at line 573 of file main.c.

References k_wlun_block_size, k_wlun_sectors, wlun_msc_read(), wlun_msc_status(), and wlun_msc_write().

Referenced by wlun_class_register().

◆ wlun_msc_read()

UINT wlun_msc_read ( VOID * storage,
ULONG lun,
UCHAR * data_pointer,
ULONG number_blocks,
ULONG lba,
ULONG * media_status )
static

Storage media-read callback: synthesize the per-LUN pattern.

Bound-checks the request against the LUN geometry, then fills each block via wlun_pattern_fill keyed on lun. One callback serves the single LUN. LED1 toggles per call so loop traffic is visible.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (0..1).
[out]data_pointerUSBX-owned destination buffer.
[in]number_blocksNumber of 512-byte blocks to produce.
[in]lbaStarting LBA.
[out]media_statusFilled with sense status word.
Returns
UX_SUCCESS if the request fits the LUN; else UX_ERROR.
Return values
UX_SUCCESSRead completed.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer / media_status are non-NULL (USBX guarantee).
lun is below k_wlun_count.
Postcondition
Either the blocks were synthesized or media_status is non-zero.
s_dbg_read_calls advanced.
Note
Called from the USBX storage class thread.
Since
0.1.0

Definition at line 404 of file main.c.

References k_ra8_board_led1, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, k_wlun_block_size, k_wlun_sectors, memcpy(), ra8_board_led_toggle(), s_dbg_read_calls, and s_disk.

Referenced by wlun_fill_lun().

◆ wlun_msc_status()

UINT wlun_msc_status ( VOID * storage,
ULONG lun,
ULONG media_id,
ULONG * media_status )
static

Storage media-status callback.

Always reports media-present.

Synthesized LUNs never go absent; status is constant 0.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (unused).
[in]media_idMedia id (unused).
[out]media_statusFilled with 0 (no fault).
Returns
Always UX_SUCCESS.
Return values
UX_SUCCESSMedia is present and ready.
Precondition
media_status is non-NULL (USBX guarantee).
The class instance is live.
Postcondition
*media_status is 0.
No other state changes.
Note
Synthesized volumes; never report media-not-present.
Since
0.1.0

Definition at line 506 of file main.c.

Referenced by wlun_fill_lun().

◆ wlun_msc_write()

UINT wlun_msc_write ( VOID * storage,
ULONG lun,
UCHAR * data_pointer,
ULONG number_blocks,
ULONG lba,
ULONG * media_status )
static

Storage media-write callback: store host data into the RAM disk.

The LUN is writable; the host's WRITE(10) data-OUT phase lands here. Copies number_blocks sectors from the USBX buffer into the RAM-backed s_disk so a later READ(10) returns exactly what was written. Bumps s_dbg_write_calls / s_dbg_write_blocks so a J-Link dump shows the device-side bulk-OUT receive actually completed.

Parameters
[in,out]storageUSBX storage class instance (unused).
[in]lunLogical unit number (unused; single LUN).
[in]data_pointerUSBX-owned source buffer (received OUT data).
[in]number_blocksNumber of 512-byte blocks the host wrote.
[in]lbaStarting LBA.
[out]media_statusFilled with the sense status word.
Returns
UX_SUCCESS if the request fits the disk; else UX_ERROR.
Return values
UX_SUCCESSBlocks stored to the RAM disk.
UX_ERROROut-of-range LBA / count.
Precondition
data_pointer / media_status are non-NULL (USBX guarantee).
The OUT data phase delivered number_blocks * 512 bytes.
Postcondition
s_disk holds the written sectors; counters advanced.
*media_status is 0 on success.
Note
Called from the USBX storage class thread.
Since
0.1.0

Definition at line 459 of file main.c.

References k_ra8_board_led2, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, k_wlun_block_size, k_wlun_sectors, memcpy(), ra8_board_led_toggle(), s_dbg_write_blocks, s_dbg_write_calls, and s_disk.

Referenced by wlun_fill_lun().

◆ wlun_panic_halt()

void wlun_panic_halt ( void )
static

Halt forever in WFI – panic stop on init failure.

Last-resort stop; only a debugger or reset recovers.

Precondition
Called only after a fatal boot error.
Interrupts may be in any state.
Postcondition
CPU is parked.
No further code runs.
Note
Not reachable post-boot.
Since
0.1.0

Definition at line 744 of file main.c.

Referenced by main(), wlun_route_usb_or_halt(), and wlun_setup_or_halt().

◆ wlun_route_usb_or_halt()

void wlun_route_usb_or_halt ( void )
static

Route both ports' pins: FS as device, HS as host.

FS device: P4_07 VBUS sense, P5_00 VBUSEN GPIO LOW (else peripheral routing forces host VBUSEN and blocks device enum), P8_14/P8_15 data. HS host: SW4-8 to Host via the U15 expander, PD07 HIGH (U18 supplies J7), P4_08 VBUS sense.

Precondition
IOPORT and the U15 expander are reachable.
Called once from wlun_setup_or_halt.
Postcondition
FS pins carry the device role, HS pins the host role.
PD07 is HIGH (J7 powered).
Note
Panic-halts on any routing failure.
Since
0.1.0

Definition at line 767 of file main.c.

References k_ra8_level_high, k_ra8_level_low, k_ra8_ok, k_ra8_psel_usb_fs, k_ra8_psel_usb_hs, k_wlun_pin_fs_dm, k_wlun_pin_fs_dp, k_wlun_pin_fs_vbus, k_wlun_pin_fs_vbusen, k_wlun_pin_hs_pwr, k_wlun_pin_hs_vbus, ra8_board_io_expander_set_usbhs_host_mode(), ra8_gpio_output_init(), ra8_pfs_route_peripheral(), and wlun_panic_halt().

Referenced by wlun_setup_or_halt().

◆ wlun_setup_or_halt()

void wlun_setup_or_halt ( void )
static

Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.

USBFS needs the 48 MHz PLL2 reference; USBHS needs its UTMI PLL. SCI8 is the J-Link OB CDC console at 115200.

Precondition
Reset_Handler finished C runtime init.
SystemInit has run.
Postcondition
Console works; both USB ports' pins and clocks are live.
LED1/LED2 are initialized.
Note
Panic-halts on any failure; called once from main.
Since
0.1.0

Definition at line 806 of file main.c.

References k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, k_wlun_baud, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_cgc_usbfs_clock_enable(), ra8_cgc_usbhs_pll_enable(), ra8_time_init(), wlun_panic_halt(), and wlun_route_usb_or_halt().

Referenced by main().

◆ wlun_usbx_stack_up()

UINT wlun_usbx_stack_up ( void )
static

Bring USBX system + device stack up with the MSC framework.

One-shot USBX pool + device-stack init (FS-only framework).

Returns
UINT UX_SUCCESS on success.
Return values
UX_SUCCESSStack ready.
Precondition
File-scope pool reserved.
Thread context.
Postcondition
Device stack accepts class registrations.
On failure USBX state is undefined.
Note
Single-call; not idempotent.
Since
0.1.0

Definition at line 539 of file main.c.

References k_wlun_usbx_pool_bytes, s_device_framework_fs, s_language_id_framework, s_string_framework, and s_usbx_pool.

Referenced by wlun_device_worker().

Variable Documentation

◆ k_wlun_pin_fs_dm

const ra8_port_pin_t k_wlun_pin_fs_dm = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dm
static

USBFS D- (P8_15).

Definition at line 113 of file main.c.

Referenced by wlun_route_usb_or_halt().

◆ k_wlun_pin_fs_dp

const ra8_port_pin_t k_wlun_pin_fs_dp = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dp
static

USBFS D+ (P8_14).

Definition at line 110 of file main.c.

Referenced by wlun_route_usb_or_halt().

◆ k_wlun_pin_fs_vbus

const ra8_port_pin_t k_wlun_pin_fs_vbus = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbus
static

USBFS VBUS sense pin (P4_07, PSEL = 0x13).

Definition at line 104 of file main.c.

Referenced by wlun_route_usb_or_halt().

◆ k_wlun_pin_fs_vbusen

const ra8_port_pin_t k_wlun_pin_fs_vbusen = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbusen
static

USBFS VBUSEN (P5_00) – GPIO LOW for the device role.

Definition at line 107 of file main.c.

Referenced by wlun_route_usb_or_halt().

◆ k_wlun_pin_hs_pwr

const ra8_port_pin_t k_wlun_pin_hs_pwr = (ra8_port_pin_t)k_ra8_board_usbhs_pin_pwr
static

J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).

Definition at line 119 of file main.c.

Referenced by wlun_route_usb_or_halt().

◆ k_wlun_pin_hs_vbus

const ra8_port_pin_t k_wlun_pin_hs_vbus = (ra8_port_pin_t)k_ra8_board_usbhs_pin_vbus
static

USBHS_VBUS sense pin (P4_08, PSEL = 0x14).

Definition at line 116 of file main.c.

Referenced by wlun_route_usb_or_halt().

◆ s_dbg_dev_err

volatile uint32_t s_dbg_dev_err
static

◆ s_dbg_dev_step

volatile uint32_t s_dbg_dev_step
static

◆ s_dbg_read_calls

volatile uint32_t s_dbg_read_calls
static

Device-side media_read invocations.

Definition at line 213 of file main.c.

Referenced by demo_msc_read(), microsd_msc_read(), mlun_msc_read(), ospirw_msc_read(), sdmsc_msc_read(), selftest_msc_read(), selftest_msc_read(), and wlun_msc_read().

◆ s_dbg_write_blocks

volatile uint32_t s_dbg_write_blocks
static

Total 512-B blocks the device media_write callback stored.

Definition at line 217 of file main.c.

Referenced by ospirw_msc_write(), sdmsc_msc_write(), and wlun_msc_write().

◆ s_dbg_write_calls

volatile uint32_t s_dbg_write_calls
static

Device-side media_write invocations (WRITE(10) data received).

Definition at line 215 of file main.c.

Referenced by ospirw_msc_write(), sdmsc_msc_write(), and wlun_msc_write().

◆ s_device_framework_fs

◆ s_device_stack

UCHAR s_device_stack[k_wlun_thread_stack]
static

Stack backing storage for s_device_thread.

Since
0.1.0

Definition at line 171 of file main.c.

Referenced by tx_application_define(), and usb_host_keyboard_device_thread_create().

◆ s_device_thread

TX_THREAD s_device_thread
static

ThreadX TCB for the USBX device-side worker thread.

Note
Single-writer (worker only).
Since
0.1.0

Definition at line 164 of file main.c.

Referenced by tx_application_define(), and usb_host_keyboard_device_thread_create().

◆ s_device_thread_name

CHAR s_device_thread_name[] = "wlun_device"
static

Definition at line 201 of file main.c.

Referenced by tx_application_define(), and usb_host_keyboard_device_thread_create().

◆ s_disk

UCHAR s_disk[(size_t) k_wlun_sectors *(size_t) k_wlun_block_size]
static

Writable RAM-backed disk: the device LUN's backing store.

Definition at line 224 of file main.c.

◆ s_host_stack

UCHAR s_host_stack[k_wlun_host_stack]
static

Stack backing storage for s_host_thread.

Since
0.1.0

Definition at line 186 of file main.c.

Referenced by tx_application_define().

◆ s_host_thread

TX_THREAD s_host_thread
static

ThreadX TCB for the host-side worker thread.

Note
Single-writer (worker only).
Since
0.1.0

Definition at line 179 of file main.c.

Referenced by tx_application_define().

◆ s_host_thread_name

CHAR s_host_thread_name[] = "wlun_host"
static

Definition at line 202 of file main.c.

Referenced by tx_application_define().

◆ s_language_id_framework

◆ s_msc_class_name

UCHAR s_msc_class_name[] = "ux_slave_class_storage"
static

Persistent mutable names retained by USBX and ThreadX.

Definition at line 200 of file main.c.

Referenced by wlun_class_register().

◆ s_msc_product_id

◆ s_msc_product_rev

◆ s_msc_vendor_id

◆ s_string_framework

UCHAR s_string_framework[]
static

USBX string descriptor table (vendor / product / serial).

Each entry: 2 bytes lang-id, 1 byte string index, 1 byte length, then ASCII bytes.

Since
0.1.0

Definition at line 299 of file main.c.

Referenced by blc_device_worker(), cdc_usbx_stack_up(), demo_usbx_stack_up(), dfu_device_worker(), dfu_usbx_stack_up(), hid_usbx_stack_up(), hid_usbx_stack_up(), microsd_usbx_stack_up(), mlun_usbx_stack_up(), ospirw_usbx_stack_up(), sdmsc_usbx_stack_up(), selftest_usbx_stack_up(), selftest_usbx_stack_up(), selftest_usbx_stack_up(), and wlun_usbx_stack_up().

◆ s_tx_kernel_up

volatile bool s_tx_kernel_up = false
static

Set in tx_application_define; gates ThreadX tick delivery.

main() starts SysTick before tx_kernel_enter and the setup window is long (U15 expander I2C blocks for ms), so the tick fires pre-kernel; feeding _tx_timer_interrupt into ThreadX's zeroed timer state bus-faults. Gate it until the kernel runs.

Since
0.1.0

Definition at line 86 of file main.c.

Referenced by SysTick_Handler(), and tx_application_define().

◆ s_usbx_pool