Reorder setup, with serial early

This commit is contained in:
Scott Lahteine 2020-04-11 21:29:52 -05:00
parent 0fec478562
commit 5a5be7e287
2 changed files with 46 additions and 55 deletions

View file

@ -76,16 +76,16 @@ void HAL_init() {
#endif #endif
#if ENABLED(SRAM_EEPROM_EMULATION) #if ENABLED(SRAM_EEPROM_EMULATION)
// Enable access to backup SRAM // Enable access to backup SRAM
__HAL_RCC_PWR_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess(); HAL_PWR_EnableBkUpAccess();
__HAL_RCC_BKPSRAM_CLK_ENABLE(); __HAL_RCC_BKPSRAM_CLK_ENABLE();
// Enable backup regulator // Enable backup regulator
LL_PWR_EnableBkUpRegulator(); LL_PWR_EnableBkUpRegulator();
// Wait until backup regulator is initialized // Wait until backup regulator is initialized
while (!LL_PWR_IsActiveFlag_BRR()); while (!LL_PWR_IsActiveFlag_BRR());
#endif // EEPROM_EMULATED_SRAM #endif
#if HAS_TMC_SW_SERIAL #if HAS_TMC_SW_SERIAL
SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0); SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0);

View file

@ -889,52 +889,15 @@ void setup() {
#endif #endif
#define SETUP_RUN(C) do{ SETUP_LOG(STRINGIFY(C)); C; }while(0) #define SETUP_RUN(C) do{ SETUP_LOG(STRINGIFY(C)); C; }while(0)
HAL_init(); #if EITHER(DISABLE_DEBUG, DISABLE_JTAG)
#if HAS_L64XX
L64xxManager.init(); // Set up SPI, init drivers
#endif
#if ENABLED(SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Put Smart Effector into NORMAL mode
#endif
#if ENABLED(DISABLE_DEBUG)
// Disable any hardware debug to free up pins for IO // Disable any hardware debug to free up pins for IO
#ifdef JTAGSWD_DISABLE #if ENABLED(DISABLE_DEBUG) && defined(JTAGSWD_DISABLE)
JTAGSWD_DISABLE(); JTAGSWD_DISABLE();
#elif defined(JTAG_DISABLE) #elif defined(JTAG_DISABLE)
JTAG_DISABLE(); JTAG_DISABLE();
#else #else
#error "DISABLE_DEBUG is not supported for the selected MCU/Board" #error "DISABLE_(DEBUG|JTAG) is not supported for the selected MCU/Board."
#endif #endif
#elif ENABLED(DISABLE_JTAG)
// Disable JTAG to free up pins for IO
#ifdef JTAG_DISABLE
JTAG_DISABLE();
#else
#error "DISABLE_JTAG is not supported for the selected MCU/Board"
#endif
#endif
#if HAS_FILAMENT_SENSOR
runout.setup();
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.setup();
#endif
setup_killpin();
#if HAS_TMC220x
tmc_serial_begin();
#endif
setup_powerhold();
#if HAS_STEPPER_RESET
disableStepperDrivers();
#endif #endif
#if NUM_SERIAL > 0 #if NUM_SERIAL > 0
@ -946,10 +909,38 @@ void setup() {
serial_connect_timeout = millis() + 1000UL; serial_connect_timeout = millis() + 1000UL;
while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
#endif #endif
SERIAL_ECHO_MSG("start");
#endif #endif
SERIAL_ECHOLNPGM("start"); SETUP_RUN(HAL_init());
SERIAL_ECHO_START();
#if HAS_L64XX
SETUP_RUN(L64xxManager.init()); // Set up SPI, init drivers
#endif
#if ENABLED(SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Put Smart Effector into NORMAL mode
#endif
#if HAS_FILAMENT_SENSOR
SETUP_RUN(runout.setup());
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
SETUP_RUN(recovery.setup());
#endif
SETUP_RUN(setup_killpin());
#if HAS_TMC220x
SETUP_RUN(tmc_serial_begin());
#endif
SETUP_RUN(setup_powerhold());
#if HAS_STEPPER_RESET
SETUP_RUN(disableStepperDrivers());
#endif
#if HAS_TMC_SPI #if HAS_TMC_SPI
#if DISABLED(TMC_USE_SW_SPI) #if DISABLED(TMC_USE_SW_SPI)
@ -966,7 +957,7 @@ void setup() {
SETUP_RUN(esp_wifi_init()); SETUP_RUN(esp_wifi_init());
// Check startup - does nothing if bootloader sets MCUSR to 0 // Check startup - does nothing if bootloader sets MCUSR to 0
byte mcu = HAL_get_reset_source(); const byte mcu = HAL_get_reset_source();
if (mcu & 1) SERIAL_ECHOLNPGM(STR_POWERUP); if (mcu & 1) SERIAL_ECHOLNPGM(STR_POWERUP);
if (mcu & 2) SERIAL_ECHOLNPGM(STR_EXTERNAL_RESET); if (mcu & 2) SERIAL_ECHOLNPGM(STR_EXTERNAL_RESET);
if (mcu & 4) SERIAL_ECHOLNPGM(STR_BROWNOUT_RESET); if (mcu & 4) SERIAL_ECHOLNPGM(STR_BROWNOUT_RESET);
@ -991,9 +982,6 @@ void setup() {
SERIAL_ECHO_START(); SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(STR_FREE_MEMORY, freeMemory(), STR_PLANNER_BUFFER_BYTES, (int)sizeof(block_t) * (BLOCK_BUFFER_SIZE)); SERIAL_ECHOLNPAIR(STR_FREE_MEMORY, freeMemory(), STR_PLANNER_BUFFER_BYTES, (int)sizeof(block_t) * (BLOCK_BUFFER_SIZE));
// UI must be initialized before EEPROM
// (because EEPROM code calls the UI).
// Set up LEDs early // Set up LEDs early
#if HAS_COLOR_LEDS #if HAS_COLOR_LEDS
SETUP_RUN(leds.setup()); SETUP_RUN(leds.setup());
@ -1003,6 +991,9 @@ void setup() {
SETUP_RUN(controllerFan.setup()); SETUP_RUN(controllerFan.setup());
#endif #endif
// UI must be initialized before EEPROM
// (because EEPROM code calls the UI).
SETUP_RUN(ui.init()); SETUP_RUN(ui.init());
SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.) SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)