ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
40
41#include <stdint.h>
42#include <string.h>
43
44#include "ra8_board_ek_ra8d2.h"
45#include "ra8_boot_entry.h"
46#include "ra8_cgc.h"
47#include "ra8_err.h"
48#include "ra8_gpio_constants.h"
49#include "ra8_isr.h"
50#include "ra8_port_constants.h"
51#include "ra8_port_utils.h"
52#include "ra8_time.h"
53#include "ra8_usb.h"
55
56#ifndef RA8_OFF_TARGET
57#include "tx_api.h"
58#include "ux_api.h"
59#include "ux_dcd_ra8_usb.h"
60#include "ux_device_class_hid.h"
61#include "ux_device_stack.h"
62
63/* Strong SysTick override: route the tick into BOTH the ra8_time millisecond
64 * counter (for ra8_delay_ms and the polled host stack's timeouts) AND
65 * ThreadX's timer; the 1 ms pulse also recovers the DCD's storm-guard mask. */
66
67extern void _tx_timer_interrupt(void);
68
78static volatile bool s_tx_kernel_up = false;
79
80void SysTick_Handler(void);
89#endif
90
91/* -------------------------------------------------------------------------- */
92/* Pinout (FSP-aligned, EK-RA8D2 v1 User's Manual) */
93/* -------------------------------------------------------------------------- */
94
97
100
103
106
109
112
113/* -------------------------------------------------------------------------- */
114/* Tunables */
115/* -------------------------------------------------------------------------- */
116
118static char s_typed[k_hid_nkeys + 1U] = {};
119
131
132#ifndef RA8_OFF_TARGET
133
134/* -------------------------------------------------------------------------- */
135/* ThreadX host worker + shared activation semaphore */
136/* -------------------------------------------------------------------------- */
137
145
152
164
165/* -------------------------------------------------------------------------- */
166/* J-Link probes (host side) */
167/* -------------------------------------------------------------------------- */
168
170static volatile uint32_t s_dbg_phase;
172static volatile uint32_t s_dbg_rounds_ok;
174static volatile uint32_t s_dbg_pid;
176static volatile uint32_t s_dbg_mismatch = (uint32_t)k_hid_no_mismatch;
178static volatile uint32_t s_dbg_pass_count;
180static volatile uint32_t s_dbg_last_seq;
181
182/* -------------------------------------------------------------------------- */
183/* Keycode decode (host side) */
184/* -------------------------------------------------------------------------- */
185
194static char hid_keycode_to_ascii(uint8_t kc)
195{
196 if ((kc >= (uint8_t)k_hid_kc_a) && (kc <= (uint8_t)k_hid_kc_z)) {
197 return (char)('A' + (int)(kc - (uint8_t)k_hid_kc_a));
198 }
199 if ((kc >= (uint8_t)k_hid_kc_1) && (kc < (uint8_t)k_hid_kc_0)) {
200 return (char)('1' + (int)(kc - (uint8_t)k_hid_kc_1));
201 }
202 if (kc == (uint8_t)k_hid_kc_0) {
203 return '0';
204 }
205 return '?';
206}
207
208/* -------------------------------------------------------------------------- */
209/* Host side: self-contained polled enumerate + HID interrupt-IN read */
210/* -------------------------------------------------------------------------- */
211
228
243
261[[nodiscard]] static ra8_err_t hid_ctrl_get_dev_desc(uint8_t* desc)
262{
263 const ra8_usb_setup_t setup = {
264 .bm_request_type = (uint8_t)k_hid_bm_std_dev_in,
265 .b_request = (uint8_t)k_hid_breq_get_desc,
266 .w_value = (uint16_t)((uint16_t)k_hid_desc_device << (uint16_t)k_hid_byte_bits),
267 .w_index = 0U,
268 .w_length = (uint16_t)k_hid_dev_desc_len,
269 };
270 uint16_t rx = 0U;
271 const ra8_err_t err =
273 if (err != k_ra8_ok) {
274 return err;
275 }
276 if (rx != (uint16_t)k_hid_dev_desc_len) {
277 return k_ra8_err_hw_error;
278 }
279 return k_ra8_ok;
280}
281
304[[nodiscard]] static ra8_err_t hid_enum_hunt(uint8_t* desc)
305{
307 const uint32_t t0 = ra8_time_ms();
308 for (uint32_t spin = 0U; spin < (uint32_t)k_hid_attach_spin; spin++) {
310 break;
311 }
312 if ((ra8_time_ms() - t0) > (uint32_t)k_hid_attach_to_ms) {
313 break;
314 }
315 }
318 for (uint8_t attempt = 0U; attempt < (uint8_t)k_hid_enum_tries; attempt++) {
325 err = hid_ctrl_get_dev_desc(desc);
326 if (err == k_ra8_ok) {
327 return k_ra8_ok;
328 }
329 }
330 return err;
331}
332
347[[nodiscard]] static ra8_err_t hid_enum_set_address(void)
348{
349 const ra8_usb_setup_t setup = {
350 .bm_request_type = (uint8_t)k_hid_bm_std_dev_out,
351 .b_request = (uint8_t)k_hid_breq_set_addr,
352 .w_value = (uint16_t)k_hid_dev_addr,
353 .w_index = 0U,
354 .w_length = 0U,
355 };
356 ra8_err_t err = ra8_usb_host_control_xfer(k_ra8_usb_speed_hs, &setup, nullptr, 0U, nullptr);
357 if (err != k_ra8_ok) {
358 return err;
359 }
362}
363
378[[nodiscard]] static ra8_err_t hid_enum_set_config(void)
379{
380 const ra8_usb_setup_t setup = {
381 .bm_request_type = (uint8_t)k_hid_bm_std_dev_out,
382 .b_request = (uint8_t)k_hid_breq_set_config,
383 .w_value = (uint16_t)k_hid_config_value,
384 .w_index = 0U,
385 .w_length = 0U,
386 };
387 return ra8_usb_host_control_xfer(k_ra8_usb_speed_hs, &setup, nullptr, 0U, nullptr);
388}
389
409[[nodiscard]] static ra8_err_t hid_open_pipes(void)
410{
412 (uint8_t)k_hid_pipe_in,
413 (uint8_t)k_hid_dev_addr,
414 (uint8_t)k_hid_ep_in_num,
415 true,
416 (uint16_t)k_hid_mps);
417}
418
439[[nodiscard]] static ra8_err_t hid_enumerate(uint32_t* out_pid)
440{
441 uint8_t desc[k_hid_dev_desc_len] = {};
442 ra8_err_t err = hid_enum_hunt(desc);
443 if (err != k_ra8_ok) {
444 (void)hid_print_fail("enumerate", err);
445 return err;
446 }
447 *out_pid = (uint32_t)desc[k_hid_off_dev_pid] |
448 ((uint32_t)desc[(uint32_t)k_hid_off_dev_pid + 1U] << (uint32_t)k_hid_byte_bits);
449 err = hid_enum_set_address();
450 if (err != k_ra8_ok) {
451 (void)hid_print_fail("set_address", err);
452 return err;
453 }
454 err = hid_enum_set_config();
455 if (err != k_ra8_ok) {
456 (void)hid_print_fail("set_config", err);
457 return err;
458 }
459 err = hid_open_pipes();
460 if (err != k_ra8_ok) {
461 (void)hid_print_fail("open_pipes", err);
462 }
463 return err;
464}
465
482[[nodiscard]] static ra8_err_t hid_print_enum(uint32_t pid)
483{
484 ra8_err_t err = hid_print("ra8d2 hid: enumerated pid=0x");
485 if (err != k_ra8_ok) {
486 return err;
487 }
488 err = hid_print_hex(pid, (uint8_t)k_hid_hex_chars_u16);
489 if (err != k_ra8_ok) {
490 return err;
491 }
492 return hid_print("\r\n");
493}
494
510[[nodiscard]] static ra8_err_t hid_print_pass(void)
511{
512 ra8_err_t err = hid_print("ra8d2 hid: host decoded keys \"");
513 if (err == k_ra8_ok) {
514 err = hid_print(s_typed);
515 }
516 if (err == k_ra8_ok) {
517 err = hid_print("\" over ");
518 }
519 if (err == k_ra8_ok) {
520 err = hid_print_dec((uint32_t)k_hid_rounds);
521 }
522 if (err == k_ra8_ok) {
523 err = hid_print(" reports -- USB HOST KEYBOARD PASS\r\n");
524 }
525 return err;
526}
527
552[[nodiscard]] static ra8_err_t hid_read_round(uint32_t round)
553{
554 static uint8_t s_expect[k_hid_read_buf] = {};
555 static uint8_t s_rx[k_hid_read_buf] = {};
556 hid_fill_report_body(s_expect, (uint32_t)k_hid_report_len);
557 uint16_t rx = 0U;
559 (uint8_t)k_hid_pipe_in,
560 s_rx,
561 (uint16_t)k_hid_read_buf,
562 &rx);
563 if (err != k_ra8_ok) {
564 (void)hid_print_fail("report read", err);
565 return err;
566 }
567 if (rx != (uint16_t)k_hid_report_len) {
568 s_dbg_mismatch = round;
569 (void)hid_print_fail("report length", k_ra8_err_invalid_size);
571 }
572 const size_t body = (size_t)((uint32_t)k_hid_report_len - (uint32_t)k_hid_body_idx);
573 if (memcmp(&s_rx[k_hid_body_idx], &s_expect[k_hid_body_idx], body) != 0) {
574 s_dbg_mismatch = round;
575 (void)hid_print_fail("report pattern mismatch", k_ra8_err_invalid_state);
577 }
578 s_dbg_last_seq = (uint32_t)s_rx[k_hid_seq_idx];
579 /* Decode the boot-keyboard keycodes (bytes 2..) back to ASCII for the verdict.
580 * The report is constant, so doing it each round is idempotent. */
581 for (uint32_t i = 0U; i < (uint32_t)k_hid_nkeys; i++) {
582 s_typed[i] = hid_keycode_to_ascii(s_rx[(uint32_t)k_hid_key0_idx + i]);
583 }
584 s_typed[(uint32_t)k_hid_nkeys] = '\0';
585 return k_ra8_ok;
586}
587
605[[nodiscard]] static ra8_err_t hid_host_pass(void)
606{
607 s_dbg_phase = (uint32_t)k_hid_phase_init;
608 ra8_err_t err = hid_print("ra8d2 hid: host up on USB-HS, probing the loop...\r\n");
609 if (err != k_ra8_ok) {
610 return err;
611 }
613 if (err != k_ra8_ok) {
614 (void)hid_print_fail("host init", err);
615 return err;
616 }
617
618 s_dbg_phase = (uint32_t)k_hid_phase_enum;
619 uint32_t pid = 0U;
620 err = hid_enumerate(&pid);
621 if (err != k_ra8_ok) {
623 return err;
624 }
625 s_dbg_pid = pid;
626 err = hid_print_enum(pid);
627 if (err != k_ra8_ok) {
628 return err;
629 }
630
632 s_dbg_rounds_ok = 0U;
633 for (uint32_t r = 0U; r < (uint32_t)k_hid_rounds; r++) {
634 err = hid_read_round(r);
635 if (err != k_ra8_ok) {
637 return err;
638 }
640 }
641
642 s_dbg_phase = (uint32_t)k_hid_phase_pass;
644 err = hid_print_pass();
645 if (err != k_ra8_ok) {
646 return err;
647 }
649 return k_ra8_ok;
650}
651
669static VOID hid_host_worker(ULONG arg)
670{
671 (void)arg;
672
674 for (;;) {
675 const ra8_err_t err = hid_host_pass();
676 if (err == k_ra8_ok) {
677 break;
678 }
680 }
681 while (1) {
683 }
684}
685
704VOID tx_application_define(VOID* first_unused_memory)
705{
706 static CHAR s_semaphore_name[] = "hid_active";
707 static CHAR s_host_thread_name[] = "hid_host";
708
709 (void)first_unused_memory;
710 s_tx_kernel_up = true;
711 (void)tx_semaphore_create(&s_usb_host_keyboard_hid_active_sem, s_semaphore_name, 0U);
716 0UL,
723}
724#endif /* !RA8_OFF_TARGET */
725
726/* -------------------------------------------------------------------------- */
727/* Startup */
728/* -------------------------------------------------------------------------- */
729
743static void hid_panic_halt(void)
744{
745 while (1) {
746 __asm__ volatile("wfi");
747 }
748}
749
790
805static void hid_setup_or_halt(void)
806{
807 uint32_t cpuclk0_hz = 0U;
808 if (ra8_cgc_init() != k_ra8_ok) {
810 }
813 }
816 }
819 }
820 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
822 }
825 }
828 }
831 }
833}
834
849void main(void)
850{
852
854
855#ifndef RA8_OFF_TARGET
856 tx_kernel_enter();
857#endif
858
860}
void main(void)
Secure fallback main entry point.
Definition main.c:37
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
Definition main.c:942
void _tx_timer_interrupt(void)
void SysTick_Handler(void)
SysTick exception handler – tail-calls the ThreadX timer.
Definition main.c:146
static volatile bool s_tx_kernel_up
Set in tx_application_define; gates ThreadX tick delivery.
Definition main.c:86
static UCHAR s_host_stack[k_wlun_host_stack]
Stack backing storage for s_host_thread.
Definition main.c:186
static CHAR s_host_thread_name[]
Definition main.c:202
static TX_THREAD s_host_thread
ThreadX TCB for the host-side worker thread.
Definition main.c:179
static volatile uint32_t s_dbg_pid
Device-reported product id captured at enumeration.
Definition main.c:208
static void hid_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
Definition main.c:766
static void hid_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
Definition main.c:805
hid_phase_t
J-Link probe values marking host-ladder progress.
Definition main.c:124
@ k_hid_phase_enum
Enumerating.
Definition main.c:127
@ k_hid_phase_boot
Host thread not started.
Definition main.c:125
@ k_hid_phase_pass
All reports verified.
Definition main.c:129
@ k_hid_phase_verify
Reading + checking reports.
Definition main.c:128
@ k_hid_phase_init
Host controller init.
Definition main.c:126
static volatile uint32_t s_dbg_last_seq
Seq byte of the most recent report the host read back.
Definition main.c:180
static ra8_err_t hid_read_round(uint32_t round)
One report round: read an interrupt-IN report, check its body.
Definition main.c:552
static ra8_err_t hid_print_enum(uint32_t pid)
Print "enumerated pid=0xNNNN" for the looped device.
Definition main.c:482
static const ra8_port_pin_t k_hid_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
Definition main.c:108
static void hid_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
Definition main.c:743
static ra8_err_t hid_enum_hunt(uint8_t *desc)
Wait for the device to attach, then bus-reset + read its descriptor.
Definition main.c:304
static const ra8_port_pin_t k_hid_pin_fs_dm
USBFS D- (P8_15).
Definition main.c:105
static ra8_err_t hid_enumerate(uint32_t *out_pid)
Run the full enumeration ladder and open the bulk pipes.
Definition main.c:439
static ra8_err_t hid_print_pass(void)
Print the decoded keys + "USB HOST KEYBOARD PASS".
Definition main.c:510
static ra8_err_t hid_open_pipes(void)
Open the host receive pipe for the device's HID interrupt-IN endpoint.
Definition main.c:409
hid_usb_req_t
Standard chapter-9 request / descriptor constants for the host.
Definition main.c:216
@ k_hid_desc_device
DEVICE descriptor type.
Definition main.c:222
@ k_hid_dev_desc_len
DEVICE descriptor length.
Definition main.c:223
@ k_hid_bm_std_dev_out
bmRequestType: Std | Device | Out.
Definition main.c:218
@ k_hid_config_value
bConfigurationValue to select.
Definition main.c:226
@ k_hid_byte_bits
Bits per byte.
Definition main.c:225
@ k_hid_off_dev_pid
idProduct LSB byte offset.
Definition main.c:224
@ k_hid_breq_set_config
SET_CONFIGURATION.
Definition main.c:221
@ k_hid_bm_std_dev_in
bmRequestType: Std | Device | In.
Definition main.c:217
@ k_hid_breq_set_addr
SET_ADDRESS.
Definition main.c:220
@ k_hid_breq_get_desc
GET_DESCRIPTOR.
Definition main.c:219
static ra8_err_t hid_enum_set_address(void)
SET_ADDRESS to k_hid_dev_addr, then retarget the DCP.
Definition main.c:347
static const ra8_port_pin_t k_hid_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
Definition main.c:99
hid_enum_tune_t
Timing / retry tunables for the polled enumeration ladder.
Definition main.c:233
@ k_hid_enum_tries
Reset+probe attempts.
Definition main.c:240
@ k_hid_vbus_settle_ms
VBUS settle before probing.
Definition main.c:234
@ k_hid_recovery_ms
Post-reset recovery (TRSTRCY).
Definition main.c:238
@ k_hid_addr_settle_ms
Post-SET_ADDRESS recovery.
Definition main.c:239
@ k_hid_reset_hold_ms
USB bus-reset hold (>=10 ms).
Definition main.c:237
@ k_hid_attach_spin
Attach spin cap (frozen-tick guard).
Definition main.c:241
@ k_hid_attach_to_ms
Wait for the D+ pull-up.
Definition main.c:235
@ k_hid_debounce_ms
Post-attach debounce (>=100 ms).
Definition main.c:236
static const ra8_port_pin_t k_hid_pin_fs_dp
USBFS D+ (P8_14).
Definition main.c:102
static VOID hid_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
Definition main.c:669
static volatile uint32_t s_dbg_rounds_ok
Reports the host confirmed pattern-equal (expect k_hid_rounds).
Definition main.c:172
static ra8_err_t hid_enum_set_config(void)
SET_CONFIGURATION(::k_hid_config_value) on the addressed device.
Definition main.c:378
static char s_typed[k_hid_nkeys+1U]
ASCII the host decoded from the read keycodes (filled by the verify).
Definition main.c:118
static ra8_err_t hid_host_pass(void)
One full host-side pass: enumerate, then read + check reports.
Definition main.c:605
static const ra8_port_pin_t k_hid_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).
Definition main.c:111
static char hid_keycode_to_ascii(uint8_t kc)
Decode one HID Usage-Table keycode to its ASCII character.
Definition main.c:194
static const ra8_port_pin_t k_hid_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
Definition main.c:96
static ra8_err_t hid_ctrl_get_dev_desc(uint8_t *desc)
GET_DESCRIPTOR(DEVICE) over the polled control engine.
Definition main.c:261
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).
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).
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.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
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_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
Definition ra8_err.h:310
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
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).
Definition ra8_isr.c:439
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.
Definition gpio.c:88
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.
Definition gpio.c:238
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.
Definition ra8_time.c:59
void ra8_time_on_tick(void)
SysTick IRQ handler – called from the vector table.
Definition ra8_time.c:170
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129
uint32_t ra8_time_ms(void)
Get the current 1 kHz tick count.
Definition ra8_time.c:108
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_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 int UINT
ThreadX-compatible unsigned int (host stub).
#define tx_thread_create
#define tx_thread_sleep
#define TX_NO_TIME_SLICE
char CHAR
ThreadX-compatible CHAR (host stub).
#define TX_AUTO_START
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Opaque thread stand-in for the host build.
Decoded 8-byte USB SETUP packet.
Shared seam between usb_host_keyboard main.c and its sibling TUs.
void usb_host_keyboard_device_thread_create(void)
Create + auto-start the USBX HID device worker thread.
ra8_err_t hid_print(const char *text)
Print a NUL-terminated ASCII string over the console.
ra8_err_t hid_print_fail(const char *what, ra8_err_t err)
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
ra8_err_t hid_print_hex(uint32_t value, uint8_t digits)
Print a value as fixed-width uppercase hex.
@ k_hid_hex_chars_u16
16-bit value -> "ABCD".
void hid_fill_report_body(uint8_t *out, uint32_t len)
Fill the fixed body of a HID report (bytes 1..len-1).
ra8_err_t hid_print_dec(uint32_t value)
Print a uint32_t as ASCII decimal.
@ k_hid_report_len
Vendor input report width (bytes).
@ k_hid_ep_in_num
Device interrupt-IN endpoint num.
@ k_hid_rounds
Reports the host reads + checks.
@ k_hid_pipe_in
Host pipe for the device IN.
@ k_hid_nkeys
Keycodes typed ("RA8D2").
@ k_hid_mps
Interrupt endpoint wMaxPacketSize.
@ k_hid_no_mismatch
Probe: no mismatch.
@ k_hid_read_buf
One-MPS receive buffer (bytes).
@ k_hid_dev_addr
Address the host assigns.
@ k_hid_key0_idx
Boot-keyboard first-keycode byte.
@ k_hid_body_idx
Report body starts at byte 1.
@ k_hid_seq_idx
Report byte 0: modifier / rolling seq.
@ k_hid_kc_a
Keycode for 'a' / 'A'.
@ k_hid_kc_z
Keycode for 'z' / 'Z'.
@ k_hid_kc_1
Keycode for '1'.
@ k_hid_kc_0
Keycode for '0' (top of digits).
TX_SEMAPHORE s_usb_host_keyboard_hid_active_sem
Activation semaphore shared by the device worker and main.c.
Definition main.c:163
@ k_hid_idle_ticks
Parked-loop back-off (ticks).
@ k_hid_host_stack
Host worker stack (bytes).
@ k_hid_host_priority
Host worker priority (below USBX).
@ k_hid_retry_ticks
Pause between ladder retries.
@ k_hid_baud
J-Link OB CDC log baud.
@ k_hid_boot_wait_ticks
Host start delay (1 ms 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.
USBX device-controller-driver (DCD) bridge to ra8_usb.