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
43
44#include <stdint.h>
45#include <string.h>
46
47#include "ra8_board_ek_ra8d2.h"
48#include "ra8_boot_entry.h"
49#include "ra8_cgc.h"
50#include "ra8_dfu.h"
51#include "ra8_dfu_device.h"
52#include "ra8_dfu_host.h"
53#include "ra8_err.h"
54#include "ra8_gpio_constants.h"
55#include "ra8_isr.h"
56#include "ra8_port_constants.h"
57#include "ra8_port_utils.h"
58#include "ra8_time.h"
59#include "ra8_usb.h"
60
61#ifndef RA8_OFF_TARGET
62#include "tx_api.h"
63#include "ux_api.h"
64#include "ux_dcd_ra8_usb.h"
65#include "ux_device_class_dfu.h"
66#include "ux_device_stack.h"
67
68extern void _tx_timer_interrupt(void);
69
77static volatile bool s_tx_kernel_up = false;
78
79void SysTick_Handler(void);
88#endif
89
90/* -------------------------------------------------------------------------- */
91/* Pinout (FSP-aligned, EK-RA8D2 v1 User's Manual) */
92/* -------------------------------------------------------------------------- */
93
96
99
102
105
108
111
112/* -------------------------------------------------------------------------- */
113/* Tunables */
114/* -------------------------------------------------------------------------- */
115
133
143
148typedef enum : uint32_t {
150} dfu_mask_t;
151
164
165#ifndef RA8_OFF_TARGET
166
167/* -------------------------------------------------------------------------- */
168/* ThreadX workers + USBX pool storage */
169/* -------------------------------------------------------------------------- */
170
181
193static const UCHAR s_boot_payload[64] = {
194 0x00U, 0x00U, 0x07U, 0x22U, 0x11U, 0x00U, 0x02U, 0x02U, 0xAFU, 0xF3U, 0x00U, 0x80U, 0xAFU,
195 0xF3U, 0x00U, 0x80U, 0x46U, 0xF2U, 0x0DU, 0x00U, 0xC6U, 0xF2U, 0x0DU, 0x00U, 0x40U, 0xF2U,
196 0x00U, 0x01U, 0xC2U, 0xF2U, 0x04U, 0x21U, 0x08U, 0x60U, 0xFEU, 0xE7U, 0xFFU, 0xFFU, 0xFFU,
197 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
198 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
199};
200
201/* -------------------------------------------------------------------------- */
202/* J-Link probes */
203/* -------------------------------------------------------------------------- */
204
206static volatile uint32_t s_dbg_phase;
208static volatile uint32_t s_dbg_pid;
210static volatile uint32_t s_dbg_pass_count;
212static volatile uint32_t s_dbg_dev_writes;
214static volatile uint32_t s_dbg_dev_step;
216static volatile uint32_t s_dbg_host_err;
217
218/* -------------------------------------------------------------------------- */
219/* USB descriptors (DFU mode: single DFU interface, EP0 only) */
220/* -------------------------------------------------------------------------- */
221
222/* DFU-mode framework: device (PID 0x0019) + one config with a single DFU
223 * interface (class 0xFE / subclass 0x01 / protocol 0x02 = DFU mode, so USBX
224 * enumerates straight into dfuIDLE) + the DFU functional descriptor
225 * (CAN_DNLOAD | CAN_UPLOAD | MANIFESTATION_TOLERANT, wTransferSize 64). No data
226 * endpoints -- DFU runs over EP0. Layout per DFU 1.1 + USB 2.0 sec 9.6. */
227static UCHAR s_device_framework[] = {
228 /* Device descriptor (18 bytes). idVendor 0x1209, idProduct 0x0019. */
229 0x12U,
230 0x01U,
231 0x00U,
232 0x02U,
233 0x00U,
234 0x00U,
235 0x00U,
236 0x40U,
237 0x09U,
238 0x12U,
239 0x19U,
240 0x00U,
241 0x00U,
242 0x01U,
243 0x01U,
244 0x02U,
245 0x03U,
246 0x01U,
247 /* Configuration descriptor (wTotalLength 0x1B = 27). */
248 0x09U,
249 0x02U,
250 0x1BU,
251 0x00U,
252 0x01U,
253 0x01U,
254 0x00U,
255 0x80U,
256 0x32U,
257 /* DFU interface (class 0xFE, subclass 0x01, protocol 0x02 = DFU mode). */
258 0x09U,
259 0x04U,
260 0x00U,
261 0x00U,
262 0x00U,
263 0xFEU,
264 0x01U,
265 0x02U,
266 0x00U,
267 /* DFU functional descriptor. bmAttributes 0x07, wTransferSize 64,
268 bcdDFUVersion 0x0110. */
269 0x09U,
270 0x21U,
271 0x07U,
272 0xFFU,
273 0x00U,
274 0x40U,
275 0x00U,
276 0x10U,
277 0x01U,
278};
279
285static UCHAR s_string_framework[] = {
286 /* idx 1: "Brighton Sikarskie". */
287 0x09U,
288 0x04U,
289 0x01U,
290 0x12U,
291 'B',
292 'r',
293 'i',
294 'g',
295 'h',
296 't',
297 'o',
298 'n',
299 ' ',
300 'S',
301 'i',
302 'k',
303 'a',
304 'r',
305 's',
306 'k',
307 'i',
308 'e',
309 /* idx 2: "RA8D2 DFU". */
310 0x09U,
311 0x04U,
312 0x02U,
313 0x09U,
314 'R',
315 'A',
316 '8',
317 'D',
318 '2',
319 ' ',
320 'D',
321 'F',
322 'U',
323 /* idx 3: serial "00000019". */
324 0x09U,
325 0x04U,
326 0x03U,
327 0x08U,
328 '0',
329 '0',
330 '0',
331 '0',
332 '0',
333 '0',
334 '1',
335 '9',
336};
337
338/* USBX LANGID descriptor 0x0409 (English-US), little-endian byte pair. */
339typedef enum : uint8_t {
343
346
347/* -------------------------------------------------------------------------- */
348/* Device side: USBX DFU class callbacks */
349/* -------------------------------------------------------------------------- */
350
362static VOID dfu_device_worker(ULONG arg)
363{
364 (void)arg;
365
366 /* Config A device half: the FS controller runs the DFU device class wired
367 * to real MRAM (libs/ra8_dfu). DFU_DNLOAD programs the inactive Slot B. */
371 (uint32_t)sizeof(s_usbx_pool),
373 (uint32_t)sizeof(s_device_framework),
375 (uint32_t)sizeof(s_string_framework),
377 (uint32_t)sizeof(s_language_id_framework));
378 if (e != k_ra8_ok) {
379 s_dbg_host_err = (uint32_t)e;
380 return;
381 }
382 s_dbg_dev_step = 4U;
383 /* Each DFU_DNLOAD block is programmed synchronously inside the DFU write
384 * callback; this worker only finalizes the image header once the host
385 * signals end-of-download (the self-test uses DFU_ABORT, so that path is
386 * the bootloader's, not this twin's). */
387 while (1) {
390 }
391}
392
393/* -------------------------------------------------------------------------- */
394/* Console helpers (SCI8 -> J-Link OB CDC) */
395/* -------------------------------------------------------------------------- */
396
409static uint8_t dfu_nibble_to_hex(uint32_t nibble)
410{
411 if (nibble < k_dfu_hex_digit_split) {
412 return (uint8_t)((uint8_t)'0' + (uint8_t)nibble);
413 }
414 return (uint8_t)((uint8_t)'A' + (uint8_t)nibble - (uint8_t)k_dfu_hex_digit_split);
415}
416
429static uint32_t dfu_str_len(const char* text)
430{
431 uint32_t len = 0U;
432 while (len < (uint32_t)k_dfu_print_cap) {
433 if (text[len] == '\0') {
434 break;
435 }
436 len++;
437 }
438 return len;
439}
440
454[[nodiscard]] static ra8_err_t dfu_sci_write(const uint8_t* data, uint32_t len)
455{
456 return ra8_board_uart_console_write(data, (size_t)len);
457}
458
471[[nodiscard]] static ra8_err_t dfu_print(const char* text)
472{
473 return dfu_sci_write((const uint8_t*)text, dfu_str_len(text));
474}
475
489[[nodiscard]] static ra8_err_t dfu_print_hex(uint32_t value, uint8_t digits)
490{
491 uint8_t out[k_dfu_hex_chars_u32] = {};
492 uint8_t width = digits;
493 if (width > (uint8_t)k_dfu_hex_chars_u32) {
494 width = (uint8_t)k_dfu_hex_chars_u32;
495 }
496 for (uint8_t i = 0U; i < width; i++) {
497 const uint8_t shift = (uint8_t)((width - 1U - i) * k_dfu_nibble_bits);
498 out[i] = dfu_nibble_to_hex((value >> shift) & k_dfu_nibble_mask);
499 }
500 return dfu_sci_write(out, (uint32_t)width);
501}
502
516[[nodiscard]] static ra8_err_t dfu_print_fail(const char* what, ra8_err_t err)
517{
518 ra8_err_t e = dfu_print("ra8d2 dfu: FAIL ");
519 if (e != k_ra8_ok) {
520 return e;
521 }
522 e = dfu_print(what);
523 if (e != k_ra8_ok) {
524 return e;
525 }
526 e = dfu_print(" err=0x");
527 if (e != k_ra8_ok) {
528 return e;
529 }
530 e = dfu_print_hex((uint32_t)err, (uint8_t)k_dfu_hex_chars_u32);
531 if (e != k_ra8_ok) {
532 return e;
533 }
534 return dfu_print("\r\n");
535}
536
537/* -------------------------------------------------------------------------- */
538/* Host side: enumerate, then DFU download + upload-verify */
539/* -------------------------------------------------------------------------- */
540
566
583
595[[nodiscard]] static ra8_err_t dfu_host_pass(void)
596{
597 s_dbg_phase = (uint32_t)k_dfu_phase_init;
598 ra8_err_t err =
599 dfu_print("ra8d2 dfu-boot: host up, DFU-flashing a bootable Slot-A payload...\r\n");
600 if (err != k_ra8_ok) {
601 return err;
602 }
603
604 /* Real DFU flash flow: DFU_DNLOAD the bootable Slot-A image, then a
605 * zero-length DFU_DNLOAD (manifest) so the DEVICE commits the slot header --
606 * exactly what dfu-util drives, but over the self-loop so no external host is
607 * needed. The device half runs on this same chip (Slot A target). */
609 ra8_dfu_host_result_t res = {};
612 (uint32_t)sizeof(s_boot_payload),
613 &res);
614 s_dbg_pid = res.pid;
615 if (err != k_ra8_ok) {
616 (void)dfu_print_fail("dfu program", err);
617 return err;
618 }
619
620 /* Wait for the device worker to commit the header, then confirm Slot A is
621 * bootable (CRC over the just-programmed body matches) from this side. */
622 bool committed = false;
623 for (uint32_t i = 0U; i < (uint32_t)k_dfu_commit_tries; i++) {
625 committed = true;
626 break;
627 }
629 }
630 if (!committed) {
631 (void)dfu_print_fail("commit timeout", k_ra8_err_hw_timeout);
633 }
635 if (cerr != k_ra8_ok) {
636 (void)dfu_print_fail("device commit", cerr);
637 return cerr;
638 }
640 (void)dfu_print_fail("Slot A not bootable after commit", k_ra8_err_crc_mismatch);
642 }
643
644 s_dbg_phase = (uint32_t)k_dfu_phase_pass;
646 err = dfu_print(
647 "ra8d2 dfu-boot: Slot A DFU-committed + bootable -- USB SELFTEST DFU-BOOT COMMIT PASS\r\n");
648 if (err != k_ra8_ok) {
649 return err;
650 }
652 return k_ra8_ok;
653}
654
666static VOID dfu_host_worker(ULONG arg)
667{
668 (void)arg;
669
671 for (;;) {
672 const ra8_err_t err = dfu_host_pass();
673 if (err == k_ra8_ok) {
674 break;
675 }
676 s_dbg_host_err = (uint32_t)err;
678 }
679 while (1) {
681 }
682}
683
695VOID tx_application_define(VOID* first_unused_memory)
696{
697 static CHAR s_device_thread_name[] = "dfu_device";
698 static CHAR s_host_thread_name[] = "dfu_host";
699
700 (void)first_unused_memory;
701 s_tx_kernel_up = true;
705 0UL,
715 0UL,
722}
723#endif /* !RA8_OFF_TARGET */
724
725/* -------------------------------------------------------------------------- */
726/* Startup */
727/* -------------------------------------------------------------------------- */
728
739static void dfu_panic_halt(void)
740{
741 while (1) {
742 __asm__ volatile("wfi");
743 }
744}
745
780
791static void dfu_setup_or_halt(void)
792{
793 uint32_t cpuclk0_hz = 0U;
794 if (ra8_cgc_init() != k_ra8_ok) {
796 }
799 }
802 }
805 }
806 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
808 }
811 }
814 }
817 }
819}
820
830void main(void)
831{
833
835
836#ifndef RA8_OFF_TARGET
837 tx_kernel_enter();
838#endif
839
841}
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 TX_THREAD s_device_thread
ThreadX TCB for the USBX device-side worker thread.
Definition main.c:164
static UCHAR s_string_framework[]
USBX string descriptor table (vendor / product / serial).
Definition main.c:299
static UCHAR s_usbx_pool[k_wlun_usbx_pool_bytes]
USBX memory pool (USBX uses tx_byte_pool internally).
Definition main.c:193
usb_langid_byte_t
Definition main.c:358
@ k_usb_langid_en_us_lo
LANGID 0x0409 low byte.
Definition main.c:359
@ k_usb_langid_en_us_hi
LANGID 0x0409 high byte.
Definition main.c:360
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 UCHAR s_language_id_framework[]
USBX language-id table – US English.
Definition main.c:368
static UCHAR s_device_stack[k_wlun_thread_stack]
Stack backing storage for s_device_thread.
Definition main.c:171
static volatile uint32_t s_dbg_dev_step
Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach, 5 parked.
Definition main.c:219
static CHAR s_device_thread_name[]
Definition main.c:201
static UCHAR s_device_framework[]
USBX device + DFU descriptors: a DFU-mode interface (bInterfaceProtocol 0x02, enumerates straight int...
Definition main.c:206
static volatile uint32_t s_dbg_dev_writes
Device-side download block-write count.
Definition main.c:212
static ra8_err_t dfu_print_fail(const char *what, ra8_err_t err)
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
Definition main.c:516
static const ra8_port_pin_t k_dfu_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
Definition main.c:107
static ra8_err_t dfu_sci_write(const uint8_t *data, uint32_t len)
Push a literal block over the board UART console (SCI8) polled.
Definition main.c:454
static void dfu_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
Definition main.c:739
static ra8_err_t dfu_host_pass(void)
Run the full host pass: enumerate, download, upload-verify.
Definition main.c:595
static const ra8_port_pin_t k_dfu_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS.
Definition main.c:110
static const ra8_port_pin_t k_dfu_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
Definition main.c:98
static VOID dfu_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds, then park.
Definition main.c:666
dfu_config_t
Compile-time settings: threads, pool, console, cadence.
Definition main.c:120
@ k_dfu_print_cap
Bound for console-string scans.
Definition main.c:128
@ k_dfu_usbx_pool_bytes
USBX memory pool (bytes).
Definition main.c:123
@ k_dfu_host_priority
Host worker priority (below USBX).
Definition main.c:130
@ k_dfu_retry_ticks
Pause between ladder retries.
Definition main.c:126
@ k_dfu_boot_wait_ticks
Host start delay (1 ms ticks).
Definition main.c:125
@ k_dfu_dev_priority
Device bring-up worker priority.
Definition main.c:129
@ k_dfu_thread_stack
Device worker stack (bytes).
Definition main.c:121
@ k_dfu_baud
J-Link OB CDC log baud.
Definition main.c:127
@ k_dfu_idle_ticks
Parked-loop back-off (ticks).
Definition main.c:124
@ k_dfu_commit_tries
Polls awaiting the device commit.
Definition main.c:131
@ k_dfu_host_stack
Host worker stack (bytes).
Definition main.c:122
dfu_req_t
Chapter-9 + DFU class request / descriptor constants.
Definition main.c:545
@ k_dfu_breq_dnload
DFU_DNLOAD.
Definition main.c:553
@ k_dfu_breq_getstatus
DFU_GETSTATUS.
Definition main.c:555
@ k_dfu_breq_get_desc
GET_DESCRIPTOR.
Definition main.c:550
@ k_dfu_byte_bits
Bits per byte.
Definition main.c:560
@ k_dfu_bm_std_dev_in
bmRequestType: Std | Device | In.
Definition main.c:546
@ k_dfu_getstatus_len
DFU_GETSTATUS payload len.
Definition main.c:561
@ k_dfu_breq_set_config
SET_CONFIGURATION.
Definition main.c:552
@ k_dfu_breq_set_addr
SET_ADDRESS.
Definition main.c:551
@ k_dfu_desc_device
DEVICE descriptor type.
Definition main.c:557
@ k_dfu_off_dev_pid
idProduct LSB byte offset.
Definition main.c:559
@ k_dfu_state_dnload_idle
dfuDNLOAD-IDLE.
Definition main.c:563
@ k_dfu_bm_class_if_in
bmRequestType: Class | Interface | In.
Definition main.c:549
@ k_dfu_breq_abort
DFU_ABORT (-> dfuIDLE).
Definition main.c:556
@ k_dfu_dev_desc_len
DEVICE descriptor length.
Definition main.c:558
@ k_dfu_breq_upload
DFU_UPLOAD.
Definition main.c:554
@ k_dfu_bm_class_if_out
bmRequestType: Class | Interface | Out.
Definition main.c:548
@ k_dfu_state_idle
dfuIDLE.
Definition main.c:564
@ k_dfu_bm_std_dev_out
bmRequestType: Std | Device | Out.
Definition main.c:547
@ k_dfu_off_status_state
bState offset in GETSTATUS.
Definition main.c:562
dfu_enum_tune_t
Timing / retry tunables for the polled enumeration + status polling.
Definition main.c:571
@ k_dfu_reset_hold_ms
USB bus-reset hold (>=10 ms).
Definition main.c:575
@ k_dfu_attach_to_ms
Wait for the D+ pull-up.
Definition main.c:573
@ k_dfu_enum_tries
Reset+probe attempts.
Definition main.c:580
@ k_dfu_attach_spin
Attach spin cap (frozen-tick guard).
Definition main.c:581
@ k_dfu_recovery_ms
Post-reset recovery (TRSTRCY).
Definition main.c:576
@ k_dfu_status_poll_ms
Pause between GETSTATUS polls.
Definition main.c:578
@ k_dfu_addr_settle_ms
Post-SET_ADDRESS recovery.
Definition main.c:577
@ k_dfu_vbus_settle_ms
VBUS settle before probing.
Definition main.c:572
@ k_dfu_debounce_ms
Post-attach debounce (>=100 ms).
Definition main.c:574
@ k_dfu_status_tries
GETSTATUS polls before giving up.
Definition main.c:579
static VOID dfu_device_worker(ULONG arg)
Device-side worker: bring the DFU device up, then park.
Definition main.c:362
static const UCHAR s_boot_payload[64]
A real bootable Slot-A image the host DFU-flashes: a 64 KiB-aligned vector table (initial MSP,...
Definition main.c:193
static volatile uint32_t s_dbg_pid
Device-reported product id captured at enumeration.
Definition main.c:208
static const ra8_port_pin_t k_dfu_pin_fs_dm
USBFS D- (P8_15).
Definition main.c:104
static uint8_t dfu_nibble_to_hex(uint32_t nibble)
Format one nibble (0..15) into an uppercase hex character.
Definition main.c:409
static void dfu_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
Definition main.c:791
dfu_phase_t
J-Link probe values marking host-ladder progress.
Definition main.c:156
@ k_dfu_phase_init
Host controller init.
Definition main.c:158
@ k_dfu_phase_pass
Image verified byte-equal.
Definition main.c:162
@ k_dfu_phase_upload
Running DFU_UPLOAD.
Definition main.c:161
@ k_dfu_phase_download
Running DFU_DNLOAD.
Definition main.c:160
@ k_dfu_phase_enum
Enumerating.
Definition main.c:159
@ k_dfu_phase_boot
Host thread not started.
Definition main.c:157
static ra8_err_t dfu_print_hex(uint32_t value, uint8_t digits)
Print a value as fixed-width uppercase hex.
Definition main.c:489
static const ra8_port_pin_t k_dfu_pin_fs_dp
USBFS D+ (P8_14).
Definition main.c:101
static const ra8_port_pin_t k_dfu_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
Definition main.c:95
static uint32_t dfu_str_len(const char *text)
Bounded ASCII string length (cap k_dfu_print_cap).
Definition main.c:429
static void dfu_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
Definition main.c:756
static ra8_err_t dfu_print(const char *text)
Print a NUL-terminated ASCII string over the console.
Definition main.c:471
static volatile uint32_t s_dbg_host_err
Host-ladder first failing return code (0 = none).
Definition main.c:216
dfu_hex_t
Hex/decimal text-formatter sizing constants.
Definition main.c:138
@ k_dfu_hex_chars_u32
32-bit value -> "ABCDEF01".
Definition main.c:139
@ k_dfu_hex_digit_split
Threshold between '0-9'/'A-F'.
Definition main.c:141
@ k_dfu_nibble_bits
Bits per hex nibble.
Definition main.c:140
dfu_mask_t
Bit-mask constant used by the hex formatter.
Definition main.c:148
@ k_dfu_nibble_mask
4-bit nibble mask.
Definition main.c:149
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_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
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.
Controller-agnostic USB-DFU MRAM bootloader core for the RA8D2.
@ k_ra8_dfu_slot_a
Slot A (0x02020000).
Definition ra8_dfu.h:134
bool ra8_dfu_slot_valid(ra8_dfu_slot_t slot)
Validate a slot live: header magic/length/CRC over its real image.
USBX DFU device class wired to real MRAM, bound to either controller.
ra8_err_t ra8_dfu_device_last_error(void)
Latched last program error (diagnostic).
ra8_err_t ra8_dfu_device_start(ra8_usb_speed_t speed, void *usbx_pool, uint32_t pool_bytes, unsigned char *framework, uint32_t framework_len, unsigned char *strings, uint32_t strings_len, unsigned char *langids, uint32_t langids_len)
Bring up USBX + the DFU class on one controller and raise D+.
void ra8_dfu_device_set_target(ra8_dfu_slot_t target_slot)
Select the slot DFU_DNLOAD programs into / DFU_UPLOAD reads from.
ra8_err_t ra8_dfu_device_worker_step(void)
Program any pending DNLOAD block into MRAM; commit on end-of-download.
bool ra8_dfu_device_committed(void)
Whether the image header has been committed (slot now bootable).
Polled on-board USB-DFU host driver, bound to either controller.
ra8_err_t ra8_dfu_host_program(ra8_usb_speed_t host_speed, const uint8_t *img, uint32_t img_len, ra8_dfu_host_result_t *out)
Enumerate, DFU_DNLOAD img, then a zero-length DFU_DNLOAD (manifest).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
Definition ra8_err.h:423
@ 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
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
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
Native USB controller driver public API (device + host modes).
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
@ k_ra8_usb_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
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.
Outcome of a DFU round-trip for diagnostics / banners.
uint32_t pid
Enumerated idProduct.
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).
USBX device-controller-driver (DCD) bridge to ra8_usb.