Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/helloworld/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "hal/interfaces/Gpio.hpp"
#include "hal_st/cortex/FaultTracer.hpp"
#include "hal_st/instantiations/NucleoUi.hpp"
#include "hal_st/instantiations/ResetReason.hpp"
#include "hal_st/instantiations/StmEventInfrastructure.hpp"
#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/UartStmDma.hpp"
Expand Down Expand Up @@ -82,6 +83,8 @@ int main()

services::SetGlobalTracerInstance(tracerWithDateTime);

services::GlobalTracer().Trace() << "Reset reason: " << hal::GetResetReasonString();

static infra::TimerRepeating timerRepeating{ std::chrono::seconds{ 1 }, []
{
services::GlobalTracer().Trace() << "Hello World !";
Expand Down
2 changes: 2 additions & 0 deletions hal_st/instantiations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target_link_libraries(hal_st.instantiations PUBLIC
hal_st.synchronous_stm32fxxx
infra.event
infra.timer
infra.util
services.tracer
)

Expand All @@ -25,4 +26,5 @@ target_sources(hal_st.instantiations PRIVATE
StmTracerInfrastructure.hpp
TracingResetStm.cpp
TracingResetStm.hpp
ResetReason.hpp
)
38 changes: 38 additions & 0 deletions hal_st/instantiations/ResetReason.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef HAL_ST_INSTANTIATIONS_RESETREASON_HPP
#define HAL_ST_INSTANTIATIONS_RESETREASON_HPP

#include "infra/util/BoundedString.hpp"
#include DEVICE_HEADER

namespace hal
{
// Note: This function clears the reset flags after reading them
infra::BoundedConstString GetResetReasonString()
{
const char* resetReason;

if (__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST))
resetReason = "LowPower";
#if defined(RCC_FLAG_PORRST)
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST))
resetReason = "PowerOn";
#endif
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST))
resetReason = "Window WatchDog";
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST))
resetReason = "Independent WatchDog";
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST))
resetReason = "Software";
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST))
resetReason = "Reset Pin";
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST))
resetReason = "BrownOut(BOR)";
else
resetReason = "Unknown";

__HAL_RCC_CLEAR_RESET_FLAGS();
return resetReason;
}
}

#endif // HAL_ST_INSTANTIATIONS_RESETREASON_HPP
Loading