Skip to content

Commit 36c9db6

Browse files
committed
Dual motor shutdown fix
1 parent c34856b commit 36c9db6

8 files changed

+58
-5
lines changed

comm_can.c

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static thread_t *process_tp = 0;
6868
static thread_t *ping_tp = 0;
6969
static volatile HW_TYPE ping_hw_last = HW_TYPE_VESC;
7070
static volatile int ping_hw_last_id = -1;
71+
static volatile bool init_done = false;
7172
#endif
7273

7374
// Variables
@@ -151,6 +152,8 @@ void comm_can_init(void) {
151152
NORMALPRIO, cancom_status_internal_thread, NULL);
152153
#endif
153154

155+
init_done = true;
156+
154157
#endif
155158
}
156159

@@ -186,6 +189,10 @@ void comm_can_set_baud(CAN_BAUD baud) {
186189
* on single motor hardware.
187190
*/
188191
void comm_can_transmit_eid_replace(uint32_t id, const uint8_t *data, uint8_t len, bool replace) {
192+
if (!init_done) {
193+
return;
194+
}
195+
189196
if (len > 8) {
190197
len = 8;
191198
}
@@ -228,6 +235,10 @@ void comm_can_transmit_eid(uint32_t id, const uint8_t *data, uint8_t len) {
228235
}
229236

230237
void comm_can_transmit_sid(uint32_t id, uint8_t *data, uint8_t len) {
238+
if (!init_done) {
239+
return;
240+
}
241+
231242
if (len > 8) {
232243
len = 8;
233244
}

conf_general.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define FW_VERSION_MAJOR 5
2525
#define FW_VERSION_MINOR 03
2626
// Set to 0 for building a release and iterate during beta test builds
27-
#define FW_TEST_VERSION_NUMBER 47
27+
#define FW_TEST_VERSION_NUMBER 48
2828

2929
#include "datatypes.h"
3030

@@ -351,4 +351,5 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
351351
int conf_general_detect_apply_all_foc_can(bool detect_can, float max_power_loss,
352352
float min_current_in, float max_current_in, float openloop_rpm, float sl_erpm);
353353

354+
354355
#endif /* CONF_GENERAL_H_ */

hwconf/hw_stormcore_100d.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mc_interface.h"
2424
#include "ledpwm.h"
2525
#include "utils.h"
26+
#include "main.h"
2627

2728
typedef enum {
2829
SWITCH_BOOTED = 0,
@@ -533,7 +534,9 @@ static THD_FUNCTION(smart_switch_thread, arg) {
533534
mc_interface_select_motor_thread(1);
534535
mc_interface_unlock();
535536
//Wait for other systems to boot up before proceeding
536-
chThdSleepMilliseconds(2000);
537+
while (!main_init_done()) {
538+
chThdSleepMilliseconds(200);
539+
}
537540
break;
538541
case SWITCH_HELD_AFTER_TURN_ON:
539542
if(smart_switch_is_pressed()){

hwconf/hw_stormcore_100s.c

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "ledpwm.h"
2525
#include "drv8323s.h"
2626

27-
2827
#if defined (HW_VER_IS_100S_V2)
2928
static THD_WORKING_AREA(switch_color_thread_wa, 128);
3029
static THD_FUNCTION(switch_color_thread, arg);

hwconf/hw_stormcore_60d.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mc_interface.h"
2424
#include "ledpwm.h"
2525
#include "utils.h"
26+
#include "main.h"
2627

2728
typedef enum {
2829
SWITCH_BOOTED = 0,
@@ -522,7 +523,9 @@ static THD_FUNCTION(smart_switch_thread, arg) {
522523
mc_interface_select_motor_thread(1);
523524
mc_interface_unlock();
524525
//Wait for other systems to boot up before proceeding
525-
chThdSleepMilliseconds(2000);
526+
while (!main_init_done()) {
527+
chThdSleepMilliseconds(200);
528+
}
526529
break;
527530
case SWITCH_HELD_AFTER_TURN_ON:
528531
if(smart_switch_is_pressed()){

hwconf/hw_unity.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mc_interface.h"
2424
#include "ledpwm.h"
2525
#include "utils.h"
26+
#include "main.h"
2627

2728
typedef enum {
2829
SWITCH_BOOTED = 0,
@@ -373,7 +374,9 @@ static THD_FUNCTION(smart_switch_thread, arg) {
373374
smart_switch_keep_on();
374375
ledpwm_set_intensity(LED_HW1, 1.0);
375376
//Wait for other systems to boot up before proceeding
376-
chThdSleepMilliseconds(3000);
377+
while (!main_init_done()) {
378+
chThdSleepMilliseconds(200);
379+
}
377380
break;
378381
case SWITCH_HELD_AFTER_TURN_ON:
379382
if(smart_switch_is_pressed()){

main.c

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "shutdown.h"
5555
#include "mempools.h"
5656
#include "events.h"
57+
#include "main.h"
5758

5859
/*
5960
* HW resources used:
@@ -77,6 +78,7 @@
7778
// Private variables
7879
static THD_WORKING_AREA(periodic_thread_wa, 1024);
7980
static THD_WORKING_AREA(flash_integrity_check_thread_wa, 256);
81+
static bool m_init_done = false;
8082

8183
static THD_FUNCTION(flash_integrity_check_thread, arg) {
8284
(void)arg;
@@ -186,6 +188,10 @@ void assert_failed(uint8_t* file, uint32_t line) {
186188
}
187189
}
188190

191+
bool main_init_done(void) {
192+
return m_init_done;
193+
}
194+
189195
int main(void) {
190196
halInit();
191197
chSysInit();
@@ -285,6 +291,8 @@ int main(void) {
285291
palSetPad(BOOT_OK_GPIO, BOOT_OK_PIN);
286292
#endif
287293

294+
m_init_done = true;
295+
288296
for(;;) {
289297
chThdSleepMilliseconds(10);
290298
}

main.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2021 Benjamin Vedder [email protected]
3+
4+
This file is part of the VESC firmware.
5+
6+
The VESC firmware is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
The VESC firmware is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef MAIN_H_
21+
#define MAIN_H_
22+
23+
bool main_init_done(void);
24+
25+
#endif /* MAIN_H_ */

0 commit comments

Comments
 (0)