@@ -26,8 +26,6 @@ uint32_t _reboot_cookie __attribute__ ((section (".noinit")));
26
26
extern char _estack; // provided by the linker script
27
27
28
28
29
- ODriveCAN::Config_t can_config;
30
- ODriveCAN *odCAN = nullptr ;
31
29
ODrive odrv{};
32
30
33
31
@@ -88,7 +86,7 @@ void StatusLedController::update() {
88
86
static bool config_read_all () {
89
87
bool success = board_read_config () &&
90
88
config_manager.read (&odrv.config_ ) &&
91
- config_manager.read (&can_config );
89
+ config_manager.read (&odrv. can_ . config_ );
92
90
for (size_t i = 0 ; (i < AXIS_COUNT) && success; ++i) {
93
91
success = config_manager.read (&encoders[i].config_ ) &&
94
92
config_manager.read (&axes[i].sensorless_estimator_ .config_ ) &&
@@ -108,7 +106,7 @@ static bool config_read_all() {
108
106
static bool config_write_all () {
109
107
bool success = board_write_config () &&
110
108
config_manager.write (&odrv.config_ ) &&
111
- config_manager.write (&can_config );
109
+ config_manager.write (&odrv. can_ . config_ );
112
110
for (size_t i = 0 ; (i < AXIS_COUNT) && success; ++i) {
113
111
success = config_manager.write (&encoders[i].config_ ) &&
114
112
config_manager.write (&axes[i].sensorless_estimator_ .config_ ) &&
@@ -127,7 +125,7 @@ static bool config_write_all() {
127
125
128
126
static void config_clear_all () {
129
127
odrv.config_ = {};
130
- can_config = {};
128
+ odrv. can_ . config_ = {};
131
129
for (size_t i = 0 ; i < AXIS_COUNT; ++i) {
132
130
encoders[i].config_ = {};
133
131
axes[i].sensorless_estimator_ .config_ = {};
@@ -145,7 +143,7 @@ static void config_clear_all() {
145
143
}
146
144
147
145
static bool config_apply_all () {
148
- bool success = true ;
146
+ bool success = odrv. can_ . apply_config () ;
149
147
for (size_t i = 0 ; (i < AXIS_COUNT) && success; ++i) {
150
148
success = encoders[i].apply_config (motors[i].config_ .motor_type )
151
149
&& axes[i].controller_ .apply_config ()
@@ -174,6 +172,12 @@ bool ODrive::save_configuration(void) {
174
172
&& config_manager.start_store (&config_size)
175
173
&& config_write_all ()
176
174
&& config_manager.finish_store ();
175
+
176
+ // FIXME: during save_configuration we might miss some interrupts
177
+ // because the CPU gets halted during a flash erase. Missing events
178
+ // (encoder updates, step/dir steps) is not good so to be sure we just
179
+ // reboot.
180
+ NVIC_SystemReset ();
177
181
}
178
182
179
183
return success;
@@ -265,24 +269,23 @@ void vApplicationIdleHook(void) {
265
269
odrv.system_stats_ .max_stack_usage_usb = stack_size_usb_thread - uxTaskGetStackHighWaterMark (usb_thread) * sizeof (StackType_t);
266
270
odrv.system_stats_ .max_stack_usage_uart = stack_size_uart_thread - uxTaskGetStackHighWaterMark (uart_thread) * sizeof (StackType_t);
267
271
odrv.system_stats_ .max_stack_usage_startup = stack_size_default_task - uxTaskGetStackHighWaterMark (defaultTaskHandle) * sizeof (StackType_t);
268
- odrv.system_stats_ .max_stack_usage_can = odCAN-> stack_size_ - uxTaskGetStackHighWaterMark (odCAN-> thread_id_ ) * sizeof (StackType_t);
272
+ odrv.system_stats_ .max_stack_usage_can = odrv. can_ . stack_size_ - uxTaskGetStackHighWaterMark (odrv. can_ . thread_id_ ) * sizeof (StackType_t);
269
273
270
274
odrv.system_stats_ .stack_size_axis = axes[0 ].stack_size_ ;
271
275
odrv.system_stats_ .stack_size_usb = stack_size_usb_thread;
272
276
odrv.system_stats_ .stack_size_uart = stack_size_uart_thread;
273
277
odrv.system_stats_ .stack_size_startup = stack_size_default_task;
274
- odrv.system_stats_ .stack_size_can = odCAN-> stack_size_ ;
278
+ odrv.system_stats_ .stack_size_can = odrv. can_ . stack_size_ ;
275
279
276
280
odrv.system_stats_ .prio_axis = osThreadGetPriority (axes[0 ].thread_id_ );
277
281
odrv.system_stats_ .prio_usb = osThreadGetPriority (usb_thread);
278
282
odrv.system_stats_ .prio_uart = osThreadGetPriority (uart_thread);
279
283
odrv.system_stats_ .prio_startup = osThreadGetPriority (defaultTaskHandle);
280
- odrv.system_stats_ .prio_can = osThreadGetPriority (odCAN-> thread_id_ );
284
+ odrv.system_stats_ .prio_can = osThreadGetPriority (odrv. can_ . thread_id_ );
281
285
282
286
status_led_controller.update ();
283
287
}
284
288
}
285
-
286
289
}
287
290
288
291
/* *
@@ -431,9 +434,6 @@ void ODrive::control_loop_cb(uint32_t timestamp) {
431
434
axis.max_endstop_ .update ();
432
435
}
433
436
434
- MEASURE_TIME (axis.task_times_ .can_heartbeat )
435
- odCAN->send_cyclic (axis);
436
-
437
437
MEASURE_TIME (axis.task_times_ .controller_update )
438
438
axis.controller_ .update (); // uses position and velocity from encoder
439
439
@@ -827,9 +827,6 @@ extern "C" int main(void) {
827
827
sem_can = osSemaphoreCreate (osSemaphore (sem_can), 1 );
828
828
osSemaphoreWait (sem_can, 0 );
829
829
830
- // Construct all objects.
831
- odCAN = new ODriveCAN (can_config, &hcan1);
832
-
833
830
// Create main thread
834
831
osThreadDef (defaultTask, rtos_main, osPriorityNormal, 0 , stack_size_default_task / sizeof (StackType_t));
835
832
defaultTaskHandle = osThreadCreate (osThread (defaultTask), NULL );
0 commit comments