mongoose/examples/stm32/nucleo-f746zg-make-baremetal-builtin/main.c

53 lines
1.4 KiB
C
Raw Normal View History

// Copyright (c) 2022-2023 Cesanta Software Limited
2022-05-26 20:53:36 +08:00
// All rights reserved
#include "hal.h"
2023-05-31 03:17:46 +08:00
#include "mongoose.h"
2023-05-26 22:48:20 +08:00
#include "net.h"
2022-05-26 20:53:36 +08:00
#define BLINK_PERIOD_MS 1000 // LED blinking period in millis
2022-05-26 20:53:36 +08:00
2023-02-09 04:14:39 +08:00
static volatile uint64_t s_ticks; // Milliseconds since boot
void SysTick_Handler(void) { // SyStick IRQ handler, triggered every 1ms
2022-05-26 20:53:36 +08:00
s_ticks++;
}
uint64_t mg_millis(void) { // Let Mongoose use our uptime function
return s_ticks; // Return number of milliseconds since boot
2022-05-26 20:53:36 +08:00
}
bool mg_random(void *buf, size_t len) { // Use on-board RNG
for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
uint32_t r = rng_read();
memcpy((char *) buf + n, &r, n + sizeof(r) > len ? len - n : sizeof(r));
}
return true;
}
static void timer_fn(void *arg) {
2024-03-14 21:41:53 +08:00
gpio_toggle(LED); // Blink LED
(void) arg;
}
int main(void) {
2023-08-02 01:19:51 +08:00
gpio_output(LED); // Setup blue LED
uart_init(UART_DEBUG, 115200); // Initialise debug printf
ethernet_init(); // Initialise ethernet pins
2023-02-09 04:14:39 +08:00
MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));
2022-05-26 20:53:36 +08:00
struct mg_mgr mgr; // Initialise
mg_mgr_init(&mgr); // Mongoose event manager
2022-08-01 18:19:32 +08:00
mg_log_set(MG_LL_DEBUG); // Set log level
2024-03-14 21:41:53 +08:00
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, NULL);
2023-01-31 03:50:28 +08:00
MG_INFO(("Initialising application..."));
2023-05-26 22:48:20 +08:00
web_init(&mgr);
2023-01-31 03:50:28 +08:00
MG_INFO(("Starting event loop"));
for (;;) {
mg_mgr_poll(&mgr, 0);
}
2022-05-26 20:53:36 +08:00
return 0;
}