64#include "ux_device_class_dfu.h"
65#include "ux_device_stack.h"
118#ifndef RA8_OFF_TARGET
287typedef enum : uint8_t {
360 *media_status = (
ULONG)UX_SLAVE_CLASS_DFU_MEDIA_STATUS_OK;
386 *actual_length = 0UL;
390 if (remain > length) {
394 *actual_length = remain;
414 *media_status = (
ULONG)UX_SLAVE_CLASS_DFU_MEDIA_STATUS_OK;
454 return _ux_device_stack_initialize((UCHAR*)UX_NULL,
494 UX_SLAVE_CLASS_DFU_PARAMETER dfu_params = {
495 .ux_slave_class_dfu_parameter_will_detach = 0UL,
496 .ux_slave_class_dfu_parameter_capabilities =
497 (
ULONG)(UX_SLAVE_CLASS_DFU_CAPABILITY_CAN_DOWNLOAD |
498 UX_SLAVE_CLASS_DFU_CAPABILITY_CAN_UPLOAD),
499 .ux_slave_class_dfu_parameter_instance_activate =
dfu_activate,
500 .ux_slave_class_dfu_parameter_instance_deactivate =
dfu_deactivate,
501 .ux_slave_class_dfu_parameter_read =
dfu_read,
504 .ux_slave_class_dfu_parameter_notify =
dfu_notify,
508 static UCHAR s_class_name[] =
"ux_slave_class_dfu";
510 return _ux_device_stack_class_register(s_class_name,
511 _ux_device_class_dfu_entry,
533 if (ux != UX_SUCCESS) {
539 if (ux != UX_SUCCESS) {
606 (void)first_unused_memory;
648 __asm__
volatile(
"wfi");
699 uint32_t cpuclk0_hz = 0U;
742#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_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_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_dev_step
Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach, 5 parked.
static CHAR s_device_thread_name[]
static UCHAR s_device_framework[]
USBX device + DFU descriptors: a DFU-mode interface (bInterfaceProtocol 0x02, enumerates straight int...
static volatile uint32_t s_dbg_dev_writes
Device-side download block-write count.
static const ra8_port_pin_t k_dfu_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
static void dfu_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
static ra8_err_t dfu_host_pass(void)
Run the full host pass: enumerate, download, upload-verify.
static const ra8_port_pin_t k_dfu_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS.
static const ra8_port_pin_t k_dfu_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
static VOID dfu_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds, then park.
@ k_dfu_usbx_pool_bytes
USBX memory pool (bytes).
@ k_dfu_host_priority
Host worker priority (below USBX).
@ k_dfu_retry_ticks
Pause between ladder retries.
@ k_dfu_boot_wait_ticks
Host start delay (1 ms ticks).
@ k_dfu_dev_priority
Device bring-up worker priority.
@ k_dfu_thread_stack
Device worker stack (bytes).
@ k_dfu_baud
J-Link OB CDC log baud.
@ k_dfu_idle_ticks
Parked-loop back-off (ticks).
@ k_dfu_host_stack
Host worker stack (bytes).
static VOID dfu_device_worker(ULONG arg)
Device-side worker: bring the DFU device up, then park.
static const ra8_port_pin_t k_dfu_pin_fs_dm
USBFS D- (P8_15).
static void dfu_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
static const ra8_port_pin_t k_dfu_pin_fs_dp
USBFS D+ (P8_14).
static const ra8_port_pin_t k_dfu_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
static void dfu_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
static volatile uint32_t s_dbg_host_err
Host-ladder first failing return code (0 = none).
@ k_dfu_xfer_size
wTransferSize: bytes per DFU block.
@ k_dfu_image_bytes
k_dfu_blocks * k_dfu_xfer_size.
static UCHAR s_dfu_image[k_dfu_image_bytes]
Device-side RAM "firmware" image: the DFU write callback stores each downloaded block here; the read ...
static volatile uint32_t s_dfu_image_len
Highest byte offset the device has captured (download high-water mark).
UINT(* dfu_write_cb_t)(VOID *dfu, ULONG block_number, UCHAR *data, ULONG length, ULONG *media_status)
Signature of the USBX DFU download-write callback field.
static VOID dfu_activate(VOID *dfu)
DFU activate callback.
static UINT dfu_read(VOID *dfu, ULONG block_number, UCHAR *data, ULONG length, ULONG *actual_length)
DFU read callback – serve one block of the RAM image on UPLOAD.
static UINT dfu_usbx_stack_up(void)
Bring USBX system + device stack up with the DFU framework.
static UINT dfu_get_status(VOID *dfu, ULONG *media_status)
DFU get-status callback – report the media always ready.
static VOID dfu_deactivate(VOID *dfu)
DFU deactivate callback.
static UINT dfu_write(VOID *dfu, ULONG block_number, const UCHAR *data, ULONG length, ULONG *media_status)
DFU write callback – store one downloaded block into the RAM image.
static UINT dfu_class_register(void)
Register the DFU class against configuration 1, interface 0.
static UINT dfu_notify(VOID *dfu, ULONG notification)
DFU notify callback – accept begin/end/manifest notifications.
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+.
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 * 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).
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.
Shared constants + host-side DFU ladder interface for usb_selftest_dfu.
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.