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

UART "hello world" HIL test for EK-RA8D2 (SCI8 @ 115200). 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_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  uart_hello_config_t : uint32_t {
  k_uart_hello_baud = 115200U ,
  k_uart_hello_period_ms = 1000U
}
 Compile-time settings for the demo. More...

Functions

static void internal_uart_hello_panic_halt (void)
 Halt forever in WFI – used as a panic stop on init failure.
static void internal_uart_hello_setup_or_halt (void)
 Bring CGC + SysTick + SCI8 + LED1 up.
void main (void)
 Application entry.

Variables

static const uint8_t s_uart_hello_greeting [] = "hello, ra8d2!\r\n"
 Greeting string sent every period.

Detailed Description

UART "hello world" HIL test for EK-RA8D2 (SCI8 @ 115200).

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

Brings the chip up via ra8_cgc_init() (XTAL -> PLL1 -> CPUCLK0 = 1 GHz, PCLKA = 125 MHz, SCICLK = PLL1R / 4 = 100 MHz), brings up the SCI8 J-Link OB console (TXD8 = PD_02 / RXD8 = PD_03 in async mode at 115200 8N1) through the board-support-package console API, and prints "hello, ra8d2!\r\n" once a second while toggling LED1 as a heartbeat. The CDC channel of the on-board J-Link OB on the EK-RA8D2 surfaces these pins as a virtual serial port on the host; connecting any terminal at 115200 8N1 to that port shows the stream.

Sequence:

  1. ra8_cgc_init() – XTAL + PLL1 up, CPUCLK0 = 1 GHz, PCLKA = 125 MHz, SCICLK = PLL1R / 4. The CGC driver also flushes the MRAM prefetch buffer, sets VSCR.VSCM = 1, programmes MRMS wait states, and routes SCICLK from PLL1R per HUM 9.2.54 – no per-app workarounds needed.
  2. ra8_cgc_get_clock_hz(k_ra8_clock_id_cpuclk0, &cpuclk0_hz) – the heartbeat delay is calibrated against CPUCLK0.
  3. ra8_time_init(cpuclk0_hz) for the heartbeat delay.
  4. ra8_board_uart_console_init(115200) – the BSP routes PD_02 / PD_03 to SCI8 async (PSEL) and brings up SCI8 at 115200 8N1, computing BRR against PCLKA internally.
  5. ra8_board_led_init(k_ra8_board_led1) for the visual heartbeat.
  6. Loop: write the greeting, toggle LED1, sleep 1 s.

Verification: open the J-Link OB CDC port at 115200 8N1, e.g. picocom -b 115200 /dev/cu.usbmodem... on macOS or minicom -D /dev/ttyACM0 -b 115200 on Linux. You should see one greeting line per second with LED1 toggling in lock-step.

Architectural ring
[Ring 6 / APP] {World: S} – application-layer code that runs in the Secure world.
Author
Brighton Sikarskie
Date
2026-04-29
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ uart_hello_config_t

enum uart_hello_config_t : uint32_t

Compile-time settings for the demo.

Enumerator
k_uart_hello_baud 

UART hello baud.

k_uart_hello_period_ms 

UART hello period ms.

Definition at line 60 of file main.c.

Function Documentation

◆ internal_uart_hello_panic_halt()

void internal_uart_hello_panic_halt ( void )
static

Halt forever in WFI – used as a panic stop on init failure.

Preserves the failed boot state in a low-activity loop that remains accessible to an attached debugger.

Returns
None.
Precondition
Called only after a fatal error in boot.
The caller has no remaining recovery or diagnostic write to perform.
Postcondition
CPU is parked; only a debugger or external reset wakes it.
The demo emits no further UART bytes or LED transitions.
Note
Interrupt wakeups return immediately to the permanent loop.
Since
0.1.0

Definition at line 85 of file main.c.

References RA8_INTERNAL.

Referenced by internal_uart_hello_setup_or_halt(), and main().

◆ internal_uart_hello_setup_or_halt()

void internal_uart_hello_setup_or_halt ( void )
static

Bring CGC + SysTick + SCI8 + LED1 up.

Panic-halts on any fail.

The SCI8 J-Link OB console (TXD8 = PD_02 / RXD8 = PD_03 @ 115200 8N1) is brought up through the board-support-package console API, which owns the PFS pin routing, the BRR calculation against PCLKA, and the SCI8 init. That keeps the demo correct when the CGC driver is retargeted to a different clock tree.

Returns
None.
Precondition
Reset-time initialization configured the core and vector table.
The EK-RA8D2 SCI8 console pins and LED1 are available to this app.
Postcondition
On success the millisecond time base and 115200-baud console are ready.
On success LED1 is initialized; on failure the function never returns.
Note
Single-shot boot helper; it is not reentrant.
Since
0.1.0

Definition at line 112 of file main.c.

References internal_uart_hello_panic_halt(), k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, k_uart_hello_baud, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, and ra8_time_init().

Referenced by main().

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Brings up CGC + SCI8 + LED1 then prints.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, FPU, and priority grouping.
Postcondition
On clean entry the CPU stays in the print + blink loop forever.
On any HAL init failure the function halts in WFI.
Since
0.1.0

Definition at line 144 of file main.c.

References internal_uart_hello_panic_halt(), internal_uart_hello_setup_or_halt(), k_ra8_board_led1, k_ra8_ok, k_uart_hello_period_ms, ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), and s_uart_hello_greeting.

Variable Documentation

◆ s_uart_hello_greeting

const uint8_t s_uart_hello_greeting[] = "hello, ra8d2!\r\n"
static

Greeting string sent every period.

Must remain ASCII.

Definition at line 66 of file main.c.

Referenced by main().