mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Move mip/ -> src/tcpip/, rename mip_ -> mg_tcpip_
This commit is contained in:
1 parent
efc54375dd
commit
2c62e58dbd
64 files changed
+515
-516
No files matched your search
@@ -9,6 +9,6 @@
|
||||
|
||||
#define MG_ARCH MG_ARCH_CUSTOM
|
||||
#define MG_ENABLE_SOCKET 0
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define mkdir(a, b) (-1)
|
||||
//#define MG_ENABLE_LOG 0
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#define SS_PIN 3 // Slave select pin
|
||||
struct mg_mgr mgr; // Mongoose event manager
|
||||
struct mip_spi spi = {
|
||||
struct mg_tcpip_spi spi = {
|
||||
NULL, // SPI data
|
||||
[](void *) { digitalWrite(SS_PIN, LOW); }, // begin transation
|
||||
[](void *) { digitalWrite(SS_PIN, HIGH); }, // end transaction
|
||||
[](void *, uint8_t c) { return SPI.transfer(c); }, // execute transaction
|
||||
};
|
||||
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // MIP network interface
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5}}; // MIP network interface
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@@ -23,15 +23,15 @@ void setup() {
|
||||
delay(3000);
|
||||
MG_INFO(("Starting TCP/IP stack..."));
|
||||
|
||||
mif.driver = &mip_driver_w5500;
|
||||
mif.driver = &mg_tcpip_driver_w5500;
|
||||
mif.driver_data = &spi;
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
|
||||
// Start a 5 sec timer, print status message periodically
|
||||
mg_timer_add(
|
||||
&mgr, 5000, MG_TIMER_REPEAT,
|
||||
[](void *) {
|
||||
MG_INFO(("ethernet: %s", mip_driver_w5500.up(&mif) ? "up" : "down"));
|
||||
MG_INFO(("ethernet: %s", mg_tcpip_driver_w5500.up(&mif) ? "up" : "down"));
|
||||
},
|
||||
NULL);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
PROG ?= example
|
||||
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_MIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1 -I../..
|
||||
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1 -I../..
|
||||
CFLAGS ?= -W -Wall $(EXTRA_CFLAGS)
|
||||
LIBS ?= -lpcap
|
||||
SOURCES = main.c ../../mongoose.c ../device-dashboard/net.c ../device-dashboard/packed_fs.c
|
||||
|
||||
@@ -18,7 +18,7 @@ void signal_handler(int signo) {
|
||||
s_signo = signo;
|
||||
}
|
||||
|
||||
static size_t pcap_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t pcap_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
int res = pcap_inject((pcap_t *) ifp->driver_data, buf, len);
|
||||
if (res == PCAP_ERROR) {
|
||||
MG_ERROR(("pcap_inject: %d", res));
|
||||
@@ -26,11 +26,11 @@ static size_t pcap_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
return res == PCAP_ERROR ? 0 : len;
|
||||
}
|
||||
|
||||
static bool pcap_up(struct mip_if *ifp) {
|
||||
static bool pcap_up(struct mg_tcpip_if *ifp) {
|
||||
return ifp->driver_data ? true : false;
|
||||
}
|
||||
|
||||
static size_t pcap_rx(void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t pcap_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
size_t received = 0;
|
||||
struct pcap_pkthdr *hdr = NULL;
|
||||
const unsigned char *pkt = NULL;
|
||||
@@ -132,11 +132,11 @@ int main(int argc, char *argv[]) {
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
struct mip_driver driver = {.tx = pcap_tx, .up = pcap_up, .rx = pcap_rx};
|
||||
struct mip_if mif = {.driver = &driver, .driver_data = ph};
|
||||
struct mg_tcpip_driver driver = {.tx = pcap_tx, .up = pcap_up, .rx = pcap_rx};
|
||||
struct mg_tcpip_if mif = {.driver = &driver, .driver_data = ph};
|
||||
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1],
|
||||
&mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]);
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
// extern void device_dashboard_fn(struct mg_connection *, int, void *, void
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
PROG ?= example
|
||||
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_MIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1 -I../..
|
||||
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_SOCKET=0 -DMG_ENABLE_PACKED_FS=1 -I../..
|
||||
CFLAGS ?= -W -Wall $(EXTRA_CFLAGS)
|
||||
LIBS ?=
|
||||
SOURCES = main.c ../../mongoose.c ../device-dashboard/net.c ../device-dashboard/packed_fs.c
|
||||
|
||||
@@ -22,7 +22,7 @@ void signal_handler(int signo) {
|
||||
s_signo = signo;
|
||||
}
|
||||
|
||||
static size_t tap_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t tap_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
ssize_t res = write(*(int*) ifp->driver_data, buf, len);
|
||||
if (res < 0) {
|
||||
MG_ERROR(("tap_tx failed: %d", errno));
|
||||
@@ -31,11 +31,11 @@ static size_t tap_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
return (size_t) res;
|
||||
}
|
||||
|
||||
static bool tap_up(struct mip_if *ifp) {
|
||||
static bool tap_up(struct mg_tcpip_if *ifp) {
|
||||
return ifp->driver_data ? true : false;
|
||||
}
|
||||
|
||||
static size_t tap_rx(void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t tap_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
ssize_t received = read(*(int *) ifp->driver_data, buf, len);
|
||||
usleep(1); // This is to avoid 100% CPU
|
||||
if (received < 0) return 0;
|
||||
@@ -92,11 +92,11 @@ int main(int argc, char *argv[]) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
|
||||
struct mip_driver driver = {.tx = tap_tx, .up = tap_up, .rx = tap_rx};
|
||||
struct mip_if mif = {.driver = &driver, .driver_data = &fd};
|
||||
struct mg_tcpip_driver driver = {.tx = tap_tx, .up = tap_up, .rx = tap_rx};
|
||||
struct mg_tcpip_if mif = {.driver = &driver, .driver_data = &fd};
|
||||
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1],
|
||||
&mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]);
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
// Start infinite event loop
|
||||
|
||||
@@ -9,7 +9,7 @@ pico_sdk_init()
|
||||
add_compile_definitions(
|
||||
MIP_DEBUG=1
|
||||
MG_ENABLE_PACKED_FS=1
|
||||
MG_ENABLE_MIP=1
|
||||
MG_ENABLE_TCPIP=1
|
||||
)
|
||||
|
||||
add_executable(firmware
|
||||
|
||||
@@ -29,7 +29,7 @@ static dma_channel_config dmacfg_tx;
|
||||
|
||||
static uint8_t s_rxbuf[2][ETH_PKT_SIZE]; // ping-pong buffer
|
||||
static uint8_t s_txbuf[ETH_PKT_SIZE];
|
||||
static struct mip_if *s_ifp; // MIP interface
|
||||
static struct mg_tcpip_if *s_ifp; // MIP interface
|
||||
|
||||
#define rmii_tx_wrap_target 0
|
||||
#define rmii_tx_wrap 8
|
||||
@@ -251,9 +251,9 @@ static uint16_t eth_read_phy(uint addr, uint reg, uint8_t gpio) {
|
||||
|
||||
static void rx_irq(void);
|
||||
|
||||
static bool mip_driver_rp2040_rmii_init(struct mip_if *ifp) {
|
||||
struct mip_driver_rp2040_rmii_data *d =
|
||||
(struct mip_driver_rp2040_rmii_data *) ifp->driver_data;
|
||||
static bool mg_tcpip_driver_rp2040_rmii_init(struct mg_tcpip_if *ifp) {
|
||||
struct mg_tcpip_driver_rp2040_rmii_data *d =
|
||||
(struct mg_tcpip_driver_rp2040_rmii_data *) ifp->driver_data;
|
||||
uint rx_sm_addr, tx_sm_addr;
|
||||
s_ifp = ifp;
|
||||
if (ifp->queue.len == 0) ifp->queue.len = 8192;
|
||||
@@ -299,8 +299,8 @@ static bool mip_driver_rp2040_rmii_init(struct mip_if *ifp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t mip_driver_rp2040_rmii_tx(const void *buf, size_t len,
|
||||
struct mip_if *ifp) {
|
||||
static size_t mg_tcpip_driver_rp2040_rmii_tx(const void *buf, size_t len,
|
||||
struct mg_tcpip_if *ifp) {
|
||||
dma_channel_wait_for_finish_blocking(dma_tx);
|
||||
memset(s_txbuf, 0, 60); // pre-pad
|
||||
memcpy(s_txbuf, buf, len);
|
||||
@@ -333,12 +333,12 @@ static void rx_irq(void) {
|
||||
// time we can linger here is what it takes for the other buffer to fill
|
||||
// (<8us) and that includes irq chaining
|
||||
if (len >= 64 && len <= ETH_PKT_SIZE)
|
||||
mip_qwrite(s_rxbuf[s_rxno], len, s_ifp);
|
||||
mg_tcpip_qwrite(s_rxbuf[s_rxno], len, s_ifp);
|
||||
s_rxno = rxno;
|
||||
}
|
||||
|
||||
static size_t mip_driver_rp2040_rmii_rx(void *buf, size_t buflen, struct mip_if *ifp) {
|
||||
size_t len = mip_qread(buf, ifp);
|
||||
static size_t mg_tcpip_driver_rp2040_rmii_rx(void *buf, size_t buflen, struct mg_tcpip_if *ifp) {
|
||||
size_t len = mg_tcpip_qread(buf, ifp);
|
||||
if (len == 0) return 0;
|
||||
len -= 4; // exclude CRC from frame length
|
||||
uint32_t crc = crc_calc(buf, len); // calculate CRC and compare
|
||||
@@ -350,17 +350,17 @@ static size_t mip_driver_rp2040_rmii_rx(void *buf, size_t buflen, struct mip_if
|
||||
return len;
|
||||
}
|
||||
|
||||
static bool mip_driver_rp2040_rmii_up(struct mip_if *ifp) {
|
||||
struct mip_driver_rp2040_rmii_data *d =
|
||||
(struct mip_driver_rp2040_rmii_data *) ifp->driver_data;
|
||||
static bool mg_tcpip_driver_rp2040_rmii_up(struct mg_tcpip_if *ifp) {
|
||||
struct mg_tcpip_driver_rp2040_rmii_data *d =
|
||||
(struct mg_tcpip_driver_rp2040_rmii_data *) ifp->driver_data;
|
||||
uint32_t bsr =
|
||||
eth_read_phy(d->phy_addr, 1, d->mdio); // Basic Status Register
|
||||
return (bsr & (1 << 2)) ? 1 : 0; // check Link Status flag
|
||||
}
|
||||
|
||||
struct mip_driver mip_driver_rp2040_rmii = {
|
||||
mip_driver_rp2040_rmii_init,
|
||||
mip_driver_rp2040_rmii_tx,
|
||||
mip_driver_rp2040_rmii_rx,
|
||||
mip_driver_rp2040_rmii_up,
|
||||
struct mg_tcpip_driver mg_tcpip_driver_rp2040_rmii = {
|
||||
mg_tcpip_driver_rp2040_rmii_init,
|
||||
mg_tcpip_driver_rp2040_rmii_tx,
|
||||
mg_tcpip_driver_rp2040_rmii_rx,
|
||||
mg_tcpip_driver_rp2040_rmii_up,
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
struct mip_driver_rp2040_rmii_data {
|
||||
struct mg_tcpip_driver_rp2040_rmii_data {
|
||||
uint8_t rx0; // RX0, RX1, CRS_DV; consecutive GPIO pins
|
||||
uint8_t tx0; // TX0, TX1, TX-EN; consecutive GPIO pins
|
||||
uint8_t mdio; // MDIO, MDC; consecutive GPIO pins
|
||||
uint8_t phy_addr; // PHY address
|
||||
};
|
||||
|
||||
extern struct mip_driver mip_driver_rp2040_rmii;
|
||||
extern struct mg_tcpip_driver mg_tcpip_driver_rp2040_rmii;
|
||||
@@ -30,7 +30,7 @@ int main(void) {
|
||||
MG_INFO(("Init MIP"));
|
||||
// Initialise Mongoose network stack and specific driver
|
||||
// Set consecutive GPIOs for RMII (tx and rx) and SMI function groups
|
||||
struct mip_driver_rp2040_rmii_data driver_data = {
|
||||
struct mg_tcpip_driver_rp2040_rmii_data driver_data = {
|
||||
// see driver_rp2040_rmii.h
|
||||
.rx0 = 6, // 6, 7, 8 : RX0, RX1, CRS_DV
|
||||
.tx0 = 10, // 10, 11, 12 : TX0, TX1, TX-EN
|
||||
@@ -39,13 +39,13 @@ int main(void) {
|
||||
};
|
||||
// Specify MAC address, either set use_dhcp or enter a static config.
|
||||
// For static configuration, specify IP/mask/GW in network byte order
|
||||
struct mip_if mif = {
|
||||
struct mg_tcpip_if mif = {
|
||||
.mac = {2, 0, 1, 2, 3, 5},
|
||||
.ip = 0,
|
||||
.driver = &mip_driver_rp2040_rmii,
|
||||
.driver = &mg_tcpip_driver_rp2040_rmii,
|
||||
.driver_data = &driver_data,
|
||||
};
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0", fn, NULL); // HTTP listener
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pico_enable_stdio_usb(firmware 0) # Route stdio
|
||||
pico_enable_stdio_uart(firmware 1) # to the UART
|
||||
|
||||
# Mongoose build flags
|
||||
add_definitions(-DMG_ENABLE_MIP=1)
|
||||
add_definitions(-DMG_ENABLE_TCPIP=1)
|
||||
add_definitions(-DMG_ENABLE_PACKED_FS=1)
|
||||
add_definitions(-DMG_ENABLE_FILE=0)
|
||||
add_definitions(-DDISABLE_ROUTING=1)
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include "tusb.h"
|
||||
|
||||
static struct mip_if *s_ifp;
|
||||
static struct mg_tcpip_if *s_ifp;
|
||||
|
||||
const uint8_t tud_network_mac_address[6] = {2, 2, 0x84, 0x6A, 0x96, 0};
|
||||
|
||||
@@ -15,7 +15,7 @@ static void blink_cb(void *arg) { // Blink periodically
|
||||
}
|
||||
|
||||
bool tud_network_recv_cb(const uint8_t *buf, uint16_t len) {
|
||||
mip_qwrite((void *) buf, len, s_ifp);
|
||||
mg_tcpip_qwrite((void *) buf, len, s_ifp);
|
||||
// MG_INFO(("RECV %hu", len));
|
||||
// mg_hexdump(buf, len);
|
||||
tud_network_recv_renew();
|
||||
@@ -30,7 +30,7 @@ uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
if (!tud_ready()) return 0;
|
||||
while (!tud_network_can_xmit(len)) tud_task();
|
||||
tud_network_xmit((void *) buf, len);
|
||||
@@ -38,7 +38,7 @@ static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
return len;
|
||||
}
|
||||
|
||||
static bool usb_up(struct mip_if *ifp) {
|
||||
static bool usb_up(struct mg_tcpip_if *ifp) {
|
||||
(void) ifp;
|
||||
return tud_inited() && tud_ready() && tud_connected();
|
||||
}
|
||||
@@ -56,15 +56,15 @@ int main(void) {
|
||||
mg_mgr_init(&mgr); // and attach it to the MIP interface
|
||||
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);
|
||||
|
||||
struct mip_driver driver = {.tx = usb_tx, .rx = mip_driver_rx, .up = usb_up};
|
||||
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
|
||||
struct mg_tcpip_driver driver = {.tx = usb_tx, .rx = mg_tcpip_driver_rx, .up = usb_up};
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
|
||||
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
|
||||
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
|
||||
.enable_dhcp_server = true,
|
||||
.driver = &driver,
|
||||
.queue.len = 4096};
|
||||
s_ifp = &mif;
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
tusb_init();
|
||||
|
||||
MG_INFO(("Initialising application..."));
|
||||
|
||||
@@ -21,7 +21,7 @@ pico_enable_stdio_usb(firmware 0)
|
||||
pico_enable_stdio_uart(firmware 1)
|
||||
|
||||
# Mongoose build flags
|
||||
add_definitions(-DMG_ENABLE_MIP=1)
|
||||
add_definitions(-DMG_ENABLE_TCPIP=1)
|
||||
add_definitions(-DMG_ENABLE_PACKED_FS=1)
|
||||
add_definitions(-DMG_ENABLE_FILE=0)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ static uint8_t spi_txn(void *spi, uint8_t byte) {
|
||||
|
||||
static void timer_cb(void *arg) {
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, !gpio_get_out_level(PICO_DEFAULT_LED_PIN));
|
||||
bool up = ((struct mip_if *) arg)->state == MIP_STATE_READY;
|
||||
bool up = ((struct mg_tcpip_if *) arg)->state == MIP_STATE_READY;
|
||||
MG_INFO(("Ethernet: %s", up ? "up" : "down")); // Show network status
|
||||
}
|
||||
|
||||
@@ -43,14 +43,14 @@ int main(void) {
|
||||
gpio_put(SPI_CS, 1); // And drive CS high (inactive)
|
||||
|
||||
// Init Mongoose
|
||||
struct mip_spi spi = {NULL, spi_begin, spi_end, spi_txn};
|
||||
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mip_driver_w5500,
|
||||
struct mg_tcpip_spi spi = {NULL, spi_begin, spi_end, spi_txn};
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mg_tcpip_driver_w5500,
|
||||
.driver_data = &spi};
|
||||
struct mg_mgr mgr; // Declare event manager
|
||||
mg_mgr_init(&mgr); // Init event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set DEBUG log level
|
||||
mip_init(&mgr, &mif); // Init TCP/IP stack
|
||||
mg_tcpip_init(&mgr, &mif); // Init TCP/IP stack
|
||||
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_cb, &mif);
|
||||
|
||||
MG_INFO(("Waiting until network is up..."));
|
||||
|
||||
@@ -14,7 +14,7 @@ SOURCES = main.c syscalls.c cmsis_device_f4/Source/Templates/gcc/startup_stm32f4
|
||||
|
||||
# Mongoose-specific build flags and source code files
|
||||
# Build options reference: https://mongoose.ws/documentation/#build-options
|
||||
CFLAGS += -I../../.. -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1 -DMG_ENABLE_MIP=1 -DMG_ENABLE_PACKED_FS=1
|
||||
CFLAGS += -I../../.. -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_PACKED_FS=1
|
||||
SOURCES += ../../../mongoose.c ../../device-dashboard/net.c ../../device-dashboard/packed_fs.c
|
||||
|
||||
# Build flashable .bin file
|
||||
|
||||
@@ -10,7 +10,7 @@ which implements the following:
|
||||
- MQTT communication with a remote MQTT server
|
||||
- No dependencies: no HAL, no CMSIS, no RTOS
|
||||
- Hand-written [mcu.h](mcu.h) header based on a [datasheet](https://www.st.com/resource/en/reference_manual/rm0090-stm32f405415-stm32f407417-stm32f427437-and-stm32f429439-advanced-armbased-32bit-mcus-stmicroelectronics.pdf)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/mip_driver_stm32.c)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/driver_stm32.c)
|
||||
- Blue LED blinky, based on SysTick interrupt
|
||||
- User button handler, turns off/on green LED, based on EXTI, interrupt-driven
|
||||
- HardFault handler that blinks red LED
|
||||
|
||||
@@ -38,7 +38,7 @@ void SystemInit(void) { // Called automatically by startup code
|
||||
|
||||
static void timer_fn(void *arg) {
|
||||
gpio_toggle(LED2); // Blink LED
|
||||
bool up = ((struct mip_if *) arg)->state == MIP_STATE_READY;
|
||||
bool up = ((struct mg_tcpip_if *) arg)->state == MIP_STATE_READY;
|
||||
MG_INFO(("Ethernet: %s", up ? "up" : "down")); // Show network status
|
||||
}
|
||||
|
||||
@@ -74,11 +74,11 @@ int main(void) {
|
||||
// Initialise Mongoose network stack
|
||||
// Specify MAC address, and IP/mask/GW in network byte order for static
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
struct mip_driver_stm32_data driver_data = {.mdc_cr = 4}; // driver_stm32.h
|
||||
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mip_driver_stm32,
|
||||
.driver_data = &driver_data};
|
||||
mip_init(&mgr, &mif);
|
||||
struct mg_tcpip_driver_stm32_data driver_data = {.mdc_cr = 4};
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mg_tcpip_driver_stm32,
|
||||
.driver_data = &driver_data};
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, &mif);
|
||||
|
||||
MG_INFO(("Waiting until network is up..."));
|
||||
|
||||
@@ -4,7 +4,7 @@ This firmware uses MIP, an experimental TCP/IP stack of the Mongoose Network Lib
|
||||
It implements the following:
|
||||
|
||||
- Minimal elementary web server, as simple as possible
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/mip_driver_stm32.c)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/driver_stm32.c)
|
||||
- Basic HAL header [mcu.h](mcu.h) based on CMSIS
|
||||
- Blue LED blinky, based on another FreeRTOS task
|
||||
- Debug log on UART3 (st-link)
|
||||
|
||||
@@ -48,14 +48,13 @@ static void server(void *args) {
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
MG_INFO(("Initializing Ethernet driver"));
|
||||
ethernet_init();
|
||||
struct mip_driver_stm32_data driver_data = {.mdc_cr =
|
||||
4}; // See driver_stm32.h
|
||||
struct mip_if mif = {
|
||||
struct mg_tcpip_driver_stm32_data driver_data = {.mdc_cr = 4};
|
||||
struct mg_tcpip_if mif = {
|
||||
.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mip_driver_stm32,
|
||||
.driver = &mg_tcpip_driver_stm32,
|
||||
.driver_data = &driver_data,
|
||||
};
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
|
||||
MG_INFO(("Starting Mongoose v%s", MG_VERSION)); // Tell the world
|
||||
mg_http_listen(&mgr, "http://0.0.0.0", fn, &mgr); // Web listener
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
#include <errno.h>
|
||||
|
||||
#define MG_ARCH MG_ARCH_FREERTOS
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_IO_SIZE 256
|
||||
@@ -18,7 +18,7 @@ SOURCES += tinyusb/src/tusb.c \
|
||||
tinyusb/lib/networking/rndis_reports.c \
|
||||
usb_descriptors.c
|
||||
CFLAGS += -Itinyusb/src -Itinyusb/lib/networking
|
||||
CFLAGS += -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_MIP=1 -DMG_ENABLE_PACKED_FS=1 -DMG_IO_SIZE=512 -DMG_ENABLE_CUSTOM_MILLIS=1
|
||||
CFLAGS += -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_PACKED_FS=1 -DMG_IO_SIZE=512 -DMG_ENABLE_CUSTOM_MILLIS=1
|
||||
CFLAGS += -DSTM32F429xx
|
||||
CFLAGS += -Wno-conversion -Wno-sign-conversion
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#define LED PIN('B', 7) // On-board LED pin (blue)
|
||||
static uint64_t s_ticks;
|
||||
static struct mip_if *s_ifp;
|
||||
static struct mg_tcpip_if *s_ifp;
|
||||
uint32_t SystemCoreClock = SYS_FREQUENCY;
|
||||
const uint8_t tud_network_mac_address[6] = {2, 2, 0x84, 0x6A, 0x96, 0};
|
||||
|
||||
@@ -25,7 +25,7 @@ void SysTick_Handler(void) { // SyStick IRQ handler, triggered every 1ms
|
||||
}
|
||||
|
||||
bool tud_network_recv_cb(const uint8_t *buf, uint16_t len) {
|
||||
mip_qwrite((void *) buf, len, s_ifp);
|
||||
mg_tcpip_qwrite((void *) buf, len, s_ifp);
|
||||
// MG_INFO(("RECV %hu", len));
|
||||
// mg_hexdump(buf, len);
|
||||
tud_network_recv_renew();
|
||||
@@ -45,7 +45,7 @@ uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
if (!tud_ready()) return 0;
|
||||
while (!tud_network_can_xmit(len)) tud_task();
|
||||
tud_network_xmit((void *) buf, len);
|
||||
@@ -53,7 +53,7 @@ static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
return len;
|
||||
}
|
||||
|
||||
static bool usb_up(struct mip_if *ifp) {
|
||||
static bool usb_up(struct mg_tcpip_if *ifp) {
|
||||
(void) ifp;
|
||||
return tud_inited() && tud_ready() && tud_connected();
|
||||
}
|
||||
@@ -84,15 +84,16 @@ int main(void) {
|
||||
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);
|
||||
|
||||
MG_INFO(("Init TCP/IP stack ..."));
|
||||
struct mip_driver driver = {.tx = usb_tx, .rx = mip_driver_rx, .up = usb_up};
|
||||
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
|
||||
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
|
||||
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
|
||||
.enable_dhcp_server = true,
|
||||
.driver = &driver,
|
||||
.queue.len = 4096};
|
||||
struct mg_tcpip_driver driver = {
|
||||
.tx = usb_tx, .rx = mg_tcpip_driver_rx, .up = usb_up};
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
|
||||
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
|
||||
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
|
||||
.enable_dhcp_server = true,
|
||||
.driver = &driver,
|
||||
.queue.len = 4096};
|
||||
s_ifp = &mif;
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
mg_http_listen(&mgr, "tcp://0.0.0.0:80", fn, &mgr);
|
||||
|
||||
MG_INFO(("Init USB ..."));
|
||||
|
||||
@@ -9,9 +9,9 @@ SOURCES = main.c syscalls.c sysinit.c
|
||||
SOURCES += cmsis_f7/Source/Templates/gcc/startup_stm32f746xx.s # ST startup file. Compiler-dependent!
|
||||
|
||||
# Mongoose-specific source code files and build options. See https://mongoose.ws/documentation/#build-options
|
||||
SOURCES += ../../../mongoose.c ../../device-dashboard/net.c ../../device-dashboard/packed_fs.c
|
||||
CFLAGS += -I../../.. -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1
|
||||
CFLAGS += -DMG_ENABLE_CUSTOM_RANDOM=1 -DMG_ENABLE_MIP=1 -DMG_ENABLE_PACKED_FS=1 $(CFLAGS_EXTRA)
|
||||
SOURCES += mongoose.c net.c packed_fs.c
|
||||
CFLAGS += -DMG_ENABLE_TCPIP=1 -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1
|
||||
CFLAGS += -DMG_ENABLE_CUSTOM_RANDOM=1 -DMG_ENABLE_PACKED_FS=1 $(CFLAGS_EXTRA)
|
||||
|
||||
all build example: firmware.bin
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG
|
||||
|
||||
static void timer_fn(void *arg) {
|
||||
gpio_toggle(LED); // Blink LED
|
||||
struct mip_if *ifp = arg; // And show
|
||||
struct mg_tcpip_if *ifp = arg; // And show
|
||||
const char *names[] = {"down", "up", "ready"}; // network stats
|
||||
MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u",
|
||||
names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent,
|
||||
@@ -66,10 +66,10 @@ int main(void) {
|
||||
// Initialise Mongoose network stack
|
||||
// Specify MAC address, and IP/mask/GW in network byte order for static
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
struct mip_driver_stm32_data driver_data = {.mdc_cr = 4}; // driver_stm32.h
|
||||
struct mip_if mif = {.driver = &mip_driver_stm32,
|
||||
struct mg_tcpip_driver_stm32_data driver_data = {.mdc_cr = 4}; // driver_stm32.h
|
||||
struct mg_tcpip_if mif = {.driver = &mg_tcpip_driver_stm32,
|
||||
.driver_data = &driver_data};
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, &mif);
|
||||
|
||||
MG_INFO(("Waiting until network is up..."));
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../mongoose.c
|
||||
@@ -0,0 +1 @@
|
||||
../../../mongoose.h
|
||||
@@ -0,0 +1 @@
|
||||
../../device-dashboard/net.c
|
||||
@@ -0,0 +1 @@
|
||||
../../device-dashboard/packed_fs.c
|
||||
@@ -6,7 +6,7 @@ It implements the following:
|
||||
- Minimal elementary web server, as simple as possible
|
||||
- No dependencies: no HAL, no CMSIS
|
||||
- Hand-written [mcu.h](mcu.h) header based on the [datasheet](https://www.st.com/resource/en/reference_manual/rm0385-stm32f75xxx-and-stm32f74xxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/mip_driver_stm32.c)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/driver_stm32.c)
|
||||
- Blue LED blinky, based on another FreeRTOS task
|
||||
- Debug log on UART3 (st-link)
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ static void ethernet_init(void) {
|
||||
}
|
||||
|
||||
static void timer_fn(void *arg) {
|
||||
struct mip_if *ifp = arg; // And show
|
||||
struct mg_tcpip_if *ifp = arg; // And show
|
||||
const char *names[] = {"down", "up", "ready"}; // network stats
|
||||
MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u",
|
||||
names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent,
|
||||
@@ -68,10 +68,10 @@ static void server(void *args) {
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
MG_INFO(("Initializing Ethernet driver"));
|
||||
ethernet_init();
|
||||
struct mip_driver_stm32_data driver_data = {.mdc_cr = 4};
|
||||
struct mip_if mif = {.driver = &mip_driver_stm32,
|
||||
.driver_data = &driver_data};
|
||||
mip_init(&mgr, &mif);
|
||||
struct mg_tcpip_driver_stm32_data driver_data = {.mdc_cr = 4};
|
||||
struct mg_tcpip_if mif = {.driver = &mg_tcpip_driver_stm32,
|
||||
.driver_data = &driver_data};
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
|
||||
MG_INFO(("Starting Mongoose v%s", MG_VERSION)); // Tell the world
|
||||
mg_http_listen(&mgr, "http://0.0.0.0", fn, &mgr); // Web listener
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
|
||||
// See https://mongoose.ws/documentation/#build-options
|
||||
#define MG_ARCH MG_ARCH_FREERTOS
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_IO_SIZE 256
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
@@ -18,7 +18,7 @@ SOURCES += tinyusb/src/tusb.c \
|
||||
tinyusb/lib/networking/rndis_reports.c \
|
||||
usb_descriptors.c
|
||||
CFLAGS += -Itinyusb/src -Itinyusb/lib/networking
|
||||
CFLAGS += -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_MIP=1 -DMG_ENABLE_PACKED_FS=1 -DMG_IO_SIZE=512 -DMG_ENABLE_CUSTOM_MILLIS=1
|
||||
CFLAGS += -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_PACKED_FS=1 -DMG_IO_SIZE=512 -DMG_ENABLE_CUSTOM_MILLIS=1
|
||||
CFLAGS += -DSTM32F746xx
|
||||
CFLAGS += -Wno-conversion -Wno-sign-conversion
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#define LED PIN('B', 7) // On-board LED pin (blue)
|
||||
static uint64_t s_ticks;
|
||||
static struct mip_if *s_ifp;
|
||||
static struct mg_tcpip_if *s_ifp;
|
||||
uint32_t SystemCoreClock = SYS_FREQUENCY;
|
||||
const uint8_t tud_network_mac_address[6] = {2, 2, 0x84, 0x6A, 0x96, 0};
|
||||
|
||||
@@ -25,7 +25,7 @@ void SysTick_Handler(void) { // SyStick IRQ handler, triggered every 1ms
|
||||
}
|
||||
|
||||
bool tud_network_recv_cb(const uint8_t *buf, uint16_t len) {
|
||||
mip_qwrite((void *) buf, len, s_ifp);
|
||||
mg_tcpip_qwrite((void *) buf, len, s_ifp);
|
||||
// MG_INFO(("RECV %hu", len));
|
||||
// mg_hexdump(buf, len);
|
||||
tud_network_recv_renew();
|
||||
@@ -45,7 +45,7 @@ uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t usb_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
if (!tud_ready()) return 0;
|
||||
while (!tud_network_can_xmit(len)) tud_task();
|
||||
tud_network_xmit((void *) buf, len);
|
||||
@@ -53,7 +53,7 @@ static size_t usb_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
return len;
|
||||
}
|
||||
|
||||
static bool usb_up(struct mip_if *ifp) {
|
||||
static bool usb_up(struct mg_tcpip_if *ifp) {
|
||||
(void) ifp;
|
||||
return tud_inited() && tud_ready() && tud_connected();
|
||||
}
|
||||
@@ -84,15 +84,16 @@ int main(void) {
|
||||
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);
|
||||
|
||||
MG_INFO(("Init TCP/IP stack ..."));
|
||||
struct mip_driver driver = {.tx = usb_tx, .rx = mip_driver_rx, .up = usb_up};
|
||||
struct mip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
|
||||
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
|
||||
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
|
||||
.enable_dhcp_server = true,
|
||||
.driver = &driver,
|
||||
.queue.len = 4096};
|
||||
struct mg_tcpip_driver driver = {
|
||||
.tx = usb_tx, .rx = mg_tcpip_driver_rx, .up = usb_up};
|
||||
struct mg_tcpip_if mif = {.mac = {2, 0, 1, 2, 3, 0x77},
|
||||
.ip = mg_htonl(MG_U32(192, 168, 3, 1)),
|
||||
.mask = mg_htonl(MG_U32(255, 255, 255, 0)),
|
||||
.enable_dhcp_server = true,
|
||||
.driver = &driver,
|
||||
.queue.len = 4096};
|
||||
s_ifp = &mif;
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
mg_http_listen(&mgr, "tcp://0.0.0.0:80", fn, &mgr);
|
||||
|
||||
MG_INFO(("Init USB ..."));
|
||||
@@ -103,8 +104,8 @@ int main(void) {
|
||||
gpio_init(PIN('A', 9), GPIO_MODE_INPUT, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_HIGH,
|
||||
GPIO_PULL_NONE, 0); // VBUS
|
||||
gpio_init(PIN('A', 10), GPIO_MODE_AF, GPIO_OTYPE_OPEN_DRAIN, GPIO_SPEED_HIGH,
|
||||
GPIO_PULL_UP, 10); // ID
|
||||
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN; // Enable USB FS clock
|
||||
GPIO_PULL_UP, 10); // ID
|
||||
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN; // Enable USB FS clock
|
||||
tusb_init();
|
||||
|
||||
MG_INFO(("Init done, starting main loop ..."));
|
||||
|
||||
@@ -8,7 +8,7 @@ LDFLAGS ?= -Tlink.ld -nostartfiles -nostdlib --specs nano.specs -lc -lgcc -Wl,--
|
||||
SOURCES = startup.c main.c syscalls.c
|
||||
|
||||
# Add Mongoose-specific flags and source files
|
||||
CFLAGS += -I../../.. -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1 -DMG_ENABLE_MIP=1 -DMG_ENABLE_DRIVER_STM32H=1 -DMG_ENABLE_PACKED_FS=1
|
||||
CFLAGS += -I../../.. -DMG_ARCH=MG_ARCH_NEWLIB -DMG_ENABLE_CUSTOM_MILLIS=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_DRIVER_STM32H=1 -DMG_ENABLE_PACKED_FS=1
|
||||
SOURCES += ../../../mongoose.c ../../device-dashboard/net.c ../../device-dashboard/packed_fs.c
|
||||
|
||||
all build example: firmware.bin
|
||||
|
||||
@@ -10,7 +10,7 @@ which implements the following:
|
||||
- MQTT communication with a remote MQTT server
|
||||
- No dependencies: no HAL, no CMSIS, no RTOS
|
||||
- Hand-written [mcu.h](mcu.h) header based on the [datasheet](https://www.st.com/resource/en/reference_manual/rm0433-stm32h742-stm32h743753-and-stm32h750-value-line-advanced-armbased-32bit-mcus-stmicroelectronics.pdf)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/mip_driver_stm32h.c)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/driver_stm32h.c)
|
||||
- Debug log on UART3 (st-link)
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -55,14 +55,13 @@ int main(void) {
|
||||
// Initialise Mongoose network stack
|
||||
// Specify MAC address, and IP/mask/GW in network byte order for static
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
struct mip_driver_stm32h_data driver_data = {.mdc_cr =
|
||||
4}; // See driver_stm32h.h
|
||||
struct mip_if mif = {
|
||||
struct mg_tcpip_driver_stm32h_data driver_data = {.mdc_cr = 4};
|
||||
struct mg_tcpip_if mif = {
|
||||
.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mip_driver_stm32h,
|
||||
.driver = &mg_tcpip_driver_stm32h,
|
||||
.driver_data = &driver_data,
|
||||
};
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
|
||||
MG_INFO(("Waiting until network is up..."));
|
||||
while (mif.state != MIP_STATE_READY) {
|
||||
|
||||
@@ -4,7 +4,7 @@ CFLAGS ?= -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion \
|
||||
-Wformat-truncation -fno-common -Wconversion \
|
||||
-g3 -Os -ffunction-sections -fdata-sections -I. -I$(ROOT) \
|
||||
-DMG_ARCH=MG_ARCH_NEWLIB -DMIP_DEBUG=1 -DMG_ENABLE_PACKED_FS=1 \
|
||||
-DMG_ENABLE_CUSTOM_MILLIS=1 -DxMG_ENABLE_LINES=1 -DMG_ENABLE_MIP=1 -DMG_ENABLE_DRIVER_TM4C=1\
|
||||
-DMG_ENABLE_CUSTOM_MILLIS=1 -DxMG_ENABLE_LINES=1 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_DRIVER_TM4C=1\
|
||||
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 $(EXTRA_CFLAGS)
|
||||
LDFLAGS ?= -Tlink.ld -nostartfiles -nostdlib --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map
|
||||
SOURCES = boot.c main.c syscalls.c \
|
||||
|
||||
@@ -10,7 +10,7 @@ which implements the following:
|
||||
- MQTT communication with a remote MQTT server
|
||||
- No dependencies: no HAL, no CMSIS, no RTOS
|
||||
- Hand-written [mcu.h](mcu.h) header based on the [datasheet](https://www.ti.com/lit/pdf/spms433)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/mip_driver_tm4c.c)
|
||||
- Interrupt-driven Ethernet driver
|
||||
- LED blinky, based on SysTick interrupt
|
||||
- User button handler, turns off/on an LED, based on GPIO IRQs (interrupt-driven)
|
||||
- HardFault handler alternate blinks LEDs
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
static uint64_t s_ticks, s_exti; // Counters, increased by IRQ handlers
|
||||
|
||||
static void blink_cb(void *arg) { // Blink periodically
|
||||
struct mip_if *ifp = arg;
|
||||
struct mg_tcpip_if *ifp = arg;
|
||||
gpio_toggle(LED1);
|
||||
MG_INFO(("Ethernet: %s", ifp->driver->up(ifp) ? "up": "down"));
|
||||
}
|
||||
@@ -86,13 +86,13 @@ int main(void) {
|
||||
// Initialize Mongoose network stack
|
||||
// Specify MAC address, and IP/mask/GW in network byte order for static
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
struct mip_driver_tm4c_data driver_data = {.mdc_cr = 1}; // See driver_tm4c.h
|
||||
struct mip_if mif = {
|
||||
struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = 1}; // See driver_tm4c.h
|
||||
struct mg_tcpip_if mif = {
|
||||
.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mip_driver_tm4c,
|
||||
.driver = &mg_tcpip_driver_tm4c,
|
||||
.driver_data = &driver_data,
|
||||
};
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
val = IMC[0xFC8 / sizeof(*IMC)]; // Turn Flash Prefetch on again
|
||||
val &= ~BIT(16);
|
||||
val |= BIT(17);
|
||||
|
||||
@@ -6,7 +6,7 @@ It implements the following:
|
||||
- Minimal elementary web server, as simple as possible
|
||||
- No dependencies: no HAL, no CMSIS
|
||||
- Hand-written [mcu.h](mcu.h) header based on the [datasheet](https://www.ti.com/lit/pdf/spms433)
|
||||
- Interrupt-driven [Ethernet driver](../../../drivers/mip_driver_tm4c.c)
|
||||
- Interrupt-driven Ethernet driver
|
||||
- LED blinky, based on another FreeRTOS task
|
||||
- Debug log on UART0 (ICDI)
|
||||
|
||||
|
||||
@@ -60,13 +60,13 @@ static void server(void *args) {
|
||||
// IP configuration. If IP/mask/GW are unset, DHCP is going to be used
|
||||
MG_INFO(("Initializing Ethernet driver"));
|
||||
ethernet_init();
|
||||
struct mip_driver_tm4c_data driver_data = {.mdc_cr = 1}; // See driver_tm4c.h
|
||||
struct mip_if mif = {
|
||||
struct mg_tcpip_driver_tm4c_data driver_data = {.mdc_cr = 1}; // See driver_tm4c.h
|
||||
struct mg_tcpip_if mif = {
|
||||
.mac = {2, 0, 1, 2, 3, 5},
|
||||
.driver = &mip_driver_tm4c,
|
||||
.driver = &mg_tcpip_driver_tm4c,
|
||||
.driver_data = &driver_data,
|
||||
};
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
volatile uint32_t *IMC = (uint32_t *) 0x400FD000;
|
||||
uint32_t val = IMC[0xFC8 / sizeof(*IMC)]; // Turn Flash Prefetch on again
|
||||
val &= ~BIT(16);
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
#include <errno.h> // we are not using lwIP
|
||||
|
||||
#define MG_ARCH MG_ARCH_FREERTOS
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_TM4C 1
|
||||
#define MG_IO_SIZE 256
|
||||
Reference in new issue
Block a user