Merge pull request #3576 from cesanta/log

Use mg_log_set_fn instead of _write override
This commit is contained in:
Sergey Lyubka
2026-06-01 12:06:21 +01:00
committed by GitHub
13 changed files with 39 additions and 50 deletions
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('B', 7)
#define LED3 PIN('B', 14)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_ethernet_init();
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('B', 7)
#define LED3 PIN('B', 14)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_ethernet_init();
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('B', 7)
#define LED3 PIN('B', 14)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_ethernet_init();
@@ -21,10 +21,8 @@ static struct spi spi_pins = {
.cs = PIN('A', 4),
};
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
uart_write_buf(param, &ch, 1);
}
bool mg_random(void *buf, size_t len) { // Use on-board RNG
@@ -74,6 +72,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
int main(void) {
gpio_output(LED); // Setup green LED
uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
// ethernet_init(); // Initialise ethernet pins
MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED_2 PIN('F', 4) // On-board LED pin (yellow)
#define LED_3 PIN('G', 4) // On-board LED pin (red)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -74,6 +72,7 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
int main(void) {
hal_clock_init();
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_rng_init();
hal_gpio_output(LED_1);
hal_gpio_output(LED_2);
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('E', 1)
#define LED3 PIN('B', 14)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -73,6 +71,7 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
int main(void) {
hal_clock_init();
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_rng_init();
hal_ethernet_init();
hal_gpio_output(LED1);
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('E', 1) // On-board LED pin (yellow)
#define LED3 PIN('B', 14) // On-board LED pin (red)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_ethernet_init();
@@ -12,10 +12,8 @@
#define LED_2 PIN('G', 8) // Blue LED
#define LED_3 PIN('G', 10) // Red LED
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1) hal_uart_write_buf(DEBUG_UART, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
// Blink green LED every 500ms
@@ -52,6 +50,7 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
int main(void) {
hal_uart_init(DEBUG_UART, UART_TX, UART_RX, 115200);
mg_log_set_fn(log_fn, DEBUG_UART);
hal_rng_init();
// Initialise pins and turn them off: they are active high
@@ -9,10 +9,8 @@
#define LED2 PIN('B', 7) // On-board LED pin (blue)
#define LED3 PIN('G', 2) // On-board LED pin (red)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(DEBUG_UART, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -53,6 +51,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(DEBUG_UART, 115200);
mg_log_set_fn(log_fn, DEBUG_UART);
extern void hwspecific_spi_init();
hwspecific_spi_init();
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('K', 6) // On-board LED pin (green)
#define LED3 PIN('K', 7) // On-board LED pin (blue)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
extern void hwspecific_sdio_init(void);
hwspecific_sdio_init();
+3 -4
View File
@@ -17,10 +17,8 @@
#define LED2 PIN('I', 8) // On-board LED pin (orange)
#define LED3 PIN('F', 1) // On-board LED pin (red)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_ethernet_init();
@@ -17,10 +17,8 @@
#define LED2 PIN('I', 13) // On-board LED pin (yellow)
#define LED3 PIN('I', 14) // On-board LED pin (red)
// Redirect stdout debug output to UART
int _write(int fd, char *ptr, int len) {
if (fd == 1 || fd == 2) hal_uart_write_buf(UART_DEBUG, ptr, (size_t) len);
return len;
static void log_fn(char ch, void *param) {
hal_uart_write_buf(param, &ch, 1);
}
static void blink_task(void) {
@@ -61,6 +59,7 @@ int main(void) {
hal_gpio_output(LED2);
hal_gpio_output(LED3);
hal_uart_init(UART_DEBUG, UART_DEBUG_TX_PIN, UART_DEBUG_RX_PIN, 115200);
mg_log_set_fn(log_fn, UART_DEBUG);
hal_ethernet_init();