mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-18 06:54:00 +08:00
move to Wizard
This commit is contained in:
parent
6cf36b5771
commit
f0df6c61c9
8
.github/workflows/nightly.yml
vendored
8
.github/workflows/nightly.yml
vendored
@ -334,6 +334,10 @@ jobs:
|
||||
- path: nxp/rt1020-evk-make-baremetal-builtin
|
||||
- path: nxp/rt1060-evk-make-baremetal-builtin
|
||||
- path: nxp/rt1170-evk-make-baremetal-builtin
|
||||
- path: pico-sdk/pico-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/pico-2-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/w5500-evb-pico-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/w5500-evb-pico2-picosdk-baremetal-builtin
|
||||
- path: stm32/nucleo-f429zi-make-baremetal-builtin
|
||||
- path: stm32/nucleo-f429zi-make-freertos-builtin
|
||||
- path: stm32/nucleo-f746zg-make-baremetal-builtin
|
||||
@ -443,12 +447,8 @@ jobs:
|
||||
- path: nxp/rt1170-evk-make-freertos-builtin
|
||||
- path: renesas/ek-ra6m4-make-baremetal-builtin
|
||||
- path: pico-sdk/pico-rndis-dashboard
|
||||
- path: pico-sdk/pico-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/pico-w-picosdk-freertos-lwip
|
||||
- path: pico-sdk/pico-2-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/pico-2-w-picosdk-freertos-lwip
|
||||
- path: pico-sdk/w5500-evb-pico-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/w5500-evb-pico2-picosdk-baremetal-builtin
|
||||
- path: stm32/nucleo-f746zg-make-freertos-tcp
|
||||
- path: stm32/nucleo-f746zg-make-baremetal-builtin-cmsis_driver
|
||||
name: ${{ matrix.example.path }} ${{ matrix.ssl }}
|
||||
|
10
.github/workflows/quicktest.yml
vendored
10
.github/workflows/quicktest.yml
vendored
@ -206,6 +206,10 @@ jobs:
|
||||
- path: nxp/rt1020-evk-make-baremetal-builtin
|
||||
- path: nxp/rt1060-evk-make-baremetal-builtin
|
||||
- path: nxp/rt1170-evk-make-baremetal-builtin
|
||||
- path: pico-sdk/pico-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/pico-2-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/w5500-evb-pico-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/w5500-evb-pico2-picosdk-baremetal-builtin
|
||||
- path: stm32/nucleo-f429zi-make-baremetal-builtin
|
||||
- path: stm32/nucleo-f429zi-make-freertos-builtin
|
||||
- path: stm32/nucleo-f746zg-make-baremetal-builtin
|
||||
@ -309,12 +313,8 @@ jobs:
|
||||
- path: nxp/rt1170-evk-make-freertos-builtin
|
||||
- path: renesas/ek-ra6m4-make-baremetal-builtin
|
||||
- path: pico-sdk/pico-rndis-dashboard
|
||||
- path: pico-sdk/pico-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/pico-w-picosdk-freertos-lwip
|
||||
- path: pico-sdk/pico-2-w-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/pico-2-w-picosdk-freertos-lwip
|
||||
- path: pico-sdk/w5500-evb-pico-picosdk-baremetal-builtin
|
||||
- path: pico-sdk/w5500-evb-pico2-picosdk-baremetal-builtin
|
||||
- path: stm32/nucleo-f746zg-make-freertos-tcp
|
||||
- path: stm32/nucleo-f746zg-make-baremetal-builtin-cmsis_driver
|
||||
name: ${{ matrix.example.path }}
|
||||
@ -738,7 +738,7 @@ jobs:
|
||||
with: { fetch-depth: 2 }
|
||||
- name: SDK
|
||||
run: |
|
||||
if ./test/match_changed_files.sh "^src|examples/device-dashboard|examples/pico-sdk/w5500-evb-pico-picosdk-baremetal-builtin" ; then
|
||||
if ./test/match_changed_files.sh "^src" ; then
|
||||
echo GO=1 >> $GITHUB_ENV
|
||||
sudo apt -y update && sudo apt -y install gcc-arm-none-eabi
|
||||
fi
|
||||
|
@ -1,28 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(firmware)
|
||||
pico_sdk_init()
|
||||
|
||||
add_executable(firmware
|
||||
main.c
|
||||
mongoose.c
|
||||
net.c
|
||||
packed_fs.c
|
||||
)
|
||||
|
||||
target_include_directories(firmware PUBLIC
|
||||
.
|
||||
)
|
||||
|
||||
target_link_libraries(firmware pico_stdlib pico_rand pico_cyw43_driver pico_cyw43_arch_none)
|
||||
pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
|
||||
|
||||
pico_enable_stdio_usb(firmware 1) # Route stdio
|
||||
pico_enable_stdio_uart(firmware 0) # to USB
|
||||
|
||||
# Mongoose build flags in mongoose_config.h
|
||||
|
||||
# Example build options
|
||||
add_definitions(-DHTTP_URL="http://0.0.0.0/")
|
||||
|
@ -1,22 +1,35 @@
|
||||
RM = rm -rf
|
||||
MKBUILD = rm -rf build && mkdir -p build # test -d build || mkdir build
|
||||
ifeq ($(OS),Windows_NT)
|
||||
RM = cmd /C del /Q /F /S
|
||||
MKBUILD = if not exist build mkdir build
|
||||
endif
|
||||
BOARD = pico2-w
|
||||
IDE = Pico-SDK
|
||||
RTOS = baremetal
|
||||
WIZARD_URL ?= http://mongoose.ws/wizard
|
||||
|
||||
all example:
|
||||
true
|
||||
all build example: firmware.uf2
|
||||
|
||||
build: pico-sdk build/firmware.uf2
|
||||
firmware.uf2: wizard
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
|
||||
build/firmware.uf2:
|
||||
$(MKBUILD)
|
||||
cd build && cmake -DPICO_BOARD="pico2_w" -G "Unix Makefiles" .. && make
|
||||
wizard:
|
||||
hash=$$(curl -s -X POST -H "Content-Type: application/json" -d '{"build":{"board":"$(BOARD)","ide":"$(IDE)","rtos":"$(RTOS)"}}' $(WIZARD_URL)/api/hash | jq -r '.hash') \
|
||||
&& curl -s $(WIZARD_URL)/api/zip/$(BOARD)/$(IDE)/$(RTOS)/$$hash -o wizard.zip
|
||||
unzip wizard.zip
|
||||
cd wizard ; rm mongoose.[ch] ; ln -s ../../../../mongoose.c ; ln -s ../../../../mongoose.h
|
||||
|
||||
pico-sdk:
|
||||
git clone --depth 1 -b 2.1.0 https://github.com/raspberrypi/pico-sdk $@
|
||||
cd $@ && git submodule update --init
|
||||
flash: firmware.uf2
|
||||
picotool load $< -f
|
||||
|
||||
# Automated remote test. Requires env variable VCON_API_KEY set. See https://vcon.io/automated-firmware-tests/
|
||||
DEVICE_URL ?= https://dash.vcon.io/api/v3/devices/??
|
||||
# stdio has to be changed from USB to UART in CMakeLists.txt
|
||||
update: wizard
|
||||
sed -i -e 's/pico_enable_stdio_usb(firmware 1)/pico_enable_stdio_usb(firmware 0)/' wizard/CMakeLists.txt
|
||||
(test `grep -c "pico_enable_stdio_uart(firmware 1)" wizard/CMakeLists.txt` -eq 0 && echo "pico_enable_stdio_uart(firmware 1)" >> wizard/CMakeLists.txt) || true
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota?uf2=1 --data-binary @firmware.uf2
|
||||
|
||||
test: update
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=15 | tee /tmp/output.txt
|
||||
grep 'READY, IP:' /tmp/output.txt # Check for network init
|
||||
|
||||
clean:
|
||||
$(RM) pico-sdk build
|
||||
rm -rf firmware.* wizard* pico-sdk
|
||||
|
||||
|
@ -1,4 +1 @@
|
||||
|
||||
# Mongoose on PICO 2 W
|
||||
|
||||
|
||||
See [Wizard](https://mongoose.ws/wizard/#/output?board=pico2-w&ide=Pico-SDK&rtos=baremetal&file=README.md)
|
||||
|
@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2024 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "net.h"
|
||||
|
||||
|
||||
#define WIFI_SSID "yourWiFiSSID"
|
||||
#define WIFI_PASS "yourWiFiPassword"
|
||||
|
||||
|
||||
int main(void) {
|
||||
// initialize stdio
|
||||
stdio_init_all();
|
||||
|
||||
struct mg_mgr mgr; // Initialise Mongoose event manager
|
||||
mg_mgr_init(&mgr); // and attach it to the interface
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
// Initialise WiFi creds
|
||||
struct mg_tcpip_driver_pico_w_data driver_data = {
|
||||
.ssid = WIFI_SSID,
|
||||
.pass = WIFI_PASS
|
||||
};
|
||||
// Initialise Mongoose network stack
|
||||
// Either set use_dhcp or enter a static config.
|
||||
// For static configuration, specify IP/mask/GW in network byte order
|
||||
struct mg_tcpip_if mif = {
|
||||
.ip = 0,
|
||||
.driver = &mg_tcpip_driver_pico_w,
|
||||
.driver_data = &driver_data,
|
||||
.recv_queue.size = 8192
|
||||
};
|
||||
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
MG_INFO(("Initialising application..."));
|
||||
web_init(&mgr);
|
||||
|
||||
MG_INFO(("Starting event loop"));
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
../../../mongoose.c
|
@ -1 +0,0 @@
|
||||
../../../mongoose.h
|
@ -1,6 +0,0 @@
|
||||
#define MG_ARCH MG_ARCH_PICOSDK
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_PICO_W 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
#define MG_ENABLE_PACKED_FS 1
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.c
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.h
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/packed_fs.c
|
@ -1,84 +0,0 @@
|
||||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
|
||||
endif ()
|
||||
|
||||
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
|
||||
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
|
||||
endif()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
@ -1,28 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(firmware)
|
||||
pico_sdk_init()
|
||||
|
||||
add_executable(firmware
|
||||
main.c
|
||||
mongoose.c
|
||||
net.c
|
||||
packed_fs.c
|
||||
)
|
||||
|
||||
target_include_directories(firmware PUBLIC
|
||||
.
|
||||
)
|
||||
|
||||
target_link_libraries(firmware pico_stdlib pico_rand pico_cyw43_driver pico_cyw43_arch_none)
|
||||
pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
|
||||
|
||||
pico_enable_stdio_usb(firmware 1) # Route stdio
|
||||
pico_enable_stdio_uart(firmware 0) # to USB
|
||||
|
||||
# Mongoose build flags in mongoose_config.h
|
||||
|
||||
# Example build options
|
||||
add_definitions(-DHTTP_URL="http://0.0.0.0/")
|
||||
|
@ -1,22 +1,35 @@
|
||||
RM = rm -rf
|
||||
MKBUILD = rm -rf build && mkdir -p build # test -d build || mkdir build
|
||||
ifeq ($(OS),Windows_NT)
|
||||
RM = cmd /C del /Q /F /S
|
||||
MKBUILD = if not exist build mkdir build
|
||||
endif
|
||||
BOARD = pico-w
|
||||
IDE = Pico-SDK
|
||||
RTOS = baremetal
|
||||
WIZARD_URL ?= http://mongoose.ws/wizard
|
||||
|
||||
all example:
|
||||
true
|
||||
all build example: firmware.uf2
|
||||
|
||||
build: pico-sdk build/firmware.uf2
|
||||
firmware.uf2: wizard
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
|
||||
build/firmware.uf2:
|
||||
$(MKBUILD)
|
||||
cd build && cmake -DPICO_BOARD="pico_w" -G "Unix Makefiles" .. && make
|
||||
wizard:
|
||||
hash=$$(curl -s -X POST -H "Content-Type: application/json" -d '{"build":{"board":"$(BOARD)","ide":"$(IDE)","rtos":"$(RTOS)"}}' $(WIZARD_URL)/api/hash | jq -r '.hash') \
|
||||
&& curl -s $(WIZARD_URL)/api/zip/$(BOARD)/$(IDE)/$(RTOS)/$$hash -o wizard.zip
|
||||
unzip wizard.zip
|
||||
cd wizard ; rm mongoose.[ch] ; ln -s ../../../../mongoose.c ; ln -s ../../../../mongoose.h
|
||||
|
||||
pico-sdk:
|
||||
git clone --depth 1 -b 2.0.0 https://github.com/raspberrypi/pico-sdk $@
|
||||
cd $@ && git submodule update --init
|
||||
flash: firmware.uf2
|
||||
picotool load $< -f
|
||||
|
||||
# Automated remote test. Requires env variable VCON_API_KEY set. See https://vcon.io/automated-firmware-tests/
|
||||
DEVICE_URL ?= https://dash.vcon.io/api/v3/devices/??
|
||||
# stdio has to be changed from USB to UART in CMakeLists.txt
|
||||
update: wizard
|
||||
sed -i -e 's/pico_enable_stdio_usb(firmware 1)/pico_enable_stdio_usb(firmware 0)/' wizard/CMakeLists.txt
|
||||
(test `grep -c "pico_enable_stdio_uart(firmware 1)" wizard/CMakeLists.txt` -eq 0 && echo "pico_enable_stdio_uart(firmware 1)" >> wizard/CMakeLists.txt) || true
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota?uf2=1 --data-binary @firmware.uf2
|
||||
|
||||
test: update
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=15 | tee /tmp/output.txt
|
||||
grep 'READY, IP:' /tmp/output.txt # Check for network init
|
||||
|
||||
clean:
|
||||
$(RM) pico-sdk build
|
||||
rm -rf firmware.* wizard* pico-sdk
|
||||
|
||||
|
@ -1,4 +1 @@
|
||||
|
||||
# Mongoose on PICO W
|
||||
|
||||
|
||||
See [Wizard](https://mongoose.ws/wizard/#/output?board=pico-w&ide=Pico-SDK&rtos=baremetal&file=README.md)
|
||||
|
@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2024 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "net.h"
|
||||
|
||||
|
||||
#define WIFI_SSID "yourWiFiSSID"
|
||||
#define WIFI_PASS "yourWiFiPassword"
|
||||
|
||||
|
||||
int main(void) {
|
||||
// initialize stdio
|
||||
stdio_init_all();
|
||||
|
||||
struct mg_mgr mgr; // Initialise Mongoose event manager
|
||||
mg_mgr_init(&mgr); // and attach it to the interface
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
// Initialise WiFi creds
|
||||
struct mg_tcpip_driver_pico_w_data driver_data = {
|
||||
.ssid = WIFI_SSID,
|
||||
.pass = WIFI_PASS
|
||||
};
|
||||
// Initialise Mongoose network stack
|
||||
// Either set use_dhcp or enter a static config.
|
||||
// For static configuration, specify IP/mask/GW in network byte order
|
||||
struct mg_tcpip_if mif = {
|
||||
.ip = 0,
|
||||
.driver = &mg_tcpip_driver_pico_w,
|
||||
.driver_data = &driver_data,
|
||||
.recv_queue.size = 8192
|
||||
};
|
||||
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
MG_INFO(("Initialising application..."));
|
||||
web_init(&mgr);
|
||||
|
||||
MG_INFO(("Starting event loop"));
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
../../../mongoose.c
|
@ -1 +0,0 @@
|
||||
../../../mongoose.h
|
@ -1,6 +0,0 @@
|
||||
#define MG_ARCH MG_ARCH_PICOSDK
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_DRIVER_PICO_W 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
#define MG_ENABLE_PACKED_FS 1
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.c
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.h
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/packed_fs.c
|
@ -1,84 +0,0 @@
|
||||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
|
||||
endif ()
|
||||
|
||||
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
|
||||
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
|
||||
endif()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
@ -1,19 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(firmware)
|
||||
pico_sdk_init()
|
||||
add_executable(firmware main.c mongoose.c net.c packed_fs.c)
|
||||
target_include_directories(firmware PUBLIC .)
|
||||
|
||||
target_link_libraries(firmware pico_stdlib hardware_spi pico_rand)
|
||||
pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
|
||||
|
||||
pico_enable_stdio_usb(firmware 0) # Route stdio
|
||||
pico_enable_stdio_uart(firmware 1) # to the UART, for remote testing
|
||||
|
||||
# Mongoose build flags in mongoose_config.h
|
||||
|
||||
# Example build options
|
||||
add_definitions(-DHTTP_URL="http://0.0.0.0/")
|
||||
add_definitions(-DHTTPS_URL="https://0.0.0.0/")
|
@ -1,34 +1,35 @@
|
||||
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
|
||||
BOARD = evb-pico
|
||||
IDE = Pico-SDK
|
||||
RTOS = baremetal
|
||||
WIZARD_URL ?= http://mongoose.ws/wizard
|
||||
|
||||
all example:
|
||||
true
|
||||
all build example: firmware.uf2
|
||||
|
||||
build build/firmware.uf2: pico-sdk main.c net.c
|
||||
$(MKBUILD)
|
||||
cd build && cmake -G "Unix Makefiles" .. && make
|
||||
firmware.uf2: wizard
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
|
||||
pico-sdk:
|
||||
git clone --depth 1 -b 1.5.0 https://github.com/raspberrypi/pico-sdk $@
|
||||
cd $@ && git submodule update --init
|
||||
wizard:
|
||||
hash=$$(curl -s -X POST -H "Content-Type: application/json" -d '{"build":{"board":"$(BOARD)","ide":"$(IDE)","rtos":"$(RTOS)"}}' $(WIZARD_URL)/api/hash | jq -r '.hash') \
|
||||
&& curl -s $(WIZARD_URL)/api/zip/$(BOARD)/$(IDE)/$(RTOS)/$$hash -o wizard.zip
|
||||
unzip wizard.zip
|
||||
cd wizard ; rm mongoose.[ch] ; ln -s ../../../../mongoose.c ; ln -s ../../../../mongoose.h
|
||||
|
||||
flash: build/firmware.uf2
|
||||
flash: firmware.uf2
|
||||
picotool load $< -f
|
||||
|
||||
# Automated remote test. Requires env variable VCON_API_KEY set. See https://vcon.io/automated-firmware-tests/
|
||||
DEVICE_URL ?= https://dash.vcon.io/api/v3/devices/3
|
||||
update: build/firmware.uf2
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota?uf2=1 --data-binary @$<
|
||||
# stdio has to be changed from USB to UART in CMakeLists.txt
|
||||
update: wizard
|
||||
sed -i -e 's/pico_enable_stdio_usb(firmware 1)/pico_enable_stdio_usb(firmware 0)/' wizard/CMakeLists.txt
|
||||
(test `grep -c "pico_enable_stdio_uart(firmware 1)" wizard/CMakeLists.txt` -eq 0 && echo "pico_enable_stdio_uart(firmware 1)" >> wizard/CMakeLists.txt) || true
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota?uf2=1 --data-binary @firmware.uf2
|
||||
|
||||
test: update
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=5 | tee /tmp/output.txt
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=15 | tee /tmp/output.txt
|
||||
grep 'READY, IP:' /tmp/output.txt # Check for network init
|
||||
# grep 'MQTT connected' /tmp/output.txt # Check for MQTT connection success
|
||||
|
||||
clean:
|
||||
$(RM) pico-sdk build
|
||||
rm -rf firmware.* wizard* pico-sdk
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# RP2040 + W5500 Ethernet chip
|
||||
|
||||
- See [Wizard](https://mongoose.ws/wizard/#/output?board=evb-pico&ide=Pico-SDK&rtos=baremetal&file=README.md)
|
||||
- See detailed tutorial (including hardware connections) at https://mongoose.ws/tutorials/rp2040/pico-w5500/
|
||||
|
||||
|
@ -1,94 +0,0 @@
|
||||
// Copyright (c) 2023 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "hardware/spi.h"
|
||||
#include "pico/rand.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/unique_id.h"
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "net.h"
|
||||
|
||||
enum { BLINK_PERIOD_MS = 1000 };
|
||||
enum { LED = 25, SPI_CS = 17, SPI_CLK = 18, SPI_TX = 19, SPI_RX = 16 }; // Pins
|
||||
|
||||
static void spi_begin(void *spi) {
|
||||
gpio_put(SPI_CS, 0);
|
||||
}
|
||||
static void spi_end(void *spi) {
|
||||
gpio_put(SPI_CS, 1);
|
||||
}
|
||||
static uint8_t spi_txn(void *spi, uint8_t byte) {
|
||||
uint8_t result = 0;
|
||||
spi_write_read_blocking(spi0, &byte, &result, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void timer_fn(void *arg) {
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, !gpio_get(PICO_DEFAULT_LED_PIN)); // Blink LED
|
||||
struct mg_tcpip_if *ifp = arg; // And show
|
||||
const char *names[] = {"down", "up", "req", "IP", "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,
|
||||
ifp->ndrop, ifp->nerr));
|
||||
}
|
||||
|
||||
static void eth_spi_init(void) {
|
||||
// Init SPI pins
|
||||
spi_init(spi0, 500 * 1000);
|
||||
gpio_set_function(SPI_RX, GPIO_FUNC_SPI); // MISO
|
||||
gpio_set_function(SPI_TX, GPIO_FUNC_SPI); // MOSI
|
||||
gpio_set_function(SPI_CLK, GPIO_FUNC_SPI); // CLK
|
||||
gpio_init(SPI_CS); // CS
|
||||
gpio_set_dir(SPI_CS, GPIO_OUT); // Set CS to output
|
||||
gpio_put(SPI_CS, 1); // And drive CS high (inactive)
|
||||
}
|
||||
|
||||
// Helper macro for MAC generation
|
||||
#define GENERATE_LOCALLY_ADMINISTERED_MAC(id) \
|
||||
{ 2, id[3], id[4], id[5], id[6], id[7] }
|
||||
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
gpio_init(LED); // Setup board LED
|
||||
gpio_set_dir(LED, GPIO_OUT);
|
||||
eth_spi_init(); // Initialise SPI pins
|
||||
MG_INFO(("Starting ..."));
|
||||
|
||||
pico_unique_board_id_t board_id;
|
||||
pico_get_unique_board_id(&board_id);
|
||||
uint8_t *id = board_id.id;
|
||||
|
||||
struct mg_mgr mgr; // Initialise
|
||||
mg_mgr_init(&mgr); // Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
// Initialise Mongoose network stack
|
||||
struct mg_tcpip_spi spi = {NULL, spi_begin, spi_end, spi_txn};
|
||||
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(id),
|
||||
// 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_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, &mif);
|
||||
|
||||
MG_INFO(("MAC: %M. Waiting for IP...", mg_print_mac, mif.mac));
|
||||
while (mif.state != MG_TCPIP_STATE_READY) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
}
|
||||
|
||||
MG_INFO(("Initialising application..."));
|
||||
web_init(&mgr);
|
||||
|
||||
MG_INFO(("Starting event loop"));
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../../mongoose.c
|
@ -1 +0,0 @@
|
||||
../../../mongoose.h
|
@ -1,6 +0,0 @@
|
||||
#define MG_ARCH MG_ARCH_PICOSDK
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_PACKED_FS 1
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.c
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.h
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/packed_fs.c
|
@ -1,19 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(firmware)
|
||||
pico_sdk_init()
|
||||
add_executable(firmware main.c mongoose.c net.c packed_fs.c)
|
||||
target_include_directories(firmware PUBLIC .)
|
||||
|
||||
target_link_libraries(firmware pico_stdlib hardware_spi pico_rand)
|
||||
pico_add_extra_outputs(firmware) # create map/bin/hex file etc.
|
||||
|
||||
pico_enable_stdio_usb(firmware 1) # Route stdio
|
||||
pico_enable_stdio_uart(firmware 0) # to USB
|
||||
|
||||
# Mongoose build flags in mongoose_config.h
|
||||
|
||||
# Example build options
|
||||
add_definitions(-DHTTP_URL="http://0.0.0.0/")
|
||||
add_definitions(-DHTTPS_URL="https://0.0.0.0/")
|
@ -1,35 +1,35 @@
|
||||
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
|
||||
BOARD = evb-pico2
|
||||
IDE = Pico-SDK
|
||||
RTOS = baremetal
|
||||
WIZARD_URL ?= http://mongoose.ws/wizard
|
||||
|
||||
all example:
|
||||
true
|
||||
all build example: firmware.uf2
|
||||
|
||||
build build/firmware.uf2: pico-sdk main.c net.c
|
||||
$(MKBUILD)
|
||||
cd build && cmake -DPICO_BOARD=pico2 -G "Unix Makefiles" .. && make
|
||||
firmware.uf2: wizard
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
|
||||
pico-sdk:
|
||||
git clone --depth 1 -b 2.0.0 https://github.com/raspberrypi/pico-sdk $@
|
||||
cd $@ && git submodule update --init
|
||||
wizard:
|
||||
hash=$$(curl -s -X POST -H "Content-Type: application/json" -d '{"build":{"board":"$(BOARD)","ide":"$(IDE)","rtos":"$(RTOS)"}}' $(WIZARD_URL)/api/hash | jq -r '.hash') \
|
||||
&& curl -s $(WIZARD_URL)/api/zip/$(BOARD)/$(IDE)/$(RTOS)/$$hash -o wizard.zip
|
||||
unzip wizard.zip
|
||||
cd wizard ; rm mongoose.[ch] ; ln -s ../../../../mongoose.c ; ln -s ../../../../mongoose.h
|
||||
|
||||
flash: build/firmware.uf2
|
||||
flash: firmware.uf2
|
||||
picotool load $< -f
|
||||
|
||||
# Automated remote test. Requires env variable VCON_API_KEY set. See https://vcon.io/automated-firmware-tests/
|
||||
DEVICE_URL ?= https://dash.vcon.io/api/v3/devices/??
|
||||
# stdio has to be changed from USB to UART in CMakeLists.txt
|
||||
update: build/firmware.uf2
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota?uf2=1 --data-binary @$<
|
||||
update: wizard
|
||||
sed -i -e 's/pico_enable_stdio_usb(firmware 1)/pico_enable_stdio_usb(firmware 0)/' wizard/CMakeLists.txt
|
||||
(test `grep -c "pico_enable_stdio_uart(firmware 1)" wizard/CMakeLists.txt` -eq 0 && echo "pico_enable_stdio_uart(firmware 1)" >> wizard/CMakeLists.txt) || true
|
||||
make -C wizard CFLAGS_EXTRA=$(CFLAGS_EXTRA) && mv wizard/build/firmware.uf2 ./
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/ota?uf2=1 --data-binary @firmware.uf2
|
||||
|
||||
test: update
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=5 | tee /tmp/output.txt
|
||||
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=15 | tee /tmp/output.txt
|
||||
grep 'READY, IP:' /tmp/output.txt # Check for network init
|
||||
# grep 'MQTT connected' /tmp/output.txt # Check for MQTT connection success
|
||||
|
||||
clean:
|
||||
$(RM) pico-sdk build
|
||||
rm -rf firmware.* wizard* pico-sdk
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# RP2350 + W5500 Ethernet chip
|
||||
|
||||
- See [detailed tutorial](https://mongoose.ws/tutorials/rp2040/pico-w5500/) (including hardware connections)
|
||||
- See [Wizard](https://mongoose.ws/wizard/#/output?board=evb-pico2&ide=Pico-SDK&rtos=baremetal&file=README.md)
|
||||
- See detailed tutorial (including hardware connections) at https://mongoose.ws/tutorials/rp2040/pico-w5500/
|
||||
|
||||
|
@ -1,96 +0,0 @@
|
||||
// Copyright (c) 2023 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "hardware/spi.h"
|
||||
#include "pico/rand.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/unique_id.h"
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "net.h"
|
||||
|
||||
enum { BLINK_PERIOD_MS = 1000 };
|
||||
// enum { LED = 25, SPI_CS = 17, SPI_CLK = 18, SPI_TX = 19, SPI_RX = 16 }; //
|
||||
// Pins
|
||||
enum { LED = 25, SPI_CS = 5, SPI_CLK = 2, SPI_TX = 3, SPI_RX = 4 }; // Pins
|
||||
|
||||
static void spi_begin(void *spi) {
|
||||
gpio_put(SPI_CS, 0);
|
||||
}
|
||||
static void spi_end(void *spi) {
|
||||
gpio_put(SPI_CS, 1);
|
||||
}
|
||||
static uint8_t spi_txn(void *spi, uint8_t byte) {
|
||||
uint8_t result = 0;
|
||||
spi_write_read_blocking(spi0, &byte, &result, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void timer_fn(void *arg) {
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, !gpio_get(PICO_DEFAULT_LED_PIN)); // Blink LED
|
||||
struct mg_tcpip_if *ifp = arg; // And show
|
||||
const char *names[] = {"down", "up", "req", "IP", "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,
|
||||
ifp->ndrop, ifp->nerr));
|
||||
}
|
||||
|
||||
static void eth_spi_init(void) {
|
||||
// Init SPI pins
|
||||
spi_init(spi0, 500 * 1000);
|
||||
gpio_set_function(SPI_RX, GPIO_FUNC_SPI); // MISO
|
||||
gpio_set_function(SPI_TX, GPIO_FUNC_SPI); // MOSI
|
||||
gpio_set_function(SPI_CLK, GPIO_FUNC_SPI); // CLK
|
||||
gpio_init(SPI_CS); // CS
|
||||
gpio_set_dir(SPI_CS, GPIO_OUT); // Set CS to output
|
||||
gpio_put(SPI_CS, 1); // And drive CS high (inactive)
|
||||
}
|
||||
|
||||
// Helper macro for MAC generation
|
||||
#define GENERATE_LOCALLY_ADMINISTERED_MAC(id) \
|
||||
{ 2, id[3], id[4], id[5], id[6], id[7] }
|
||||
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
gpio_init(LED); // Setup board LED
|
||||
gpio_set_dir(LED, GPIO_OUT);
|
||||
eth_spi_init(); // Initialise SPI pins
|
||||
MG_INFO(("Starting ..."));
|
||||
|
||||
pico_unique_board_id_t board_id;
|
||||
pico_get_unique_board_id(&board_id);
|
||||
uint8_t *id = board_id.id;
|
||||
|
||||
struct mg_mgr mgr; // Initialise
|
||||
mg_mgr_init(&mgr); // Mongoose event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
|
||||
// Initialise Mongoose network stack
|
||||
struct mg_tcpip_spi spi = {NULL, spi_begin, spi_end, spi_txn};
|
||||
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(id),
|
||||
// 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_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, &mif);
|
||||
|
||||
MG_INFO(("MAC: %M. Waiting for IP...", mg_print_mac, mif.mac));
|
||||
while (mif.state != MG_TCPIP_STATE_READY) {
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
}
|
||||
|
||||
MG_INFO(("Initialising application..."));
|
||||
web_init(&mgr);
|
||||
|
||||
MG_INFO(("Starting event loop"));
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../../mongoose.c
|
@ -1 +0,0 @@
|
||||
../../../mongoose.h
|
@ -1,6 +0,0 @@
|
||||
#define MG_ARCH MG_ARCH_PICOSDK
|
||||
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_TCPIP_DRIVER_INIT 0
|
||||
#define MG_ENABLE_DRIVER_W5500 1
|
||||
#define MG_ENABLE_PACKED_FS 1
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.c
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/net.h
|
@ -1 +0,0 @@
|
||||
../../device-dashboard/packed_fs.c
|
Loading…
Reference in New Issue
Block a user