72static const char*
s_tag =
"XSPI";
78typedef enum : uint8_t {
100typedef enum : uint8_t {
118typedef enum : uint32_t {
167 if (expected != 0U) {
227 static bool s_xspi_clock_inited =
false;
228 if (s_xspi_clock_inited) {
242 const uint8_t src_moco = 0x01U;
261 s_xspi_clock_inited =
true;
409 if (reg ==
nullptr) {
418 for (uint8_t i = 0U; i < len; i++) {
419 word |= ((uint32_t)cmd_buf[i]) << ((i % 4U) * 8U);
420 if ((i % 4U) == 3U) {
421 reg->
CDBUF[i / 4U] = word;
425 if ((len % 4U) != 0U) {
426 reg->
CDBUF[len / 4U] = word;
500 if (reg ==
nullptr) {
507 const uint32_t mask = reg->
INTS;
579typedef enum : uint8_t {
595typedef enum : uint8_t {
604typedef enum : uint8_t {
613typedef enum : uint32_t {
628 const uint8_t base = 0U;
739 uint16_t cmd_word = (uint16_t)(opcode << 8U);
741 cmd_word = (uint16_t)(opcode | (((uint16_t)(uint8_t)~opcode) << 8U));
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
static ra8_err_t ra8_hw_wait_flag_clear8(volatile const uint8_t *reg, uint8_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
static ra8_err_t ra8_hw_wait_flag_set8(volatile const uint8_t *reg, uint8_t mask, uint32_t budget)
Spin until (*reg & mask) != 0 or budget runs out.
static ra8_err_t ra8_hw_wait_flag_clear32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_info(tag, message)
RA8 log info.
#define ra8_log_error(tag, message)
RA8 log error.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
ra8_mstp_t
Packed (reg << 8) | bit module-stop identifier.
@ k_ra8_mstp_ospi0
MSTPB16 OSPI0+DOTF0.
@ k_ra8_mstp_ospi1
MSTPB17 OSPI1+DOTF1.
xSPI / Octo-SPI controller register layout for the Renesas RA8D2
@ k_ra8_xspi_cdt_trtype_write
Write transaction (host drives).
@ k_ra8_xspi_cmctlch_xipencode_pos
XIPENCODE[7..0] enter.
@ k_ra8_xspi_cmctlch_xipexcode_pos
XIPEXCODE[15..8] exit.
@ k_ra8_xspi_cmctlch_xipen_mask
XIPEN[16] enable.
@ k_ra8_xspi_ints_mask_all
Clear every pending flag.
@ k_ra8_xspi_cdt_addsize_0
No address phase (e.g.
@ k_ra8_xspi_cdt_pos_cmd
CMD[31..16] JEDEC opcode.
@ k_ra8_xspi_cdt_pos_cmdsize
CMDSIZE[1..0] command bytes.
@ k_ra8_xspi_cdt_pos_trtype
TRTYPE[15] 0=read 1=write.
@ k_ra8_xspi_cdt_pos_addsize
ADDSIZE[4..2] address bytes.
@ k_ra8_xspi_cdt_mask_addsize
ADDSIZE field is 3 bits.
@ k_ra8_xspi_cdt_mask_trtype
TRTYPE field is 1 bit.
@ k_ra8_xspi_cdt_mask_cmdsize
CMDSIZE field is 2 bits.
@ k_ra8_xspi_cdctl0_mask_cssel
CSSEL (target select).
@ k_ra8_xspi_cmcfgcs_pos_addr_size
ADDSIZE[2..0] addr bytes.
@ k_ra8_xspi_cmcfgcs_pos_cmd
CMD[31..16] read opcode.
@ k_ra8_xspi_cdctl0_bit_cssel
Chip-select select (0 = CS0).
static volatile r_xspi_regs_t * ra8_xspi(uint8_t instance)
Get pointer to xSPI instance N (0..1).
ra8_xspi_lio_mode_t
Protocol mode values written to LIOCFGCS[n].PRTMD.
@ k_ra8_xspi_cmcfgcs_word_addr
+0x0C address-byte width.
@ k_ra8_xspi_cmcfgcs_word_read_cmd
+0x04 read-cmd + dummy cycles.
@ k_ra8_xspi_bmctl0_read_write
11 per pair: read/write.
@ k_ra8_xspi_bmctl0_disabled
All AHB access disabled.
@ k_ra8_xspi_bmctl0_read_only
01 per pair: read-only.
@ k_ra8_xspi_ccctl0_mask_caen
CAEN enable mask.
@ k_ra8_xspi_lioctl_mask_wpcs
WPCS – write-protect drive.
@ k_ra8_xspi_lioctl_mask_rstcs
RSTCS – hardware-reset drive.
@ k_ra8_xspi_instance_count
XSPI0 and XSPI1.
@ k_ra8_xspi_liocfgcs_mask_ddren
DDR / DTR enable bit.
Scoped PRCR unlock helper.
#define RA8_PROTECTED_WRITE(unlock_val)
Scoped PRCR unlock block.
System Control (SYSC) register layout for the Renesas RA8D2.
@ k_ra8_prcr_unlock_cgc
RA8 prcr unlock cgc.
static volatile uint8_t * ra8_sys_octackcr(void)
Get pointer to the 8-bit OCTACKCR (Octal-SPI clock source select).
static volatile uint8_t * ra8_sys_octackdivcr(void)
Get pointer to the 8-bit OCTACKDIVCR (Octal-SPI clock divider).
@ k_ra8_usbckcr_bit_srdy
USBCKSRDY – handshake ready.
@ k_ra8_usbckcr_bit_sreq
USBCKSREQ – request switch.
ra8_xspi_addr_bytes_t
Allowed address-byte widths for ra8_xspi_set_xip_mode.
@ k_ra8_xspi_addr_bytes_4
32-bit JEDEC address.
@ k_ra8_xspi_addr_bytes_3
24-bit JEDEC address.
ra8_xspi_jedec_extra_t
Extra JEDEC opcodes used by suspend/resume control.
@ k_ra8_spi_flash_op_suspend
0x75 erase/program suspend.
@ k_ra8_spi_flash_op_resume
0x7A erase/program resume.
@ k_ra8_spi_flash_op_reset_dev
0x99 RST – IS25LX512M Ch 8.21 p 39.
@ k_ra8_spi_flash_op_reset_en
0x66 RSTEN – IS25LX512M Ch 8.20 p 39.
ra8_err_t ra8_xspi_attach_handler(uint8_t instance, ra8_xspi_event_fn_t fn, void *ctx)
Attach a completion callback.
ra8_err_t ra8_xspi_calibrate_dqs(uint8_t instance)
Run the data-strobe (DQS) calibration sequence.
ra8_err_t ra8_xspi_enter_stop(uint8_t instance)
Put an xSPI instance into MSTP-gated stop.
static ra8_err_t internal_xspi_clock_block_init(void)
Block-level OCTA clock init – run BEFORE the first MSTP release.
ra8_err_t ra8_xspi_xip_enter(uint8_t instance, uint8_t enter_code, uint8_t exit_code)
Enable XIP (execute-in-place) memory-mapped read mode.
ra8_err_t ra8_xspi_deinit(uint8_t instance)
Tear down the xSPI instance (disable + MSTP release).
ra8_xspi_chip_select_t
Which controller chip-select drives the on-board OSPI flash.
@ k_ra8_xspi_onboard_cs
IS25LX512M is on controller CS1.
ra8_err_t ra8_xspi_set_xip_mode(uint8_t instance, bool enable, uint8_t read_cmd, uint8_t addr_bytes)
Enable or disable memory-mapped (XIP) read mode.
ra8_xspi_cmd_limits_t
Byte-count limits on raw direct-command buffers.
@ k_ra8_xspi_cmd_max_bytes
A CDBUF slot holds 16 bytes.
ra8_err_t ra8_xspi_set_dtr_mode(uint8_t instance, bool enable)
Enable or disable double-data-rate (DDR / DTR) link mode.
ra8_xspi_calib_spin_t
Bounded spin budget for the auto-calibration handshake.
@ k_ra8_xspi_calib_spin
CCCTL0.CAEN poll budget.
static void internal_xspi_reset_spin(void)
Bounded busy-spin used between the RSTCS reset edges.
static ra8_err_t internal_issue_reset_opcode(volatile r_xspi_regs_t *reg, uint8_t opcode, uint8_t cmd_bytes)
Issue a single RSTEN-or-RST opcode in either 1S or 8D form.
static void internal_xspi_reset_device(volatile r_xspi_regs_t *reg)
Pulse the controller-driven flash RESET (LIOCTL.RSTCS) low->high.
ra8_err_t ra8_xspi_exit_stop(uint8_t instance)
Exit MSTP-gated stop.
ra8_xspi_reset_cmd_bytes_t
Allowed cmd_bytes values for ra8_xspi_software_reset.
@ k_ra8_xspi_reset_cmd_bytes_1s
1-byte opcode for 1S-1S-1S.
@ k_ra8_xspi_reset_cmd_bytes_8d
2-byte opcode pair for 8D-8D-8D.
ra8_xspi_reset_delay_t
Bounded busy-spin counts for the LIOCTL.RSTCS reset pulse.
@ k_ra8_xspi_reset_spin
~tens of us busy-spin per reset edge.
static void internal_xspi_apply_config(volatile r_xspi_regs_t *reg, ra8_xspi_lio_mode_t mode)
Apply the manual-command controller config for the on-board flash.
ra8_err_t ra8_xspi_direct_command(uint8_t instance, const uint8_t *cmd_buf, uint8_t len)
Issue a raw command via the direct-command registers.
ra8_err_t ra8_xspi_software_reset(uint8_t instance, uint8_t cmd_bytes)
Issue the JEDEC software-reset pair (RSTEN 0x66 + RST 0x99).
ra8_err_t ra8_xspi_init(uint8_t instance, ra8_xspi_lio_mode_t mode)
Initialise an xSPI instance in the chosen link-layer IO mode.
static ra8_err_t internal_wait_octacksrdy(uint8_t expected)
Bounded wait on OCTACKCR.OCTACKSRDY reaching expected.
static const ra8_mstp_t s_xspi_mstp_table[]
Instance-index -> MSTP id lookup.
ra8_err_t ra8_xspi_get_status(uint8_t instance, uint32_t *out_mask)
Read the xSPI COMSTT busy/error mask.
static ra8_xspi_state_t s_xspi_state[k_ra8_xspi_instance_count]
Per-instance callback state (s_ prefix for file-static).
ra8_err_t ra8_xspi_suspend(uint8_t instance)
Suspend a long-running flash erase / program operation.
ra8_err_t ra8_xspi_clear_status(uint8_t instance, uint32_t mask)
Clear transfer-complete / error bits in INTS via INTC.
ra8_err_t ra8_xspi_resume(uint8_t instance)
Resume a previously suspended erase / program.
ra8_err_t ra8_xspi_xip_exit(uint8_t instance)
Disable XIP mode and restore command-only access.
void ra8_xspi_dispatch(uint8_t instance)
Dispatch an xSPI event – snapshot INTS + fire callback.
xSPI / Octo-SPI driver (flash read/program/erase + ID/status)
void(* ra8_xspi_event_fn_t)(void *ctx, uint32_t status_mask)
xSPI event callback.
ra8_err_t priv_ra8_xspi_kick_command(volatile r_xspi_regs_t *reg)
Kick a prepared manual-command transfer by raising TRREQ.
ra8_err_t priv_ra8_xspi_issue_simple_opcode(volatile r_xspi_regs_t *reg, uint8_t opcode)
Build CDBUF[0] for a 1-byte opcode with no address / no data.
Module-private seam shared between the ra8_xspi translation units.
@ k_ra8_xspi_cdbuf_idx_data1
CDBUF[3] CDD1 – data bytes 4..7.
@ k_ra8_xspi_cdbuf_idx_data0
CDBUF[2] CDD0 – data bytes 0..3.
@ k_ra8_xspi_cdbuf_idx_cdt
CDBUF[0] CDT – type/opcode word.
@ k_ra8_xspi_cdbuf_idx_addr
CDBUF[1] CDA – flash address.
@ k_ra8_xspi_ckcr_spin
OCTACKCR SREQ/SRDY handshake budget.
xSPI per-instance register window.
volatile uint32_t COMCFG
+0x004 Channel arbitration + INT en.
volatile uint32_t LIOCFGCS[2]
+0x050..+0x054 Link I/O per target.
volatile uint32_t BMCTL0
+0x060 Bridge map control 0.
volatile uint32_t LIOCTL
+0x108 Link I/O control (WP/RST).
volatile uint32_t INTC
+0x194 Interrupt clear (W1C).
volatile uint32_t COMSTT
+0x184 Common status (MEMACC/PBUFNE).
volatile uint32_t INTS
+0x190 Interrupt status (CMDCMP=b0).
volatile uint32_t WRAPCFG
+0x000 Wrapper config (CK/DS shift).
volatile uint32_t CCCTLCS[k_ra8_xspi_ccctlcs_words]
+0x130 Calib 2x8.
volatile uint32_t INTE
+0x198 Interrupt enable.
volatile uint32_t CMCFGCS[8]
+0x010..+0x02C Command map (2x4 u32).
volatile uint32_t CDCTL0
+0x070 Manual cmd ctl 0 (TRREQ/CSSEL)
volatile uint32_t CMCTLCH[2]
+0x068..+0x06C XiP command control.
volatile uint32_t CDBUF[16]
+0x080..+0x0BC Command buf (4x4 u32).
Per-instance callback state.
void * ctx
Opaque context pointer for fn.
ra8_xspi_event_fn_t fn
User-supplied completion callback.