|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
USB self-loop: the board is its own dfu-util – DFU-flash + commit a bootable Slot-A image. More...
#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_dfu.h"#include "ra8_dfu_device.h"#include "ra8_dfu_host.h"#include "ra8_err.h"#include "ra8_gpio_constants.h"#include "ra8_isr.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_time.h"#include "ra8_usb.h"#include "tx_api.h"#include "ux_api.h"#include "ux_dcd_ra8_usb.h"#include "ux_device_class_dfu.h"#include "ux_device_stack.h"Go to the source code of this file.
Functions | |
| void | _tx_timer_interrupt (void) |
| ThreadX 1 ms tick worker. | |
| void | SysTick_Handler (void) |
| Service the SysTick exception selected by the linked application. | |
| static VOID | dfu_device_worker (ULONG arg) |
| Device-side worker: bring the DFU device up, then park. | |
| static uint8_t | dfu_nibble_to_hex (uint32_t nibble) |
| Format one nibble (0..15) into an uppercase hex character. | |
| static uint32_t | dfu_str_len (const char *text) |
| Bounded ASCII string length (cap k_dfu_print_cap). | |
| 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. | |
| static ra8_err_t | dfu_print (const char *text) |
| Print a NUL-terminated ASCII string over the console. | |
| static ra8_err_t | dfu_print_hex (uint32_t value, uint8_t digits) |
| Print a value as fixed-width uppercase hex. | |
| static ra8_err_t | dfu_print_fail (const char *what, ra8_err_t err) |
| Print "FAIL <what> err=0xNNNNNNNN" on its own line. | |
| static ra8_err_t | dfu_host_pass (void) |
| Run the full host pass: enumerate, download, upload-verify. | |
| static VOID | dfu_host_worker (ULONG arg) |
| Host-side worker: retry the full pass until it succeeds, then park. | |
| VOID | tx_application_define (VOID *first_unused_memory) |
| ThreadX application-define hook. | |
| static void | dfu_panic_halt (void) |
| Halt forever in WFI – panic stop on init failure. | |
| static void | dfu_route_usb_or_halt (void) |
| Route both ports' pins: FS as device, HS as host. | |
| static void | dfu_setup_or_halt (void) |
| Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up. | |
| void | main (void) |
| Application entry: bring the board up, then hand off to ThreadX. | |
Variables | |
| static volatile bool | s_tx_kernel_up = false |
| Set in tx_application_define; gates ThreadX tick delivery so a pre-kernel SysTick (the U15 expander I2C blocks for ms during setup) cannot feed ThreadX's zeroed timer state. | |
| static const ra8_port_pin_t | k_dfu_pin_fs_vbus = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbus |
| USBFS VBUS sense pin (P4_07, PSEL = 0x13). | |
| static const ra8_port_pin_t | k_dfu_pin_fs_vbusen = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbusen |
| USBFS VBUSEN (P5_00) – GPIO LOW for the device role. | |
| static const ra8_port_pin_t | k_dfu_pin_fs_dp = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dp |
| USBFS D+ (P8_14). | |
| static const ra8_port_pin_t | k_dfu_pin_fs_dm = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dm |
| USBFS D- (P8_15). | |
| static const ra8_port_pin_t | k_dfu_pin_hs_vbus = (ra8_port_pin_t)k_ra8_board_usbhs_pin_vbus |
| USBHS_VBUS sense pin (P4_08, PSEL = 0x14). | |
| static const ra8_port_pin_t | k_dfu_pin_hs_pwr = (ra8_port_pin_t)k_ra8_board_usbhs_pin_pwr |
| J7 host-power switch (PD07): HIGH = U18 supplies VBUS. | |
| static TX_THREAD | s_device_thread |
| ThreadX TCB for the USBX device-side worker thread. | |
| static UCHAR | s_device_stack [k_dfu_thread_stack] |
| Stack backing storage for s_device_thread. | |
| static TX_THREAD | s_host_thread |
| ThreadX TCB for the host-side worker thread. | |
| static UCHAR | s_host_stack [k_dfu_host_stack] |
| Stack backing storage for s_host_thread. | |
| static UCHAR | s_usbx_pool [k_dfu_usbx_pool_bytes] |
| USBX memory pool (USBX uses tx_byte_pool internally). | |
| 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, reset = entry+1) followed by a reset stub that writes the sentinel 0x600D600D to SRAM 0x22040000 and spins. | |
| static volatile uint32_t | s_dbg_phase |
| Host-ladder phase marker (dfu_phase_t). | |
| static volatile uint32_t | s_dbg_pid |
| Device-reported product id captured at enumeration. | |
| static volatile uint32_t | s_dbg_pass_count |
| Completed full passes (sticky success counter). | |
| static volatile uint32_t | s_dbg_dev_writes |
| Device-side download block-write count. | |
| static volatile uint32_t | s_dbg_dev_step |
| Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach. | |
| static volatile uint32_t | s_dbg_host_err |
| Host-ladder first failing return code (0 = none). | |
| static UCHAR | s_device_framework [] |
| static UCHAR | s_string_framework [] |
| USBX string descriptor table (vendor / product / serial). | |
| static UCHAR | s_language_id_framework [] = {k_usb_langid_en_us_lo, k_usb_langid_en_us_hi} |
| USBX language-id table – US English. | |
USB self-loop: the board is its own dfu-util – DFU-flash + commit a bootable Slot-A image.
Validates the dfu_bootloader's REAL flash flow on-chip, with no external USB host: the two USB ports are cabled to EACH OTHER and one image runs both stacks, so the board plays the dfu-util host AND the DFU device.
After the manifest the driver waits for ra8_dfu_device_committed and confirms Slot A is bootable (ra8_dfu_slot_valid – CRC over the just-programmed body), then prints the pass banner. This exercises the program + COMMIT path the bootloader uses for a real dfu-util flash. The complementary jump – the dfu_bootloader booting this committed slot – is verified by flashing the bootloader and reading the sentinel over J-Link (see dfu_bootloader/README).
Verdicts stream over SCI8 (J-Link OB CDC console, 115200).
FS device: P4_07 VBUS sense, P5_00 VBUSEN GPIO LOW (device role), P8_14 D+, P8_15 D- (PSEL usb_fs). HS host: SW4-8 to Host via the U15 expander, PD07 HIGH (U18 supplies J7 VBUS), P4_08 USBHS_VBUS (PSEL usb_hs). Console: PD_02/ PD_03 SCI8 (PSEL sci_async).
Definition in file main.c.
| enum dfu_config_t : uint32_t |
Compile-time settings: threads, pool, console, cadence.
| enum dfu_enum_tune_t : uint32_t |
Timing / retry tunables for the polled enumeration + status polling.
| enum dfu_hex_t : uint8_t |
| enum dfu_mask_t : uint32_t |
| enum dfu_phase_t : uint32_t |
| enum dfu_req_t : uint16_t |
Chapter-9 + DFU class request / descriptor constants.
| enum usb_langid_byte_t : uint8_t |
|
extern |
ThreadX 1 ms tick worker.
|
static |
Device-side worker: bring the DFU device up, then park.
| [in] | arg | ThreadX entry argument (unused). |
Definition at line 362 of file main.c.
References k_dfu_idle_ticks, k_ra8_dfu_slot_a, k_ra8_ok, k_ra8_usb_speed_fs, ra8_dfu_device_set_target(), ra8_dfu_device_start(), ra8_dfu_device_worker_step(), s_dbg_dev_step, s_dbg_host_err, s_device_framework, s_language_id_framework, s_string_framework, s_usbx_pool, and tx_thread_sleep.
Referenced by tx_application_define().
|
staticnodiscard |
Run the full host pass: enumerate, download, upload-verify.
| k_ra8_ok | The pass printed DFU PASS. |
Definition at line 595 of file main.c.
References dfu_print(), dfu_print_fail(), k_dfu_commit_tries, k_dfu_idle_ticks, k_dfu_phase_download, k_dfu_phase_init, k_dfu_phase_pass, k_ra8_board_led2, k_ra8_dfu_slot_a, k_ra8_err_crc_mismatch, k_ra8_err_hw_timeout, k_ra8_ok, k_ra8_usb_speed_hs, ra8_dfu_host_result_t::pid, ra8_board_led_on(), ra8_dfu_device_committed(), ra8_dfu_device_last_error(), ra8_dfu_host_program(), ra8_dfu_slot_valid(), s_boot_payload, s_dbg_pass_count, s_dbg_phase, s_dbg_pid, and tx_thread_sleep.
Referenced by dfu_host_worker().
|
static |
Host-side worker: retry the full pass until it succeeds, then park.
| [in] | arg | ThreadX entry argument (unused). |
Definition at line 666 of file main.c.
References dfu_host_pass(), k_dfu_boot_wait_ticks, k_dfu_idle_ticks, k_dfu_retry_ticks, k_ra8_ok, s_dbg_host_err, and tx_thread_sleep.
Referenced by tx_application_define().
|
static |
Format one nibble (0..15) into an uppercase hex character.
| [in] | nibble | 4-bit value. |
| '0' | For a zero nibble. |
Definition at line 409 of file main.c.
References k_dfu_hex_digit_split.
Referenced by dfu_print_hex().
|
static |
Halt forever in WFI – panic stop on init failure.
Definition at line 739 of file main.c.
Referenced by dfu_route_usb_or_halt(), dfu_setup_or_halt(), and main().
|
staticnodiscard |
Print a NUL-terminated ASCII string over the console.
| [in] | text | String to print (CR/LF included by the caller). |
| k_ra8_ok | All bytes queued. |
text is non-NULL. text is NUL-terminated within k_dfu_print_cap bytes. Definition at line 471 of file main.c.
References dfu_sci_write(), and dfu_str_len().
Referenced by dfu_host_pass(), and dfu_print_fail().
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
| [in] | what | Short description of the failed step. |
| [in] | err | Error code returned by the step. |
| k_ra8_ok | The diagnostic line is queued. |
what is NUL-terminated within the cap. Definition at line 516 of file main.c.
References dfu_print(), dfu_print_hex(), k_dfu_hex_chars_u32, and k_ra8_ok.
Referenced by dfu_host_pass().
|
staticnodiscard |
Print a value as fixed-width uppercase hex.
| [in] | value | Value to print. |
| [in] | digits | Hex digit count (4 for u16, 8 for u32). |
| k_ra8_ok | All bytes queued. |
digits is at most k_dfu_hex_chars_u32. Definition at line 489 of file main.c.
References dfu_nibble_to_hex(), dfu_sci_write(), k_dfu_hex_chars_u32, k_dfu_nibble_bits, and k_dfu_nibble_mask.
Referenced by dfu_host_pass(), and dfu_print_fail().
|
static |
Route both ports' pins: FS as device, HS as host.
Definition at line 756 of file main.c.
References dfu_panic_halt(), k_dfu_pin_fs_dm, k_dfu_pin_fs_dp, k_dfu_pin_fs_vbus, k_dfu_pin_fs_vbusen, k_dfu_pin_hs_pwr, k_dfu_pin_hs_vbus, k_ra8_level_high, k_ra8_level_low, k_ra8_ok, k_ra8_psel_usb_fs, k_ra8_psel_usb_hs, ra8_board_io_expander_set_usbhs_host_mode(), ra8_gpio_output_init(), and ra8_pfs_route_peripheral().
Referenced by dfu_setup_or_halt().
|
staticnodiscard |
Push a literal block over the board UART console (SCI8) polled.
| [in] | data | Buffer to send. |
| [in] | len | Byte count. |
| k_ra8_ok | All bytes queued. |
data is non-NULL; the board console init already ran. len excludes any NUL terminator. Definition at line 454 of file main.c.
References ra8_board_uart_console_write().
Referenced by dfu_print(), dfu_print_dec(), and dfu_print_hex().
|
static |
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
Definition at line 791 of file main.c.
References dfu_panic_halt(), dfu_route_usb_or_halt(), k_dfu_baud, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_cgc_usbfs_clock_enable(), ra8_cgc_usbhs_pll_enable(), and ra8_time_init().
Referenced by main().
|
static |
Bounded ASCII string length (cap k_dfu_print_cap).
| [in] | text | NUL-terminated string. |
| 0 | For an empty string. |
text is non-NULL with readable storage. text fits the cap. Definition at line 429 of file main.c.
References k_dfu_print_cap.
Referenced by dfu_print().
| void main | ( | void | ) |
Application entry: bring the board up, then hand off to ThreadX.
The application entry point Reset_Handler hands control to.
Definition at line 830 of file main.c.
References dfu_panic_halt(), dfu_setup_or_halt(), and ra8_isr_globals_enable().
| void SysTick_Handler | ( | void | ) |
Service the SysTick exception selected by the linked application.
Service one SysTick event for the core timebase.
Service one SysTick event for the core timebase.
Resolves to the weak core timebase handler unless a strong RTOS or application handler overrides it. The vector table references the selected implementation without owning its subsystem policy.
The weak firmware implementation advances the millisecond counter, then services linked ThreadX and USB hooks when their weak symbols and readiness state permit. The host-test implementation advances only the counter. An application may replace either weak definition with a strong handler.
Service the SysTick exception selected by the linked application.
The weak firmware implementation advances the millisecond counter, then services linked ThreadX and USB hooks when their weak symbols and readiness state permit. The host-test implementation advances only the counter. An application may replace either weak definition with a strong handler.
Service the SysTick exception selected by the linked application.
Definition at line 80 of file main.c.
References _tx_timer_interrupt(), ra8_time_on_tick(), s_tx_kernel_up, and ux_dcd_ra8_usb_irq_reenable().
| VOID tx_application_define | ( | VOID * | first_unused_memory | ) |
ThreadX application-define hook.
Spawns both workers.
| [in] | first_unused_memory | Sentinel (unused; static stacks). |
Definition at line 695 of file main.c.
References dfu_device_worker(), dfu_host_worker(), k_dfu_dev_priority, k_dfu_host_priority, k_dfu_host_stack, k_dfu_thread_stack, s_device_stack, s_device_thread, s_device_thread_name, s_host_stack, s_host_thread, s_host_thread_name, s_tx_kernel_up, TX_AUTO_START, TX_NO_TIME_SLICE, and tx_thread_create.
|
static |
|
static |
|
static |
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
Definition at line 95 of file main.c.
Referenced by dfu_route_usb_or_halt().
|
static |
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
Definition at line 98 of file main.c.
Referenced by dfu_route_usb_or_halt().
|
static |
J7 host-power switch (PD07): HIGH = U18 supplies VBUS.
Definition at line 110 of file main.c.
Referenced by dfu_route_usb_or_halt().
|
static |
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
Definition at line 107 of file main.c.
Referenced by dfu_route_usb_or_halt().
|
static |
A real bootable Slot-A image the host DFU-flashes: a 64 KiB-aligned vector table (initial MSP, reset = entry+1) followed by a reset stub that writes the sentinel 0x600D600D to SRAM 0x22040000 and spins.
Hand-assembled (cortex-m thumb) linked at the Slot-A base 0x02020000, so vector[1] = 0x02020011. After the bootloader jumps to the committed slot, a J-Link read of 0x22040000 == 0x600D600D proves the e-ink-free hand-off executed the DFU-received image. Padded to one 64-byte block.
Definition at line 193 of file main.c.
Referenced by dfu_host_pass().
|
static |
|
static |
Device-side download block-write count.
Definition at line 212 of file main.c.
Referenced by dfu_write().
|
static |
Host-ladder first failing return code (0 = none).
Definition at line 216 of file main.c.
Referenced by dfu_device_worker(), and dfu_host_worker().
|
static |
|
static |
Host-ladder phase marker (dfu_phase_t).
|
static |
Device-reported product id captured at enumeration.
Definition at line 208 of file main.c.
Referenced by cdc_host_pass(), dfu_host_enumerate(), dfu_host_pass(), hid_host_pass(), and hid_host_pass().
|
static |
Stack backing storage for s_device_thread.
|
static |
|
static |
Stack backing storage for s_host_thread.
|
static |
|
static |
|
static |
|
static |
Set in tx_application_define; gates ThreadX tick delivery so a pre-kernel SysTick (the U15 expander I2C blocks for ms during setup) cannot feed ThreadX's zeroed timer state.
|
static |