|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
EK-RA8D2 BSP – DA7212 audio CODEC, USB-HS, and U15 I/O expander. More...
#include <stddef.h>#include <stdint.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_board_ek_ra8d2_audio_usb_internal.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_gpio_constants.h"#include "ra8_i2c.h"#include "ra8_mpc.h"#include "ra8_mstp.h"#include "ra8_pfs_regs.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_ssie.h"#include "ra8_time.h"#include "ra8_usb.h"Go to the source code of this file.
Functions | |
| static ra8_err_t | internal_audio_bits_to_word (uint8_t bit_depth, ra8_ssie_data_word_t *out_dwl, ra8_ssie_system_word_t *out_swl) |
| static ra8_err_t | internal_audio_route_pins (void) |
| static ra8_ssie_cfg_t | internal_audio_build_ssie_cfg (uint8_t channels, ra8_ssie_data_word_t dwl, ra8_ssie_system_word_t swl) |
| Build the SSIE0 controller-mode I2S config for the DA7212 link. | |
| ra8_err_t | ra8_board_audio_init (uint32_t sample_rate_hz, uint8_t bit_depth, uint8_t channels) |
| Route the CODEC pins and bring up SSIE0 in I2S controller mode. | |
| ra8_err_t | ra8_board_audio_play_sample_block (const int16_t *buf, uint32_t len) |
| Push one block of stereo PCM samples to the CODEC's DAC. | |
| static ra8_err_t | internal_usbhs_clock_and_mstp (void) |
| Shared CGC + MSTP bring-up for both USBHS modes. | |
| static ra8_err_t | internal_io_expander_write_reg (uint8_t reg, uint8_t val) |
| static void | internal_io_expander_bus_settle (void) |
| Crude busy-wait for roughly one I2C SCL half-period. | |
| static ra8_err_t | internal_io_expander_bus_recover (void) |
| Bit-bang up to 9 SCL clocks to free a wedged system I2C bus. | |
| static ra8_err_t | internal_io_expander_enable_pullups (void) |
| Drive the system-I2C pull-up enable pins (P109/P311) high. | |
| static ra8_err_t | internal_io_expander_route_pins (void) |
| Route P512/P511 to SCL1/SDA1 with N-channel open-drain enabled. | |
| static ra8_err_t | internal_io_expander_program_u15 (uint8_t output_byte, uint8_t output_mask) |
| Issue the three U15 register writes that latch a given SW4 layout. | |
| static ra8_err_t | internal_io_expander_apply_mask (uint8_t output_byte, uint8_t output_mask) |
Shared U15 bring-up: route SCL1/SDA1, initialize RIIC1, then load output_byte into the expander's output register. | |
| ra8_err_t | ra8_board_io_expander_set_usbhs_device_mode (void) |
| Drive the U15 PI4IOE5V6408 I/O expander to select USB-HS device mode. | |
| ra8_err_t | ra8_board_io_expander_set_usbhs_host_mode (void) |
| Implementation of ra8_board_io_expander_set_usbhs_host_mode(). | |
| ra8_err_t | ra8_board_io_expander_apply_project_sw4_defaults (void) |
| Program U15 with this project's SW4 override pattern. | |
| ra8_err_t | ra8_board_io_expander_apply_sw4 (uint8_t output_byte) |
| Program an exact U15 SW4 override byte in one bring-up sequence. | |
| ra8_err_t | ra8_board_io_expander_apply_sw4_mask (uint8_t output_byte, uint8_t output_mask) |
| Override selected SW4 positions while releasing every other position. | |
| ra8_err_t | ra8_board_io_expander_set_octospi_active (void) |
| Program the U15 I/O expander to request the Octo-SPI SW4 layout. | |
| static ra8_err_t | internal_usbhs_role_select_device (void) |
| Drive PD07 low to strap the J7 USB-HS role line to "Device". | |
| ra8_err_t | ra8_board_usbhs_device_init (void) |
| Bring the chip USBHS module up in device mode (HS PHY). | |
| ra8_err_t | ra8_board_usbhs_host_init (void) |
| Bring the chip USBHS module up in host mode. | |
Variables | |
| static bool | s_audio_initialized = false |
| Tracks whether ra8_board_audio_init has succeeded. | |
| volatile uint32_t | g_usbhs_probe = 0U |
| Temporary bisect probe for USBHS bring-up HardFault. | |
| static const ra8_port_pin_t | s_ra8_board_io_expander_pin_scl |
| Pins that carry SCL1 / SDA1 to U15 (the system I2C bus). | |
| static const ra8_port_pin_t | s_ra8_board_io_expander_pin_sda |
| SDA1 (P511). | |
| static const ra8_port_pin_t | s_ra8_board_io_expander_pin_pullup_a |
| Pull-up enable pins for the system I2C bus (P109 / P311). | |
| static const ra8_port_pin_t | s_ra8_board_io_expander_pin_pullup_b |
| P311 pull-up enable. | |
| static volatile uint32_t | s_io_expander_probe = 0U |
| Bisect-probe progress counter for ra8_board_io_expander_set_usbhs_device_mode. | |
| volatile uint32_t | g_usbhs_role_pin_probe = 0U |
| Bisect-probe progress counter for the PD07 USB-HS role-select drive. | |
| volatile uint32_t | g_usbhs_role_pin_err = 0U |
| Last ra8_err_t returned by the PD07 GPIO drive (0 = k_ra8_ok). | |
EK-RA8D2 BSP – DA7212 audio CODEC, USB-HS, and U15 I/O expander.
Sibling translation unit of ra8_board_ek_ra8d2.c carrying the board's audio + USB sub-responsibilities:
The BSP itself never touches MCU registers; ra8_ssie_* / ra8_i2c_* / ra8_mpc_* / ra8_usb_* / ra8_pfs_route_peripheral carry every register write. Source-of-truth for the pin tables is docs/reference/ek-ra8d2-v1-users-manual.pdf (R20UT5523EG0101 Rev 1.01, October 2025).
Definition in file ra8_board_ek_ra8d2_audio_usb.c.
| enum io_exp_probe_step_t : uint32_t |
Step values for s_io_expander_probe (see variable docs).
Definition at line 497 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_audio_bit_depth_t : uint8_t |
Supported PCM significant-bit-depth values for the DA7212 path.
Names every bit depth the BSP knows how to map to an SSIE DWL/SWL pair. The DA7212 supports 16/24/32-bit native; 8/18/20/22 are accepted because the SSIE itself supports those data-word widths and an application may want to feed pre-padded streams.
Definition at line 67 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_audio_channels_t : uint8_t |
Sample-frame channel counts the BSP accepts.
| Enumerator | |
|---|---|
| k_ra8_audio_channels_mono | RA8 audio channels mono. |
| k_ra8_audio_channels_stereo | RA8 audio channels stereo. |
Definition at line 80 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_audio_pack_t : uint8_t |
Stereo-frame packing factor (two int16_t samples per 32-bit word).
| Enumerator | |
|---|---|
| k_ra8_audio_samples_per_word | RA8 audio samples per word. |
Definition at line 88 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_board_i2c_recover_t : uint32_t |
Bit-bang bus-recovery tunables for the system I2C bus.
| Enumerator | |
|---|---|
| k_ra8_board_i2c_recover_pulses | SCL clocks to flush one stuck byte + ACK. |
| k_ra8_board_i2c_recover_spins | Busy-loop iterations ~= one SCL half-period. |
Definition at line 450 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_board_io_expander_addr_t : uint8_t |
PI4IOE5V6408 7-bit I2C address on EK-RA8D2 v1 (SW4 sibling).
| Enumerator | |
|---|---|
| k_ra8_board_io_expander_addr | RA8 board io expander address. |
Definition at line 368 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_board_io_expander_channel_t : uint8_t |
IIC channel index used for the U15 expander (RIIC channel 1).
| Enumerator | |
|---|---|
| k_ra8_board_io_expander_iic_channel | RA8 board io expander iic channel. |
Definition at line 411 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_board_io_expander_clk_t : uint32_t |
IIC1 (system I2C) configuration shared by every U15 access.
| Enumerator | |
|---|---|
| k_ra8_board_io_expander_bus_hz | 100 kHz Sm. |
| k_ra8_board_io_expander_pclkb_hz | PCLKB = PLL1P/16 post-CGC. |
Definition at line 405 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_board_pi4ioe_magic_t : uint8_t |
Magic-value writes for ra8_board_io_expander_set_usbhs_device_mode.
Polarity per FSP reference: OFF == output bit HIGH. SW4-8 OFF selects USB-HS device mode on J7, so bit 7 must be HIGH. We write 0xFF (every SW4 channel in its mechanical-default OFF position), which keeps every other SW4-gated peripheral at its EK-RA8D2 default routing while still forcing SW4-8 = OFF.
Definition at line 398 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum ra8_board_pi4ioe_reg_t : uint8_t |
PI4IOE5V6408 register addresses.
The expander is auto-incrementing; we always do single-byte writes. Values cite ra-fsp-examples/ek_ra8t2/board_cfg_switch.c.
Definition at line 379 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum usbhs_probe_step_t : uint32_t |
Bisect-probe step values for g_usbhs_probe.
Definition at line 300 of file ra8_board_ek_ra8d2_audio_usb.c.
| enum usbhs_role_probe_step_t : uint32_t |
Probe step values for g_usbhs_role_pin_probe.
| Enumerator | |
|---|---|
| k_usbhs_role_probe_pre_init | Usbhs role probe pre init. |
| k_usbhs_role_probe_post_init | Usbhs role probe post init. |
| k_usbhs_role_probe_success | Usbhs role probe success. |
Definition at line 870 of file ra8_board_ek_ra8d2_audio_usb.c.
|
static |
Definition at line 93 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_audio_bits_16, k_ra8_audio_bits_18, k_ra8_audio_bits_20, k_ra8_audio_bits_22, k_ra8_audio_bits_24, k_ra8_audio_bits_32, k_ra8_audio_bits_8, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_dwl_16, k_ra8_ssie_dwl_18, k_ra8_ssie_dwl_20, k_ra8_ssie_dwl_22, k_ra8_ssie_dwl_24, k_ra8_ssie_dwl_32, k_ra8_ssie_dwl_8, k_ra8_ssie_swl_16, k_ra8_ssie_swl_24, k_ra8_ssie_swl_32, k_ra8_ssie_swl_8, and RA8_INTERNAL.
Referenced by ra8_board_audio_init().
|
static |
Build the SSIE0 controller-mode I2S config for the DA7212 link.
AUDIO_MCK / 4 lands close to 12.288 MHz / 4 = 3.072 MHz BCK for 48 kHz x 2ch x 32-bit frames; finer rate matching is left to applications that re-call ra8_ssie_init() with a tuned divider.
| [in,out] | channels | See function signature. |
| [in,out] | dwl | See function signature. |
| [in,out] | swl | See function signature. |
| 0 | Success or default value. |
Definition at line 178 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_audio_channels_mono, k_ra8_ssie_bclk_div_4, k_ra8_ssie_format_i2s, k_ra8_ssie_format_monaural, k_ra8_ssie_role_controller, and RA8_INTERNAL.
Referenced by ra8_board_audio_init().
|
static |
< Pin.
< Psel.
< Owner.
Definition at line 132 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_board_audio_pin_bclk, k_ra8_board_audio_pin_datin, k_ra8_board_audio_pin_datout, k_ra8_board_audio_pin_i2c_scl, k_ra8_board_audio_pin_i2c_sda, k_ra8_board_audio_pin_wclk, k_ra8_ok, k_ra8_psel_iic, k_ra8_psel_ssie, owner, pin, RA8_INTERNAL, and ra8_pfs_route_peripheral().
Referenced by ra8_board_audio_init().
|
static |
Shared U15 bring-up: route SCL1/SDA1, initialize RIIC1, then load output_byte into the expander's output register.
The public entry points differ only in the SW4 layout they program, so factor the PFS route + RIIC1 init + U15 write sequence into one helper. The probe word s_io_expander_probe is updated between steps so a JLink halt can pinpoint which step NACKed.
| [in] | output_byte | Value to latch into U15's output register (see internal_io_expander_program_u15). |
| [in] | output_mask | Value to latch into U15's IODIR register. |
| k_ra8_ok | All bring-up steps completed. |
| k_ra8_err_gpio_conflict | P512/P511 already owned. |
| k_ra8_err_hw_init_failed | RIIC1 initialization failed. |
| k_ra8_err_nack | U15 didn't ACK one of the register writes. |
output_byte. Definition at line 714 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_bus_recover(), internal_io_expander_enable_pullups(), internal_io_expander_program_u15(), internal_io_expander_route_pins(), k_io_exp_probe_pre_init, k_io_exp_probe_pre_pfs, k_io_exp_probe_success, k_ra8_board_io_expander_bus_hz, k_ra8_board_io_expander_iic_channel, k_ra8_board_io_expander_pclkb_hz, k_ra8_ok, ra8_i2c_init(), RA8_INTERNAL, and s_io_expander_probe.
Referenced by ra8_board_io_expander_apply_project_sw4_defaults(), ra8_board_io_expander_apply_sw4(), ra8_board_io_expander_apply_sw4_mask(), ra8_board_io_expander_set_octospi_active(), ra8_board_io_expander_set_usbhs_device_mode(), and ra8_board_io_expander_set_usbhs_host_mode().
|
static |
Bit-bang up to 9 SCL clocks to free a wedged system I2C bus.
If a previous, aborted transfer left a peripheral (e.g. U15) holding SDA low mid-byte, the bus is stuck and every START fails. Drive SCL (P512) as a GPIO output and pulse it – with SDA (P511) released as an input – until SDA reads high or the pulse budget is spent, then frame a STOP. Finally release both pins so the caller can route them to the IIC mux. Runs before every U15 access so a wedged bus self-recovers on the next boot.
| k_ra8_ok | Recovery sequence completed and pins released. |
Definition at line 544 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_bus_settle(), k_ra8_board_i2c_recover_pulses, k_ra8_level_high, k_ra8_level_low, k_ra8_ok, k_ra8_pull_up, ra8_gpio_input_init(), ra8_gpio_output_init(), ra8_gpio_read(), ra8_gpio_release(), ra8_gpio_write(), RA8_INTERNAL, s_ra8_board_io_expander_pin_scl, and s_ra8_board_io_expander_pin_sda.
Referenced by internal_io_expander_apply_mask().
|
static |
Crude busy-wait for roughly one I2C SCL half-period.
Used only by the bit-bang bus-recovery, which does not need precise timing – any peripheral that clock-stretches will release on the slow clocks this produces. Avoids a dependency on ra8_time being initialized this early in board bring-up.
Definition at line 519 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_board_i2c_recover_spins, and RA8_INTERNAL.
Referenced by internal_io_expander_bus_recover().
|
static |
Drive the system-I2C pull-up enable pins (P109/P311) high.
EK-RA8D2 v1 UM Table 23 routes the SCL1/SDA1 bus pull-ups through P109 and P311; in I2C mode they must be push-pull outputs driven high or the open-drain bus has no pull-ups and no peripheral can ACK. Run before routing SCL1/SDA1 so the bus is pulled up the instant the IIC mux takes the pins.
| k_ra8_ok | Both pull-up enables are driven high. |
Definition at line 599 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_level_high, k_ra8_ok, ra8_gpio_output_init(), RA8_INTERNAL, s_ra8_board_io_expander_pin_pullup_a, and s_ra8_board_io_expander_pin_pullup_b.
Referenced by internal_io_expander_apply_mask().
|
static |
Issue the three U15 register writes that latch a given SW4 layout.
Order matches the FSP reference (output-latch -> Hi-Z clear -> iodir) so each pin only flips to output once the latch is already driving the desired level. Updates s_io_expander_probe between writes so JLink can pinpoint a NACK.
| [in] | output_byte | Bit-pattern written to PI4IOE5V6408 reg 0x05 (Output state). Bit n = 1 -> SW4-(n+1) reads OFF; bit n = 0 -> reads ON. Use 0xFF to mirror the all-DIPs-OFF mechanical default or k_ra8_board_pi4ioe_output_project_default (0xF2) for this project's wiring. |
| [in] | output_mask | Bit n = 1 drives U15 pin n as an output; clear bits release that SW4 position to the physical switch. |
| k_ra8_ok | U15 driving exactly the positions selected by output_mask. |
| k_ra8_err_nack | U15 didn't ACK one of the register writes. |
Definition at line 666 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_write_reg(), k_io_exp_probe_pre_write_dir, k_io_exp_probe_pre_write_hiz, k_io_exp_probe_pre_write_out, k_ra8_board_pi4ioe_hiz_none, k_ra8_board_pi4ioe_reg_hiz, k_ra8_board_pi4ioe_reg_iodir, k_ra8_board_pi4ioe_reg_output, k_ra8_ok, RA8_INTERNAL, and s_io_expander_probe.
Referenced by internal_io_expander_apply_mask().
|
static |
Route P512/P511 to SCL1/SDA1 with N-channel open-drain enabled.
I2C requires NCODR on both signals; ra8_pfs_route_peripheral leaves NCODR clear, so the route+open-drain pair runs per pin.
| k_ra8_ok | All four register writes succeeded. |
Definition at line 621 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_ok, k_ra8_pin_11, k_ra8_pin_12, k_ra8_port_5, k_ra8_psel_iic, RA8_INTERNAL, ra8_mpc_set_open_drain(), ra8_pfs_route_peripheral(), s_ra8_board_io_expander_pin_scl, and s_ra8_board_io_expander_pin_sda.
Referenced by internal_io_expander_apply_mask().
|
static |
Definition at line 456 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_board_io_expander_addr, k_ra8_board_io_expander_iic_channel, ra8_i2c_write(), and RA8_INTERNAL.
Referenced by internal_io_expander_program_u15().
|
static |
Shared CGC + MSTP bring-up for both USBHS modes.
Sequence per HUM Ch 9 (CGC, USBCKCR / USBCKDIVCR, p 365) and Ch 11 (MSTP, MSTPCRB12 USBHS, p 469):
| 0 | Success or default value. |
Definition at line 335 of file ra8_board_ek_ra8d2_audio_usb.c.
References g_usbhs_probe, k_ra8_mstp_usbhs, k_ra8_ok, k_usbhs_probe_pre_mstp_enable, k_usbhs_probe_pre_pll_enable, ra8_cgc_usbhs_pll_enable(), RA8_INTERNAL, and ra8_mstp_enable().
Referenced by ra8_board_usbhs_device_init(), and ra8_board_usbhs_host_init().
|
static |
Drive PD07 low to strap the J7 USB-HS role line to "Device".
EK-RA8D2 v1 UM Rev 1.01 Section 6.2 p 34: PD07 is the J7 USB-HS role select. Low = Device, High = Host. This is a plain MCU GPIO; the U15 I/O expander only matters if the firmware needs to override the SW4-8 strap from a different code path.
| k_ra8_ok | PD07 owned and driven low. |
Definition at line 895 of file ra8_board_ek_ra8d2_audio_usb.c.
References g_usbhs_role_pin_err, g_usbhs_role_pin_probe, k_ra8_level_low, k_ra8_ok, k_ra8_pin_7, k_ra8_port_13, k_usbhs_role_probe_post_init, k_usbhs_role_probe_pre_init, k_usbhs_role_probe_success, ra8_gpio_output_init(), RA8_INTERNAL, and RA8_PIN.
Referenced by ra8_board_usbhs_device_init().
|
nodiscard |
Route the CODEC pins and bring up SSIE0 in I2S controller mode.
| k_ra8_ok | / k_ra8_err_invalid_arg / k_ra8_err_gpio_conflict |
Definition at line 203 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_audio_bits_to_word(), internal_audio_build_ssie_cfg(), internal_audio_route_pins(), k_ra8_audio_channels_mono, k_ra8_audio_channels_stereo, k_ra8_board_audio_ssie_channel, k_ra8_err_hw_init_failed, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ssie_dwl_16, k_ra8_ssie_swl_16, ra8_ssie_init(), and s_audio_initialized.
Referenced by internal_audio_loopback_init_codec().
|
nodiscard |
Push one block of stereo PCM samples to the CODEC's DAC.
| [in] | buf | Sample buffer (interleaved L/R, 16-bit). |
| [in] | len | Number of samples (must be even). |
| k_ra8_ok | Block enqueued or transmitted. |
| k_ra8_err_invalid_arg | buf NULL or len odd / zero. |
| k_ra8_err_not_initialized | ra8_board_audio_init not called. |
Definition at line 237 of file ra8_board_ek_ra8d2_audio_usb.c.
References k_ra8_audio_samples_per_word, k_ra8_board_audio_ssie_channel, k_ra8_err_hw_timeout, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, ra8_ssie_write_buffer(), and s_audio_initialized.
Referenced by main().
|
nodiscard |
Program U15 with this project's SW4 override pattern.
Program the U15 I/O expander to apply the project's SW4 layout.
Writes k_ra8_board_pi4ioe_output_project_default (0xF2) to the expander's output register, which forces SW4-1 ON + SW4-2 OFF (Pmod1 UART) + SW4-3 ON (Octo-SPI inactive) + SW4-4 ON (Arduino/mikroBUS active) + SW4-5 OFF (I2C), regardless of the physical DIP positions. See the header for the full per-bit table.
| k_ra8_ok | All bring-up steps completed; SW4 layout latched. |
| k_ra8_err_gpio_conflict | P512/P511 already owned. |
| k_ra8_err_hw_init_failed | RIIC1 initialization failed. |
| k_ra8_err_nack | U15 didn't ACK one of the register writes. |
Definition at line 814 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_apply_mask(), k_ra8_board_pi4ioe_iodir_all_outputs, and k_ra8_board_pi4ioe_output_project_default.
Referenced by combo_setup_or_halt(), internal_setup_or_halt(), and riic_target_setup_or_halt().
|
nodiscard |
Program an exact U15 SW4 override byte in one bring-up sequence.
Writes the requested output latch before enabling U15's outputs, avoiding an intermediate board-mux layout. Bit n = 1 requests SW4-(n+1) OFF and bit n = 0 requests it ON.
| [in] | output_byte | Exact byte for U15's output register. |
| k_ra8_ok | U15 is driving output_byte. |
| k_ra8_err_gpio_conflict | RIIC1 pins are already owned. |
| k_ra8_err_hw_init_failed | RIIC1 initialization failed. |
| k_ra8_err_nack | U15 did not acknowledge a register write. |
output_byte. Definition at line 820 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_apply_mask(), and k_ra8_board_pi4ioe_iodir_all_outputs.
|
nodiscard |
Override selected SW4 positions while releasing every other position.
| [in] | output_byte | Output latch values using the SW4 active-low convention. |
| [in] | output_mask | Bit mask of U15 pins to drive; clear bits remain inputs. |
output_byte and IODIR is output_mask. Definition at line 826 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_apply_mask().
Referenced by ra8_board_camera_select_parallel().
|
nodiscard |
Program the U15 I/O expander to request the Octo-SPI SW4 layout.
Writes k_ra8_board_pi4ioe_output_octospi_active (0xF8, the all-SW4-OFF layout with OSPI_OE_L asserted – see that enum's definition) to the U15 output register with the port set to outputs.
IMPORTANT – this does NOT, and CANNOT, connect the flash. A firmware sweep over the entire U15 output space (all 256 output bytes, plus released-inputs / Hi-Z / per-bit single-line overrides; 2026-06, issue #44, docs/HARDWARE_BRINGUP.md) re-read the 1S JEDEC ID after each config and saw zero change: the flash stays silent (bus at the board pull-ups) for every U15 state. The U15 expander is therefore a pure SW4 sense / override whose GPIOs are NOT in the OSPI DQ/CK/CS path; the flash is gated only by the SW4-3 analog mux, which is hardware-only and not reachable from firmware. (When U15 is released to inputs, reg 0x0F reads 0xF8, but the exact U15<->SW4 bit mapping is not published in the UM – it lives in the EK-RA8D2 Design Package schematic – and has not yet been verified on this EVM, so that value is NOT actionable.) This call is kept only as an inert courtesy write; it has no bearing on flash reachability. See examples/.../flash_journal/README.md and issue #44.
| k_ra8_ok | All U15 register writes succeeded. |
| k_ra8_err_busy | RIIC1 bus was held by another controller. |
| k_ra8_err_hw_timeout | U15 did not respond on RIIC1. |
| k_ra8_err_nack | U15 didn't ACK the register write. |
).
Definition at line 831 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_apply_mask(), k_ra8_board_pi4ioe_iodir_all_outputs, and k_ra8_board_pi4ioe_output_octospi_active.
Referenced by flash_journal_setup_or_halt(), ospirw_ospi_provision(), and selftest_ospi_provision().
|
nodiscard |
Drive the U15 PI4IOE5V6408 I/O expander to select USB-HS device mode.
The EK-RA8D2 v1 carries a PI4IOE5V6408 8-bit I2C I/O expander at U15 (I2C address 0x43, EK-RA8D2 v1 UM Rev 1.01 Section 5.5.3 p 32 + Section 4 p 16). U15 sits in parallel with the eight DIP switches of SW4 – when configured as outputs, U15's port pins override SW4 and gate the same on-board mux that SW4 drives, including SW4-8 which selects USB function on J7 (USB-HS): OFF = Device, ON = Host.
U15 register convention (from the PI4IOE5V6408 datasheet register map):
Polarity: the PI4IOE5V6408 datasheet defines a HIGH output bit as the released (pulled-up) level, so SW4-8 OFF (the silk-screen "Device" position) corresponds to U15.P7 = 1. The exact bit<->SW4-channel mapping is not in the UM (it is in the Design Package schematic) and is pending on-hardware verification on this EVM. We write 0xFF (all bits HIGH = all SW4 channels in their default OFF position) which puts USB-HS into Device mode and leaves the other muxed peripherals at their EK-RA8D2 default routing.
Routes P512 -> SCL1 and P511 -> SDA1 and initializes RIIC channel 1 at 100 kHz.
| k_ra8_ok | All three register writes succeeded; U15 is driving SW4-8 = OFF (Device mode). |
| k_ra8_err_gpio_conflict | P512/P511 already owned. |
| k_ra8_err_hw_init_failed | RIIC1 initialization failed. |
| k_ra8_err_nack | U15 didn't ACK the register write. |
Definition at line 762 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_apply_mask(), k_ra8_board_pi4ioe_iodir_all_outputs, and k_ra8_board_pi4ioe_output_all_high.
Referenced by ra8_board_usbhs_device_init().
|
nodiscard |
Implementation of ra8_board_io_expander_set_usbhs_host_mode().
Drive the U15 I/O expander to select USB-HS HOST mode.
See the public header for the documented contract; applies the project SW4 layout with SW4-8 (USBHS role) driven ON so the board supplies VBUS on J7.
| k_ra8_ok | U15 is driving the host-role layout. |
Definition at line 782 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_io_expander_apply_mask(), k_ra8_board_pi4ioe_iodir_all_outputs, and k_ra8_board_pi4ioe_output_usbhs_host.
Referenced by cdc_route_usb_or_halt(), dfu_route_usb_or_halt(), fileops_route_usb_or_halt(), hid_route_usb_or_halt(), microsd_route_usb_or_halt(), mlun_route_usb_or_halt(), ospirw_route_usb_or_halt(), selftest_route_usb_or_halt(), and wlun_route_usb_or_halt().
|
nodiscard |
Bring the chip USBHS module up in device mode (HS PHY).
| k_ra8_ok | / k_ra8_err_not_supported (until USBHS HAL lands) |
Definition at line 912 of file ra8_board_ek_ra8d2_audio_usb.c.
References g_usbhs_probe, internal_usbhs_clock_and_mstp(), internal_usbhs_role_select_device(), k_ra8_ok, k_ra8_usb_speed_hs, k_usbhs_probe_post_usb_dev_init, k_usbhs_probe_pre_usb_dev_init, ra8_board_io_expander_set_usbhs_device_mode(), and ra8_usb_device_init().
Referenced by internal_usb_audio_usb_or_halt().
|
nodiscard |
Bring the chip USBHS module up in host mode.
| k_ra8_ok | / k_ra8_err_not_supported (until USBHS HAL lands) |
Definition at line 948 of file ra8_board_ek_ra8d2_audio_usb.c.
References internal_usbhs_clock_and_mstp(), k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_init().
| volatile uint32_t g_usbhs_probe = 0U |
Temporary bisect probe for USBHS bring-up HardFault.
USB-HS bring-up step visible to host tests and J-Link.
Stepped through the sub-calls of internal_usbhs_clock_and_mstp + ra8_usb_device_init so a JLink session can read which sub-step is in flight when the worker thread takes the IACCVIOL/PRECISERR fault. Values: 1 = pre cgc_usbhs_pll_enable, 2 = pre mstp_init, 3 = pre mstp_enable(usbhs), 4 = pre ra8_usb_device_init(hs), 5 = post ra8_usb_device_init returned. Remove once the offending sub-call is identified.
The board implementation advances this value around clock, module-stop, and device-initialization operations. It is volatile because a debugger reads it asynchronously and because every intermediate step must remain observable.
Definition at line 294 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_usbhs_clock_and_mstp(), and ra8_board_usbhs_device_init().
| volatile uint32_t g_usbhs_role_pin_err = 0U |
Last ra8_err_t returned by the PD07 GPIO drive (0 = k_ra8_ok).
JLink-readable so the bench operator can disambiguate a pin conflict from a port-mux failure.
Definition at line 867 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_usbhs_role_select_device().
| volatile uint32_t g_usbhs_role_pin_probe = 0U |
Bisect-probe progress counter for the PD07 USB-HS role-select drive.
EK-RA8D2 v1 UM Rev 1.01 Section 6.2 p 34 ("USB High Speed"): "For a USB Device configuration, set PD07 to low and configure the RA MCU firmware to use the USB High Speed ports in device mode." PD07 is a direct-drive MCU GPIO (PORT 13, pin 7) that selects the J7 role; the U15 I/O expander is an alternate override path but is not required when PD07 is driven explicitly. JLink-readable so a bench reflash can confirm the pin was reached and driven low.
Step values: 0 = not yet entered 1 = pre ra8_gpio_output_init(PD07, low) 2 = output-init returned (success or failure recorded in g_usbhs_role_pin_err) 3 = drive confirmed (gpio_init returned k_ra8_ok)
Definition at line 858 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_usbhs_role_select_device().
|
static |
Tracks whether ra8_board_audio_init has succeeded.
Definition at line 56 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by ra8_board_audio_init(), and ra8_board_audio_play_sample_block().
|
static |
Bisect-probe progress counter for ra8_board_io_expander_set_usbhs_device_mode.
JLink-readable counter that records the last step the U15 bring-up function reached before either succeeding or returning an error. Mirrors the g_usbhs_probe pattern used by internal_usbhs_clock_and_mstp.
Step values: 1 = pre-PFS (entered function, before SCL/SDA route) 2 = pre-init (PFS + open-drain done, before ra8_i2c_init) 3 = pre-write-output (init done, before output-latch write) 4 = pre-write-hiz (output-latch written, before Hi-Z clear) 5 = pre-write-iodir (Hi-Z cleared, before iodir write) 6 = success (all three U15 writes acknowledged)
Definition at line 492 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_io_expander_apply_mask(), and internal_io_expander_program_u15().
|
static |
Pull-up enable pins for the system I2C bus (P109 / P311).
EK-RA8D2 v1 UM Table 23 ("I2C/I3C Pullup Configuration") routes the SCL1/SDA1 bus pull-up resistors through P109 and P311: in I2C mode (SW4-5 OFF, P512/P511) these two pins must be driven as push-pull outputs HIGH for the bus to have pull-ups at all. Without them SCL1/ SDA1 float, the open-drain bus never reaches a valid high level, and U15 (and every other I2C peripheral) cannot ACK – the symptom that made every RIIC1 transaction time out. P109 pull-up enable.
Definition at line 444 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_io_expander_enable_pullups().
|
static |
P311 pull-up enable.
Definition at line 446 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_io_expander_enable_pullups().
|
static |
Pins that carry SCL1 / SDA1 to U15 (the system I2C bus).
The EK-RA8D2 v1 wires U15 (and the Grove / Pmod / mikroBUS / Arduino I2C) to the SYS_I2C bus = RIIC channel 1 on P512 (SCL1) / P511 (SDA1) – confirmed against the FSP EK-RA8D2 quickstart board_cfg_switch (R_IIC_MASTER channel 1, iic1.scl1.p512 / iic1.sda1.p511) and HUM Ch 39. NOT P400/P401 (those are the I3C bus). The earlier P400/P401
Definition at line 427 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_io_expander_bus_recover(), and internal_io_expander_route_pins().
|
static |
SDA1 (P511).
Definition at line 429 of file ra8_board_ek_ra8d2_audio_usb.c.
Referenced by internal_io_expander_bus_recover(), and internal_io_expander_route_pins().