mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-20 19:41:58 +00:00
Add esp32c6 802.15.4
This commit is contained in:
1 parent
9d0b015217
commit
5d0abc50e0
40 files changed
+963
-237
No files matched your search
@@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(IDF_TARGET esp32c6)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(mongoose-minimal-802154)
|
||||
@@ -0,0 +1,23 @@
|
||||
# Environment setup: https://mongoose.ws/documentation/tutorials/tools/
|
||||
# Build: ESP-IDF from the espressif/idf Docker image. Flash: esptool.
|
||||
# Monitor: esputil, https://github.com/cpq/esputil
|
||||
|
||||
THISDIR = $(realpath $(CURDIR))
|
||||
ROOTDIR = $(realpath $(CURDIR)/../../..)
|
||||
DOCKER ?= docker run --rm -v $(ROOTDIR):$(ROOTDIR) -w $(THISDIR) espressif/idf
|
||||
PORT ?= /dev/cu.usbmodem2101
|
||||
|
||||
all build:
|
||||
$(DOCKER) idf.py build
|
||||
|
||||
flash: build
|
||||
cd build && esptool --chip esp32c6 -p $(PORT) -b 460800 write-flash @flash_args
|
||||
|
||||
monitor:
|
||||
esputil -p $(PORT) monitor
|
||||
|
||||
menuconfig:
|
||||
docker run --rm -it -v $(ROOTDIR):$(ROOTDIR) -w $(THISDIR) espressif/idf idf.py menuconfig
|
||||
|
||||
clean:
|
||||
test -d build && $(DOCKER) rm -rf build sdkconfig || true
|
||||
@@ -0,0 +1,5 @@
|
||||
idf_component_register(SRCS "main.c" "../../../../mongoose.c"
|
||||
"../../../mqtt/mqtt-client/mongoose_mqtt.c"
|
||||
INCLUDE_DIRS "." "../../../.."
|
||||
REQUIRES ieee802154 esp_timer esp_hw_support
|
||||
esp_driver_gpio app_update)
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright (c) 2026 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
void mg_mqtt_init(struct mg_mgr *mgr); // From tutorials/mqtt/mqtt-client
|
||||
void mg_mqtt_poll(struct mg_mgr *mgr);
|
||||
|
||||
// Seeed XIAO ESP32-C6
|
||||
#define LED1 GPIO_NUM_15 // User LED, active low
|
||||
#define RF_SW_PWR GPIO_NUM_3 // RF switch power, active low
|
||||
#define RF_SW_SEL GPIO_NUM_14 // Antenna select: low built-in, high U.FL
|
||||
|
||||
// Self-signed P-256 certificate and key for the HTTPS listener. Created by:
|
||||
// openssl ecparam -genkey -name prime256v1 -noout -out key.pem
|
||||
// openssl req -x509 -key key.pem -out cert.pem -days 3650 -subj /CN=mg
|
||||
#define TLS_CERT \
|
||||
"-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIBgjCCASegAwIBAgIUIJOq77Qn7lHbH6WseMemeqorR50wCgYIKoZIzj0EAwIw\n" \
|
||||
"FjEUMBIGA1UEAwwLbnVjbGVvLWg3MjMwHhcNMjYxMDEyMTUwMjE5WhcNMzYxMDA5\n" \
|
||||
"MTUwMjE5WjAWMRQwEgYDVQQDDAtudWNsZW8taDcyMzBZMBMGByqGSM49AgEGCCqG\n" \
|
||||
"SM49AwEHA0IABB6IQJNmzrsdQL+2BnZYS7GYOaj7sz8f6cjBmz3n8D9Em19XodlU\n" \
|
||||
"uy4ybIvyhr766lL0ERoTmMUivb/lGmzx9C+jUzBRMB0GA1UdDgQWBBQqxMuc4gj7\n" \
|
||||
"MTMzreWlRMNI3QMqTzAfBgNVHSMEGDAWgBQqxMuc4gj7MTMzreWlRMNI3QMqTzAP\n" \
|
||||
"BgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQDY4xaJpuxq6b3rHK3b\n" \
|
||||
"lOIQyfkQX+orCRqQUkseplqpqwIhAKswZFNn+2zUNRRNY8+cHmdIwmdpsmxtoWYP\n" \
|
||||
"BCjX++LI\n" \
|
||||
"-----END CERTIFICATE-----\n"
|
||||
|
||||
#define TLS_KEY \
|
||||
"-----BEGIN EC PRIVATE KEY-----\n" \
|
||||
"MHcCAQEEIJ/GBl0TlD52q9PMg1KWaNIdXqp8b/HyIsABmBpqC+O1oAoGCCqGSM49\n" \
|
||||
"AwEHoUQDQgAEHohAk2bOux1Av7YGdlhLsZg5qPuzPx/pyMGbPefwP0SbX1eh2VS7\n" \
|
||||
"LjJsi/KGvvrqUvQRGhOYxSK9v+UabPH0Lw==\n" \
|
||||
"-----END EC PRIVATE KEY-----\n"
|
||||
|
||||
// Power the XIAO RF switch and select the built-in antenna
|
||||
static void antenna_init(void) {
|
||||
gpio_set_direction(RF_SW_PWR, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(RF_SW_PWR, 0);
|
||||
gpio_set_direction(RF_SW_SEL, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(RF_SW_SEL, 0);
|
||||
}
|
||||
|
||||
// Toggle the user LED twice a second
|
||||
static void blink_task(void) {
|
||||
static uint64_t blink_timer = 0;
|
||||
static int on = 0;
|
||||
if (mg_timer_expired(&blink_timer, 500, mg_millis())) {
|
||||
gpio_set_level(LED1, on ^= 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_ACCEPT && c->is_tls) { // Accepted on the https:// listener
|
||||
struct mg_tls_opts opts = {.cert = mg_str(TLS_CERT),
|
||||
.key = mg_str(TLS_KEY)};
|
||||
mg_tls_init(c, &opts);
|
||||
} else if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
||||
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), mg_millis());
|
||||
} else if (mg_match(hm->uri, mg_str("/api/crash"), NULL)) {
|
||||
__asm volatile("unimp"); // Illegal instruction: ESP-IDF prints a panic
|
||||
} else {
|
||||
mg_http_reply(c, 200, "",
|
||||
"Hi from Mongoose!\n"
|
||||
"tick: %llu\n"
|
||||
"ram free: %zu\n"
|
||||
"ram min: %zu\n",
|
||||
mg_millis(), heap_caps_get_free_size(MALLOC_CAP_DEFAULT),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
antenna_init();
|
||||
gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
|
||||
|
||||
mg_mgr_init(&mgr); // Also starts the 802.15.4 driver
|
||||
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
||||
mg_http_listen(&mgr, "https://0.0.0.0", http_ev_handler, NULL);
|
||||
mg_mqtt_init(&mgr);
|
||||
|
||||
MG_INFO(("Initialised. RAM free: %zu",
|
||||
heap_caps_get_free_size(MALLOC_CAP_DEFAULT)));
|
||||
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
mg_mqtt_poll(&mgr);
|
||||
blink_task();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <esp_mac.h>
|
||||
|
||||
// See https://mongoose.ws/docs/getting-started/build-options/
|
||||
#define MG_ARCH MG_ARCH_ESP32
|
||||
#define MG_TLS MG_TLS_BUILTIN
|
||||
#define MQTT_CLIENT_ID "esp32c6" // For tutorials/mqtt/mqtt-client
|
||||
|
||||
#define MG_ENABLE_TCPIP 1 // Built-in TCP/IP stack, not lwIP
|
||||
#define MG_ENABLE_DRIVER_ESP32_802154 1 // ESP32-C6 802.15.4 radio
|
||||
#define MG_ENABLE_TCPIP_TCPRTX 1 // Link can be lossy, enable retransmit
|
||||
|
||||
// Stable MAC, so the DHCP address stays the same across reboots: the factory
|
||||
// MAC, locally administered
|
||||
#define MG_SET_MAC_ADDRESS(mac) \
|
||||
do { \
|
||||
esp_read_mac(mac, ESP_MAC_BASE); \
|
||||
(mac)[0] |= 2; \
|
||||
} while (0)
|
||||
|
||||
// mdash.net device management service support
|
||||
#define MG_ENABLE_MDASH 0
|
||||
#define MG_MDASH_KEY "..." // Set this - mDash device token
|
||||
#define MG_FIRMWARE_VERSION "esp32c6.1.0.0"
|
||||
@@ -0,0 +1,8 @@
|
||||
CONFIG_IDF_TARGET="esp32c6"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
|
||||
CONFIG_IEEE802154_ENABLED=y
|
||||
# Built-in TLS handshakes need a larger stack
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=12288
|
||||
# The main task busy-loops the mesh, so the idle task does not run
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
||||
@@ -17,9 +17,6 @@ static void blink_task(void) {
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t mg_millis(void) {
|
||||
return hal_get_tick();
|
||||
}
|
||||
|
||||
bool mg_random(void *buf, size_t len) {
|
||||
for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_NRF52 1
|
||||
#define MG_ENABLE_TCPIP_TCPRTX 1
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_MICROS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
#define MG_TLS MG_TLS_BUILTIN
|
||||
#define MQTT_CLIENT_ID "xiao-nrf52840"
|
||||
|
||||
@@ -25,9 +25,6 @@ static void blink_task(void) {
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t mg_millis(void) {
|
||||
return hal_get_tick();
|
||||
}
|
||||
|
||||
bool mg_random(void *buf, size_t len) {
|
||||
for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_MCXW71 1
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_MICROS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1
|
||||
#define MG_ENABLE_TCPIP_TCPRTX 1 // Link can be lossy, enable retransmit
|
||||
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
-3
@@ -43,9 +43,6 @@ static void log_fn(char ch, void *arg) {
|
||||
hal_uart_write_buf(arg, &ch, 1);
|
||||
}
|
||||
|
||||
uint64_t mg_millis(void) {
|
||||
return hal_get_tick();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
static struct mg_tcpip_driver_rw612_data eth_data;
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_RW612 1 // Ethernet
|
||||
#define MG_ENABLE_DRIVER_RW612W 1 // Mesh bridge over raw 802.15.4
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_MICROS 1
|
||||
|
||||
|
||||
// The bridge initializes and polls its two L2 interfaces directly.
|
||||
File renamed without changes.
File renamed without changes.
@@ -26,9 +26,6 @@ static void blink_task(void) {
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t mg_millis(void) {
|
||||
return hal_get_tick();
|
||||
}
|
||||
|
||||
bool mg_random(void *buf, size_t len) {
|
||||
for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_MG24 1
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define MG_ENABLE_CUSTOM_MICROS 1
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 1 // Secure Engine TRNG, see hal.c
|
||||
#define MG_ENABLE_TCPIP_TCPRTX 1 // Link can be lossy, enable retransmit
|
||||
|
||||
|
||||
Reference in new issue
Block a user