diff --git a/NANOVNA_STM32_F072/rtc_v2.c b/NANOVNA_STM32_F072/rtc_v2.c index f6df158..68deac0 100644 --- a/NANOVNA_STM32_F072/rtc_v2.c +++ b/NANOVNA_STM32_F072/rtc_v2.c @@ -149,7 +149,9 @@ void rtc_init(void){ // If calendar has not been initialized yet then proceed with the initial setup. if ((RTC->ISR & RTC_ISR_INITS) == 0 || RTC->PRER != rtc_prer) { if (rtc_enter_init()){ - RTC->CR &= ~RTC_CR_COE; + RTC->CR = 0 +// | RTC_CR_COSEL // RTC output 1Hz (or 512Hz if disabled) + ; RTC->ISR = RTC_ISR_INIT; // Clearing all but RTC_ISR_INIT. RTC->PRER = rtc_prer; // Prescaler value loaded in registers 2 times RTC->PRER = rtc_prer; @@ -162,14 +164,10 @@ void rtc_init(void){ } void rtc_set_cal(float ppm) { - ppm*= (1<<20) / 1000000.0f; - int32_t cal = ppm > 0 ? ppm + 0.5f : ppm - 0.5f; - if ((RTC->ISR & RTC_ISR_RECALPF) != 0 || cal < -511 || cal > 512) + int32_t cal = ppm * (1<<20) / 1000000.0f + 511.5f; + if ((RTC->ISR & RTC_ISR_RECALPF) || (uint32_t)cal > 1024) return; - if (cal > 0) - RTC->CALR = RTC_CALR_CALP | (512 - cal); - else - RTC->CALR = -cal; + RTC->CALR = (511 - cal) & (RTC_CALR_CALP | RTC_CALR_CALM); } float rtc_get_cal(void) { diff --git a/NANOVNA_STM32_F303/rtc_v2.c b/NANOVNA_STM32_F303/rtc_v2.c index f6df158..bf5fe27 100644 --- a/NANOVNA_STM32_F303/rtc_v2.c +++ b/NANOVNA_STM32_F303/rtc_v2.c @@ -149,7 +149,9 @@ void rtc_init(void){ // If calendar has not been initialized yet then proceed with the initial setup. if ((RTC->ISR & RTC_ISR_INITS) == 0 || RTC->PRER != rtc_prer) { if (rtc_enter_init()){ - RTC->CR &= ~RTC_CR_COE; + RTC->CR = 0 +// | RTC_CR_COSEL // RTC output 1Hz (or 512Hz if disabled) + ; RTC->ISR = RTC_ISR_INIT; // Clearing all but RTC_ISR_INIT. RTC->PRER = rtc_prer; // Prescaler value loaded in registers 2 times RTC->PRER = rtc_prer; @@ -162,14 +164,10 @@ void rtc_init(void){ } void rtc_set_cal(float ppm) { - ppm*= (1<<20) / 1000000.0f; - int32_t cal = ppm > 0 ? ppm + 0.5f : ppm - 0.5f; - if ((RTC->ISR & RTC_ISR_RECALPF) != 0 || cal < -511 || cal > 512) + int32_t cal = ppm * (1<<20) / 1000000.0f + 511.5f; + if ((RTC->ISR & RTC_ISR_RECALPF) || (uint32_t)cal > 1024) return; - if (cal > 0) - RTC->CALR = RTC_CALR_CALP | (512 - cal); - else - RTC->CALR = -cal; + RTC->CALR = ((511 - cal) & (RTC_CALR_CALP | RTC_CALR_CALM)); } float rtc_get_cal(void) { diff --git a/main.c b/main.c index 67feddf..b5c1231 100644 --- a/main.c +++ b/main.c @@ -125,7 +125,7 @@ static uint16_t p_sweep = 0; float measured[2][SWEEP_POINTS_MAX][2]; #undef VERSION -#define VERSION "1.2.28" +#define VERSION "1.2.29" // Version text, displayed in Config->Version menu, also send by info command const char *info_about[]={ @@ -772,7 +772,7 @@ VNA_SHELL_FUNCTION(cmd_time) dt_buf[0] = rtc_get_tr_bcd(); // TR should be read first for sync dt_buf[1] = rtc_get_dr_bcd(); // DR should be read second static const uint8_t idx_to_time[] = {6,5,4,2, 1, 0}; - static const char time_cmd[] = "y|m|d|h|min|sec"; + static const char time_cmd[] = "y|m|d|h|min|sec|ppm"; // 0 1 2 4 5 6 // time[] ={sec, min, hr, 0, day, month, year, 0} uint8_t *time = (uint8_t*)dt_buf; @@ -782,6 +782,10 @@ VNA_SHELL_FUNCTION(cmd_time) } if (argc!=2) goto usage; int idx = get_str_index(argv[0], time_cmd); + if(idx == 6) { + rtc_set_cal(my_atof(argv[1])); + return; + } uint32_t val = my_atoui(argv[1]); if (idx < 0 || val > 99) goto usage; diff --git a/ui.c b/ui.c index 29e8ec7..662daab 100644 --- a/ui.c +++ b/ui.c @@ -2306,8 +2306,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_rtc_out_acb) } const menuitem_t menu_rtc_cal[] = { - { MT_ADV_CALLBACK, KM_RTC_CAL, "RTC CAL\n " R_LINK_COLOR "%b.4f " S_PPM, menu_keyboard_acb }, - { MT_ADV_CALLBACK, 0, "RTC OUT\n%s" , menu_rtc_out_acb }, + { MT_ADV_CALLBACK, KM_RTC_CAL, "RTC CAL\n" R_LINK_COLOR "%+b.4f" S_PPM, menu_keyboard_acb }, + { MT_ADV_CALLBACK, 0, "RTC OUT\n%s" , menu_rtc_out_acb }, { MT_NEXT, 0, NULL, menu_back } // next-> menu_back }; #endif