Skip to content

Commit

Permalink
parameters: defer auto-saving to after disarming for flash-based params
Browse files Browse the repository at this point in the history
This is especially important for DShot, that does not update when the CPU
stalls.
  • Loading branch information
bkueng committed Oct 11, 2019
1 parent 6750012 commit 8210610
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/parameters/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ using namespace time_literals;
#if !defined(PARAM_NO_ORB)
# include "uORB/uORB.h"
# include "uORB/topics/parameter_update.h"
# include <uORB/topics/actuator_armed.h>
# include <uORB/Subscription.hpp>
#endif

#if defined(FLASH_BASED_PARAMS)
Expand Down Expand Up @@ -614,6 +616,21 @@ autosave_worker(void *arg)
{
bool disabled = false;

#if !defined(PARAM_NO_ORB)

if (!param_get_default_file()) {
// In case we save to FLASH, defer param writes until disarmed,
// as writing to FLASH can stall the entire CPU (in rare cases around 300ms on STM32F7)
uORB::SubscriptionData<actuator_armed_s> armed_sub{ORB_ID(actuator_armed)};

if (armed_sub.get().armed) {
work_queue(LPWORK, &autosave_work, (worker_t)&autosave_worker, nullptr, USEC2TICK(1_s));
return;
}
}

#endif

param_lock_writer();
last_autosave_timestamp = hrt_absolute_time();
autosave_scheduled = false;
Expand Down

0 comments on commit 8210610

Please sign in to comment.