Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion process-node-stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ LDFLAGS := \
-specs=nano.specs \
-specs=nosys.specs

APP_SRCS := main.c analog.c env.c i2cbus.c i2ctarget.c spi2.c uart3.c bench_cmds.c mcp2515.c syscalls.c sysmem.c system_stm32f4xx.c
APP_SRCS := main.c rl78emu.c rl78emu_port.c analog.c env.c i2cbus.c i2ctarget.c spi2.c uart3.c bench_cmds.c mcp2515.c syscalls.c sysmem.c system_stm32f4xx.c

HAL_SRCS := \
stm32f4xx_hal.c \
Expand Down Expand Up @@ -102,5 +102,7 @@ test-host: | $(BUILD_DIR)
$(BUILD_DIR)/test_mcp2515_timing
$(HOSTCC) -std=c11 -Wall -Wextra -Werror -I. tests/test_proc.c -o $(BUILD_DIR)/test_proc
$(BUILD_DIR)/test_proc
$(HOSTCC) -std=c11 -Wall -Wextra -Werror -I. tests/test_rl78emu.c rl78emu.c -o $(BUILD_DIR)/test_rl78emu
$(BUILD_DIR)/test_rl78emu

.PHONY: all clean flash test-host
28 changes: 28 additions & 0 deletions process-node-stm32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ With 8 MHz the fastest bitrate is 500 kbit/s; 1 Mbit/s needs a 16 MHz crystal.

Received frames print as `CAN rx id=0x123 ext=0 rtr=0 dlc=2 data=0102`.

## RL78 boot ROM emulator

Holding the console TX (PA9, the bench's LA3) low through reset starts an emulated RL78 boot
ROM instead of the node, the way an RL78 enters its programming mode when TOOL0 is low at reset.
It speaks RL78 Protocol A (Renesas R01AN0815) on that one wire, so a programmer can be tested on
this board with no RL78 on the bench:

- The part is an R5F100LE (RL78/G13): 64 KB code flash at 000000H, 4 KB data flash at 0F1000H,
1 KB blocks. Its flash lives in RAM, so every entry starts with an erased part.
- Commands: Reset, Baud Rate Set (115200, 250000, 500000, 1000000), Silicon Signature, Block
Erase, Block Blank Check, Programming, Verify, Checksum, Security Set, Get and Release, with the
guide's frames, checksums and status codes. Like real flash, a byte is written only when blank
(an erase comes first), and the security flags are enforced.
- The line is open drain, single-wire half duplex, 1 stop bit from the emulator (a programmer sends
2). It answers no sooner than the end of the programmer's second stop bit.
- TOOL0 has to stay low for about 6 ms after the reset release (the emulator sets up its flash in
that time). A real RL78 needs only 723 us plus tHD, so a programmer written for the real part
should hold it longer when it runs against this board.
- A normal boot is unchanged: the strap is sampled with the internal pull-up on, so an undriven
LA3 never starts the emulator.

`tests/rl78_programmer.py` is a minimal Protocol A programmer over the BenchPod's one-wire UART
(`open_uart(half_duplex=True, entry=UartEntry(...))`, pod firmware with gateware v57), and
`tests/test_rl78.py` (marker `rl78`) runs it against the emulator: entry and signature, program,
verify and checksum, data flash, parameter errors, every baud rate, security, and a normal boot
afterwards. The protocol core (`rl78emu.c`) is also covered on the host by
`tests/test_rl78emu.c` (`make test-host`).

## HIL tests

```bash
Expand Down
10 changes: 10 additions & 0 deletions process-node-stm32/STM32F446RETX_FLASH.ld
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ SECTIONS
__bss_end__ = _ebss;
} >RAM

/* Not zeroed at startup: the RL78 emulator's 68 KB flash (rl78emu_port.c fills it itself), so
the C runtime reaches main() fast enough to see the TOOL0 strap. */
.noinit (NOLOAD) :
{
. = ALIGN(4);
*(.noinit)
*(.noinit*)
. = ALIGN(4);
} >RAM

/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
._user_heap_stack :
{
Expand Down
10 changes: 9 additions & 1 deletion process-node-stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
* PB15 MOSI / PB14 MISO / PB12 CS (spi), USART3 PC10 TX / PC11 RX (uart3).
*
* Console: USART1 PA9 (TX) / PA10 (RX), 115200 8N1. Type "help".
* PA9 held low through reset starts the RL78 boot ROM emulator instead (rl78emu.h, README).
*/

#include "rl78emu.h"
#include "stm32f4xx_hal.h"
#include "alarm.h"
#include "analog.h"
Expand All @@ -42,7 +44,7 @@
#include <string.h>

#define FW_NAME "process-node"
#define FW_VERSION "0.3.0"
#define FW_VERSION "0.3.1"

#define CMD_BUF_SIZE 200

Expand Down Expand Up @@ -179,6 +181,12 @@ int main(void)
reset_cause_capture();
HAL_Init();
SystemClock_Config();
/* TOOL0 strap: the console TX held low through reset starts the RL78 boot ROM emulator
(rl78emu.h) instead of the node, so a Protocol A programmer can be tested on this board. */
if (rl78emu_strap())
{
rl78emu_main();
}

HAL_DBGMCU_EnableDBGSleepMode();
HAL_DBGMCU_EnableDBGStopMode();
Expand Down
Loading