Skip to content
Draft
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
73 changes: 73 additions & 0 deletions src/port/rtl8735b/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# wolfIP on RealTek RTL8735B (AmebaPro2)

wolfIP TCP/IP stack running over the RTL8735B's native 10/100 Ethernet MAC (with its integrated Fast-Ethernet PHY), built inside the RealTek AmebaPro2 FreeRTOS SDK. Two demos, built from the same sources:

1. **Milestone 1** - DHCP client + raw TCP echo server (port 7). Proves the driver and stack.
2. **Milestone 2** - a wolfSSL TLS 1.2/1.3 client over a real wolfIP socket (add `--tls`).

## How it works

The RTL8735B has a native Ethernet MAC + integrated FEPHY (no external PHY). The vendor SDK exposes a frame-level mbed HAL (`ethernet_init/write/send/receive/read`) that owns the DMA descriptor rings and the D-cache clean/invalidate internally. This port is a thin adapter that binds wolfIP's two driver callbacks onto that HAL - no register-level MAC/DMA/MDIO code:

- wolfIP `send()` -> `ethernet_write()` + `ethernet_send()`
- wolfIP `poll()` -> `ethernet_receive()` + `ethernet_read()`

The whole stack runs in a single FreeRTOS task, so no wolfIP locking is required. RX is polled (milestone 1/2); the MAC IRQ hook only latches link up/down. The vendor lwIP layer is not used - wolfIP owns the interface.

## Files

| File | Purpose |
|------|---------|
| `wolfip_rtl8735b.c` / `.h` | wolfIP poll/send driver glue over the mbed Ethernet HAL |
| `main.c` | App: single task - MAC init, link/DHCP wait, echo server, optional TLS client |
| `config.h` | wolfIP build config (DHCP, socket counts, static-IP fallback) |
| `user_settings.h` | wolfSSL config for the TLS client (software crypto, ECDHE-ECDSA/AES-GCM) |
| `tls_client.c` / `.h` | Board-agnostic wolfIP TLS client (shared with the other ports) |
| `wolfip_eth.cmake` | SDK build integration (append wolfIP + optional wolfSSL sources) |
| `wolfip_cycle.sh` | Build -> flash -> read-console helper |

## Build and run

Prerequisites: the AmebaPro2 FreeRTOS SDK (`~/GitHub/ameba-rtos-pro2`), the ASDK 10.3.0 toolchain, and the hardware bench (Pi4 GPIO 21 boot-mode, J-Link nRESET for the CHIP_EN power-on reset, console on `/dev/ttyUSB5`). The system `arm-none-eabi-gcc` will not work - use the ASDK toolchain.

### SDK config

No SDK source edits are required. The non-TrustZone (`ntz`) app build already compiles the mbed Ethernet HAL: `DEVICE_ETHERNET=1` (device.h non-secure branch) and `CONFIG_MII_EN=1` (platform_conf_ntz.h). This port calls that HAL directly, so the vendor `CONFIG_ETHERNET`/lwIP path stays disabled (`CONFIG_ETHERNET=0`) and no lwIP is linked in.

### Hands-free cycle

```bash
cd ~/GitHub/wolfip/src/port/rtl8735b
./wolfip_cycle.sh # milestone 1: DHCP + echo
./wolfip_cycle.sh --tls # milestone 2: also build/run the TLS client
```

### Manual build

```bash
export PATH=~/ameba-pro2-workspace/asdk/asdk-10.3.0/linux/newlib/bin:$PATH
P=~/GitHub/ameba-rtos-pro2/project/realtek_amebapro2_v0_example
mkdir -p $P/component/example/wolfip_eth
cp main.c user_settings.h wolfip_eth.cmake $P/component/example/wolfip_eth/
cp main.c $P/src/main.c
cd $P/GCC-RELEASE && mkdir -p build && cd build
cmake .. -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake \
-DBUILD_FPGA=OFF -DBUILD_PXP=OFF -DEXAMPLE=wolfip_eth \
-DWOLFIP_ROOT=~/GitHub/wolfip
make flash -j8 # -> build/flash_ntz.bin
~/.claude/skills/amebapro2-flash/amebapro2_flash.sh build/flash_ntz.bin
uart-monitor tail GENERIC_UART_ttyUSB5
```

For the TLS build add `-DWOLFIP_ENABLE_TLS=ON -DWOLFSSL_ROOT=~/GitHub/wolfssl`.

## Verify

- **M1:** the console prints the MAC, `Link up`, and `DHCP bound: ip=...`. From the host: `ping <ip>` and `nc <ip> 7` (whatever you type is echoed back).
- **M2:** additionally `TLS: connecting to ...` and `TLS: received N bytes` with the server's response. The TLS target defaults to an ECDSA host; override with `-DTLS_TARGET_IP`/`-DTLS_TARGET_HOST`/`-DTLS_TARGET_PORT`. Certificate verification is disabled in the demo (no RTC / CA store).

## Notes / limits

- Certificate validation is off (`WOLFSSL_VERIFY_NONE`) - demo only. Add a CA store and an RTC/`NO_ASN_TIME` removal for production.
- RX is polled today. An IRQ-driven path (push frames via `wolfIP_recv_ex()` from the RX thread) is a planned follow-up.
- Descriptor rings are placed in the reserved `__sram_rev_start__` SRAM region and packet buffers in the vendor DMA heap, mirroring the SDK's own `ethernet_mii` driver.
71 changes: 71 additions & 0 deletions src/port/rtl8735b/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* config.h
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfIP TCP/IP stack.
*
* wolfIP is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfIP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*
* wolfIP build configuration for the RTL8735B (AmebaPro2) port.
*/
#ifndef WOLF_CONFIG_H
#define WOLF_CONFIG_H

#ifndef CONFIG_IPFILTER
#define CONFIG_IPFILTER 0
#endif

#define ETHERNET
#define LINK_MTU 1536

/* Socket configuration. The RTL8735B has ample DDR, but keep the stack's
* static footprint modest for the demo. */
#define MAX_TCPSOCKETS 8
#define MAX_UDPSOCKETS 2
#define MAX_ICMPSOCKETS 1
#define RXBUF_SIZE (LINK_MTU * 6)
#define TXBUF_SIZE (LINK_MTU * 6)

#define MAX_NEIGHBORS 16

#ifndef WOLFIP_MAX_INTERFACES
#define WOLFIP_MAX_INTERFACES 1
#endif

#ifndef WOLFIP_ENABLE_FORWARDING
#define WOLFIP_ENABLE_FORWARDING 0
#endif

#ifndef WOLFIP_ENABLE_LOOPBACK
#define WOLFIP_ENABLE_LOOPBACK 0
#endif

#ifndef WOLFIP_ENABLE_DHCP
#define WOLFIP_ENABLE_DHCP 1
#endif

/* Static IP fallback (used when DHCP is disabled or times out). */
#define WOLFIP_IP "192.168.1.100"
#define WOLFIP_NETMASK "255.255.255.0"
#define WOLFIP_GW "192.168.1.1"
#define WOLFIP_STATIC_DNS_IP "8.8.8.8"

#if WOLFIP_ENABLE_DHCP
#define DHCP
#define DHCP_DISCOVER_RETRIES 6
#define DHCP_REQUEST_RETRIES 6
#endif

#endif /* WOLF_CONFIG_H */
Loading
Loading