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

External SDRAM bring-up + 64 KB write/read benchmark on EK-RA8D2. More...

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

Go to the source code of this file.

Data Structures

struct  sdram_demo_diag_t
 First-mismatch diagnostic captured by sdram_demo_read_check. More...

Enumerations

enum  sdram_demo_const_t : uint32_t {
  k_sdram_demo_baud = 115200U ,
  k_sdram_demo_period_ms = 1000U ,
  k_sdram_demo_block_bytes = 65536U ,
  k_sdram_demo_block_words = 16384U ,
  k_sdram_demo_us_per_ms = 1000U
}
 App-wide tunables. More...
enum  sdram_demo_byte_t : uint8_t {
  k_sdram_demo_ascii_zero = '0' ,
  k_sdram_demo_ascii_a = 'a' ,
  k_sdram_demo_dec_base = 10U ,
  k_sdram_demo_uint_dec_max = 10U ,
  k_sdram_demo_print_buf = 64U ,
  k_sdram_demo_fail_buf = 96U ,
  k_sdram_demo_hex_digits = 8U ,
  k_sdram_demo_nyb_bits = 4U ,
  k_sdram_demo_nyb_mask = 0x0FU
}
 Single-byte ASCII conversion constants. More...
enum  sdram_demo_seed_t : uint32_t { k_sdram_demo_pattern_seed = 0xC0FFEE00UL }
 Pattern seed – recognisable hex word for SWD inspection. More...

Functions

static void sdram_demo_panic_halt (void)
 Park forever after a fatal init failure.
static void sdram_demo_setup_or_halt (void)
 Bring CGC + SysTick + console + SDRAM up.
static uint32_t sdram_demo_mbps (uint32_t bytes, uint32_t ms)
 Compute throughput in MB/s given a byte count and millisecond span.
static uint32_t sdram_demo_write_pass (uint32_t base)
 Write base + i into every word of the SDRAM block.
static bool sdram_demo_read_check (uint32_t base, uint32_t *elapsed, sdram_demo_diag_t *diag)
 Read every word back and check it matches base + i.
static uint8_t sdram_demo_uint_to_hex (uint8_t *buf, uint32_t v)
 Render v as exactly 8 lowercase hex digits into buf.
static uint8_t sdram_demo_uint_to_dec (uint8_t *buf, uint32_t v)
 Write a decimal uint32 into buf; returns bytes written.
static uint32_t sdram_demo_format_line (uint8_t *out, uint32_t w_mbps, uint32_t r_mbps)
 Format the per-cycle MB/s line into out, return its length.
static uint32_t sdram_demo_format_fail (uint8_t *out, const sdram_demo_diag_t *diag)
 Format the read-back FAIL diagnostic line into out.
void main (void)
 Application entry.

Variables

static const uint8_t k_sdram_demo_pass_msg [] = "sdram: bench OK\r\n"
 Verdict line emitted only when a read-back pass matched every word (never on a "sdram: FAIL idx=" path); the HIL scrape keys on this success-only string.

Detailed Description

External SDRAM bring-up + 64 KB write/read benchmark on EK-RA8D2.

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

Standalone EVM-tier app that exercises the external SDRAM controller driver (libs/ra8_hal/inc/ra8_sdramc.h). The EK-RA8D2 carries a 64 MB ISSI IS42S32160F SDRAM (16M x 32) wired to the BUS pins with the controller-mapped window starting at k_ra8_sdram_base_addr (0x68000000). The flow:

  1. ra8_cgc_init – clocks up.
  2. ra8_mstp_init + console pins (PD02 / PD03 SCI8).
  3. ra8_sdramc_init – runs the documented SDRAM bring-up sequence (PALL -> MRS -> AREF enable).
  4. Write a 64 KB block of incrementing 32-bit words into the SDRAM window starting at k_ra8_sdram_base_addr. Time the write and read phases via ra8_time_ms and emit "sdram: w=NN MB/s r=NN MB/s\r\n" over SCI8 once a second. On a clean read-back it also emits the success-only verdict line "sdram: bench OK\r\n" that the HIL scrape keys on (never printed on a "sdram: FAIL idx=" path). LED1 toggles per cycle; LED2 latches on read-back mismatch.

Bare EK-RA8D2 only – the SDRAM is on-board.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ sdram_demo_byte_t

enum sdram_demo_byte_t : uint8_t

Single-byte ASCII conversion constants.

Enumerator
k_sdram_demo_ascii_zero 

SDRAM demo ascii zero.

k_sdram_demo_ascii_a 

SDRAM demo ascii a.

k_sdram_demo_dec_base 

SDRAM demo dec base.

k_sdram_demo_uint_dec_max 

Max digits in a uint32 base-10.

k_sdram_demo_print_buf 

Max bytes in one throughput line.

k_sdram_demo_fail_buf 

Max bytes in the FAIL diag line.

k_sdram_demo_hex_digits 

Hex digits in a uint32.

k_sdram_demo_nyb_bits 

Bits per hex nibble.

k_sdram_demo_nyb_mask 

Mask for one nibble.

Definition at line 57 of file main.c.

◆ sdram_demo_const_t

enum sdram_demo_const_t : uint32_t

App-wide tunables.

Enumerator
k_sdram_demo_baud 

SDRAM demo baud.

k_sdram_demo_period_ms 

SDRAM demo period ms.

k_sdram_demo_block_bytes 

64 KB window per pass.

k_sdram_demo_block_words 

65536 / sizeof(uint32_t).

k_sdram_demo_us_per_ms 

Conversion factor used in mbps.

Definition at line 48 of file main.c.

◆ sdram_demo_seed_t

enum sdram_demo_seed_t : uint32_t

Pattern seed – recognisable hex word for SWD inspection.

Enumerator
k_sdram_demo_pattern_seed 

SDRAM demo pattern seed.

Definition at line 85 of file main.c.

Function Documentation

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Bench-tests SDRAM and prints MB/s.

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 bench + blink loop.
On read-back mismatch LED2 latches ON.
Since
0.1.0

Definition at line 365 of file main.c.

References k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, k_sdram_demo_block_bytes, k_sdram_demo_fail_buf, k_sdram_demo_pass_msg, k_sdram_demo_pattern_seed, k_sdram_demo_period_ms, k_sdram_demo_print_buf, ra8_board_led_on(), ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), sdram_demo_format_fail(), sdram_demo_format_line(), sdram_demo_mbps(), sdram_demo_panic_halt(), sdram_demo_read_check(), sdram_demo_setup_or_halt(), and sdram_demo_write_pass().

◆ sdram_demo_format_fail()

uint32_t sdram_demo_format_fail ( uint8_t * out,
const sdram_demo_diag_t * diag )
static

Format the read-back FAIL diagnostic line into out.

Emits sdram: FAIL idx=<dec> exp=<hex> got=<hex> n=<dec> so a HIL log shows the corruption signature. The literal sdram: FAIL prefix is what the HIL negative-match regex keys on.

Parameters
[out]outDestination buffer (>= k_sdram_demo_fail_buf bytes).
[in]diagFirst-mismatch diagnostic from sdram_demo_read_check.
Returns
Number of bytes written (no NUL terminator).
Precondition
out is non-NULL with >= k_sdram_demo_fail_buf capacity.
diag->count is non-zero (a mismatch was found).
Postcondition
No bytes beyond the returned length are touched.
Since
0.1.0

Definition at line 324 of file main.c.

References sdram_demo_diag_t::count, sdram_demo_diag_t::expected, sdram_demo_diag_t::first_idx, sdram_demo_diag_t::got, sdram_demo_uint_to_dec(), and sdram_demo_uint_to_hex().

Referenced by main().

◆ sdram_demo_format_line()

uint32_t sdram_demo_format_line ( uint8_t * out,
uint32_t w_mbps,
uint32_t r_mbps )
static

Format the per-cycle MB/s line into out, return its length.

Parameters
[out]outDestination buffer (>= k_sdram_demo_print_buf bytes).
[in]w_mbpsWrite throughput in MB/s.
[in]r_mbpsRead throughput in MB/s.
Returns
Number of bytes written (no NUL terminator).
Precondition
out is non-NULL with >= k_sdram_demo_print_buf capacity.
Postcondition
No bytes beyond the returned length are touched.
Since
0.1.0

Definition at line 288 of file main.c.

References sdram_demo_uint_to_dec().

Referenced by main().

◆ sdram_demo_mbps()

uint32_t sdram_demo_mbps ( uint32_t bytes,
uint32_t ms )
static

Compute throughput in MB/s given a byte count and millisecond span.

Returns (bytes / 1e6) / (ms / 1000) = bytes / (ms * 1000). The function clamps ms to 1 to avoid divide-by-zero when the benchmark loop is too fast to register on the millisecond tick.

Parameters
[in]bytesTotal bytes transferred.
[in]msElapsed time in milliseconds.
Returns
MB/s as an integer (truncated).
Precondition
None.
Postcondition
Return value never overflows uint32 for bytes <= 4 GB and ms >= 1.
Since
0.1.0

Definition at line 159 of file main.c.

References k_sdram_demo_us_per_ms.

Referenced by main().

◆ sdram_demo_panic_halt()

void sdram_demo_panic_halt ( void )
static

Park forever after a fatal init failure.

Precondition
Called only after a fatal error in boot.
Postcondition
CPU is parked; only a debugger or external reset wakes it.
Since
0.1.0

Definition at line 100 of file main.c.

Referenced by main(), and sdram_demo_setup_or_halt().

◆ sdram_demo_read_check()

bool sdram_demo_read_check ( uint32_t base,
uint32_t * elapsed,
sdram_demo_diag_t * diag )
static

Read every word back and check it matches base + i.

Parameters
[in]baseSeed used by the matching write pass.
[out]elapsedReceives the elapsed milliseconds.
[out]diagReceives the first-mismatch diagnostic.
Returns
true if every word matches the expected pattern.
Precondition
elapsed and diag are non-NULL.
Postcondition
On success *elapsed holds the read-pass duration.
diag->count holds the total mismatch count.
Since
0.1.0

Definition at line 198 of file main.c.

References sdram_demo_diag_t::count, sdram_demo_diag_t::expected, sdram_demo_diag_t::first_idx, sdram_demo_diag_t::got, k_ra8_sdram_base_addr, k_sdram_demo_block_words, and ra8_time_ms().

Referenced by main().

◆ sdram_demo_setup_or_halt()

void sdram_demo_setup_or_halt ( void )
static

◆ sdram_demo_uint_to_dec()

uint8_t sdram_demo_uint_to_dec ( uint8_t * buf,
uint32_t v )
static

Write a decimal uint32 into buf; returns bytes written.

Parameters
[out]bufDestination buffer (must hold at least 10 chars).
[in]vValue to render.
Returns
Number of ASCII digits written.
Precondition
buf is non-NULL with >= 10 bytes capacity.
Postcondition
No null terminator is written.
Since
0.1.0

Definition at line 254 of file main.c.

References k_sdram_demo_ascii_zero, k_sdram_demo_dec_base, and k_sdram_demo_uint_dec_max.

Referenced by sdram_demo_format_fail(), and sdram_demo_format_line().

◆ sdram_demo_uint_to_hex()

uint8_t sdram_demo_uint_to_hex ( uint8_t * buf,
uint32_t v )
static

Render v as exactly 8 lowercase hex digits into buf.

Parameters
[out]bufDestination (must hold >= k_sdram_demo_hex_digits).
[in]vValue to render.
Returns
Number of digits written (always k_sdram_demo_hex_digits).
Precondition
buf is non-NULL with >= 8 bytes capacity.
Postcondition
No null terminator is written.
Since
0.1.0

Definition at line 229 of file main.c.

References k_sdram_demo_ascii_a, k_sdram_demo_ascii_zero, k_sdram_demo_dec_base, k_sdram_demo_hex_digits, k_sdram_demo_nyb_bits, and k_sdram_demo_nyb_mask.

Referenced by sdram_demo_format_fail().

◆ sdram_demo_write_pass()

uint32_t sdram_demo_write_pass ( uint32_t base)
static

Write base + i into every word of the SDRAM block.

Parameters
[in]baseSeed value mixed into the pattern.
Returns
Elapsed milliseconds.
Precondition
ra8_sdramc_init succeeded so the SDRAM window is live.
Postcondition
Every word in the 64 KB block holds base + i.
Since
0.1.0

Definition at line 175 of file main.c.

References k_ra8_sdram_base_addr, k_sdram_demo_block_words, and ra8_time_ms().

Referenced by main().

Variable Documentation

◆ k_sdram_demo_pass_msg

const uint8_t k_sdram_demo_pass_msg[] = "sdram: bench OK\r\n"
static

Verdict line emitted only when a read-back pass matched every word (never on a "sdram: FAIL idx=" path); the HIL scrape keys on this success-only string.

Definition at line 92 of file main.c.

Referenced by main().