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_err.h"
51#include "ra8_fs.h"
52#include "ra8_gpio_constants.h"
53#include "ra8_isr.h"
54#include "ra8_port_constants.h"
55#include "ra8_port_utils.h"
56#include "ra8_time.h"
57#include "ra8_usb.h"
58#include "ra8_usb_hmsc.h"
59#include "usb_selftest_common.h"
61#include "usb_selftest_device.h"
62#include "usb_selftest_host.h"
63
64#ifndef RA8_OFF_TARGET
65#include "tx_api.h"
66#include "ux_api.h"
67#include "ux_dcd_ra8_usb.h"
68#include "ux_device_class_storage.h"
69#include "ux_device_stack.h"
70
71/* Strong SysTick override: route the tick into BOTH the ra8_time millisecond
72 * counter (for ra8_delay_ms and the polled host stack's timeouts) AND
73 * ThreadX's timer (for tx_thread_sleep and USBX class-thread scheduling).
74 * The 1 ms pulse also recovers the DCD's storm-guard NVIC mask. */
75
76extern void _tx_timer_interrupt(void);
77
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#ifndef RA8_OFF_TARGET
125
126/* -------------------------------------------------------------------------- */
127/* ThreadX worker thread storage (device + host TCBs and stacks) */
128/* -------------------------------------------------------------------------- */
129
137
144
152
159
179{
180 (void)arg;
181
183 for (;;) {
184 const ra8_err_t err = selftest_host_pass();
185 if (err == k_ra8_ok) {
186 break;
187 }
189 }
190 while (1) {
192 }
193}
194
210VOID tx_application_define(VOID* first_unused_memory)
211{
212 static CHAR s_device_thread_name[] = "selftest_device";
213 static CHAR s_host_thread_name[] = "selftest_host";
214
215 (void)first_unused_memory;
216 s_tx_kernel_up = true; /* ThreadX timer state is initialized past here. */
220 0UL,
230 0UL,
237}
238#endif /* !RA8_OFF_TARGET */
239
240/* -------------------------------------------------------------------------- */
241/* Startup helpers */
242/* -------------------------------------------------------------------------- */
243
257static void selftest_panic_halt(void)
258{
259 while (1) {
260 __asm__ volatile("wfi");
261 }
262}
263
281{
282 /* FS port: device role. */
284 k_ra8_ok) {
286 }
289 }
291 k_ra8_ok) {
293 }
295 k_ra8_ok) {
297 }
298 /* HS port: host role. */
301 }
304 }
306 k_ra8_ok) {
308 }
309}
310
326static void selftest_setup_or_halt(void)
327{
328 uint32_t cpuclk0_hz = 0U;
329 if (ra8_cgc_init() != k_ra8_ok) {
331 }
334 }
337 }
340 }
341 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
343 }
346 }
349 }
352 }
354}
355
370void main(void)
371{
373
375
376#ifndef RA8_OFF_TARGET
377 /* tx_kernel_enter is __noreturn -- it never comes back. */
378 tx_kernel_enter();
379#endif
380
382}
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 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_device_stack[k_wlun_thread_stack]
Stack backing storage for s_device_thread.
Definition main.c:171
static CHAR s_device_thread_name[]
Definition main.c:201
static const ra8_port_pin_t k_selftest_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
Definition main.c:105
static VOID selftest_device_worker(ULONG arg)
Device-side worker: bring the FS device stack up, then park.
Definition main.c:416
static const ra8_port_pin_t k_selftest_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
Definition main.c:114
static VOID selftest_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
Definition main.c:457
static void selftest_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
Definition main.c:605
static void selftest_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
Definition main.c:536
static const ra8_port_pin_t k_selftest_pin_fs_dm
USBFS D- (P8_15).
Definition main.c:111
static const ra8_port_pin_t k_selftest_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).
Definition main.c:117
static const ra8_port_pin_t k_selftest_pin_fs_dp
USBFS D+ (P8_14).
Definition main.c:108
static void selftest_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
Definition main.c:559
static const ra8_port_pin_t k_selftest_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
Definition main.c:102
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_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_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
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
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).
Native USB host-side MSC (Mass Storage Class) class layer.
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.
ra8_err_t selftest_host_pass(void)
One full host-side pass: enumerate, mount, browse, verify, WP.
@ k_selftest_boot_wait_ticks
Host start delay (1 ms ticks).
@ k_selftest_thread_stack
Device worker stack (bytes).
@ k_selftest_idle_ticks
Parked-loop back-off (ticks).
@ k_selftest_retry_ticks
Pause between ladder retries.
@ k_selftest_host_priority
Host worker: BELOW the USBX storage class thread (UX_THREAD_PRIORITY_CLASS = 20).
@ k_selftest_dev_priority
Device bring-up worker priority.
@ k_selftest_host_stack
Host worker stack (bytes).
@ k_selftest_baud
J-Link OB CDC log baud.
Shared constants for the usb_selftest_soak translation units.
Shared SCI8 console + text formatters for the soak self-test.
Device-side worker entry of the soak self-test.
Host-side entry point of the soak self-test.
USBX device-controller-driver (DCD) bridge to ra8_usb.