diff --git a/tutorials/stm32/nucleo_f429zi/cubemx/README.md b/tutorials/stm32/nucleo_f429zi/cubemx/README.md index 3833cc51..b543045f 100644 --- a/tutorials/stm32/nucleo_f429zi/cubemx/README.md +++ b/tutorials/stm32/nucleo_f429zi/cubemx/README.md @@ -1,98 +1,34 @@ -# Mongoose CubeMX integration +# Nucleo-F429ZI Mongoose Integration -This is a step-by-step guide on how to bring up a production-grade Web UI -dashboard on STM32 Nucleo-F429ZI development board. +This guide explains how to bring up a production-grade Web UI dashboard on the +STM32 Nucleo-F429ZI development board. -A pre-configured project .zip is available for download at https://mongoose.ws. -However for those who want to configure the project from scratch, follow the steps -below. +A pre-configured, ready-to-run project archive is available for download at +https://mongoose.ws. -## Generate project code -- Open the .ioc file in your CubeMX -- Click on "Project Manager" - - If you're using CubeIDE, select "CubeIDE" in the toolchain/IDE dropdown - - If you're using VSCode, select "Cmake" in the toolchain/IDE dropdown - - If you're using Makefile, select "Makefile" in the toolchain/IDE dropdown -- Click "Generate Code" button on the top right +To integrate the Web UI dashboard into an existing CubeMX project, or to create a +new project from scratch: -This should generate project code in this directory the directory where .ioc file lives. -Open this directory in your IDE. +1. Configure the peripherals (described below). +2. Regenerate your project code and integrate Mongoose core by following + https://mongoose.ws/docs/guides/stm32-tcpip-stack/. After Mongoose core has + been integrated, the protocol examples at + https://github.com/cesanta/mongoose/tree/master/tutorials should run on your + board. Copy the corresponding functionality from the example's `main.c` into + your project's `main.c`. +3. Add the Web UI dashboard by following + https://mongoose.ws/docs/guides/web-dashboard-guide/. -## Configure .bin generation +## Configure peripherals -Normally, IDEs generate .elf firmware file, cause it is easier for a debugger -to load it to a device. However, for the firmware OTA update, the .bin file -is required. The .bin file is the firmware image that gets copied to the -beginning of the microcontroller's flash memory and gets executed after the -system boot. +An `.ioc` file is included in this directory for your reference. It was created +using the following steps: -So, we need to tell the IDE to generate .bin firmware flash image file. - -- If you're using CubeIDE, select Project / Properties / C/C++ build / Settings - / MCU/MPU Post build outputs, enable "Convert to binary file (-O binary)" -- If you're using VSCode, add a section to the end of the top-level `CMakeLists.txt`: -```cmake -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary - ${PROJECT_NAME}.elf - ${PROJECT_NAME}.bin -) -``` - -## Call Mongoose from main.c - - -Edit `Core/Src/main.c` and update the following snippets - notice the `USER CODE BEGIN` / `USER CODE END` placeholders. At the top of the file: - -```c -/* USER CODE BEGIN Includes */ -#include "mongoose_glue.h" -/* USER CODE END Includes */ -``` - -Before the `main()` function: -```c -/* USER CODE BEGIN 0 */ -int _write(int fd, unsigned char *buf, int len) { - HAL_UART_Transmit(&huart3, buf, len, HAL_MAX_DELAY); - return len; -} - -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; - if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) { - mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), HAL_GetTick()); - } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", HAL_GetTick()); - } - } -} - -// This blocks forever. Call it at the end of main(), or in a -// separate RTOS task. Give that task 8k stack space. -void run_mongoose(void) { - 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, 0); - } -} -/* USER CODE END 0 */ -``` - -Inside the `main()` function: -```c -/* USER CODE BEGIN WHILE */ -run_mongoose(); // <----------------- Add this line -while (1) -{ - /* USER CODE END WHILE */ -``` - -## Build, flash, test - -Start serial console. -Use STM32CubeProgrammer to flash the firmware. +- Open CubeMX. If you are starting a new project, select the STM32F429ZI + microcontroller and create a new project. +- In Clock Configuration, set the maximum clock frequency to 180 MHz. +- In the MCU pinout view, set pins PB0, PB7, and PB14 to GPIO_Output mode. +- In Pinout & Configuration / Connectivity, enable USART3 in asynchronous mode. + Configure pins PD8 and PD9 for USART. +- In Pinout & Configuration / Connectivity, enable ETH in RMII mode and set pins + PA1, PA2, PA7, PC1, PC4, PC5, PB13, PG11, and PG13 for Ethernet. diff --git a/tutorials/stm32/nucleo_f756zg/cubemx/README.md b/tutorials/stm32/nucleo_f756zg/cubemx/README.md index 2ef1fe35..441e1c35 100644 --- a/tutorials/stm32/nucleo_f756zg/cubemx/README.md +++ b/tutorials/stm32/nucleo_f756zg/cubemx/README.md @@ -1,98 +1,34 @@ -# Mongoose CubeMX integration +# Nucleo-F756ZG Mongoose Integration -This is a step-by-step guide on how to bring up a production-grade Web UI -dashboard on STM32 Nucleo-F756ZG development board. +This guide explains how to bring up a production-grade Web UI dashboard on the +STM32 Nucleo-F756ZG development board. -A pre-configured project .zip is available for download at https://mongoose.ws. -However for those who want to configure the project from scratch, follow the steps -below. +A pre-configured, ready-to-run project archive is available for download at +https://mongoose.ws. -## Generate project code -- Open the .ioc file in your CubeMX -- Click on "Project Manager" - - If you're using CubeIDE, select "CubeIDE" in the toolchain/IDE dropdown - - If you're using VSCode, select "Cmake" in the toolchain/IDE dropdown - - If you're using Makefile, select "Makefile" in the toolchain/IDE dropdown -- Click "Generate Code" button on the top right +To integrate the Web UI dashboard into an existing CubeMX project, or to create a +new project from scratch: -This should generate project code in this directory the directory where .ioc file lives. -Open this directory in your IDE. +1. Configure the peripherals (described below). +2. Regenerate your project code and integrate Mongoose core by following + https://mongoose.ws/docs/guides/stm32-tcpip-stack/. After Mongoose core has + been integrated, the protocol examples at + https://github.com/cesanta/mongoose/tree/master/tutorials should run on your + board. Copy the corresponding functionality from the example's `main.c` into + your project's `main.c`. +3. Add the Web UI dashboard by following + https://mongoose.ws/docs/guides/web-dashboard-guide/. -## Configure .bin generation +## Configure peripherals -Normally, IDEs generate .elf firmware file, cause it is easier for a debugger -to load it to a device. However, for the firmware OTA update, the .bin file -is required. The .bin file is the firmware image that gets copied to the -beginning of the microcontroller's flash memory and gets executed after the -system boot. +An `.ioc` file is included in this directory for your reference. It was created +using the following steps: -So, we need to tell the IDE to generate .bin firmware flash image file. - -- If you're using CubeIDE, select Project / Properties / C/C++ build / Settings - / MCU/MPU Post build outputs, enable "Convert to binary file (-O binary)" -- If you're using VSCode, add a section to the end of the top-level `CMakeLists.txt`: -```cmake -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary - ${PROJECT_NAME}.elf - ${PROJECT_NAME}.bin -) -``` - -## Call Mongoose from main.c - - -Edit `Core/Src/main.c` and update the following snippets - notice the `USER CODE BEGIN` / `USER CODE END` placeholders. At the top of the file: - -```c -/* USER CODE BEGIN Includes */ -#include "mongoose_glue.h" -/* USER CODE END Includes */ -``` - -Before the `main()` function: -```c -/* USER CODE BEGIN 0 */ -int _write(int fd, unsigned char *buf, int len) { - HAL_UART_Transmit(&huart3, buf, len, HAL_MAX_DELAY); - return len; -} - -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; - if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) { - mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), HAL_GetTick()); - } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", HAL_GetTick()); - } - } -} - -// This blocks forever. Call it at the end of main(), or in a -// separate RTOS task. Give that task 8k stack space. -void run_mongoose(void) { - 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, 0); - } -} -/* USER CODE END 0 */ -``` - -Inside the `main()` function: -```c -/* USER CODE BEGIN WHILE */ -run_mongoose(); // <----------------- Add this line -while (1) -{ - /* USER CODE END WHILE */ -``` - -## Build, flash, test - -Start serial console. -Use STM32CubeProgrammer to flash the firmware. +- Open CubeMX. If you are starting a new project, select the STM32F756ZG + microcontroller and create a new project. +- In Clock Configuration, set the maximum clock frequency to 216 MHz. +- In the MCU pinout view, set pins PB0, PB7, and PB14 to GPIO_Output mode. +- In Pinout & Configuration / Connectivity, enable USART3 in asynchronous mode. + Configure pins PD8 and PD9 for USART. +- In Pinout & Configuration / Connectivity, enable ETH in RMII mode and set pins + PA1, PA2, PA7, PC1, PC4, PC5, PB13, PG11, and PG13 for Ethernet. diff --git a/tutorials/stm32/nucleo_h563zi/cubemx/README.md b/tutorials/stm32/nucleo_h563zi/cubemx/README.md index d3e60b1e..d38babdd 100644 --- a/tutorials/stm32/nucleo_h563zi/cubemx/README.md +++ b/tutorials/stm32/nucleo_h563zi/cubemx/README.md @@ -1,98 +1,35 @@ -# Mongoose CubeMX integration +# Nucleo-H563ZI Mongoose Integration -This is a step-by-step guide on how to bring up a production-grade Web UI -dashboard on STM32 Nucleo-H563ZI development board. +This guide explains how to bring up a production-grade Web UI dashboard on the +STM32 Nucleo-H563ZI development board. -A pre-configured project .zip is available for download at https://mongoose.ws. -However for those who want to configure the project from scratch, follow the steps -below. +A pre-configured, ready-to-run project archive is available for download at +https://mongoose.ws. +To integrate the Web UI dashboard into an existing CubeMX project, or to create a +new project from scratch: -## Generate project code -- Open the .ioc file in your CubeMX -- Click on "Project Manager" - - If you're using CubeIDE, select "CubeIDE" in the toolchain/IDE dropdown - - If you're using VSCode, select "Cmake" in the toolchain/IDE dropdown - - If you're using Makefile, select "Makefile" in the toolchain/IDE dropdown -- Click "Generate Code" button on the top right +1. Configure the peripherals (described below). +2. Regenerate your project code and integrate Mongoose core by following + https://mongoose.ws/docs/guides/stm32-tcpip-stack/. After Mongoose core has + been integrated, the protocol examples at + https://github.com/cesanta/mongoose/tree/master/tutorials should run on your + board. Copy the corresponding functionality from the example's `main.c` into + your project's `main.c`. +3. Add the Web UI dashboard by following + https://mongoose.ws/docs/guides/web-dashboard-guide/. -This should generate project code in this directory the directory where .ioc file lives. -Open this directory in your IDE. +## Configure peripherals -## Configure .bin generation +An `.ioc` file is included in this directory for your reference. It was created +using the following steps: -Normally, IDEs generate .elf firmware file, cause it is easier for a debugger -to load it to a device. However, for the firmware OTA update, the .bin file -is required. The .bin file is the firmware image that gets copied to the -beginning of the microcontroller's flash memory and gets executed after the -system boot. - -So, we need to tell the IDE to generate .bin firmware flash image file. - -- If you're using CubeIDE, select Project / Properties / C/C++ build / Settings - / MCU/MPU Post build outputs, enable "Convert to binary file (-O binary)" -- If you're using VSCode, add a section to the end of the top-level `CMakeLists.txt`: -```cmake -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary - ${PROJECT_NAME}.elf - ${PROJECT_NAME}.bin -) -``` - -## Call Mongoose from main.c - -Edit `Core/Src/main.c` and update the following snippets - notice the `USER CODE BEGIN` / `USER CODE END` placeholders. At the top of the file: - -```c -/* USER CODE BEGIN Includes */ -#include "mongoose_glue.h" -/* USER CODE END Includes */ -``` - -Before the `main()` function: -```c -/* USER CODE BEGIN 0 */ -int _write(int fd, unsigned char *buf, int len) { - HAL_UART_Transmit(&huart3, buf, len, HAL_MAX_DELAY); - return len; -} - -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; - if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) { - mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), HAL_GetTick()); - } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", HAL_GetTick()); - } - } -} - -// This blocks forever. Call it at the end of main(), or in a -// separate RTOS task. Give that task 8k stack space. -void run_mongoose(void) { - 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, 0); - } -} -/* USER CODE END 0 */ -``` - -Inside the `main()` function: -```c -/* USER CODE BEGIN WHILE */ -run_mongoose(); // <----------------- Add this line -while (1) -{ - /* USER CODE END WHILE */ -``` - -## Build, flash, test - -Start serial console. -Use STM32CubeProgrammer to flash the firmware. +- Open CubeMX. If you are starting a new project, select the STM32H563ZI + microcontroller and create a new project. +- In Pinout & Configuration / Security, enable RNG and select "Activated". +- In Clock Configuration, set the maximum clock frequency to 250 MHz. +- In the MCU pinout view, set pins PB0, PF4, and PG4 to GPIO_Output mode. +- In Pinout & Configuration / Connectivity, enable USART3 in asynchronous mode. + Configure pins PD8 and PD9 for USART. +- In Pinout & Configuration / Connectivity, enable ETH in RMII mode and set pins + PA1, PA2, PA7, PC1, PC4, PC5, PB15, PG11, and PG13 for Ethernet. diff --git a/tutorials/stm32/nucleo_h723zg/cubemx/README.md b/tutorials/stm32/nucleo_h723zg/cubemx/README.md index adce66c2..4918ec27 100644 --- a/tutorials/stm32/nucleo_h723zg/cubemx/README.md +++ b/tutorials/stm32/nucleo_h723zg/cubemx/README.md @@ -1,105 +1,34 @@ -# Mongoose CubeMX integration +# Nucleo-H723ZG Mongoose Integration -This is a step-by-step guide on how to bring up a production-grade Web UI -dashboard on STM32 Nucleo-H723ZG development board. +This guide explains how to bring up a production-grade Web UI dashboard on the +STM32 Nucleo-H723ZG development board. -A pre-configured project .zip is available for download at https://mongoose.ws. -However for those who want to configure the project from scratch, follow the steps -below. +A pre-configured, ready-to-run project archive is available for download at +https://mongoose.ws. +To integrate the Web UI dashboard into an existing CubeMX project, or to create a +new project from scratch: -## Generate project code -- Open the .ioc file in your CubeMX -- Click on "Project Manager" - - If you're using CubeIDE, select "CubeIDE" in the toolchain/IDE dropdown - - If you're using VSCode, select "Cmake" in the toolchain/IDE dropdown - - If you're using Makefile, select "Makefile" in the toolchain/IDE dropdown -- Click "Generate Code" button on the top right +1. Configure the peripherals (described below). +2. Regenerate your project code and integrate Mongoose core by following + https://mongoose.ws/docs/guides/stm32-tcpip-stack/. After Mongoose core has + been integrated, the protocol examples at + https://github.com/cesanta/mongoose/tree/master/tutorials should run on your + board. Copy the corresponding functionality from the example's `main.c` into + your project's `main.c`. +3. Add the Web UI dashboard by following + https://mongoose.ws/docs/guides/web-dashboard-guide/. -This should generate project code in this directory the directory where .ioc file lives. -Open this directory in your IDE. +## Configure peripherals -## Configure .bin generation +An `.ioc` file is included in this directory for your reference. It was created +using the following steps: -Normally, IDEs generate .elf firmware file, cause it is easier for a debugger -to load it to a device. However, for the firmware OTA update, the .bin file -is required. The .bin file is the firmware image that gets copied to the -beginning of the microcontroller's flash memory and gets executed after the -system boot. - -So, we need to tell the IDE to generate .bin firmware flash image file. - -- If you're using CubeIDE, select Project / Properties / C/C++ build / Settings - / MCU/MPU Post build outputs, enable "Convert to binary file (-O binary)" -- If you're using VSCode, add a section to the end of the top-level `CMakeLists.txt`: -```cmake -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary - ${PROJECT_NAME}.elf - ${PROJECT_NAME}.bin -) -``` - -## Call Mongoose from main.c - -Edit `Core/Src/main.c` and update the following snippets - notice the `USER CODE BEGIN` / `USER CODE END` placeholders. At the top of the file: - -```c -/* USER CODE BEGIN Includes */ -#include "mongoose_glue.h" -/* USER CODE END Includes */ -``` -Before the `main()` function: -```c -/* USER CODE BEGIN 0 */ -int _write(int fd, unsigned char *buf, int len) { - HAL_UART_Transmit(&huart3, buf, len, HAL_MAX_DELAY); - return len; -} - -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; - if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) { - mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), HAL_GetTick()); - } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", HAL_GetTick()); - } - } -} - -// This blocks forever. Call it at the end of main(), or in a -// separate RTOS task. Give that task 8k stack space. -void run_mongoose(void) { - 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, 0); - } -} -/* USER CODE END 0 */ -``` - -Inside the `main()` function: -```c -/* USER CODE BEGIN WHILE */ -run_mongoose(); // <----------------- Add this line -while (1) -{ - /* USER CODE END WHILE */ -``` - - -## Edit linker script - -Edit `STM32H723XG_FLASH.ld`, add the following line before the `.bss (NOLOAD)` line: -```text -.eth_ram : { *(.eth_ram .eth_ram*) } > RAM_D2 AT > FLASH -``` - -## Build, flash, test - -Start serial console. -Use STM32CubeProgrammer to flash the firmware. +- Open CubeMX. If you are starting a new project, select the STM32H723ZG + microcontroller and create a new project. +- In Clock Configuration, set the maximum clock frequency to 550 MHz. +- In the MCU pinout view, set pins PB0, PE1, and PB14 to GPIO_Output mode. +- In Pinout & Configuration / Connectivity, enable USART3 in asynchronous mode. + Configure pins PD8 and PD9 for USART. +- In Pinout & Configuration / Connectivity, enable ETH in RMII mode and set pins + PA1, PA2, PA7, PC1, PC4, PC5, PB13, PG11, and PG13 for Ethernet. diff --git a/tutorials/stm32/nucleo_n657x0_q/cubemx/README.md b/tutorials/stm32/nucleo_n657x0_q/cubemx/README.md index 14cf1253..93e49659 100644 --- a/tutorials/stm32/nucleo_n657x0_q/cubemx/README.md +++ b/tutorials/stm32/nucleo_n657x0_q/cubemx/README.md @@ -1,17 +1,28 @@ -# Mongoose CubeMX integration +# Nucleo-N657X0-Q Mongoose Integration -This is a step-by-step guide on how to bring up a production-grade Web UI -dashboard on STM32 Nucleo-N657X0-Q development board. +This guide explains how to bring up a production-grade Web UI dashboard on the +STM32 Nucleo-N657X0-Q development board. -A pre-configured project .zip is available for download at https://mongoose.ws. -However for those who want to configure the project from scratch, follow the steps -below. +A pre-configured, ready-to-run project archive is available for download at +https://mongoose.ws. -## Generate .ioc file +To integrate the Web UI dashboard into an existing CubeMX project, or to create a +new project from scratch: -This directory already has a pre-configured `.ioc` file so you can just open it -in your CubeMX and skip this step. However for those who want to create the -project from scratch, here are the steps: +1. Configure the peripherals (described below). +2. Regenerate your project code and integrate Mongoose core by following + https://mongoose.ws/docs/guides/stm32-tcpip-stack/. After Mongoose core has + been integrated, the protocol examples at + https://github.com/cesanta/mongoose/tree/master/tutorials should run on your + board. Copy the corresponding functionality from the example's `main.c` into + your project's `main.c`. +3. Add the Web UI dashboard by following + https://mongoose.ws/docs/guides/web-dashboard-guide/. + +## Configure peripherals + +An `.ioc` file is included in this directory for your reference. It was created +using the following steps: - Open CubeMX, File / New project, type "STM32N657X0H3Q" in the part number, select it from the list, click "Start project" on the top right, choose "Secure domain only" @@ -30,93 +41,3 @@ project from scratch, here are the steps: - Peripherals (RISUP), enable "Privilege" on ETH1 - Domains (RIMU): for ETH1, enable SECURE and PRIVILEGE - Clock configuration: resolve clocks if required. Find "To ETH1" and make sure it has 100 MHz - -## Generate project code -- Clone this repo to your workstation. Open the .ioc file in your CubeMX -- Click on "Project Manager" - - If you're using CubeIDE, select "CubeIDE" in the toolchain/IDE dropdown - - If you're using VSCode, select "Cmake" in the toolchain/IDE dropdown - - If you're using Makefile, select "Makefile" in the toolchain/IDE dropdown -- Click "Generate Code" button on the top right - -## Configure .bin generation - -Normally, IDEs generate .elf firmware file, cause it is easier for a debugger -to load it to a device. However, for the firmware OTA update, the .bin file -is required. The .bin file is the firmware image that gets copied to the -beginning of the microcontroller's flash memory and gets executed after the -system boot. - -So, we need to tell the IDE to generate .bin firmware flash image file. - -- If you're using CubeIDE, select Project / Properties / C/C++ build / Settings - / MCU/MPU Post build outputs, enable "Convert to binary file (-O binary)" -- If you're using VSCode, add a section to the end of the top-level `CMakeLists.txt`: -```cmake -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -O binary - ${PROJECT_NAME}.elf - ${PROJECT_NAME}.bin -) -``` - -## Call Mongoose from main.c - -Edit `Core/Src/main.c` and update the following snippets - notice the `USER CODE BEGIN` / `USER CODE END` placeholders. At the top of the file: - -```c -/* USER CODE BEGIN Includes */ -#include "mongoose_glue.h" -/* USER CODE END Includes */ -``` - -Before the `main()` function: -```c -/* USER CODE BEGIN 0 */ -int _write(int fd, unsigned char *buf, int len) { - HAL_UART_Transmit(&huart1, buf, len, HAL_MAX_DELAY); - return len; -} - -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; - if (mg_match(hm->uri, mg_str("/api/tick"), NULL)) { - mg_http_reply(c, 200, "", "{%m:%llu}\n", MG_ESC("tick"), HAL_GetTick()); - } else { - mg_http_reply(c, 200, "", "Hi from Mongoose, tick %llu\n", HAL_GetTick()); - } - } -} - -// This blocks forever. Call it at the end of main(), or in a -// separate RTOS task. Give that task 8k stack space. -void run_mongoose(void) { - 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, 0); - } -} -/* USER CODE END 0 */ -``` - -Inside the `main()` function: -```c -/* USER CODE BEGIN WHILE */ -HAL_GPIO_WritePin(GPIOG, GPIO_PIN_0, 1); -HAL_GPIO_WritePin(GPIOG, GPIO_PIN_8, 1); -HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, 1); -run_mongoose(); -while (1) -{ - /* USER CODE END WHILE */ -``` - -## Build, flash, test - -Start serial console. -Use STM32CubeProgrammer to flash the firmware. Don't forget to specify -the `MX25UM51245G_STM32N6570-NUCLEO.stldr` external loader for this board.