|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
USB Audio Class 1.0 device-mode smoke test for EK-RA8D2 (USB-FS, 48 kHz / 16-bit / stereo iso-IN sine generator). More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_nsc_comms.h"#include "ra8_time.h"#include "ra8_usb.h"#include "ra8_usb_paud.h"Go to the source code of this file.
Enumerations | |
| enum | usb_audio_config_t : uint32_t { k_usb_audio_baud = 115200U , k_usb_audio_log_period = 1000U , k_usb_audio_idle_step_ms = 1U } |
| Numeric configuration constants for the demo. More... | |
| enum | usb_audio_format_t : uint32_t { k_usb_audio_sample_rate_hz = 48000U , k_usb_audio_channels = 2U , k_usb_audio_bytes_per_samp = 2U , k_usb_audio_lut_samples = 48U , k_usb_audio_lut_bytes = (uint32_t)(48U * 2U * 2U) } |
| Audio format constants used to seed the format shadow. More... | |
| enum | usb_audio_volume_t : int16_t { k_usb_audio_volume_0_db = 0 } |
| Q8.8-format volume constant (USB Audio 1.0 sec 5.2.2.4.3.2). More... | |
Functions | |
| static void | internal_usb_audio_panic_halt (void) |
| Park the CPU forever in WFI on fatal init failure. | |
| static void | internal_usb_audio_log (const char *s) |
| Send a NUL-terminated ASCII line over SCI8 (best-effort). | |
| static void | internal_usb_audio_u32_to_ascii (uint32_t value, char *buf, uint32_t cap) |
| Convert a uint32_t to ASCII decimal in caller-supplied buffer. | |
| static void | internal_usb_audio_clocks_or_halt (uint32_t *cpuclk0_hz) |
| Bring up clocks, time, GPIO. | |
| static void | internal_usb_audio_usb_or_halt (void) |
| Bring up USB-FS pin mux + UAC1 class layer + format/volume shadows. | |
| static void | internal_usb_audio_setup_or_halt (void) |
| Bring up CGC + SysTick + GPIO + SCI8 + USB-FS + UAC1. | |
| static ra8_err_t | internal_usb_audio_send_one_frame (void) |
| Push one iso frame (1 ms = 48 stereo samples) on PIPE1. | |
| static void | internal_usb_audio_log_frames (uint32_t frames) |
| Emit one log line announcing the running frame count. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static const uint8_t | s_usb_audio_sine_lut [k_usb_audio_lut_bytes] |
| 1 kHz sine LUT, 48 stereo 16-bit samples per cycle. | |
USB Audio Class 1.0 device-mode smoke test for EK-RA8D2 (USB-FS, 48 kHz / 16-bit / stereo iso-IN sine generator).
Brings the chip up via ra8_cgc_init(), routes the four USB-FS pins to the EK-RA8D2 v1 USB-FS receptacle (J11), brings the device-mode UAC1 stack up via the NSC USB veneers + the ra8_usb_paud class layer, and feeds a precomputed 1 kHz sine wave (48-sample LUT – exactly one cycle at 48 kHz) into the iso-IN endpoint every USB-FS 1 ms frame so the host enumerates the gadget as a UAC1 microphone / headset and renders the test tone.
USB Audio Class 1.0 sec 2.2.5 "Format Type Descriptor" (Type-I PCM 16-bit, 2 channels, 48 kHz) and sec 5.2.3.2.3.1 "Sampling Frequency Control" frame the descriptor + class-request behaviour the driver synthesises around the LUT below.
| Net | Pin | PFS PSEL | Notes |
|---|---|---|---|
| USB_FS_VBUS | P4_07 | k_ra8_psel_usb_fs (0x13) | VBUS sense (input). |
| USB_FS_VBUSEN | P5_00 | k_ra8_psel_usb_fs (0x13) | VBUS-enable drive (output). |
| USB_FS_DP | P8_14 | k_ra8_psel_usb_fs (0x13) | D+ data line (analog buffer). |
| USB_FS_DM | P8_15 | k_ra8_psel_usb_fs (0x13) | D- data line (analog buffer). |
Pin assignments are copied verbatim from examples/usb_cdc_echo because the EK-RA8D2 v1 board only routes USB-FS to one pad set.
ra8_nsc_usb_attach(k_ra8_usb_speed_fs, true) – raise D+ pull-up so the host begins enumeration.
Definition in file main.c.
| enum usb_audio_config_t : uint32_t |
Numeric configuration constants for the demo.
Every literal used by the bring-up path lives here so the magic- number lint never sees a bare integer. The BSP console uses the on-board J-Link OB CDC bridge pins (PD_02 / PD_03) for log output.
| Enumerator | |
|---|---|
| k_usb_audio_baud | J-Link OB CDC log baud. |
| k_usb_audio_log_period | Frames per SCI8 log line. |
| k_usb_audio_idle_step_ms | USB-FS frame period. |
| enum usb_audio_format_t : uint32_t |
Audio format constants used to seed the format shadow.
USB Audio 1.0 sec 2.2.5 "Format Type Descriptor" – Type-I PCM, 16-bit sub-frame, 2 channels, 48 kHz. The LUT below stores 48 stereo samples (one full cycle of a 1 kHz tone), which is exactly the FS iso payload of one microframe.
| enum usb_audio_volume_t : int16_t |
|
static |
Bring up clocks, time, GPIO.
Panic-halts on any failure.
Initializes the CGC, reads CPUCLK0, starts the timebase, and claims LED1 in the dependency order required by the board support package.
| [out] | cpuclk0_hz | Receives CPUCLK0 rate. |
Definition at line 307 of file main.c.
References internal_usb_audio_panic_halt(), 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_INTERNAL, and ra8_time_init().
Referenced by internal_usb_audio_setup_or_halt().
|
static |
Send a NUL-terminated ASCII line over SCI8 (best-effort).
Measures the string locally and forwards exactly its payload bytes to the BSP console without a terminator or dynamic allocation.
| [in] | s | ASCII string (NUL-terminated). May be nullptr. |
Definition at line 227 of file main.c.
References ra8_board_uart_console_write(), and RA8_INTERNAL.
Referenced by internal_usb_audio_log_frames(), and main().
|
static |
Emit one log line announcing the running frame count.
Formats the counter in a bounded stack buffer, emits three string fragments, and toggles the activity LED once.
| [in] | frames | Frame counter snapshot. |
< Decimal buffer for the frame counter.
Definition at line 440 of file main.c.
References internal_usb_audio_log(), internal_usb_audio_u32_to_ascii(), k_ra8_board_led1, ra8_board_led_toggle(), and RA8_INTERNAL.
Referenced by main().
|
static |
Park the CPU forever in WFI on fatal init failure.
Re-enters WFI indefinitely so the failing boot context remains available to a debugger without executing additional peripheral accesses.
Definition at line 202 of file main.c.
References RA8_INTERNAL.
Referenced by internal_usb_audio_clocks_or_halt(), internal_usb_audio_setup_or_halt(), internal_usb_audio_usb_or_halt(), and main().
|
staticnodiscard |
Push one iso frame (1 ms = 48 stereo samples) on PIPE1.
Submits the immutable interleaved stereo LUT as one bounded UAC1 isochronous frame and returns the class driver's exact status.
| k_ra8_ok | Bytes queued onto iso-IN. |
| k_ra8_err_invalid_state | Driver not initialized. |
| k_ra8_err_invalid_arg | LUT byte count out of range. |
Definition at line 418 of file main.c.
References k_usb_audio_lut_bytes, RA8_INTERNAL, ra8_usb_paud_send_frame(), and s_usb_audio_sine_lut.
Referenced by main().
|
static |
Bring up CGC + SysTick + GPIO + SCI8 + USB-FS + UAC1.
Panic-halts on any failure.
Mirrors usb_cdc_echo setup but swaps CDC for the UAC1 audio class. Split into clocks, console, and USB stages so each helper stays inside the NASA-rule-4 line budget.
Definition at line 386 of file main.c.
References internal_usb_audio_clocks_or_halt(), internal_usb_audio_panic_halt(), internal_usb_audio_usb_or_halt(), k_ra8_ok, k_usb_audio_baud, ra8_board_uart_console_init(), and RA8_INTERNAL.
Referenced by main().
|
static |
Convert a uint32_t to ASCII decimal in caller-supplied buffer.
Builds digits in reverse order in a fixed local array and copies as many as fit, always terminating a nonzero-capacity destination.
| [in] | value | Value to format. |
| [out] | buf | Destination buffer (>= 11 bytes incl. NUL). |
| [in] | cap | Capacity of buf in bytes. |
< Dec radix.
< Maximum digits.
Definition at line 259 of file main.c.
References k_dec_radix, and RA8_INTERNAL.
Referenced by internal_usb_audio_log_frames().
|
static |
Bring up USB-FS pin mux + UAC1 class layer + format/volume shadows.
Pin-mux first, then ra8_nsc_usb_init to release the MSTP gate, then ra8_usb_paud_init to install the iso-IN / iso-OUT pipes, then ra8_usb_paud_set_format / ra8_usb_paud_set_volume to seed the format + volume shadows, then ra8_nsc_usb_attach to raise the D+ pull-up so the host begins enumeration.
Definition at line 343 of file main.c.
References internal_usb_audio_panic_halt(), k_ra8_ok, k_ra8_usb_speed_fs, k_usb_audio_bytes_per_samp, k_usb_audio_channels, k_usb_audio_sample_rate_hz, k_usb_audio_volume_0_db, ra8_board_usbhs_device_init(), RA8_INTERNAL, ra8_nsc_usb_attach(), ra8_usb_paud_init(), ra8_usb_paud_set_format(), and ra8_usb_paud_set_volume().
Referenced by internal_usb_audio_setup_or_halt().
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
Definition at line 464 of file main.c.
References internal_usb_audio_log(), internal_usb_audio_log_frames(), internal_usb_audio_panic_halt(), internal_usb_audio_send_one_frame(), internal_usb_audio_setup_or_halt(), k_ra8_ok, k_usb_audio_idle_step_ms, k_usb_audio_log_period, ra8_delay_ms(), and ra8_isr_globals_enable().
|
static |
1 kHz sine LUT, 48 stereo 16-bit samples per cycle.
Each entry is interleaved L/R 16-bit little-endian (USB Audio 1.0 sec 2.2.5 Format Type-I sample byte order). The amplitude is 0x4000 (half full-scale) so the host can downstream-mix without clipping. Hand-computed with sin(2*pi*n/48) at integer step 1 of 48; floating-point math is forbidden in this firmware so the LUT is precomputed and stored in MRAM as constant rodata.
Index 0 = sin(0), 12 = sin(pi/2) = +0x4000, 24 = sin(pi) = 0, 36 = sin(3pi/2) = -0x4000, ... back to 0 at index 48.
Definition at line 136 of file main.c.
Referenced by internal_usb_audio_send_one_frame().