Skip to content

Commit 98ccefd

Browse files
authored
Increase STM32 emulated EEPROM commit delay (ExpressLRS#1143)
* Extend commit pause by one more cycle -- At the current rate because that's the rate the timer is running at, not the new rate. -- ChangeRadioParams after commit since it changes the Radio.freq * Correct 50Hz 25Hz time on air to be accurate
1 parent a04791d commit 98ccefd

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/src/common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ expresslrs_mod_settings_s ExpressLRS_AirRateConfig[RATE_MAX] = {
1414
expresslrs_rf_pref_params_s ExpressLRS_AirRateRFperf[RATE_MAX] = {
1515
{0, RATE_200HZ, -112, 4380, 3000, 2500, 600, 5000},
1616
{1, RATE_100HZ, -117, 8770, 3500, 2500, 600, 5000},
17-
{2, RATE_50HZ, -120, 17540, 4000, 2500, 600, 5000},
18-
{3, RATE_25HZ, -123, 17540, 6000, 4000, 0, 5000}};
17+
{2, RATE_50HZ, -120, 18560, 4000, 2500, 600, 5000},
18+
{3, RATE_25HZ, -123, 29950, 6000, 4000, 0, 5000}};
1919
#endif
2020

2121
#if defined(Regulatory_Domain_ISM_2400)

src/src/tx_main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,11 @@ void ICACHE_RAM_ATTR ModelUpdateReq()
549549

550550
static void ConfigChangeCommit()
551551
{
552-
ChangeRadioParams();
553-
554-
// Write the uncommitted eeprom values
552+
// Write the uncommitted eeprom values (may block for a while)
555553
config.Commit();
556-
// Resume the timer, will take one hop for the radio to be on the right frequency
557-
// if we missed a hop
554+
// Change params after the blocking finishes as a rate change will change the radio freq
555+
ChangeRadioParams();
556+
// Resume the timer, will take one hop for the radio to be on the right frequency if we missed a hop
558557
hwTimer.callbackTock = &timerCallbackNormal;
559558
devicesTriggerEvent();
560559
}
@@ -575,10 +574,11 @@ static void CheckConfigChangePending()
575574
// The code expects to enter here shortly after the tock ISR has started sending the last
576575
// sync packet, before the tick ISR. Because the EEPROM write takes so long and disables
577576
// interrupts, FastForward the timer
578-
const uint32_t EEPROM_WRITE_DURATION = 30000; // us, ~27ms is where it starts getting off by one
579-
const uint32_t cycleInterval = get_elrs_airRateConfig(config.GetRate())->interval;
577+
const uint32_t EEPROM_WRITE_DURATION = 30000; // us, a page write on F103C8 takes ~29.3ms
578+
const uint32_t cycleInterval = ExpressLRS_currAirRate_Modparams->interval;
580579
// Total time needs to be at least DURATION, rounded up to next cycle
581-
uint32_t pauseCycles = (EEPROM_WRITE_DURATION + cycleInterval - 1) / cycleInterval;
580+
// adding one cycle that will be eaten by busywaiting for the transmit to end
581+
uint32_t pauseCycles = ((EEPROM_WRITE_DURATION + cycleInterval - 1) / cycleInterval) + 1;
582582
// Pause won't return until paused, and has just passed the tick ISR (but not fired)
583583
hwTimer.pause(pauseCycles * cycleInterval);
584584

0 commit comments

Comments
 (0)