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
54
55#include <stdint.h>
56
57#include "ra8_board_ek_ra8d2.h"
58#include "ra8_boot_entry.h"
59#include "ra8_cgc.h"
60#include "ra8_dfu.h"
61#include "ra8_dfu_device.h"
62#include "ra8_err.h"
63#include "ra8_gpio_constants.h"
64#include "ra8_isr.h"
65#include "ra8_port_constants.h"
66#include "ra8_port_utils.h"
67#include "ra8_sci.h"
68#include "ra8_time.h"
69#include "ra8_usb.h"
70#ifdef RA8_ENABLE_ROOT_OF_TRUST
71#include "mbedtls/memory_buffer_alloc.h"
72#include "ra8_psa_crypto.h"
73#endif
74
75#ifndef RA8_OFF_TARGET
76#include "tx_api.h"
77#include "ux_api.h"
78#include "ux_dcd_ra8_usb.h"
79#include "ux_device_class_dfu.h"
80#include "ux_device_stack.h"
81
82extern void _tx_timer_interrupt(void);
83
89static volatile bool s_tx_kernel_up = false;
90
91void SysTick_Handler(void);
100#endif
101
102/* -------------------------------------------------------------------------- */
103/* Pinout (FSP-aligned, EK-RA8D2 v1 User's Manual) */
104/* -------------------------------------------------------------------------- */
105
108
111
114
117
120
123
124/* -------------------------------------------------------------------------- */
125/* Tunables */
126/* -------------------------------------------------------------------------- */
127
141
151
153typedef enum : uint32_t {
155} blc_mask_t;
156
165typedef enum : uintptr_t {
166 k_blc_scb_aircr_addr = 0xE000ED0CU,
167} blc_scb_t;
168
170typedef enum : uint32_t {
171 k_blc_aircr_sysreset = 0x05FA0004U,
173
184[[gnu::section(".noinit")]] static volatile uint32_t g_dfu_trigger;
185
186#ifndef RA8_OFF_TARGET
187
188/* -------------------------------------------------------------------------- */
189/* ThreadX worker + USBX pool storage */
190/* -------------------------------------------------------------------------- */
191
198
206static UCHAR s_device_framework[] = {
207 /* Device descriptor (18 bytes). idVendor 0x1209, idProduct 0x0019. */
208 0x12U,
209 0x01U,
210 0x00U,
211 0x02U,
212 0x00U,
213 0x00U,
214 0x00U,
215 0x40U,
216 0x09U,
217 0x12U,
218 0x19U,
219 0x00U,
220 0x00U,
221 0x01U,
222 0x01U,
223 0x02U,
224 0x03U,
225 0x01U,
226 /* Configuration descriptor (wTotalLength 0x1B = 27). */
227 0x09U,
228 0x02U,
229 0x1BU,
230 0x00U,
231 0x01U,
232 0x01U,
233 0x00U,
234 0x80U,
235 0x32U,
236 /* DFU interface (class 0xFE, subclass 0x01, protocol 0x02 = DFU mode). */
237 0x09U,
238 0x04U,
239 0x00U,
240 0x00U,
241 0x00U,
242 0xFEU,
243 0x01U,
244 0x02U,
245 0x00U,
246 /* DFU functional descriptor. bmAttributes 0x07, wTransferSize 64. */
247 0x09U,
248 0x21U,
249 0x07U,
250 0xFFU,
251 0x00U,
252 0x40U,
253 0x00U,
254 0x10U,
255 0x01U,
256};
257
263static UCHAR s_string_framework[] = {
264 /* idx 1: "Brighton Sikarskie". */
265 0x09U,
266 0x04U,
267 0x01U,
268 0x12U,
269 'B',
270 'r',
271 'i',
272 'g',
273 'h',
274 't',
275 'o',
276 'n',
277 ' ',
278 'S',
279 'i',
280 'k',
281 'a',
282 'r',
283 's',
284 'k',
285 'i',
286 'e',
287 /* idx 2: "RA8D2 DFU". */
288 0x09U,
289 0x04U,
290 0x02U,
291 0x09U,
292 'R',
293 'A',
294 '8',
295 'D',
296 '2',
297 ' ',
298 'D',
299 'F',
300 'U',
301 /* idx 3: serial "00000019". */
302 0x09U,
303 0x04U,
304 0x03U,
305 0x08U,
306 '0',
307 '0',
308 '0',
309 '0',
310 '0',
311 '0',
312 '1',
313 '9',
314};
315
317typedef enum : uint8_t {
321
324
325#endif /* !RA8_OFF_TARGET */
326
327/* -------------------------------------------------------------------------- */
328/* J-Link probes */
329/* -------------------------------------------------------------------------- */
330
332typedef enum : uint32_t {
333 k_blc_dbg_unset = 0xFFFFFFFFU,
334} blc_dbg_t;
335
337static volatile uint32_t s_dbg_action = k_blc_dbg_unset;
339static volatile uint32_t s_dbg_target = k_blc_dbg_unset;
341static volatile uint32_t s_dbg_dev_step;
343static volatile uint32_t s_dbg_dev_err;
344
366volatile uint32_t g_blc_dfu_tick = 0U;
367
368/* -------------------------------------------------------------------------- */
369/* Console helpers (SCI8 -> J-Link OB CDC) */
370/* -------------------------------------------------------------------------- */
371
384static uint8_t blc_nibble_to_hex(uint32_t nibble)
385{
386 if (nibble < k_blc_hex_digit_split) {
387 return (uint8_t)((uint8_t)'0' + (uint8_t)nibble);
388 }
389 return (uint8_t)((uint8_t)'A' + (uint8_t)nibble - (uint8_t)k_blc_hex_digit_split);
390}
391
404static uint32_t blc_str_len(const char* text)
405{
406 uint32_t len = 0U;
407 while (len < (uint32_t)k_blc_print_cap) {
408 if (text[len] == '\0') {
409 break;
410 }
411 len++;
412 }
413 return len;
414}
415
428[[nodiscard]] static ra8_err_t blc_print(const char* text)
429{
430 return ra8_sci_write_polling((uint8_t)k_blc_sci_channel, (const uint8_t*)text, blc_str_len(text));
431}
432
445[[nodiscard]] static ra8_err_t blc_print_hex(uint32_t value)
446{
447 uint8_t out[k_blc_hex_chars_u32] = {};
448 for (uint8_t i = 0U; i < (uint8_t)k_blc_hex_chars_u32; i++) {
449 const uint8_t shift = (uint8_t)(((uint8_t)k_blc_hex_chars_u32 - 1U - i) * k_blc_nibble_bits);
450 out[i] = blc_nibble_to_hex((value >> shift) & k_blc_nibble_mask);
451 }
452 return ra8_sci_write_polling((uint8_t)k_blc_sci_channel, out, (uint32_t)k_blc_hex_chars_u32);
453}
454
455/* -------------------------------------------------------------------------- */
456/* Boot decision + slot hand-off */
457/* -------------------------------------------------------------------------- */
458
483{
484 if (out_target == nullptr) {
485 return k_ra8_dfu_action_dfu; /* safe fallback: never jump on a bad caller */
486 }
487 const bool trig = (g_dfu_trigger == (uint32_t)k_ra8_dfu_trigger_magic);
488 g_dfu_trigger = 0U; /* one-shot: consume the request */
489
490 const bool a_valid = ra8_dfu_slot_valid(k_ra8_dfu_slot_a);
491 const bool b_valid = ra8_dfu_slot_valid(k_ra8_dfu_slot_b);
492 uint32_t a_seq = 0U;
493 uint32_t b_seq = 0U;
494 /* A failed read leaves seq at 0 (treated as oldest) -- a safe default that
495 * never wins the higher-seq tiebreak, so the discarded return is intentional. */
496 (void)ra8_dfu_slot_seq(k_ra8_dfu_slot_a, &a_seq);
497 (void)ra8_dfu_slot_seq(k_ra8_dfu_slot_b, &b_seq);
498
499 const ra8_dfu_slot_t active = ra8_dfu_select_slot(a_valid, a_seq, b_valid, b_seq);
500 *out_target = (active == k_ra8_dfu_slot_none) ? k_ra8_dfu_slot_a : ra8_dfu_other_slot(active);
501
502 return ra8_dfu_boot_decide(trig, a_valid, a_seq, b_valid, b_seq);
503}
504
530{
531 ra8_dfu_img_hdr_t hdr = {};
532 if (ra8_dfu_read_header(slot, &hdr) != k_ra8_ok) {
533 return; /* unreadable header -> let main fall through to DFU */
534 }
536 /* Returns only if ra8_dfu_run_target_valid rejected the image -> main -> DFU. */
537}
538
539#ifndef RA8_OFF_TARGET
540
550[[noreturn]] static void blc_system_reset(void)
551{
552 __asm__ volatile("dsb 0xF" ::: "memory");
553 /* HUM Ch 6.1 Table 6.1 p 244 "Software reset (AIRCR.SYSRESETREQ)"; the
554 * Cortex-M85 AIRCR itself is defined in ARMv8-M ARM B3.2.6 at 0xE000ED0C. */
555 *(volatile uint32_t*)(uintptr_t)k_blc_scb_aircr_addr = (uint32_t)k_blc_aircr_sysreset;
556 __asm__ volatile("dsb 0xF" ::: "memory");
557 /* NASA Rule 2 exemption: spin until the reset lands (a few cycles); the
558 * function is [[noreturn]] and never iterates unboundedly in practice. */
559 while (1) {
560 __asm__ volatile("wfi");
561 }
562}
563
575static VOID blc_device_worker(ULONG arg)
576{
577 (void)arg;
578
581 (uint32_t)sizeof(s_usbx_pool),
583 (uint32_t)sizeof(s_device_framework),
585 (uint32_t)sizeof(s_string_framework),
587 (uint32_t)sizeof(s_language_id_framework));
588 if (e != k_ra8_ok) {
589 s_dbg_dev_err = (uint32_t)e;
590 (void)blc_print("dfu-bootloader: FAIL device bring-up\r\n");
591 return;
592 }
593 s_dbg_dev_step = 4U;
594 (void)blc_print("dfu-bootloader: DFU device up on USB-FS, awaiting DFU_DNLOAD...\r\n");
595
596 /* NASA Rule 2 exemption: deliberate RTOS service loop. It exits only via
597 * blc_system_reset() once an image commits (that call does not return). */
598 while (1) {
600 g_blc_dfu_tick += 1U; /* HIL liveness: proves the DFU service loop iterates */
602 (void)blc_print("dfu-bootloader: image committed -- resetting into new slot\r\n");
604 }
606 }
607}
608
619VOID tx_application_define(VOID* first_unused_memory)
620{
621 static CHAR s_device_thread_name[] = "dfu_device";
622
623 (void)first_unused_memory;
624 s_tx_kernel_up = true;
628 0UL,
635}
636#endif /* !RA8_OFF_TARGET */
637
638/* -------------------------------------------------------------------------- */
639/* Startup */
640/* -------------------------------------------------------------------------- */
641
652[[noreturn]] static void blc_panic_halt(void)
653{
654 /* NASA Rule 2 exemption: terminal panic spin -- intentionally never exits. */
655 while (1) {
656 __asm__ volatile("wfi");
657 }
658}
659
685
686#ifdef RA8_ENABLE_ROOT_OF_TRUST
691typedef enum : uint32_t {
692 k_blc_psa_heap_bytes = 0x10000U,
693} blc_rot_const_t;
694
704static uint8_t s_blc_psa_heap[k_blc_psa_heap_bytes];
705#endif
706
717static void blc_setup_or_halt(void)
718{
719 uint32_t cpuclk0_hz = 0U;
720 uint32_t pclka_hz = 0U;
721 if (ra8_cgc_init() != k_ra8_ok) {
723 }
726 }
729 }
732 }
733 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
735 }
738 }
741 }
742 const ra8_sci_cfg_t sci_cfg = {
743 .baud = k_blc_baud,
744 .data_bits = k_ra8_sci_data_8,
745 .parity = k_ra8_sci_parity_none,
746 .stop_bits = k_ra8_sci_stop_1,
747 .pclk_hz = pclka_hz,
748 };
749 if (ra8_sci_init((uint8_t)k_blc_sci_channel, &sci_cfg) != k_ra8_ok) {
751 }
754 }
755#ifdef RA8_ENABLE_ROOT_OF_TRUST
756 /* Bring up the tf-psa-crypto backend for the root-of-trust launch gate: a
757 * static buffer-alloc arena (no malloc) then psa_crypto_init. A failure here
758 * means the bootloader cannot authenticate any slot, so halt rather than boot
759 * an unverified image. */
760 mbedtls_memory_buffer_alloc_init(s_blc_psa_heap, sizeof(s_blc_psa_heap));
761 if (ra8_psa_crypto_init() != k_ra8_ok) {
763 }
764#endif
766}
767
777void main(void)
778{
781
782 (void)blc_print("\r\nra8d2 dfu-bootloader (immutable, 128K @ 0x02000000)\r\n");
783
785 const ra8_dfu_action_t action = blc_decide(&target);
786 s_dbg_action = (uint32_t)action;
787 s_dbg_target = (uint32_t)target;
788
789 if (action == k_ra8_dfu_action_jump_a) {
790 (void)blc_print("dfu-bootloader: Slot A -> copy-to-run @0x");
791 (void)blc_print_hex((uint32_t)k_ra8_dfu_run_base);
792 (void)blc_print("\r\n");
793 blc_boot_slot(k_ra8_dfu_slot_a); /* returns only if the run target is invalid */
794 }
795 if (action == k_ra8_dfu_action_jump_b) {
796 (void)blc_print("dfu-bootloader: Slot B -> copy-to-run @0x");
797 (void)blc_print_hex((uint32_t)k_ra8_dfu_run_base);
798 (void)blc_print("\r\n");
799 blc_boot_slot(k_ra8_dfu_slot_b); /* returns only if the run target is invalid */
800 }
801
802 /* k_ra8_dfu_action_dfu (or a slot whose run target failed validation): no
803 * bootable slot -- accept a DFU update into the inactive slot over USB-FS. */
804 (void)blc_print("dfu-bootloader: no bootable slot -- entering DFU\r\n");
805#ifndef RA8_OFF_TARGET
807 tx_kernel_enter();
808#endif
809
811}
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 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 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 volatile uint32_t s_dbg_dev_err
Device worker first failing return code (0 = none).
Definition main.c:221
static CHAR s_device_thread_name[]
Definition main.c:201
blc_reset_t
AIRCR write to request a system reset (VECTKEY 0x05FA | SYSRESETREQ).
Definition main.c:170
@ k_blc_aircr_sysreset
0x05FA<<16 | (1<<2).
Definition main.c:171
static volatile uint32_t s_dbg_action
Boot decision outcome (ra8_dfu_action_t), J-Link-readable.
Definition main.c:337
blc_mask_t
4-bit nibble mask for the hex formatter.
Definition main.c:153
@ k_blc_nibble_mask
4-bit nibble mask.
Definition main.c:154
blc_dbg_t
J-Link debug-probe "not yet written" sentinel.
Definition main.c:332
@ k_blc_dbg_unset
Probe word value before main writes it.
Definition main.c:333
static ra8_err_t blc_print(const char *text)
Print a NUL-terminated ASCII string over SCI8 (polled).
Definition main.c:428
static const ra8_port_pin_t k_blc_pin_sci_rx
J-Link OB CDC RX pin (PD_03 – SCI8 RX).
Definition main.c:122
blc_scb_t
Cortex-M85 System Control Block address used by the DFU-commit reset.
Definition main.c:165
@ k_blc_scb_aircr_addr
SCB->AIRCR (reset control).
Definition main.c:166
static VOID blc_device_worker(ULONG arg)
DFU device worker: bring the DFU class up, drain commits, reset on done.
Definition main.c:575
static const ra8_port_pin_t k_blc_pin_fs_dm
USBFS D- (P8_15).
Definition main.c:116
static void blc_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
Definition main.c:652
static UCHAR s_device_framework[]
USBX device + DFU descriptors: a DFU-mode interface (bInterfaceProtocol 0x02, enumerates straight int...
Definition main.c:206
static void blc_system_reset(void)
Request a system reset via AIRCR.SYSRESETREQ.
Definition main.c:550
static void blc_route_usb_or_halt(void)
Route the USB-FS device pins (P4_07/P5_00/P8_14/P8_15).
Definition main.c:670
static const ra8_port_pin_t k_blc_pin_sci_tx
J-Link OB CDC TX pin (PD_02 – SCI8 TX).
Definition main.c:119
static uint8_t blc_nibble_to_hex(uint32_t nibble)
Format one nibble (0..15) into an uppercase hex character.
Definition main.c:384
static const ra8_port_pin_t k_blc_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
Definition main.c:110
static const ra8_port_pin_t k_blc_pin_fs_dp
USBFS D+ (P8_14).
Definition main.c:113
static volatile uint32_t s_dbg_target
Slot the DFU path targets (ra8_dfu_slot_t), J-Link-readable.
Definition main.c:339
static ra8_err_t blc_print_hex(uint32_t value)
Print a value as fixed-width (8-digit) uppercase hex.
Definition main.c:445
static volatile uint32_t g_dfu_trigger
No-init SRAM word an application writes (== k_ra8_dfu_trigger_magic) before resetting to request the ...
Definition main.c:184
blc_hex_t
Hex text-formatter sizing constants.
Definition main.c:146
@ k_blc_nibble_bits
Bits per hex nibble.
Definition main.c:148
@ k_blc_hex_chars_u32
32-bit value -> "ABCDEF01".
Definition main.c:147
@ k_blc_hex_digit_split
Threshold between '0-9'/'A-F'.
Definition main.c:149
static void blc_setup_or_halt(void)
Bring CGC + USB-FS clock + SysTick + SCI8 + LEDs + pins up.
Definition main.c:717
static ra8_dfu_action_t blc_decide(ra8_dfu_slot_t *out_target)
Read the trigger + both slots and resolve the reset-time action.
Definition main.c:482
static const ra8_port_pin_t k_blc_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
Definition main.c:107
blc_config_t
Compile-time settings: thread, pool, console, cadence.
Definition main.c:132
@ k_blc_baud
J-Link OB CDC log baud.
Definition main.c:136
@ k_blc_sci_channel
SCI8 -> J-Link OB CDC bridge.
Definition main.c:137
@ k_blc_usbx_pool_bytes
USBX memory pool (bytes).
Definition main.c:134
@ k_blc_thread_stack
Device worker stack (bytes).
Definition main.c:133
@ k_blc_idle_ticks
Worker back-off (1 ms ticks).
Definition main.c:135
@ k_blc_print_cap
Bound for console-string scans.
Definition main.c:138
@ k_blc_dev_priority
Device bring-up worker priority.
Definition main.c:139
volatile uint32_t g_blc_dfu_tick
HIL liveness counter – advanced once per DFU device service step.
Definition main.c:366
static void blc_boot_slot(ra8_dfu_slot_t slot)
Copy a validated slot's image to the SRAM run base and launch it.
Definition main.c:529
static uint32_t blc_str_len(const char *text)
Bounded ASCII string length (cap k_blc_print_cap).
Definition main.c:404
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_led1
LED1, BLUE, P600 (jumper E27).
@ k_ra8_board_uart_console_pin_txd
PD02 TXD.
@ k_ra8_board_uart_console_pin_rxd
PD03 RXD.
@ 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
@ k_ra8_clock_id_pclka
PCLKA.
Definition ra8_cgc.h:73
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).
Controller-agnostic USB-DFU MRAM bootloader core for the RA8D2.
ra8_err_t ra8_dfu_slot_seq(ra8_dfu_slot_t slot, uint32_t *out_seq)
Read a slot header's sequence number (0 if the magic is wrong).
ra8_dfu_slot_t
Application-slot identifier.
Definition ra8_dfu.h:133
@ k_ra8_dfu_slot_b
Slot B (0x02090000).
Definition ra8_dfu.h:135
@ k_ra8_dfu_slot_a
Slot A (0x02020000).
Definition ra8_dfu.h:134
@ k_ra8_dfu_slot_none
No valid slot present.
Definition ra8_dfu.h:136
ra8_dfu_slot_t ra8_dfu_select_slot(bool a_valid, uint32_t a_seq, bool b_valid, uint32_t b_seq)
Pick the active slot from the two slots' validity + sequence.
ra8_dfu_action_t
Outcome of the reset-time boot decision.
Definition ra8_dfu.h:143
@ k_ra8_dfu_action_jump_b
Jump to the Slot B application.
Definition ra8_dfu.h:146
@ k_ra8_dfu_action_dfu
Enter the DFU device; do not jump.
Definition ra8_dfu.h:144
@ k_ra8_dfu_action_jump_a
Jump to the Slot A application.
Definition ra8_dfu.h:145
@ k_ra8_dfu_trigger_magic
No-init SRAM DFU-request magic.
Definition ra8_dfu.h:106
ra8_err_t ra8_dfu_read_header(ra8_dfu_slot_t slot, ra8_dfu_img_hdr_t *out_hdr)
Copy a slot's 32-byte header out of MRAM.
uintptr_t ra8_dfu_slot_base(ra8_dfu_slot_t slot)
Return the MRAM base address of a slot.
ra8_dfu_action_t ra8_dfu_boot_decide(bool dfu_trigger, bool a_valid, uint32_t a_seq, bool b_valid, uint32_t b_seq)
Reset-time boot decision: jump to a slot, or enter DFU.
ra8_dfu_slot_t ra8_dfu_other_slot(ra8_dfu_slot_t slot)
Return the opposite slot (A<->B).
@ k_ra8_dfu_run_base
SRAM copy-to-run / payload link base.
Definition ra8_dfu.h:126
void ra8_dfu_launch(uintptr_t src, uint32_t img_len, uint32_t entry)
Copy an image to the SRAM run base and branch to it (copy-to-run).
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).
Error Code Definitions for ra8-firmware.
@ 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_sci_async
00100b: SCI async serial (UART).
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_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
Application-level PSA Crypto facade over tf-psa-crypto.
ra8_err_t ra8_psa_crypto_init(void)
One-shot facade initialisation.
Full-featured Serial Communications Interface driver.
ra8_err_t ra8_sci_write_polling(uint8_t channel, const uint8_t *data, uint32_t len)
Send len bytes by polling (convenience wrapper).
Definition ra8_sci.c:516
@ k_ra8_sci_stop_1
RA8 SCI stop 1.
Definition ra8_sci.h:81
@ k_ra8_sci_parity_none
RA8 SCI parity none.
Definition ra8_sci.h:71
ra8_err_t ra8_sci_init(uint8_t channel, const ra8_sci_cfg_t *cfg)
Initialise an SCI channel using the descriptor.
Definition ra8_sci.c:410
@ k_ra8_sci_data_8
RA8 SCI data 8.
Definition ra8_sci.h:91
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_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.
32-byte application-image header at the base of each slot.
Definition ra8_dfu.h:174
uint32_t entry
SRAM run base (== k_ra8_dfu_run_base).
Definition ra8_dfu.h:179
uint32_t img_len
Image body length in bytes (32-byte multiple).
Definition ra8_dfu.h:177
Configuration descriptor for ra8_sci_init.
Definition ra8_sci.h:103
USBX device-controller-driver (DCD) bridge to ra8_usb.