add watchdog and better debugging
This commit is contained in:
parent
5de420d908
commit
4821a782ee
3
global.h
3
global.h
|
@ -19,6 +19,9 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/** enable debugging functionalities */
|
||||||
|
#define DEBUG true
|
||||||
|
|
||||||
/** get the length of an array */
|
/** get the length of an array */
|
||||||
#define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
|
#define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
/** concatenate 2 arguments (used to defer concatenation) */
|
/** concatenate 2 arguments (used to defer concatenation) */
|
||||||
|
|
31
main.c
31
main.c
|
@ -27,13 +27,15 @@
|
||||||
#include <math.h> // mathematical utilities
|
#include <math.h> // mathematical utilities
|
||||||
|
|
||||||
/* STM32 (including CM3) libraries */
|
/* STM32 (including CM3) libraries */
|
||||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
|
||||||
#include <libopencm3/stm32/gpio.h> // general purpose input output library
|
|
||||||
#include <libopencm3/cm3/scb.h> // vector table definition
|
|
||||||
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities
|
#include <libopencmsis/core_cm3.h> // Cortex M3 utilities
|
||||||
|
#include <libopencm3/cm3/scb.h> // vector table definition
|
||||||
#include <libopencm3/cm3/nvic.h> // interrupt utilities
|
#include <libopencm3/cm3/nvic.h> // interrupt utilities
|
||||||
|
#include <libopencm3/stm32/gpio.h> // general purpose input output library
|
||||||
|
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||||
#include <libopencm3/stm32/exti.h> // external interrupt utilities
|
#include <libopencm3/stm32/exti.h> // external interrupt utilities
|
||||||
#include <libopencm3/stm32/rtc.h> // real time clock utilities
|
#include <libopencm3/stm32/rtc.h> // real time clock utilities
|
||||||
|
#include <libopencm3/stm32/iwdg.h> // independent watchdog utilities
|
||||||
|
#include <libopencm3/stm32/dbgmcu.h> // debug utilities
|
||||||
|
|
||||||
/* own libraries */
|
/* own libraries */
|
||||||
#include "global.h" // board definitions
|
#include "global.h" // board definitions
|
||||||
|
@ -143,6 +145,14 @@ void main(void)
|
||||||
{
|
{
|
||||||
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
|
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
DBGMCU_CR |= DBGMCU_CR_IWDG_STOP; // stop independent watchdog counter when code is halted
|
||||||
|
DBGMCU_CR |= DBGMCU_CR_WWDG_STOP; // stop window watchdog counter when code is halted
|
||||||
|
DBGMCU_CR |= DBGMCU_CR_STANDBY; // allow debug also in standby mode (keep digital part and clock powered)
|
||||||
|
DBGMCU_CR |= DBGMCU_CR_STOP; // allow debug also in stop mode (keep clock powered)
|
||||||
|
DBGMCU_CR |= DBGMCU_CR_SLEEP; // allow debug also in sleep mode (keep clock powered)
|
||||||
|
#endif
|
||||||
|
|
||||||
// setup board
|
// setup board
|
||||||
board_setup();
|
board_setup();
|
||||||
|
|
||||||
|
@ -189,14 +199,24 @@ void main(void)
|
||||||
radio_esp8266_setup();
|
radio_esp8266_setup();
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
|
|
||||||
|
#if !(DEBUG)
|
||||||
|
//setup watchdog to reset in case we get stuck (i.e. when an error occurred)
|
||||||
|
#define WATCHDOG_PERIOD 10000 /**< watchdog period in ms */
|
||||||
|
printf("setup watchdog (%.2fs): ",WATCHDOG_PERIOD/1000.0);
|
||||||
|
iwdg_set_period_ms(WATCHDOG_PERIOD); // set independent watchdog period
|
||||||
|
iwdg_start(); // start independent watchdog
|
||||||
|
printf("OK\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// send HTTP POST request
|
// send HTTP POST request
|
||||||
printf("making HTTP request: ");
|
printf("making HTTP request: ");
|
||||||
radio_esp8266_tcp_open("192.168.42.2",8086); // open connection
|
radio_esp8266_tcp_open("192.168.42.3",8086); // open connection
|
||||||
while (!radio_esp8266_activity) { // wait until response has been received
|
while (!radio_esp8266_activity) { // wait until response has been received
|
||||||
__WFI(); // wait until something happens
|
__WFI(); // wait until something happens
|
||||||
}
|
}
|
||||||
if (!radio_esp8266_success) { // could not open port
|
if (!radio_esp8266_success) { // could not open port
|
||||||
return; // not ideal error handling
|
printf("TCP connection failed\n");
|
||||||
|
while (true); // unhandled error. wait for debugging or watchdog
|
||||||
}
|
}
|
||||||
char http_line[256+1] = {0};
|
char http_line[256+1] = {0};
|
||||||
int http_length = snprintf(http_line, LENGTH(http_line), "POST /write?db=test HTTP/1.1\r\n");
|
int http_length = snprintf(http_line, LENGTH(http_line), "POST /write?db=test HTTP/1.1\r\n");
|
||||||
|
@ -263,6 +283,7 @@ void main(void)
|
||||||
char c = ' '; // to store received character
|
char c = ' '; // to store received character
|
||||||
bool char_flag = false; // a new character has been received
|
bool char_flag = false; // a new character has been received
|
||||||
while (true) { // infinite loop
|
while (true) { // infinite loop
|
||||||
|
iwdg_reset(); // kick the dog
|
||||||
while (usart_received) { // data received over UART
|
while (usart_received) { // data received over UART
|
||||||
action = true; // action has been performed
|
action = true; // action has been performed
|
||||||
led_toggle(); // toggle LED
|
led_toggle(); // toggle LED
|
||||||
|
|
Loading…
Reference in New Issue