ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

First raw SPI link probe against the ESP32-C6 wireless co-processor. More...

#include <stdint.h>
#include "c6_probe.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_mstp.h"
#include "ra8_spi.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

static void c6_probe_panic_halt (void)
 Park forever after a fatal initialisation failure.
static void c6_probe_clocks_or_halt (void)
 Bring CGC, MSTP and SysTick up, caching PCLKA.
static void c6_probe_setup_or_halt (void)
 Bring clocks, console, LEDs and side-band inputs up.
static void c6_probe_print_map (const c6_probe_stats_t *st, uint8_t hs_idx, uint8_t dr_idx)
 Print the resolved DATA_READY / HANDSHAKE side-band map.
static void c6_probe_print_verdict (const c6_probe_stats_t *st, ra8_spi_mode_t mode, bool link_live)
 Print the single-line PASS / FAIL verdict.
static void c6_probe_run (void)
 Sweep the SPI modes, resolve the side-band map, report the outcome.
void main (void)
 Application entry: probe the ESP32-C6 esp-hosted SPI link.

Variables

static c6_probe_stats_t s_c6_stats
 Accumulated probe evidence for the final verdict and pin map.
static uint32_t s_c6_pclka_hz
 Cached PCLKA rate, the SCI baud-clock source.
static const ra8_spi_mode_t k_c6_mode_order [k_c6_probe_mode_count]
 SPI modes tried, most likely first.

Detailed Description

First raw SPI link probe against the ESP32-C6 wireless co-processor.

Tag
[Ring 6 / APP] {World: S}

Stand-alone EK-RA8D2 application that opens the physical esp-hosted SPI full-duplex link to the ESP32-C6 soldered to Pmod1 (J26) and proves it end-to-end: it clocks the fixed-size transport buffer, hand-decodes the esp-hosted payload header out of the received bytes, and prints a PASS/FAIL verdict on the board console.

The app also resolves the two facts that are not recorded anywhere in the tree:

  1. Which MCU pin the board's Pmod1 mode mux has actually wired to the C6's chip-select. EK-RA8D2 UM Table 18 p 26 makes J26-1 either P804 (SPI position) or P800 (UART position), and UM Table 3 p 16 adds SW4-3, which frees those pins from the Octo-SPI flash only when it is ON. The chip-select hunt asserts each candidate and watches for the C6 to answer, so the log states the mux position rather than assuming it.
  2. Which Pmod1 side-band pin carries DATA_READY and which carries HANDSHAKE. The two are found by different means because the C6 treats them differently. HANDSHAKE moves: the image is built with CONFIG_ESP_SPI_DEASSERT_HS_ON_CS=y, so it drops on the chip-select falling edge and re-raises once the next transaction is queued, and the pin that repeatedly tracks the chip-select is HANDSHAKE. DATA_READY typically does not move: an esp-hosted peripheral with an empty transmit queue holds it low indefinitely. It is identified electrically instead, by c6_probe_pull_contest – a pin that reads low against the RA8D2's own pull-up is being sunk by a real driver on the far end. A pin that neither moves nor sinks the pull-up is the one that is not wired to the C6.

Flow:

  1. ra8_cgc_init – bring CPUCLK0 / PCLKA up, start SysTick.
  2. Board UART console on SCI8 at 115200 8N1.
  3. Pmod1 side-band pins as plain GPIO inputs; report their levels.
  4. Muxed-net wire test, then the chip-select hunt.
  5. PFS-route Pmod1 SCI2 Simple-SPI and own the chip-select as a GPIO.
  6. Sweep SPI modes starting at the C6's configured mode 3, running a few full-size transactions per mode until one decodes.
  7. Pull-up contest on the side-band pins, with the C6's queue drained.
  8. Print the resolved side-band map and the PASS/FAIL verdict.
Since
0.1.0

Definition in file main.c.

Function Documentation

◆ c6_probe_clocks_or_halt()

void c6_probe_clocks_or_halt ( void )
static

Bring CGC, MSTP and SysTick up, caching PCLKA.

Precondition
Reset_Handler has copied .data and zeroed .bss.
Interrupts are masked or this is a single-threaded init context.
Postcondition
s_c6_pclka_hz is non-zero and SysTick is running.
The function panic-halts instead of returning on any failure.
Note
Never returns on error.
Since
0.1.0

Definition at line 133 of file main.c.

References c6_probe_panic_halt(), k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), ra8_time_init(), and s_c6_pclka_hz.

Referenced by c6_probe_setup_or_halt().

◆ c6_probe_panic_halt()

void c6_probe_panic_halt ( void )
static

Park forever after a fatal initialisation failure.

Precondition
Called only once a bring-up step has failed unrecoverably.
Postcondition
The CPU is parked; only a debugger or a reset wakes it.
Note
Never returns; not callable from interrupt context.
Since
0.1.0

Definition at line 115 of file main.c.

Referenced by c6_probe_clocks_or_halt(), c6_probe_setup_or_halt(), and main().

◆ c6_probe_print_map()

void c6_probe_print_map ( const c6_probe_stats_t * st,
uint8_t hs_idx,
uint8_t dr_idx )
static

Print the resolved DATA_READY / HANDSHAKE side-band map.

Parameters
[in]stAccumulated evidence.
[in]hs_idxResolved handshake index, or k_c6_sb_count.
[in]dr_idxResolved data-ready index, or k_c6_sb_count.
Precondition
The console is up and st is non-NULL.
Both indices are valid or k_c6_sb_count.
Postcondition
One evidence line per pin plus one map line were printed.
Nothing is modified.
Note
Not thread-safe.
Since
0.1.0

Definition at line 202 of file main.c.

References c6_probe_put_u32(), c6_probe_puts(), c6_probe_sideband_name(), c6_probe_stats_t::dr_vote, c6_probe_stats_t::ever_high, c6_probe_stats_t::ever_low, c6_probe_stats_t::hs_vote, k_c6_sb_count, c6_probe_stats_t::pull_low, and c6_probe_stats_t::pull_samples.

Referenced by c6_probe_run().

◆ c6_probe_print_verdict()

void c6_probe_print_verdict ( const c6_probe_stats_t * st,
ra8_spi_mode_t mode,
bool link_live )
static

Print the single-line PASS / FAIL verdict.

Parameters
[in]stAccumulated evidence.
[in]modeMode that decoded, or the last mode tried.
[in]link_liveWhether any recognisable frame was decoded.
Precondition
The console is up and st is non-NULL.
mode is one of ra8_spi_mode_t.
Postcondition
Exactly one verdict line beginning c6_probe: PASS or c6_probe: FAIL was printed.
Nothing is modified.
Note
The verdict line is what a HIL scrape would match on.
Since
0.1.0

Definition at line 247 of file main.c.

References c6_probe_stats_t::attempts, c6_probe_stats_t::bad_csum_frames, c6_probe_put_u32(), c6_probe_puts(), c6_probe_stats_t::data_frames, c6_probe_stats_t::idle_frames, and k_c6_probe_sck_hz.

Referenced by c6_probe_run().

◆ c6_probe_run()

void c6_probe_run ( void )
static

Sweep the SPI modes, resolve the side-band map, report the outcome.

Ordering is load-bearing: the pull-up contest runs after the sweep so it measures DATA_READY's idle state rather than the boot event the C6 has queued, and c6_probe_resolve_map runs after both so it sees every kind of evidence the run produced.

Precondition
Setup completed, the console is up and the SPI pins are routed.
s_c6_stats already holds the chip-select hunt's evidence.
Postcondition
A map line and a verdict line were printed exactly once.
LED2 is lit when the link failed to come up.
Note
Not thread-safe; runs once from main.
Since
0.1.0

Definition at line 285 of file main.c.

References c6_probe_best(), c6_probe_print_map(), c6_probe_print_verdict(), c6_probe_pull_contest(), c6_probe_puts(), c6_probe_resolve_map(), c6_probe_sweep_mode(), k_c6_mode_order, k_c6_probe_min_votes, k_c6_probe_mode_count, k_c6_sb_count, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), s_c6_pclka_hz, and s_c6_stats.

Referenced by main().

◆ c6_probe_setup_or_halt()

void c6_probe_setup_or_halt ( void )
static

Bring clocks, console, LEDs and side-band inputs up.

Deliberately stops short of routing the Pmod1 SPI pins: the wire test and the chip-select hunt run next and need those nets unclaimed so they can drive and release them.

Precondition
Reset_Handler has initialised .data and .bss.
The console SCI is not otherwise claimed.
Postcondition
The console prints and the side-band pins are inputs.
The function panic-halts instead of returning on any failure.
Note
Never returns on error.
Since
0.1.0

Definition at line 169 of file main.c.

References c6_probe_clocks_or_halt(), c6_probe_panic_halt(), c6_probe_puts(), c6_probe_sideband_init(), k_c6_probe_uart_baud, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_init(), and ra8_board_uart_console_init().

Referenced by main().

◆ main()

void main ( void )

Application entry: probe the ESP32-C6 esp-hosted SPI link.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, the FPU and priority grouping.
Postcondition
The probe ran exactly once and printed its verdict.
The CPU stays in a slow heartbeat loop afterwards.
Since
0.1.0

Definition at line 325 of file main.c.

References c6_probe_cs_hunt(), c6_probe_panic_halt(), c6_probe_print_sideband(), c6_probe_puts(), c6_probe_run(), c6_probe_sample_sideband(), c6_probe_setup_or_halt(), c6_probe_spi_pins_init(), c6_probe_wire_test(), k_c6_probe_boot_wait_ms, k_c6_probe_idle_ms, k_ra8_board_led1, k_ra8_ok, ra8_board_led_toggle(), ra8_delay_ms(), ra8_isr_globals_enable(), and s_c6_stats.

Variable Documentation

◆ k_c6_mode_order

const ra8_spi_mode_t k_c6_mode_order[k_c6_probe_mode_count]
static
Initial value:
= {
}
@ k_ra8_spi_mode_0
CPOL=0, CPHA=0.
Definition ra8_spi.h:62
@ k_ra8_spi_mode_3
CPOL=1, CPHA=1.
Definition ra8_spi.h:65
@ k_ra8_spi_mode_1
CPOL=0, CPHA=1.
Definition ra8_spi.h:63
@ k_ra8_spi_mode_2
CPOL=1, CPHA=0.
Definition ra8_spi.h:64

SPI modes tried, most likely first.

The C6 image in coprocessor/esp32c6/ is built with CONFIG_ESP_SPI_MODE=3, so mode 3 leads; the rest are a bring-up fallback reached only if mode 3 decodes nothing.

Note
Read-only.
Warning
Reordering this changes which transaction drains the C6's queued boot event, which only a power cycle restores.
Since
0.1.0

Definition at line 99 of file main.c.

Referenced by c6_probe_run().

◆ s_c6_pclka_hz

uint32_t s_c6_pclka_hz
static

Cached PCLKA rate, the SCI baud-clock source.

Read once during bring-up and handed to every SPI mode opened.

Note
Written once during setup.
Warning
Zero until c6_probe_clocks_or_halt has run.
Since
0.1.0

Definition at line 86 of file main.c.

Referenced by c6_probe_clocks_or_halt(), and c6_probe_run().

◆ s_c6_stats

c6_probe_stats_t s_c6_stats
static

Accumulated probe evidence for the final verdict and pin map.

Deliberately not reset between SPI modes: the side-band map is built from the whole run, including the chip-select hunt that precedes any clocking.

Note
Single-threaded; touched only from the probe flow.
Warning
Do not clear mid-run or the map loses its evidence.
Since
0.1.0

Definition at line 76 of file main.c.

Referenced by c6_probe_run(), and main().