|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
ThreadX + USBX CDC ACM echo for EK-RA8D2 (USB-FS). More...
#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_gpio_constants.h"#include "ra8_isr.h"#include "ra8_log.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_cdc_acm.h"#include "ux_device_stack.h"#include "ux_system.h"Go to the source code of this file.
Data Structures | |
| struct | demo_diag_t |
| Demo-loop counters; read via JLink to localise stalls. More... | |
Enumerations | |
| enum | demo_config_t : uint32_t { k_demo_thread_stack = 8192U , k_demo_usbx_pool_bytes = 32768U , k_demo_echo_buf_bytes = 64U , k_demo_idle_ticks = 1U } |
| Compile-time settings for the echo loop and ThreadX worker. More... | |
| enum | usb_langid_byte_t : uint8_t { k_usb_langid_en_us_lo = 0x09U , k_usb_langid_en_us_hi = 0x04U } |
Functions | |
| static VOID | demo_cdc_activate (VOID *cdc_instance) |
| CDC-ACM activate callback. | |
| static VOID | demo_cdc_deactivate (VOID *cdc_instance) |
| CDC-ACM deactivate callback. | |
| static UINT | demo_usbx_stack_up (void) |
| Brings USBX system + device stack up with the FS framework. | |
| static UINT | demo_cdc_class_register (void) |
| Registers the CDC-ACM class against the device-stack configuration. | |
| static void | demo_pin_configured_state (void) |
| Pin USBX peripheral state at CONFIGURED. | |
| static void | demo_echo_iter (UCHAR *buf, ULONG cap) |
| One iteration of the CDC echo loop. | |
| static VOID | demo_worker (ULONG arg) |
| Worker thread entry. | |
| VOID | tx_application_define (VOID *first_unused_memory) |
| ThreadX application-define hook. | |
| static void | demo_panic_halt (void) |
| Halt forever in WFI – panic stop on init failure. | |
| static ra8_err_t | demo_pins_init (void) |
| Route the four USB-FS pins to the USBFS controller. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static const ra8_port_pin_t | k_demo_pin_vbus = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbus |
| USB-FS pin identifiers, packed ra8_port_pin_t (port << 8 | pin). | |
| static const ra8_port_pin_t | k_demo_pin_vbusen = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbusen |
| static const ra8_port_pin_t | k_demo_pin_dp = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dp |
| static const ra8_port_pin_t | k_demo_pin_dm = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dm |
| static TX_THREAD | s_demo_thread |
| ThreadX TCB for the USBX worker thread. | |
| static UCHAR | s_demo_stack [k_demo_thread_stack] |
| Stack backing storage for s_demo_thread. | |
| static UCHAR | s_usbx_pool [k_demo_usbx_pool_bytes] |
| USBX memory pool (USBX uses tx_byte_pool internally). | |
| static UX_SLAVE_CLASS_CDC_ACM * | s_cdc_acm = UX_NULL |
| Active CDC-ACM class instance, captured by activate callback. | |
| volatile demo_diag_t | s_demo_diag = {} |
| Externally-readable counters for demo loop progress. | |
| static TX_SEMAPHORE | s_cdc_active_sem |
| Posted by demo_cdc_activate; demo thread blocks on it instead of polling s_cdc_acm with tx_thread_sleep (which never returned on this silicon – SysTick may be silenced under polled-dispatch worker load). | |
| static UCHAR | s_device_framework_fs [] |
| 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. | |
ThreadX + USBX CDC ACM echo for EK-RA8D2 (USB-FS).
Brings the chip up via ra8_cgc_init() (XTAL -> PLL1 -> CPUCLK0 = 1 GHz, PCLKA = 125 MHz), routes the four USB-FS pins per the EK-RA8D2 v1 User's Manual to the on-board USB-FS receptacle, hands control to ThreadX, and brings the CDC ACM device class up via Eclipse USBX (_ux_device_class_cdc_acm_initialize). The class sits on top of the project's port/usbx/ux_dcd_ra8_usb bridge to the hand-written ra8_usb register-level driver (HUM Ch. 36 USBFS, sec. 36.2.x for SYSCFG / DCPCFG / DCPMAXP / PIPECFG / CFIFO). The host actually enumerates the device because USBX's chapter-9 state machine answers SETUP packets through the DCD bridge.
Once enumerated, the worker thread loops on _ux_device_class_cdc_acm_read -> _ux_device_class_cdc_acm_write (echo). LED1 toggles per byte echoed.
| Net | Pin | PFS PSEL |
|---|---|---|
| USB_FS_VBUS | P4_07 | k_ra8_psel_usb_fs (0x13) |
| USB_FS_VBUSEN | P5_00 | k_ra8_psel_usb_fs (0x13) |
| USB_FS_DP | P8_14 | k_ra8_psel_usb_fs (0x13) |
| USB_FS_DM | P8_15 | k_ra8_psel_usb_fs (0x13) |
After flashing, the EK-RA8D2's USB-FS receptacle (J11) enumerates as /dev/cu.usbmodem*. Open it RDWR with picocom or screen and type characters; every byte echoes back and LED1 toggles per byte.
Definition in file main.c.
| enum demo_config_t : uint32_t |
Compile-time settings for the echo loop and ThreadX worker.
| enum usb_langid_byte_t : uint8_t |
|
static |
CDC-ACM activate callback.
Captures the live class instance.
| [in] | cdc_instance | Pointer to UX_SLAVE_CLASS_CDC_ACM. |
Definition at line 420 of file main.c.
References s_cdc_acm, s_cdc_active_sem, and ux_dcd_ra8_usb_auto_echo_enable().
Referenced by demo_cdc_class_register(), and demo_worker_register_cdc().
|
static |
Registers the CDC-ACM class against the device-stack configuration.
| UX_SUCCESS | Class registered. |
Definition at line 511 of file main.c.
References demo_cdc_activate(), and demo_cdc_deactivate().
Referenced by demo_worker().
|
static |
CDC-ACM deactivate callback.
Drops the live class pointer.
| [in] | cdc_instance | Unused. |
Definition at line 457 of file main.c.
References s_cdc_acm.
Referenced by demo_cdc_class_register(), and demo_worker_register_cdc().
|
static |
One iteration of the CDC echo loop.
| [in,out] | buf | Scratch buffer (echo data). |
| [in] | cap | Buffer capacity in bytes. |
Definition at line 565 of file main.c.
References demo_pin_configured_state(), k_demo_idle_ticks, k_ra8_board_led1, ra8_board_led_toggle(), s_cdc_acm, s_demo_diag, and tx_thread_sleep.
Referenced by demo_worker().
|
static |
|
static |
Pin USBX peripheral state at CONFIGURED.
Works around a residual DVSQ-poll race on this silicon that can leave ux_slave_device_state at ATTACHED after SET_CONFIGURATION, breaking _ux_device_class_cdc_acm_read's state gate. Safe to assert once s_cdc_acm is non-NULL.
Definition at line 543 of file main.c.
Referenced by demo_echo_iter().
|
staticnodiscard |
Route the four USB-FS pins to the USBFS controller.
| k_ra8_ok | All four pins routed. |
Definition at line 707 of file main.c.
References k_demo_pin_dm, k_demo_pin_dp, k_demo_pin_vbus, k_demo_pin_vbusen, k_ra8_level_low, k_ra8_ok, k_ra8_psel_usb_fs, ra8_gpio_output_init(), and ra8_pfs_route_peripheral().
|
static |
Brings USBX system + device stack up with the FS framework.
| UX_SUCCESS | Stack initialized. |
Definition at line 481 of file main.c.
References k_demo_usbx_pool_bytes, s_device_framework_fs, s_language_id_framework, s_string_framework, and s_usbx_pool.
Referenced by demo_worker().
|
static |
Worker thread entry.
Brings USBX + CDC up, then echoes forever.
| [in] | arg | Unused (ThreadX entry signature). |
Definition at line 602 of file main.c.
References demo_cdc_class_register(), demo_echo_iter(), demo_usbx_stack_up(), k_demo_echo_buf_bytes, k_demo_idle_ticks, k_ra8_ok, k_ra8_usb_speed_fs, ra8_usb_device_attach(), s_cdc_acm, s_cdc_active_sem, s_demo_diag, tx_thread_sleep, TX_WAIT_FOREVER, and ux_dcd_ra8_usb_initialize().
Referenced by tx_application_define().
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS pins + LED1 + ThreadX.
Definition at line 743 of file main.c.
References demo_panic_halt(), demo_pins_init(), k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_cgc_usbfs_clock_enable(), ra8_isr_globals_enable(), ra8_log_info, ra8_log_init(), and ra8_time_init().
| VOID tx_application_define | ( | VOID * | first_unused_memory | ) |
ThreadX application-define hook.
Spawns the demo worker.
| [in] | first_unused_memory | Sentinel (unused; static stacks). |
Definition at line 654 of file main.c.
References demo_worker(), k_demo_thread_stack, s_cdc_active_sem, s_demo_stack, s_demo_thread, s_thread_name, TX_AUTO_START, TX_NO_TIME_SLICE, and tx_thread_create.
|
static |
|
static |
|
static |
USB-FS pin identifiers, packed ra8_port_pin_t (port << 8 | pin).
Built as a runtime cast so clang-tidy's enum-range check is happy with the otherwise out-of-enum value.
|
static |
|
static |
|
static |
Posted by demo_cdc_activate; demo thread blocks on it instead of polling s_cdc_acm with tx_thread_sleep (which never returned on this silicon – SysTick may be silenced under polled-dispatch worker load).
| volatile demo_diag_t s_demo_diag = {} |
Externally-readable counters for demo loop progress.
Definition at line 182 of file main.c.
Referenced by demo_echo_iter(), demo_worker(), and demo_worker_echo_loop().
|
static |
|
static |
|
static |
|
static |
|
static |