Skip to content

Commit d4399b3

Browse files
committed
esp32: Fix first line ESP32-C2 serial output after reset or deepsleep.
ESP32-C2 ROM prints at 74880bps (same as ESP8266), so need a newline before first MicroPython output to avoid it being appended on end of a line of noise. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 77c9eb7 commit d4399b3

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2025 Angus Gratton
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#include "py/mpconfig.h"
27+
28+
void GENERIC_C2_board_startup(void) {
29+
// With a 26MHz crystal the ESP32-C2 ROM prints output at 74880 which is
30+
// interpreted mostly as noise, then boot.py output and/or the REPL banner
31+
// prints at the end of a line of noise unless we inject a newline here
32+
printf("\n");
33+
34+
boardctrl_startup();
35+
}

ports/esp32/boards/ESP32_GENERIC_C2/mpconfigboard.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ set(SDKCONFIG_DEFAULTS
77
# C2 has unusably low free RAM without these optimisations
88
boards/sdkconfig.free_ram
99
)
10+
11+
set(MICROPY_SOURCE_BOARD
12+
${MICROPY_BOARD_DIR}/board_init.c
13+
)
14+

ports/esp32/boards/ESP32_GENERIC_C2/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55

66
#define MICROPY_HW_ENABLE_SDCARD (0)
77
#define MICROPY_PY_MACHINE_I2S (0)
8+
9+
#define MICROPY_BOARD_STARTUP GENERIC_C2_board_startup
10+
void GENERIC_C2_board_startup(void);

ports/esp32/boards/sdkconfig.c2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
CONFIG_XTAL_FREQ_26=y
55
# CONFIG_XTAL_FREQ_40 is not set
66
CONFIG_XTAL_FREQ=26
7+
8+
# When using 26MHz crystal the baud rate defaults to 74880,
9+
# same as ESP8266 - MicroPython uses 115200, so switch early
10+
CONFIG_ESP_CONSOLE_UART_CUSTOM=y
11+
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
12+
713
# Increase NimBLE stack size for functional BT
814
CONFIG_BT_NIMBLE_TASK_STACK_SIZE=5120
915

0 commit comments

Comments
 (0)