Skip to content

Commit 29633af

Browse files
authored
Merge pull request #22 from cpq/eth
Add pico-w5500
2 parents 253087d + f100b7a commit 29633af

File tree

13 files changed

+9447
-208
lines changed

13 files changed

+9447
-208
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- run: make -C step-5-cmsis
1616
- run: make -C step-6-clock
1717
- run: make -C step-7-webserver/nucleo-f429zi
18-
- run: make -C step-7-webserver/pico-w
18+
- run: make -C step-7-webserver/pico-w5500
1919
macos:
2020
runs-on: macos-latest
2121
steps:
@@ -29,4 +29,4 @@ jobs:
2929
- run: make -C step-5-cmsis
3030
- run: make -C step-6-clock
3131
- run: make -C step-7-webserver/nucleo-f429zi
32-
- run: make -C step-7-webserver/pico-w
32+
- run: make -C step-7-webserver/pico-w5500

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ table, startup code, linker script, build automation using `make`, GPIO
1515
peripheral and LED blinky, SysTick timer, UART peripheral and debug output,
1616
`printf` redirect to UART (IO retargeting), debugging with Segger Ozone,
1717
system clock setup, web server implementation with device dashboard, and
18-
automatic tests.
18+
automatic tests (including
19+
[automatic tests on a real hardware](https://github.com/cpq/continuous-hardware-test)).
1920

2021
Throughout the guide, we will be using a
2122
[Nucleo-F429ZI](https://www.st.com/en/evaluation-tools/nucleo-f429zi.html)
@@ -32,7 +33,7 @@ Nucleo-F429ZI.
3233
| --------- | ---------------- | ------------- | ------------ |
3334
| [STM32 Nucleo-F429ZI](step-7-webserver/nucleo-f429zi/) | [mcu datasheet](https://www.st.com/resource/en/reference_manual/dm00031020-stm32f405-415-stm32f407-417-stm32f427-437-and-stm32f429-439-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf) | [board datasheet](https//www.st.com/resource/en/user_manual/dm00244518-stm32-nucleo144-boards-mb1137-stmicroelectronics.pdf) | complete |
3435
| [TI EK-TM4C1294XL](step-7-webserver/ek-tm4c1294xl/) | [mcu datasheet](https://www.ti.com/lit/ds/symlink/tm4c1294ncpdt.pdf) | [board datasheet](https://www.ti.com/lit/ug/spmu365c/spmu365c.pdf) | complete |
35-
| [RP2040 Pico-W](step-7-webserver/pico-w/) | [mcu datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) | [board datasheet](https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf) | in progress |
36+
| [RP2040 Pico-W5500](step-7-webserver/pico-w/) | [mcu datasheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) | [board datasheet](https://datasheets.raspberrypi.com/picow/pico-datasheet.pdf) | complete |
3637

3738
Feel free to file an issue to support the board you work with.
3839

@@ -1681,7 +1682,8 @@ run](https://github.com/cpq/bare-metal-programming-guide/actions/runs/3840030588
16811682
16821683
Would it be great to also test built firmware binaries on a real hardware, to
16831684
test not only the build process, but that the built firmware is correct and
1684-
functional? Easy. See my other guide [COMING SOON] for detailed instructions.
1685+
functional? Easy. See my https://github.com/cpq/continuous-hardware-test
1686+
for detailed instructions.
16851687
16861688
## About the author
16871689

step-7-webserver/pico-w/main.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

step-7-webserver/pico-w/mcu.h

Lines changed: 0 additions & 167 deletions
This file was deleted.
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
CFLAGS ?= -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion \
22
-Wformat-truncation -fno-common -Wconversion -ffreestanding \
3-
-g3 -Os -ffunction-sections -fdata-sections -I. -Iinclude \
3+
-g3 -Os -ffunction-sections -fdata-sections -I. \
44
-mcpu=cortex-m0plus -mthumb $(EXTRA_CFLAGS)
55
LDFLAGS ?= -Tlink.ld -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map
66
SOURCES = main.c startup.c syscalls.c
77

8+
SOURCES += mongoose.c
9+
CFLAGS += -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1 -DMG_ENABLE_MIP=1
10+
11+
build: firmware.uf2
12+
813
ifeq ($(OS),Windows_NT)
914
RM = cmd /C del /Q /F
1015
BIN2UF2 = bin2uf2.exe
1116
else
1217
BIN2UF2 = ./bin2uf2
1318
RM = rm -f
19+
$(BIN2UF2): tools/bin2uf2.c
20+
$(CC) -W -Wall $< -o $@
1421
endif
1522

16-
build: firmware.uf2
17-
1823
firmware.elf: $(SOURCES) mcu.h
1924
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(LDFLAGS) -o $@
2025

@@ -24,8 +29,5 @@ firmware.bin: firmware.elf
2429
firmware.uf2: firmware.bin $(BIN2UF2)
2530
$(BIN2UF2) $< $@
2631

27-
$(BIN2UF2): tools/bin2uf2.c
28-
$(CC) -W -Wall $< -o $@
29-
3032
clean:
3133
$(RM) firmware.* bin2uf2
File renamed without changes.

step-7-webserver/pico-w5500/main.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) 2023 Cesanta Software Limited
2+
// All rights reserved
3+
4+
#include "mcu.h"
5+
#include "mongoose.h"
6+
7+
enum { LED = 25, UART_TX = 0, UART_RX = 1 }; // Pins
8+
enum { SPI_CS = 17, SPI_CLK = 18, SPI_TX = 19, SPI_RX = 16 }; // SPI pins
9+
enum { STATUS_TIMER_MS = 1000, BLINK_TIMER_MS = 500 }; // Timeouts
10+
11+
void my_spi_begin(void *spi) {
12+
spi_begin(spi);
13+
}
14+
void my_spi_end(void *spi) {
15+
spi_end(spi);
16+
}
17+
uint8_t my_spi_txn(void *spi, uint8_t byte) {
18+
uint8_t result = spi_txn(spi, byte);
19+
// MG_INFO(("%x -> %x", byte, result));
20+
return result;
21+
}
22+
23+
void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
24+
if (ev == MG_EV_HTTP_MSG) {
25+
mg_http_reply(c, 200, "", "ok\n");
26+
}
27+
(void) ev_data, (void) fn_data;
28+
}
29+
30+
static volatile uint32_t s_ticks;
31+
void SysTick_Handler(void) { // SyStick IRQ handler, triggered every 1ms
32+
s_ticks++;
33+
}
34+
35+
uint64_t mg_millis(void) {
36+
return s_ticks;
37+
}
38+
39+
int main(void) {
40+
clock_init(); // Init clocks
41+
uart_init(UART0, 115200, UART_RX, UART_TX); // Init UART
42+
gpio_init(LED, GPIO_MODE_OUTPUT, 0); // Init LED
43+
44+
MG_INFO(("Starting ..."));
45+
46+
// Init SPI
47+
struct spi spi0 = {
48+
.miso = SPI_TX, .mosi = SPI_RX, .clk = SPI_CLK, .cs = SPI_CS, .spin = 50};
49+
spi_init(&spi0);
50+
51+
// Init Mongoose
52+
struct mip_spi spi = {&spi0, my_spi_begin, my_spi_end, my_spi_txn};
53+
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
54+
.driver = &mip_driver_w5500,
55+
.driver_data = &spi};
56+
struct mg_mgr mgr; // Declare event manager
57+
mg_mgr_init(&mgr); // Init event manager
58+
mg_log_set(MG_LL_DEBUG); // Set DEBUG log level
59+
//mip_init(&mgr, &mif); // Init TCP/IP stack
60+
//mg_http_listen(&mgr, "http://0.0.0.0", fn, NULL); // HTTP listener
61+
62+
bool led_on = false; // Initial LED state
63+
uint32_t status_timer = 0, blink_timer = 0; // Initial timer expirations
64+
65+
// Infinite event manager loop
66+
for (;;) {
67+
if (timer_expired(&blink_timer, BLINK_TIMER_MS, s_ticks)) {
68+
led_on = !led_on; // Flip LED state
69+
// if (mip_driver_w5500.up(&mif)) led_on = true; // Always on if Eth up
70+
gpio_write(LED, led_on); // Set LED
71+
}
72+
if (timer_expired(&status_timer, STATUS_TIMER_MS, s_ticks)) {
73+
MG_INFO(("Ethernet: %s", mip_driver_w5500.up(&mif) ? "up" : "down"));
74+
}
75+
// mg_mgr_poll(&mgr, 1);
76+
}
77+
78+
return 0;
79+
}

0 commit comments

Comments
 (0)