mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
Make w5500 driver like the rest
This commit is contained in:
1 parent
277741ca53
commit
93f2939655
17 files changed
+182
-130
No files matched your search
@@ -4,13 +4,12 @@
|
||||
CFLAGS = -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion
|
||||
CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion
|
||||
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
|
||||
CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_g0/Include -Imongoose
|
||||
CFLAGS += -I. -I../../../.. -Icmsis_core/CMSIS/Core/Include -Icmsis_g0/Include
|
||||
CFLAGS += -mcpu=cortex-m0 -mthumb -mfloat-abi=soft $(CFLAGS_EXTRA)
|
||||
LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections
|
||||
|
||||
SOURCES = main.c hal.c
|
||||
SOURCES = main.c hal.c ../../../../mongoose.c
|
||||
SOURCES += cmsis_g0/Source/Templates/gcc/startup_stm32g031xx.s
|
||||
SOURCES += mongoose/mongoose.c
|
||||
|
||||
CFLAGS += -DHTTP_URL=\"http://0.0.0.0/\"
|
||||
|
||||
@@ -19,7 +18,7 @@ all build example: firmware.bin
|
||||
mongoose/mongoose.c mongoose/mongoose.h:
|
||||
cp ../../../../mongoose.[ch] mongoose/
|
||||
|
||||
firmware.elf: cmsis_core cmsis_g0 hal.h link.ld Makefile $(SOURCES) mongoose/mongoose.h
|
||||
firmware.elf: cmsis_core cmsis_g0 hal.h link.ld Makefile $(SOURCES) ../../../../mongoose.h
|
||||
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(CFLAGS_EXTRA) $(LDFLAGS) -o $@
|
||||
|
||||
firmware.bin: firmware.elf
|
||||
|
||||
@@ -21,6 +21,14 @@ static struct spi spi_pins = {
|
||||
.cs = PIN('A', 4),
|
||||
};
|
||||
|
||||
// SPI bus used by the W5500 driver, see MG_TCPIP_DRIVER_W5500_INIT
|
||||
struct mg_tcpip_spi mg_spi = {
|
||||
.begin = (void (*)(void *)) spi_begin,
|
||||
.end = (void (*)(void *)) spi_end,
|
||||
.txn = (void (*)(void *, uint8_t *, uint8_t *, size_t)) spi_txn,
|
||||
.spi = &spi_pins,
|
||||
};
|
||||
|
||||
static void log_fn(char ch, void *param) {
|
||||
uart_write_buf(param, &ch, 1);
|
||||
}
|
||||
@@ -82,35 +90,19 @@ int main(void) {
|
||||
// ethernet_init(); // Initialise ethernet pins
|
||||
MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));
|
||||
|
||||
spi_init(&spi_pins); // SPI must be ready before mg_mgr_init()
|
||||
struct mg_mgr mgr; // Initialise
|
||||
mg_mgr_init(&mgr); // Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Mongoose event manager and W5500 driver
|
||||
|
||||
// Initialise Mongoose network stack
|
||||
spi_init(&spi_pins);
|
||||
struct mg_tcpip_spi spi = {
|
||||
.begin = (void (*)(void *)) spi_begin,
|
||||
.end = (void (*)(void *)) spi_end,
|
||||
.txn = (void (*)(void *, uint8_t *, uint8_t *, size_t)) spi_txn,
|
||||
.spi = &spi_pins,
|
||||
};
|
||||
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(),
|
||||
// Uncomment below for static configuration:
|
||||
// .ip = mg_htonl(MG_U32(192, 168, 0, 223)),
|
||||
// .mask = mg_htonl(MG_U32(255, 255, 255, 0)),
|
||||
// .gw = mg_htonl(MG_U32(192, 168, 0, 1)),
|
||||
.driver = &mg_tcpip_driver_w5500,
|
||||
.driver_data = &spi};
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
|
||||
MG_INFO(("MAC: %M. Waiting for IP...", mg_print_mac, mif.mac));
|
||||
while (mif.state != MG_TCPIP_STATE_READY) {
|
||||
MG_INFO(("Waiting for IP..."));
|
||||
while (mgr.ifp->state != MG_TCPIP_STATE_READY) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
}
|
||||
|
||||
MG_INFO(("Initialising application..."));
|
||||
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, &mif);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:80", fn, &mif);
|
||||
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, mgr.ifp);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:80", fn, mgr.ifp);
|
||||
|
||||
MG_INFO(("Starting event loop"));
|
||||
for (;;) {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// See https://mongoose.ws/docs/getting-started/build-environment/
|
||||
#define MG_ARCH MG_ARCH_ARMGCC
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
#define MG_IO_SIZE 128
|
||||
#define MG_ENABLE_LINES 1
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
// See https://mongoose.ws/docs/getting-started/build-environment/
|
||||
#define MG_ARCH MG_ARCH_ARMGCC
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
#define MG_IO_SIZE 128
|
||||
#define MG_ENABLE_LINES 1
|
||||
|
||||
// For static IP configuration, define MG_TCPIP_{IP,MASK,GW}
|
||||
// #define MG_TCPIP_IP MG_IPV4(192, 168, 0, 223)
|
||||
// #define MG_TCPIP_GW MG_IPV4(192, 168, 0, 1)
|
||||
// #define MG_TCPIP_MASK MG_IPV4(255, 255, 255, 0)
|
||||
|
||||
// Construct MAC address from the MCU unique ID. It is defined in the
|
||||
// ST CMSIS header as UID_BASE
|
||||
#define MGUID ((uint32_t *) 0x1FFF7590) // Unique 96-bit chip ID
|
||||
#define MG_SET_MAC_ADDRESS(mac) \
|
||||
do { \
|
||||
mac[0] = 2; \
|
||||
mac[1] = MGUID[0] & 255; \
|
||||
mac[2] = (MGUID[0] >> 10) & 255; \
|
||||
mac[3] = (MGUID[0] >> 19) & 255; \
|
||||
mac[4] = MGUID[1] & 255; \
|
||||
mac[5] = MGUID[2] & 255; \
|
||||
} while (0)
|
||||
Reference in new issue
Block a user