diff --git a/STM32L476_ParaMETEO/__stackanalysis/dummy.txt b/STM32L476_ParaMETEO/__stackanalysis/dummy.txt deleted file mode 100644 index e69de29..0000000 diff --git a/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch b/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch index af82e71..e916c43 100644 --- a/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch +++ b/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch @@ -58,6 +58,6 @@ - + diff --git a/doc/memory_map_parameteo_stm32l476.xls b/doc/memory_map_parameteo_stm32l476.xls index fd4374c..7c9b592 100644 Binary files a/doc/memory_map_parameteo_stm32l476.xls and b/doc/memory_map_parameteo_stm32l476.xls differ diff --git a/include/backup_registers.h b/include/backup_registers.h index bd1524c..9357292 100644 --- a/include/backup_registers.h +++ b/include/backup_registers.h @@ -81,6 +81,11 @@ void backup_reg_set_telemetry(uint16_t); void backup_reg_get_packet_counters(uint8_t * beacon_counter, uint8_t * meteo_counter, uint8_t * meteo_gsm_counter); void backup_reg_set_packet_counters(uint8_t beacon_counter, uint8_t meteo_counter, uint8_t meteo_gsm_counter); +void backup_reg_increment_aprsis_check_reset(void); +void backup_reg_increment_weather_measurements_check_reset(void); +void backup_reg_increment_dallas_degraded_reset(void); +void backup_reg_increment_is_rtc_ok_check_reset(void); + #endif /* BACKUP_REGISTERS_H_ */ diff --git a/include/etc/misc_config.h b/include/etc/misc_config.h new file mode 100644 index 0000000..9c0f040 --- /dev/null +++ b/include/etc/misc_config.h @@ -0,0 +1,17 @@ +/* + * misc_config.h + * Misc configuration which doesn't match to any other place + * + * + * Created on: Apr 15, 2024 + * Author: mateusz + */ + +#ifndef ETC_MISC_CONFIG_H_ +#define ETC_MISC_CONFIG_H_ + +#define RTE_WX_PROBLEMS_MAX_THRESHOLD 20 + + + +#endif /* ETC_MISC_CONFIG_H_ */ diff --git a/include/main.h b/include/main.h index 51d5f63..2fc1299 100644 --- a/include/main.h +++ b/include/main.h @@ -15,8 +15,8 @@ #define SYSTICK_TICKS_PER_SECONDS 100 #define SYSTICK_TICKS_PERIOD 10 -#define INTERNAL_WATCHDOG -#define EXTERNAL_WATCHDOG +//#define INTERNAL_WATCHDOG +//#define EXTERNAL_WATCHDOG #define PWR_SWITCH_BOTH diff --git a/include/rte_wx.h b/include/rte_wx.h index 83f9b4b..30a8893 100644 --- a/include/rte_wx.h +++ b/include/rte_wx.h @@ -104,6 +104,7 @@ extern "C" void rte_wx_init(void); void rte_wx_update_last_measuremenet_timers(uint16_t measurement_type); void rte_wx_reset_last_measuremenet_timers(uint16_t measurement_type); +int8_t rte_wx_check_weather_measurements(void); #ifdef __cplusplus diff --git a/include/software_version.h b/include/software_version.h index bec50fe..92e5ffe 100644 --- a/include/software_version.h +++ b/include/software_version.h @@ -8,8 +8,8 @@ #ifndef SOFTWARE_VERSION_H_ #define SOFTWARE_VERSION_H_ -#define SW_VER "EB04" -#define SW_DATE "10042024" +#define SW_VER "EB05" +#define SW_DATE "18042024" #define SW_KISS_PROTO "B" extern const char software_version_str[5]; diff --git a/ldscripts/stm32l476/STM32L471RETx_FLASH.ld b/ldscripts/stm32l476/STM32L471RETx_FLASH.ld index ee4ce0f..aa14fc9 100644 --- a/ldscripts/stm32l476/STM32L471RETx_FLASH.ld +++ b/ldscripts/stm32l476/STM32L471RETx_FLASH.ld @@ -56,7 +56,7 @@ ENTRY(Reset_Handler) _estack = 0x20018000; /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ +_Min_Stack_Size = 0x800; /* required amount of stack */ /* Specify the memory areas */ MEMORY diff --git a/src/backup_registers.c b/src/backup_registers.c index c19dbf3..665d07d 100644 --- a/src/backup_registers.c +++ b/src/backup_registers.c @@ -16,6 +16,7 @@ #define REGISTER_COUNTERS RTC->BKP4R #define REGISTER_LAST_SLTIM RTC->BKP6R #define REGISTER_PACKET_COUNTERS RTC->BKP7R +#define REGISTER_RESET_CHECK_FAIL RTC->BKP8R #endif #define BACKUP_REG_INHIBIT_PWR_SWITCH_PERIODIC_H 1u @@ -39,6 +40,7 @@ // 5 -> monitor // 6 -> last sleep time // 7 -> weather and telemetry timers & counters +// 8 -> counters of resets caused by validation checks failures // 7th register map // xxxxyyAA - telemetry frames counter @@ -47,6 +49,12 @@ // xxAAyyyy - value of packet_tx_beacon_counter // Axxxyyyy - checksum +// 8th register map +// xxxxyyAA - resets caused by 'aprsis_check_connection_attempt_alive()' +// xxxxAAyy - resets caused by 'rte_wx_check_weather_measurements()' +// xxAAyyyy - resets caused by value of 'rte_wx_dallas_degraded_counter' +// AAxxyyyy - resets caused by 'system_is_rtc_ok()' + static void backup_reg_unclock(void) { // enable access to backup domain PWR->CR1 |= PWR_CR1_DBP; @@ -421,7 +429,10 @@ uint32_t backup_reg_get_last_sleep_duration(void) { return out; } - +/** + * + * @param in + */ void backup_reg_set_last_sleep_duration(uint32_t in) { #ifdef PARAMETEO backup_reg_unclock(); @@ -512,6 +523,12 @@ void backup_reg_set_telemetry(uint16_t in) { } +/** + * + * @param beacon_counter + * @param meteo_counter + * @param meteo_gsm_counter + */ void backup_reg_get_packet_counters(uint8_t * beacon_counter, uint8_t * meteo_counter, uint8_t * meteo_gsm_counter) { #ifdef PARAMETEO uint32_t reg_value = REGISTER_PACKET_COUNTERS; @@ -539,6 +556,12 @@ void backup_reg_get_packet_counters(uint8_t * beacon_counter, uint8_t * meteo_co #endif } +/** + * + * @param beacon_counter + * @param meteo_counter + * @param meteo_gsm_counter + */ void backup_reg_set_packet_counters(uint8_t beacon_counter, uint8_t meteo_counter, uint8_t meteo_gsm_counter) { #ifdef PARAMETEO volatile uint32_t reg_value = REGISTER_PACKET_COUNTERS; @@ -572,3 +595,95 @@ void backup_reg_set_packet_counters(uint8_t beacon_counter, uint8_t meteo_counte #endif } + +void backup_reg_increment_aprsis_check_reset(void) { + // REGISTER_RESET_CHECK_FAIL + volatile uint32_t reg_value = REGISTER_RESET_CHECK_FAIL; + + // get existing value + uint8_t counter = (uint8_t)(reg_value & 0xFFU); + + // increment it + counter++; + + // clear existing value from register + reg_value &= 0xFFFFFF00U; + + // add incremented counter value + reg_value |= counter; + + backup_reg_unclock(); + + REGISTER_RESET_CHECK_FAIL = reg_value; + + backup_reg_lock(); +} + +void backup_reg_increment_weather_measurements_check_reset(void) { + // REGISTER_RESET_CHECK_FAIL + volatile uint32_t reg_value = REGISTER_RESET_CHECK_FAIL; + + // get existing value + uint8_t counter = (uint8_t)((reg_value & 0xFF00U) >> 8U); + + // increment it + counter++; + + // clear existing value from register + reg_value &= 0xFFFF00FFU; + + // add incremented counter value + reg_value |= ((uint32_t)counter << 8U); + + backup_reg_unclock(); + + REGISTER_RESET_CHECK_FAIL = reg_value; + + backup_reg_lock(); +} + +void backup_reg_increment_dallas_degraded_reset(void) { + // REGISTER_RESET_CHECK_FAIL + volatile uint32_t reg_value = REGISTER_RESET_CHECK_FAIL; + + // get existing value + uint8_t counter = (uint8_t)((reg_value & 0xFF0000U) >> 16U); + + // increment it + counter++; + + // clear existing value from register + reg_value &= 0xFF00FFFFU; + + // add incremented counter value + reg_value |= ((uint32_t)counter << 16U); + + backup_reg_unclock(); + + REGISTER_RESET_CHECK_FAIL = reg_value; + + backup_reg_lock(); +} + +void backup_reg_increment_is_rtc_ok_check_reset(void) { + // REGISTER_RESET_CHECK_FAIL + volatile uint32_t reg_value = REGISTER_RESET_CHECK_FAIL; + + // get existing value + uint8_t counter = (uint8_t)((reg_value & 0xFF000000U) >> 24U); + + // increment it + counter++; + + // clear existing value from register + reg_value &= 0x00FFFFFFU; + + // add incremented counter value + reg_value |= ((uint32_t)counter << 24U); + + backup_reg_unclock(); + + REGISTER_RESET_CHECK_FAIL = reg_value; + + backup_reg_lock(); +} diff --git a/src/main.c b/src/main.c index 63ad56f..2516fdb 100644 --- a/src/main.c +++ b/src/main.c @@ -122,8 +122,8 @@ // 3 -> controller configuration status // 4 -> wakeup events MSB, sleep events LSB // 5 -> monitor -// 6 -> weather and telemetry timers & counters - +// 6 -> last sleep time +// 7 -> weather and telemetry timers & counters #define CONFIG_FIRST_RESTORED (1) #define CONFIG_FIRST_FAIL_RESTORING (1 << 1) @@ -1485,16 +1485,31 @@ int main(int argc, char* argv[]){ if ((main_config_data_gsm->aprsis_enable != 0) && (main_config_data_mode->gsm == 1)) { if (pwr_save_is_currently_cutoff() == 0) { + // this checks when APRS-IS was alive last time and when any packet + // has been sent to the server. const int i_am_ok_with_aprsis = aprsis_check_connection_attempt_alive(); if (i_am_ok_with_aprsis != 0) { + + // increase counter stored in RTC backup register + backup_reg_increment_aprsis_check_reset(); + + // trigger a restart NVIC_SystemReset(); } } } #endif + if (rte_wx_check_weather_measurements() == 0) { + backup_reg_increment_weather_measurements_check_reset(); + + NVIC_SystemReset(); + } + if (rte_wx_dallas_degraded_counter > DALLAS_MAX_LIMIT_OF_DEGRADED) { + backup_reg_increment_dallas_degraded_reset(); + rte_main_reboot_req = 1; } @@ -1504,7 +1519,11 @@ int main(int argc, char* argv[]){ if (--main_one_hour_pool_timer < 0) { main_one_hour_pool_timer = 60; + // check if RTC is working correctly if (system_is_rtc_ok() == 0) { + + backup_reg_increment_is_rtc_ok_check_reset(); + rte_main_reboot_req = 1; } diff --git a/src/rte_wx.c b/src/rte_wx.c index bd90568..f456921 100644 --- a/src/rte_wx.c +++ b/src/rte_wx.c @@ -9,6 +9,11 @@ #include #include #include "main.h" +#include "misc_config.h" + +#ifndef RTE_WX_PROBLEMS_MAX_THRESHOLD +#define RTE_WX_PROBLEMS_MAX_THRESHOLD 20 +#endif /** * A little word of explanataion: @@ -21,7 +26,6 @@ * */ -//float rte_wx_temperature_average_external = 0.0f; //= WIND_AVERAGE_LEN - 1) { + rte_wx_problems_wind_buffers++; + } + + // go through wind speed buffer and checks if it contains the same value + for (i = 0; i < WIND_AVERAGE_LEN - 1; i++) { + if (rte_wx_windspeed[i] != rte_wx_windspeed[i + 1]) { + break; + } + } + + // check if an end of the buffer has been reached + if (i >= WIND_AVERAGE_LEN - 1) { + rte_wx_problems_wind_buffers++; + } + + // check if average wind speed is different from zero and the same than gusts + if (rte_wx_average_windspeed != 0 && + (rte_wx_average_windspeed == rte_wx_max_windspeed)) + { + // if so a wind sensor had been blocked by icing very rapidly + // before next DMA interrupt so rte_wx_windspeed is also + // not updated at all + rte_wx_problems_wind_values++; + } + + // check if wind direction equals exactly north (zero degrees) + if (rte_wx_average_winddirection == 0) { + // open wind direction input (anemometer disconnected) gives + // a reading of about 6 do 8 degrees. If it is stuck on zero + // the U->f converted or its reference clock generator + // might not work at all + rte_wx_problems_wind_values++; + } + else { + rte_wx_problems_wind_values = 0; + } + + if (rte_wx_problems_wind_values > RTE_WX_PROBLEMS_MAX_THRESHOLD) { + looks_good = 0; + } + + if (rte_wx_problems_wind_buffers > RTE_WX_PROBLEMS_MAX_THRESHOLD * 3) { + looks_good = 0; + } + + return looks_good; +} diff --git a/src/stored_configuration_nvm/configuration_handler.c b/src/stored_configuration_nvm/configuration_handler.c index 97943d5..07d6f1a 100644 --- a/src/stored_configuration_nvm/configuration_handler.c +++ b/src/stored_configuration_nvm/configuration_handler.c @@ -56,6 +56,9 @@ const uint32_t * const config_section_first_start = (const uint32_t *)CONFIG_S const uint32_t * const config_section_second_start = (const uint32_t *)CONFIG_SECTION_SECOND_START; const uint32_t * const config_section_default_start = (const uint32_t *)CONFIG_SECTION_DEFAULT_START; +uint8_t config_engineering_1 = 0xFFU; +uint8_t config_engineering_2 = 0xFFU; + #ifdef PARAMETEO #define STRUCT_COUNT 6 #endif @@ -638,6 +641,9 @@ void configuration_handler_load_configuration(configuration_handler_region_t reg configuration_handler_loaded = region; + config_engineering_1 = main_config_data_basic->engineering1; + config_engineering_2 = main_config_data_basic->engineering2; + } kiss_communication_nrc_t configuration_handler_erase_startup(void) { diff --git a/src/wx_handler.c b/src/wx_handler.c index 96c029b..4d48f69 100644 --- a/src/wx_handler.c +++ b/src/wx_handler.c @@ -180,7 +180,7 @@ void wx_pool_anemometer(const config_data_wx_sources_t * const config_sources, c short i = 0; uint8_t average_ln; - int32_t modbus_retval; + int32_t modbus_retval = MODBUS_RET_UNINITIALIZED; uint16_t scaled_windspeed = 0; //#ifdef STM32L471xx