restart reason

Dependencies:   mbed BSP_DISCO_F746NG

Committer:
iliatumash
Date:
Wed Dec 09 11:22:48 2020 +0000
Revision:
0:b487e94f8ecd
restart reason

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iliatumash 0:b487e94f8ecd 1 #include "mbed.h"
iliatumash 0:b487e94f8ecd 2 #include "stm32746g_discovery_lcd.h"
iliatumash 0:b487e94f8ecd 3 #include "ResetReason.h"
iliatumash 0:b487e94f8ecd 4 #include <string>
iliatumash 0:b487e94f8ecd 5
iliatumash 0:b487e94f8ecd 6
iliatumash 0:b487e94f8ecd 7 static BufferedSerial pc(USBTX, USBRX);
iliatumash 0:b487e94f8ecd 8 Thread reading;
iliatumash 0:b487e94f8ecd 9
iliatumash 0:b487e94f8ecd 10 std::string reset_reason_to_string(const reset_reason_t reason)
iliatumash 0:b487e94f8ecd 11 {
iliatumash 0:b487e94f8ecd 12 switch (reason) {
iliatumash 0:b487e94f8ecd 13 case RESET_REASON_PIN_RESET:
iliatumash 0:b487e94f8ecd 14 return "Button Reset";
iliatumash 0:b487e94f8ecd 15 case RESET_REASON_SOFTWARE:
iliatumash 0:b487e94f8ecd 16 return "Comand Reset";
iliatumash 0:b487e94f8ecd 17 case RESET_REASON_WATCHDOG:
iliatumash 0:b487e94f8ecd 18 return "Watchdog Reset";
iliatumash 0:b487e94f8ecd 19 default:
iliatumash 0:b487e94f8ecd 20 return "Other Reason";
iliatumash 0:b487e94f8ecd 21 }
iliatumash 0:b487e94f8ecd 22 }
iliatumash 0:b487e94f8ecd 23
iliatumash 0:b487e94f8ecd 24 void read_serial(){
iliatumash 0:b487e94f8ecd 25 char *c = new char[1];
iliatumash 0:b487e94f8ecd 26 while (1) {
iliatumash 0:b487e94f8ecd 27 pc.read(c, sizeof(c));
iliatumash 0:b487e94f8ecd 28 if(*c == 'r'){
iliatumash 0:b487e94f8ecd 29 NVIC_SystemReset();
iliatumash 0:b487e94f8ecd 30 }
iliatumash 0:b487e94f8ecd 31 }
iliatumash 0:b487e94f8ecd 32 }
iliatumash 0:b487e94f8ecd 33 void display(){
iliatumash 0:b487e94f8ecd 34 BSP_LCD_Init();
iliatumash 0:b487e94f8ecd 35 BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
iliatumash 0:b487e94f8ecd 36 BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
iliatumash 0:b487e94f8ecd 37 BSP_LCD_Clear(LCD_COLOR_BLUE);
iliatumash 0:b487e94f8ecd 38 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
iliatumash 0:b487e94f8ecd 39 BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
iliatumash 0:b487e94f8ecd 40 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
iliatumash 0:b487e94f8ecd 41 }
iliatumash 0:b487e94f8ecd 42
iliatumash 0:b487e94f8ecd 43 int main() {
iliatumash 0:b487e94f8ecd 44
iliatumash 0:b487e94f8ecd 45 display();
iliatumash 0:b487e94f8ecd 46
iliatumash 0:b487e94f8ecd 47 const reset_reason_t reason = ResetReason::get();
iliatumash 0:b487e94f8ecd 48
iliatumash 0:b487e94f8ecd 49 BSP_LCD_DisplayStringAt(0, 80, (uint8_t *)reset_reason_to_string(reason).c_str(), CENTER_MODE);
iliatumash 0:b487e94f8ecd 50 printf("Reason: %s\n", reset_reason_to_string(reason).c_str());
iliatumash 0:b487e94f8ecd 51 Watchdog &watchdog = Watchdog::get_instance();
iliatumash 0:b487e94f8ecd 52 watchdog.start(5000);
iliatumash 0:b487e94f8ecd 53
iliatumash 0:b487e94f8ecd 54 reading.start(read_serial);
iliatumash 0:b487e94f8ecd 55
iliatumash 0:b487e94f8ecd 56 while(1) {}
iliatumash 0:b487e94f8ecd 57
iliatumash 0:b487e94f8ecd 58 }