43typedef enum : uint8_t {
55typedef enum : uint32_t {
64typedef enum : uint32_t {
113 for (uint32_t i = 0U; i < len; i++) {
145 return (uint8_t)((uint8_t)
'0' + (uint8_t)nibble);
172 if (text[len] ==
'\0') {
252 out[0] = (uint8_t)
'0';
259 scratch[count] = (uint8_t)((uint8_t)
'0' + (uint8_t)(v %
k_cdc_dec_radix));
263 for (uint8_t i = 0U; i < count; i++) {
264 out[i] = scratch[count - 1U - i];
291 uint8_t width = digits;
295 for (uint8_t i = 0U; i < width; i++) {
350typedef enum : uint16_t {
367typedef enum : uint32_t {
452 for (uint8_t attempt = 0U; attempt < (uint8_t)
k_cdc_enum_tries; attempt++) {
661 return cdc_print(
" rounds echoed -- USB SELFTEST CDC-ECHO PASS\r\n");
768 for (uint32_t r = 0U; r < (uint32_t)
k_cdc_rounds; r++) {
static volatile uint32_t s_dbg_pid
Device-reported product id captured at enumeration.
static volatile uint32_t s_dbg_rounds_ok
Reports the host confirmed pattern-equal (expect k_hid_rounds).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
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).
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
@ 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.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
SysTick-based tick counter, delay and timestamp helpers.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
uint32_t ra8_time_ms(void)
Get the current 1 kHz tick count.
Native USB controller driver public API (device + host modes).
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
ra8_err_t ra8_usb_host_bulk_out(ra8_usb_speed_t speed, uint8_t pipe_num, const uint8_t *data, uint16_t len)
Transmit one bulk packet to the device and wait for the ACK.
ra8_err_t ra8_usb_host_bus_reset(ra8_usb_speed_t speed, bool assert_reset)
Drive (or release) the bus reset line.
uint16_t ra8_usb_host_line_state(ra8_usb_speed_t speed)
Read the host port's D+/D- line state (SYSSTS0.LNST).
ra8_err_t ra8_usb_host_pipe_setup(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t dev_addr, uint8_t ep_num, bool device_to_host, uint16_t max_packet)
Configure a controller pipe against an attached device's bulk endpoint.
ra8_err_t ra8_usb_host_bulk_in(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t *buf, uint16_t max_len, uint16_t *out_received)
Receive a bulk transfer from the device into buf.
ra8_err_t ra8_usb_host_init(ra8_usb_speed_t speed)
Bring up a USB controller in HOST mode.
ra8_err_t ra8_usb_host_deinit(ra8_usb_speed_t speed)
Tear down a host-mode controller and drop its MSTP reference.
ra8_err_t ra8_usb_host_control_xfer(ra8_usb_speed_t speed, const ra8_usb_setup_t *setup, uint8_t *data, uint16_t data_len, uint16_t *out_received)
Run a complete host control transfer (SETUP, optional DATA, STATUS).
ra8_err_t ra8_usb_host_set_uact(ra8_usb_speed_t speed, bool enable)
Enable / disable SOF (Start-of-Frame) generation on the bus.
ra8_err_t ra8_usb_host_set_target(ra8_usb_speed_t speed, uint8_t dev_addr)
Retarget the host's default control pipe at a device address.
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Decoded 8-byte USB SETUP packet.
static ra8_err_t cdc_print_pass(void)
Print "N rounds echoed -- USB SELFTEST CDC-ECHO PASS".
static ra8_err_t cdc_host_pass(void)
One full host-side pass: enumerate, then run the echo rounds.
static ra8_err_t cdc_ctrl_get_dev_desc(uint8_t *desc)
GET_DESCRIPTOR(DEVICE) over the polled control engine.
static ra8_err_t cdc_enum_set_address(void)
SET_ADDRESS to k_cdc_dev_addr, then retarget the DCP.
static uint8_t cdc_nibble_to_hex(uint32_t nibble)
Format one nibble (0..15) into an uppercase hex character.
static ra8_err_t cdc_print_enum(uint32_t pid)
Print "enumerated pid=0xNNNN" for the looped device.
static uint32_t cdc_str_len(const char *text)
Bounded ASCII string length (cap k_cdc_print_cap).
static ra8_err_t cdc_sci_write(const uint8_t *data, uint32_t len)
Push a literal block over SCI8 polled.
static ra8_err_t cdc_enum_set_config(void)
SET_CONFIGURATION(::k_cdc_config_value) on the addressed device.
cdc_hex_t
Hex/decimal text-formatter sizing constants.
@ k_cdc_hex_chars_u16
16-bit value -> "ABCD".
@ k_cdc_hex_chars_u32
32-bit value -> "ABCDEF01".
@ k_cdc_hex_digit_split
Threshold between '0-9'/'A-F'.
@ k_cdc_dec_chars_u32
Max digits for a 32-bit count.
@ k_cdc_nibble_bits
Bits per hex nibble.
static ra8_err_t cdc_print_dec(uint32_t value)
Print a uint32_t as ASCII decimal.
cdc_phase_t
J-Link probe values marking host-ladder progress.
@ k_cdc_phase_pass
All rounds echoed back OK.
@ k_cdc_phase_enum
Enumerating.
@ k_cdc_phase_verify
Running echo rounds.
@ k_cdc_phase_boot
Host thread not started.
@ k_cdc_phase_init
Host controller init.
VOID cdc_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
static ra8_err_t cdc_enum_hunt(uint8_t *desc)
Wait for the device to attach, then bus-reset + read its descriptor.
cdc_enum_tune_t
Timing / retry tunables for the polled enumeration ladder.
@ k_cdc_addr_settle_ms
Post-SET_ADDRESS recovery.
@ k_cdc_attach_spin
Attach spin cap (frozen-tick guard).
@ k_cdc_attach_to_ms
Wait for the D+ pull-up.
@ k_cdc_enum_tries
Reset+probe attempts.
@ k_cdc_reset_hold_ms
USB bus-reset hold (>=10 ms).
@ k_cdc_vbus_settle_ms
VBUS settle before probing.
@ k_cdc_debounce_ms
Post-attach debounce (>=100 ms).
@ k_cdc_recovery_ms
Post-reset recovery (TRSTRCY).
static ra8_err_t cdc_echo_round(uint32_t round)
One echo round: bulk-OUT a pattern, bulk-IN the echo, compare.
cdc_usb_req_t
Standard chapter-9 request / descriptor constants for the host.
@ k_cdc_breq_set_addr
SET_ADDRESS.
@ k_cdc_config_value
bConfigurationValue to select.
@ k_cdc_bm_std_dev_in
bmRequestType: Std | Device | In.
@ k_cdc_breq_get_desc
GET_DESCRIPTOR.
@ k_cdc_desc_device
DEVICE descriptor type.
@ k_cdc_bm_std_dev_out
bmRequestType: Std | Device | Out.
@ k_cdc_byte_bits
Bits per byte.
@ k_cdc_dev_desc_len
DEVICE descriptor length.
@ k_cdc_off_dev_pid
idProduct LSB byte offset.
@ k_cdc_breq_set_config
SET_CONFIGURATION.
static ra8_err_t cdc_print_fail(const char *what, ra8_err_t err)
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
cdc_mask_t
Bit-mask constants used by the text formatters.
@ k_cdc_nibble_mask
4-bit nibble mask.
@ k_cdc_dec_radix
Base for decimal conversion.
static ra8_err_t cdc_print_hex(uint32_t value, uint8_t digits)
Print a value as fixed-width uppercase hex.
static void cdc_pattern_fill(uint32_t round, uint8_t *out, uint32_t len)
Fill an echo payload with this round's deterministic bytes.
static ra8_err_t cdc_enumerate(uint32_t *out_pid)
Run the full enumeration ladder and open the bulk pipes.
static ra8_err_t cdc_open_pipes(void)
Open the host bulk pipes for the device's CDC data endpoints.
static ra8_err_t cdc_print(const char *text)
Print a NUL-terminated ASCII string over the console.
Host-side self-test ladder + console helpers shared with main.c.
@ k_cdc_rounds
Echo rounds the host runs.
@ k_cdc_pipe_in
Host pipe for the device bulk-IN.
@ k_cdc_echo_buf
One-MPS scratch buffer (bytes).
@ k_cdc_ep_out_num
Device bulk-OUT endpoint number.
@ k_cdc_no_mismatch
Probe: no mismatch.
@ k_cdc_pat_idx_mul
Per-index pattern multiplier.
@ k_cdc_payload
Bytes per echo round (sub-MPS).
@ k_cdc_byte_mask
Byte mask.
@ k_cdc_pat_bias
Pattern constant bias.
@ k_cdc_ep_in_num
Device bulk-IN endpoint number.
@ k_cdc_pipe_out
Host pipe for the device bulk-OUT.
@ k_cdc_pat_round_mul
Per-round pattern multiplier.
@ k_cdc_mps
Bulk endpoint wMaxPacketSize (FS).
@ k_cdc_dev_addr
Address the host assigns.
@ k_cdc_retry_ticks
Pause between ladder retries.
@ k_cdc_print_cap
Bound for console-string scans.
@ k_cdc_boot_wait_ticks
Host start delay (1 ms ticks).
@ k_cdc_idle_ticks
Parked-loop back-off (ticks).
static volatile uint32_t s_dbg_phase
Host-ladder phase marker (wlun_phase_t).
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.