mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
pico2_w
This commit is contained in:
1 parent
af54beffa9
commit
ce1a7181a3
5 files changed
+148
-1
No files matched your search
@@ -2,7 +2,7 @@ TOP ?= ../..
|
||||
# ST_TARGETS = nucleo_h723zg nucleo_f756zg nucleo_h563zi
|
||||
ST_TARGETS = $(basename $(notdir $(wildcard $(TOP)/tutorials/stm32/*/cubemx/*.ioc)))
|
||||
PROJECTS = full
|
||||
TARGETS = desktop $(ST_TARGETS)
|
||||
TARGETS = desktop pico2_w $(ST_TARGETS)
|
||||
MX ?= /Applications/STMicroelectronics/STM32CubeMX.app/Contents/MacOs/STM32CubeMX
|
||||
|
||||
DIRS = $(foreach P,$(PROJECTS),$(foreach T,$(TARGETS),$(T)_dashboard_$(P)))
|
||||
@@ -13,6 +13,8 @@ all:
|
||||
|
||||
dirs: $(DIRS)
|
||||
|
||||
zips: $(ZIPS)
|
||||
|
||||
DESKTOP_DIRS = $(foreach P,$(PROJECTS),desktop_dashboard_$(P))
|
||||
|
||||
$(DESKTOP_DIRS): desktop_dashboard_%:
|
||||
@@ -24,6 +26,21 @@ $(DESKTOP_DIRS): desktop_dashboard_%:
|
||||
cp $(TOP)/resources/*.js $@/resources
|
||||
sed -i "" "s,../../..,.," $@/Makefile
|
||||
|
||||
.PHONY: pico2_w_dashboard_full
|
||||
|
||||
pico2_w_dashboard_full pico2_w_dashboard_minimal: pico2_w_dashboard_%:
|
||||
mkdir -p $@
|
||||
$(MAKE) -C $(TOP)/tutorials/pico-sdk/pico2_w fullclean
|
||||
cp $(TOP)/tutorials/pico-sdk/pico2_w/* $@/
|
||||
cp $(TOP)/{mongoose.c,mongoose.c,LICENSE} $@/
|
||||
cp $(TOP)/resources/html2c.js $@/
|
||||
cp $(TOP)/tutorials/device-dashboard/$*/{dashboard.c,dashboard.html} $@/
|
||||
sed -i '' -e '/mg_http_listen/d' $@/main.c
|
||||
grep -q 'mg_dash_init' $@/main.c || perl -i -ne 'print; print " mg_dash_init(&mgr);\n" if /mg_mgr_init/' $@/main.c
|
||||
grep -q 'mg_dash_poll' $@/main.c || perl -i -ne 'print; print " mg_dash_poll(&mgr);\n" if /mg_mgr_poll/' $@/main.c
|
||||
grep -q 'dashboard.c' $@/CMakeLists.txt || sed -i -e 's,mongoose.c,mongoose.c dashboard.c file_data.c,' $@/CMakeLists.txt
|
||||
grep -q 'html2c.js' $@/CMakeLists.txt || perl -i -ne 'print "\nadd_custom_command(\n OUTPUT \$${CMAKE_SOURCE_DIR}/file_data.c\n COMMAND node \$${CMAKE_SOURCE_DIR}/html2c.js \$${CMAKE_SOURCE_DIR}/dashboard.html -o \$${CMAKE_SOURCE_DIR}/file_data.c\n DEPENDS \$${CMAKE_SOURCE_DIR}/dashboard.html\n VERBATIM\n)\n\n" if /add_executable/; print;' $@/CMakeLists.txt
|
||||
|
||||
define ST_DASHBOARD_RULE
|
||||
$(1)_dashboard_$(2): $(TOP)/tutorials/stm32/$(1)/cubemx/$(1).ioc
|
||||
mkdir -p $$@
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
# If you will set board type here, do it BEFORE including the SDK
|
||||
set(PICO_BOARD pico2_w)
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(firmware)
|
||||
pico_sdk_init()
|
||||
add_executable(firmware main.c mongoose.c)
|
||||
|
||||
target_link_libraries(firmware pico_stdlib hardware_spi pico_rand pico_cyw43_driver pico_cyw43_arch_none hardware_flash pico_bootrom)
|
||||
pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
|
||||
pico_enable_stdio_usb(firmware 1) # Route stdio
|
||||
|
||||
# Prevent extreme optimization from breaking OTA
|
||||
target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns)
|
||||
@@ -0,0 +1,40 @@
|
||||
# Environment setup: https://mongoose.ws/docs/getting-started/build-environment/
|
||||
|
||||
CWD = $(realpath $(PWD))
|
||||
SDK_PATH ?= $(CWD)/pico-sdk
|
||||
RM = rm -rf
|
||||
MKBUILD = test -d build || mkdir build
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
RM = cmd /C del /Q /F /S
|
||||
MKBUILD = if not exist build mkdir build
|
||||
endif
|
||||
|
||||
.PHONY: build
|
||||
|
||||
all build: build/firmware.uf2
|
||||
|
||||
build/firmware.uf2: pico_sdk_import.cmake mongoose.c mongoose.h
|
||||
|
||||
pico_sdk_import.cmake: $(SDK_PATH)
|
||||
cp $(SDK_PATH)/external/$@ $@
|
||||
|
||||
mongoose.c mongoose.h:
|
||||
cp ../../../$@ .
|
||||
|
||||
build/firmware.uf2: $(SDK_PATH) $(wildcard *.[ch]) CMakeLists.txt Makefile
|
||||
$(MKBUILD)
|
||||
cd build && PICO_SDK_PATH=$(SDK_PATH) cmake -G "Unix Makefiles" .. && make
|
||||
|
||||
flash: build/firmware.uf2
|
||||
picotool load $< -f
|
||||
|
||||
clean:
|
||||
$(RM) build pico_sdk_import.cmake mongoose.c mongoose.h
|
||||
|
||||
fullclean: clean
|
||||
$(RM) $(SDK_PATH)
|
||||
|
||||
$(SDK_PATH):
|
||||
git clone -c advice.detachedHead=false --quiet --depth 1 -b 2.1.1 https://github.com/raspberrypi/pico-sdk $@
|
||||
cd $@ && git submodule update --quiet --init
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-FileCopyrightText: 2024 Cesanta Software Limited
|
||||
// SPDX-License-Identifier: GPL-2.0-only or commercial
|
||||
|
||||
#define WIFI_NAME "mywifi"
|
||||
#define WIFI_PASS "mypassword"
|
||||
#define WIFI_AP_NAME "mywifi2"
|
||||
#define WIFI_AP_PASS "mypassword2"
|
||||
#define ENABLE_AP 0
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
void wifi_setconfig(void *data) {
|
||||
struct mg_tcpip_driver_pico_w_data *d =
|
||||
(struct mg_tcpip_driver_pico_w_data *) data;
|
||||
struct mg_wifi_data *wifi = &d->wifi;
|
||||
wifi->ssid = WIFI_NAME;
|
||||
wifi->pass = WIFI_PASS;
|
||||
wifi->apssid = WIFI_AP_NAME;
|
||||
wifi->appass = WIFI_AP_PASS;
|
||||
wifi->apip = MG_IPV4(192, 168, 111, 1);
|
||||
wifi->apmask = MG_IPV4(255, 255, 255, 0);
|
||||
wifi->security = 0;
|
||||
wifi->apsecurity = 0;
|
||||
wifi->apchannel = 10;
|
||||
wifi->apmode = ENABLE_AP;
|
||||
}
|
||||
|
||||
static void blink_timer(void *arg) {
|
||||
(void) arg;
|
||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN,
|
||||
!cyw43_arch_gpio_get(CYW43_WL_GPIO_LED_PIN));
|
||||
}
|
||||
|
||||
static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) { // New HTTP request received
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
uint64_t tick = to_ms_since_boot(get_absolute_time());
|
||||
if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) {
|
||||
mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), tick);
|
||||
} else {
|
||||
mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", tick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
// do not access the CYW43 LED before Mongoose initializes !
|
||||
MG_INFO(("Hardware initialised, starting firmware..."));
|
||||
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);
|
||||
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
// Build options: https://mongoose.ws/docs/getting-started/build-options/
|
||||
#define MG_ARCH MG_ARCH_PICOSDK
|
||||
#define MG_OTA MG_OTA_PICOSDK
|
||||
#define MG_IO_SIZE 2048
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_PICO_W 1
|
||||
|
||||
// MAC address is read from OTP by the driver
|
||||
// Set your Wi-Fi configuration using a custom function:
|
||||
extern void wifi_setconfig(void *data);
|
||||
#define MG_SET_WIFI_CONFIG(data) wifi_setconfig(data)
|
||||
Reference in new issue
Block a user