diff --git a/stm32-modules/include/thermocycler-gen2/firmware/motor_hardware.h b/stm32-modules/include/thermocycler-gen2/firmware/motor_hardware.h index 88a2fecd..579a6aae 100644 --- a/stm32-modules/include/thermocycler-gen2/firmware/motor_hardware.h +++ b/stm32-modules/include/thermocycler-gen2/firmware/motor_hardware.h @@ -189,7 +189,7 @@ void motor_hardware_seal_switch_interrupt(); * reset of the software. * @return a string describing the reason for reset. * */ -char* motor_hardware_reset_reason(); +uint16_t motor_hardware_reset_reason(); #ifdef __cplusplus } // extern "C" diff --git a/stm32-modules/include/thermocycler-gen2/firmware/motor_policy.hpp b/stm32-modules/include/thermocycler-gen2/firmware/motor_policy.hpp index 48646393..b633ee37 100644 --- a/stm32-modules/include/thermocycler-gen2/firmware/motor_policy.hpp +++ b/stm32-modules/include/thermocycler-gen2/firmware/motor_policy.hpp @@ -191,7 +191,7 @@ class MotorPolicy { * reset of the software. * @return a string describing the reason for reset. * */ - [[nodiscard]] auto last_reset_reason() const -> char*; + [[nodiscard]] auto last_reset_reason() const -> uint16_t; /** * @brief Call the seal callback function diff --git a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/gcodes.hpp b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/gcodes.hpp index ce901eb2..40e58c73 100644 --- a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/gcodes.hpp +++ b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/gcodes.hpp @@ -157,11 +157,12 @@ struct GetResetReason { template requires std::forward_iterator && std::sized_sentinel_for - static auto write_response_into(InputIt buf, InLimit limit, char* reason) + static auto write_response_into(InputIt buf, InLimit limit, uint16_t reason) -> InputIt { int res = 0; - res = snprintf(&*buf, (limit - buf), - "M114 Last Reset Reason: %s OK\n", reason); + // print a hexadecimal representation of the reset flags + res = snprintf(&*buf, (limit - buf), "M114 Last Reset Reason: %X OK\n", + reason); if (res <= 0) { return buf; } diff --git a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/host_comms_task.hpp b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/host_comms_task.hpp index b72bfc6c..175d79f8 100644 --- a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/host_comms_task.hpp +++ b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/host_comms_task.hpp @@ -258,8 +258,7 @@ class HostCommsTask { return errors::write_into(tx_into, tx_limit, msg.with_error); } else { - return cache_element.write_response_into( - tx_into, tx_limit); + return cache_element.write_response_into(tx_into, tx_limit); } }, cache_entry); diff --git a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/messages.hpp b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/messages.hpp index b7d81c28..b135d72e 100644 --- a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/messages.hpp +++ b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/messages.hpp @@ -359,7 +359,7 @@ struct GetResetReasonMessage { struct GetResetReasonResponse { uint32_t responding_to_id; - char* reason; + uint16_t reason; }; struct OpenLidMessage { diff --git a/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c b/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c index 148128cb..843f374d 100644 --- a/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c +++ b/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c @@ -184,6 +184,38 @@ static motor_hardware_t _motor_hardware = { } }; +enum RCC_FLAGS { + NONE, + // high speed internal clock ready + HSIRDY, // = 1 + // high speed external clock ready + HSERDY, // = 2 + // main phase-locked loop clock ready + PLLRDY, // = 3 + // hsi48 clock ready + HSI48RDY, // = 4 + // low-speed external clock ready + LSERDY, // = 5 + // lse clock security system failure + LSECSSD, // = 6 + // low-speed internal clock ready + LSIRDY, // = 7 + // brown out + BORRST, // = 8 + // option byte-loader reset + OBLRST, // = 9 + // pin reset + PINRST, // = 10 + // software reset + SFTRST, // = 11 + // independent watchdog + IWDGRST, // = 12 + // window watchdog + WWDGRST, // = 13 + // low power reset + LPWRRST, // = 14 +}; + // ---------------------------------------------------------------------------- // Local function declaration @@ -194,7 +226,8 @@ static void init_tim2(TIM_HandleTypeDef* htim); static void init_tim6(TIM_HandleTypeDef* htim); static bool lid_active(); static void save_reset_reason(); -static char* reset_reason; +//static char* reset_reason; +uint16_t reset_reason; // ---------------------------------------------------------------------------- // Public function implementation @@ -410,7 +443,7 @@ void motor_hardware_seal_switch_set_disarmed() { _motor_hardware.seal.retraction_switch_armed = false; } -char* motor_hardware_reset_reason() { +uint16_t motor_hardware_reset_reason() { return reset_reason; } @@ -633,62 +666,63 @@ static bool lid_active() { static void save_reset_reason() { // check various reset flags to see if the HAL RCC // reset flag matches any of them + reset_reason = 0; // high speed internal clock ready if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) { - reset_reason = "hsi clock ready"; + reset_reason |= HSIRDY; } // high speed external clock ready else if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) { - reset_reason = "hse clock ready"; + reset_reason |= HSERDY; } // main phase-locked loop clock ready else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY)) { - reset_reason = "pll clock ready"; + reset_reason |= PLLRDY; } - // hsi48 clock ready if applicable ? + // hsi48 clock ready else if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY)) { - reset_reason = "hsi 48 clock ready"; + reset_reason |= HSI48RDY; } // low-speed external clock ready else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY)) { - reset_reason = "lsi clock ready"; + reset_reason |= LSERDY; } // lse clock security system failure else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSECSSD)) { - reset_reason = "lse security failure"; + reset_reason |= LSECSSD; } // low-speed internal clock ready else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY)) { - reset_reason = "lsi clock ready"; + reset_reason |= LSIRDY; } // brown out else if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST)) { - reset_reason = "brown out"; + reset_reason |= BORRST; } // option byte-loader reset else if (__HAL_RCC_GET_FLAG(RCC_FLAG_OBLRST)) { - reset_reason = "oblrst"; + reset_reason |= OBLRST; } - // pin reset ? + // pin reset else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST)) { - reset_reason = "pin reset"; + reset_reason |= PINRST; } // software reset else if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST)) { - reset_reason = "software reset"; + reset_reason |= SFTRST; } // independent watchdog else if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST)) { - reset_reason = "independent watchdog"; + reset_reason |= IWDGRST; } // window watchdog else if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST)) { - reset_reason = "window watchdog"; + reset_reason |= WWDGRST; } // low power reset else if (__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST)) { - reset_reason = "low power"; + reset_reason |= LPWRRST; } } diff --git a/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_policy.cpp b/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_policy.cpp index 9817ac08..713f26c0 100644 --- a/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_policy.cpp +++ b/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_policy.cpp @@ -154,6 +154,6 @@ auto MotorPolicy::seal_switch_set_disarmed() -> void { } // NOLINTNEXTLINE(readability-convert-member-functions-to-static) -[[nodiscard]] auto MotorPolicy::last_reset_reason() const -> char* { +[[nodiscard]] auto MotorPolicy::last_reset_reason() const -> uint16_t { return motor_hardware_reset_reason(); } \ No newline at end of file