Skip to content

Commit bd96da6

Browse files
dgarskedanielinux
authored andcommitted
Minor cleanups
1 parent 4bd4e9c commit bd96da6

3 files changed

Lines changed: 191 additions & 17 deletions

File tree

src/port/stm32h563/Makefile

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ SRCS += $(ROOT)/src/port/wolfssl_io.c
7171

7272
# HTTPS web server (requires TLS) - uses existing wolfIP httpd
7373
ifeq ($(ENABLE_HTTPS),1)
74+
75+
# HTTPS requires TLS
76+
ifeq ($(ENABLE_TLS),0)
77+
$(error ENABLE_HTTPS=1 requires ENABLE_TLS=1)
78+
endif
79+
7480
CFLAGS += -DENABLE_HTTPS
7581
SRCS += $(ROOT)/src/http/httpd.c
7682
endif
@@ -241,7 +247,27 @@ ifeq ($(ENABLE_MQTT),1)
241247
rm -f $(WOLFMQTT_ROOT)/src/*.o
242248
endif
243249

244-
.PHONY: all clean
250+
# Verify what features are compiled into the binary
251+
verify: app.bin
252+
@echo "=== Build Verification ==="
253+
@echo "Checking compiled features in app.bin..."
254+
@strings app.bin | grep -q "Initializing TLS server" && echo " ✓ TLS server enabled" || echo " ✗ TLS server disabled"
255+
@strings app.bin | grep -q "Initializing HTTPS server" && echo " ✓ HTTPS server enabled" || echo " ✗ HTTPS server disabled"
256+
@strings app.bin | grep -q "Initializing SSH server" && echo " ✓ SSH server enabled" || echo " ✗ SSH server disabled"
257+
@strings app.bin | grep -q "Initializing MQTT client" && echo " ✓ MQTT client enabled" || echo " ✗ MQTT client disabled"
258+
@echo ""
259+
@echo "Binary size: $$(ls -lh app.bin | awk '{print $$5}')"
260+
@echo "Build flags: TZEN=$(TZEN) ENABLE_TLS=$(ENABLE_TLS) ENABLE_HTTPS=$(ENABLE_HTTPS) ENABLE_SSH=$(ENABLE_SSH) ENABLE_MQTT=$(ENABLE_MQTT)"
261+
262+
# Show memory usage
263+
size: app.elf
264+
@echo "=== Memory Usage ==="
265+
@arm-none-eabi-size app.elf
266+
@echo ""
267+
@echo "Flash usage: $$(arm-none-eabi-size app.elf | awk 'NR==2{printf "%.1f%% (%d / %d bytes)", ($$1+$$2)*100/2097152, $$1+$$2, 2097152}')"
268+
@echo "RAM usage (static): $$(arm-none-eabi-size app.elf | awk 'NR==2{printf "%.1f%% (%d / %d bytes)", ($$2+$$3)*100/655360, $$2+$$3, 655360}')"
269+
270+
.PHONY: all clean verify size
245271

246272
# -----------------------------------------------------------------------------
247273
# Help
@@ -254,6 +280,8 @@ help:
254280
@echo "Targets:"
255281
@echo " all Build app.bin (default)"
256282
@echo " clean Remove build artifacts"
283+
@echo " verify Check which features are compiled in"
284+
@echo " size Show memory usage statistics"
257285
@echo " help Show this help"
258286
@echo ""
259287
@echo "Options:"
@@ -265,6 +293,8 @@ help:
265293
@echo " WOLFSSL_ROOT= Path to wolfSSL (default: ../wolfssl)"
266294
@echo " WOLFSSH_ROOT= Path to wolfSSH (default: ../wolfssh)"
267295
@echo " WOLFMQTT_ROOT= Path to wolfMQTT (default: ../wolfmqtt)"
296+
@echo " CC= C compiler (default: arm-none-eabi-gcc)"
297+
@echo " OBJCOPY= Objcopy tool (default: arm-none-eabi-objcopy)"
268298
@echo ""
269299
@echo "Examples:"
270300
@echo " make # Basic TCP echo (port 7)"
@@ -274,6 +304,10 @@ help:
274304
@echo " make ENABLE_TLS=1 ENABLE_MQTT=1 # TLS + MQTT client"
275305
@echo " make ENABLE_TLS=1 ENABLE_HTTPS=1 ENABLE_SSH=1 ENABLE_MQTT=1 # Full featured"
276306
@echo ""
307+
@echo "Full Build Command (recommended):"
308+
@echo " CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy \\"
309+
@echo " make ENABLE_TLS=1 ENABLE_HTTPS=1 ENABLE_SSH=1 ENABLE_MQTT=1"
310+
@echo ""
277311
@echo "Testing:"
278312
@echo " nc <ip> 7 # TCP echo"
279313
@echo " echo 'Hello' | openssl s_client -connect <ip>:8443 -quiet # TLS echo"

src/port/stm32h563/README.md

Lines changed: 152 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22

33
This directory contains a bare-metal port of wolfIP for the STM32H563 microcontroller, featuring an Ethernet driver and TCP/IP echo server example.
44

5+
## Quick Start
6+
7+
1. **Build with all features:**
8+
```bash
9+
cd src/port/stm32h563
10+
CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy \
11+
make ENABLE_TLS=1 ENABLE_HTTPS=1 ENABLE_SSH=1 ENABLE_MQTT=1
12+
```
13+
14+
2. **Flash to board:**
15+
```bash
16+
openocd -f interface/stlink-dap.cfg -f target/stm32h5x.cfg \
17+
-c "program app.bin 0x08000000 verify reset exit"
18+
```
19+
20+
3. **Monitor UART output** (115200 baud on /dev/ttyACM0):
21+
```bash
22+
screen /dev/ttyACM0 115200
23+
```
24+
Get the device IP address from the DHCP output.
25+
26+
4. **Test features** (replace `<device-ip>` with IP from step 3):
27+
```bash
28+
# TCP Echo
29+
echo "Hello" | nc <device-ip> 7
30+
31+
# HTTPS Web
32+
curl -k https://<device-ip>/
33+
34+
# SSH (password: wolfip)
35+
ssh admin@<device-ip>
36+
```
37+
538
## Hardware Requirements
639

740
- STM32H563 development board (e.g., NUCLEO-H563ZI)
@@ -27,11 +60,47 @@ sudo apt install gcc-arm-none-eabi openocd
2760

2861
```bash
2962
cd src/port/stm32h563
30-
make
63+
CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy make
3164
```
3265

3366
This produces `app.elf` and `app.bin` for use with TZEN=0 (TrustZone disabled).
3467

68+
### Verifying Build
69+
70+
After building, verify which features are compiled in:
71+
72+
```bash
73+
make verify
74+
```
75+
76+
Output example:
77+
```
78+
=== Build Verification ===
79+
Checking compiled features in app.bin...
80+
✓ TLS server enabled
81+
✓ HTTPS server enabled
82+
✓ SSH server enabled
83+
✓ MQTT client enabled
84+
85+
Binary size: 262K
86+
```
87+
88+
### Checking Memory Usage
89+
90+
```bash
91+
make size
92+
```
93+
94+
Output example:
95+
```
96+
=== Memory Usage ===
97+
text data bss dec hex filename
98+
265560 1804 400676 668040 a3188 app.elf
99+
100+
Flash usage: 12.7% (267364 / 2097152 bytes)
101+
RAM usage (static): 61.4% (402480 / 655360 bytes)
102+
```
103+
35104
### TrustZone Enabled Build
36105

37106
```bash
@@ -468,16 +537,15 @@ openssl s_client -connect <device-ip>:443 -tls1_3
468537

469538
```html
470539
<!DOCTYPE html><html><head><title>wolfIP STM32H563</title>
471-
...
472-
<h1>wolfIP Status</h1>
473-
<table>
474-
<tr><td class="label">Device</td><td class="value">STM32H563</td></tr>
475-
<tr><td class="label">IP Address</td><td class="value">192.168.0.197</td></tr>
476-
<tr><td class="label">Uptime</td><td class="value">1234 sec</td></tr>
477-
<tr><td class="label">TLS</td><td class="value">TLS 1.3</td></tr>
478-
<tr><td class="label">Cipher</td><td class="value">ECC P-256</td></tr>
479-
</table>
480-
...
540+
<style>body{font-family:sans-serif;margin:40px;}
541+
h1{color:#333;}table{border-collapse:collapse;}
542+
td{padding:8px 16px;border:1px solid #ddd;}</style></head>
543+
<body><h1>wolfIP Status</h1><table>
544+
<tr><td>Device</td><td>STM32H563</td></tr>
545+
<tr><td>IP Address</td><td>10.0.4.117</td></tr>
546+
<tr><td>Uptime</td><td>1234 sec</td></tr>
547+
<tr><td>TLS</td><td>TLS 1.3</td></tr>
548+
</table></body></html>
481549
```
482550

483551
### HTTPS Status Page
@@ -487,7 +555,6 @@ The status page displays:
487555
- IP address (dynamically updated from DHCP or static config)
488556
- Uptime in seconds (continuously updated)
489557
- TLS version (TLS 1.3)
490-
- Cipher suite (ECC P-256)
491558

492559
## SSH Server
493560

@@ -695,14 +762,16 @@ This provides:
695762
| `target_tzen.ld` | Linker script for TZEN=1 |
696763
| `config.h` | Build configuration |
697764
| `Makefile` | Build system |
698-
| `user_settings.h` | wolfSSL/wolfSSH configuration |
765+
| `user_settings.h` | wolfSSL/wolfSSH/wolfMQTT configuration |
699766
| `certs.h` | Embedded TLS certificates (TLS builds only) |
700767
| `tls_server.c/h` | TLS echo server (TLS builds only) |
701768
| `tls_client.c/h` | TLS client for outbound connections (TLS builds only) |
702-
| `https_server.c/h` | HTTPS web server (HTTPS builds only) |
769+
| `../http/httpd.c` | HTTPS web server - wolfIP httpd (HTTPS builds only) |
703770
| `ssh_server.c/h` | SSH shell server (SSH builds only) |
704771
| `ssh_keys.h` | Embedded SSH host key (SSH builds only) |
705772
| `mqtt_client.c/h` | MQTT client state machine (MQTT builds only) |
773+
| `../wolfssl_io.c` | wolfSSL I/O callbacks for wolfIP (TLS builds only) |
774+
| `../wolfssh_io.c` | wolfSSH I/O callbacks for wolfIP (SSH builds only) |
706775
| `../wolfmqtt_io.c` | wolfMQTT I/O callbacks for wolfIP (MQTT builds only) |
707776

708777
## Troubleshooting
@@ -712,25 +781,92 @@ This provides:
712781
- Check USB connection and correct serial port
713782
- Verify baud rate is 115200
714783
- Try resetting the board
784+
- Check that you're monitoring the correct port (usually /dev/ttyACM0)
715785

716786
### OpenOCD Connection Fails
717787

718788
- Ensure ST-LINK drivers are installed
719789
- Try `sudo` if permission denied
720790
- Check that no other debugger is connected
791+
- Use `openocd --version` to verify installation
792+
793+
### Features Not Initializing
794+
795+
If you don't see "Initializing TLS/HTTPS/SSH/MQTT" messages in UART output:
796+
797+
**Problem:** Built without proper `ENABLE_*` flags
798+
799+
**Solution:** Rebuild with required flags:
800+
```bash
801+
CC=arm-none-eabi-gcc OBJCOPY=arm-none-eabi-objcopy \
802+
make clean && make ENABLE_TLS=1 ENABLE_HTTPS=1 ENABLE_SSH=1 ENABLE_MQTT=1
803+
```
804+
805+
**Verify build:** Check that strings exist in binary:
806+
```bash
807+
strings app.bin | grep "Initializing TLS"
808+
strings app.bin | grep "Initializing HTTPS"
809+
strings app.bin | grep "Initializing SSH"
810+
strings app.bin | grep "Initializing MQTT"
811+
```
721812

722813
### Ethernet Not Responding
723814

724815
- Verify physical Ethernet connection
725-
- Check that host PC is on same subnet (192.168.12.x)
726-
- Confirm PHY link is up (check serial output for "link" status)
816+
- Check that host PC is on same subnet
817+
- Confirm PHY link is up (check serial output for "PHY link: UP")
818+
- If using DHCP, ensure a DHCP server is available on the network
819+
- Try pinging the device: `ping <device-ip>`
820+
821+
### DHCP Netmask Display Issue
822+
823+
**Known Issue:** The DHCP netmask may display incorrectly in UART output (showing gateway IP instead).
824+
825+
**Workaround:** The device still functions correctly - the netmask is stored properly internally. This is a display-only issue in the UART output. You can verify correct operation by testing network connectivity.
826+
827+
**Example UART output:**
828+
```
829+
DHCP configuration received:
830+
IP: 10.0.4.117
831+
Mask: 10.0.4.1 <- Shows gateway instead of 255.255.255.0
832+
GW: 10.0.4.1
833+
```
834+
835+
### HTTPS Content-Length Error
836+
837+
If `curl` shows "Invalid Content-Length" error:
838+
- This is a known issue with the httpd implementation
839+
- Use `-k` flag: `curl -k https://<device-ip>/`
840+
- Or access via web browser and accept the self-signed certificate
841+
842+
### Build Fails with "arpa/inet.h not found"
843+
844+
**Problem:** wolfSSL trying to include system headers
845+
846+
**Solution:** Ensure `user_settings.h` contains:
847+
```c
848+
#define WOLFSSL_NO_SOCK
849+
#define NO_WOLFSSL_DIR
850+
```
851+
These are already in the default `user_settings.h`.
727852

728853
### TrustZone Errors
729854

730855
If you see `stm32h5x.cpu in Secure state` but built with TZEN=0:
731856
- The board has TrustZone enabled
732857
- Either rebuild with `make TZEN=1` or disable TrustZone via option bytes
733858

859+
### Compiler Not Found
860+
861+
If make fails with "command not found":
862+
```bash
863+
# Install ARM toolchain
864+
sudo apt install gcc-arm-none-eabi
865+
866+
# Or specify full path
867+
make CC=/usr/bin/arm-none-eabi-gcc OBJCOPY=/usr/bin/arm-none-eabi-objcopy
868+
```
869+
734870
## License
735871

736872
This code is part of wolfIP and is licensed under GPLv3. See the LICENSE file in the repository root for details.

src/port/stm32h563/user_settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ extern "C" {
3939
#define NO_WRITEV
4040
#define NO_MAIN_DRIVER
4141

42+
/* Bare-metal: no system headers */
43+
#define WOLFSSL_NO_SOCK
44+
#define NO_WOLFSSL_DIR
45+
4246
/* ------------------------------------------------------------------------- */
4347
/* Math - Portable C implementation */
4448
/* ------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)