Skip to content

Commit 2e0926e

Browse files
committed
fix analog thread stack overflow
1 parent e535ed6 commit 2e0926e

File tree

6 files changed

+16
-3
lines changed

6 files changed

+16
-3
lines changed

Firmware/MotorControl/low_level.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/* Global constant data ------------------------------------------------------*/
2626
constexpr float adc_full_scale = static_cast<float>(1UL << 12UL);
2727
constexpr float adc_ref_voltage = 3.3f;
28+
const uint32_t stack_size_analog_thread = 1024; // Bytes
2829
/* Global variables ----------------------------------------------------------*/
2930

3031
// This value is updated by the DC-bus reading ADC.
@@ -34,6 +35,7 @@ float ibus_ = 0.0f; // exposed for monitoring only
3435
bool brake_resistor_armed = false;
3536
bool brake_resistor_saturated = false;
3637
float brake_resistor_current = 0.0f;
38+
osThreadId analog_thread = 0;
3739
/* Private constant data -----------------------------------------------------*/
3840
/* CPU critical section helpers ----------------------------------------------*/
3941

@@ -404,6 +406,6 @@ static void analog_polling_thread(void *)
404406
}
405407

406408
void start_analog_thread() {
407-
osThreadDef(thread_def, analog_polling_thread, osPriorityLow, 0, 512 / sizeof(StackType_t));
408-
osThreadCreate(osThread(thread_def), NULL);
409+
osThreadDef(analog_thread_def, analog_polling_thread, osPriorityLow, 0, stack_size_analog_thread / sizeof(StackType_t));
410+
analog_thread = osThreadCreate(osThread(analog_thread_def), NULL);
409411
}

Firmware/MotorControl/low_level.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ extern bool brake_resistor_armed;
2323
extern bool brake_resistor_saturated;
2424
extern float brake_resistor_current;
2525
extern uint16_t adc_measurements_[ADC_CHANNEL_COUNT];
26+
extern osThreadId analog_thread;
27+
extern const uint32_t stack_size_analog_thread;
2628
/* Exported macro ------------------------------------------------------------*/
2729
/* Exported functions --------------------------------------------------------*/
2830

Firmware/MotorControl/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,21 @@ void vApplicationIdleHook(void) {
270270
odrv.system_stats_.max_stack_usage_uart = stack_size_uart_thread - uxTaskGetStackHighWaterMark(uart_thread) * sizeof(StackType_t);
271271
odrv.system_stats_.max_stack_usage_startup = stack_size_default_task - uxTaskGetStackHighWaterMark(defaultTaskHandle) * sizeof(StackType_t);
272272
odrv.system_stats_.max_stack_usage_can = odrv.can_.stack_size_ - uxTaskGetStackHighWaterMark(odrv.can_.thread_id_) * sizeof(StackType_t);
273+
odrv.system_stats_.max_stack_usage_analog = stack_size_analog_thread - uxTaskGetStackHighWaterMark(analog_thread) * sizeof(StackType_t);
273274

274275
odrv.system_stats_.stack_size_axis = axes[0].stack_size_;
275276
odrv.system_stats_.stack_size_usb = stack_size_usb_thread;
276277
odrv.system_stats_.stack_size_uart = stack_size_uart_thread;
277278
odrv.system_stats_.stack_size_startup = stack_size_default_task;
278279
odrv.system_stats_.stack_size_can = odrv.can_.stack_size_;
280+
odrv.system_stats_.stack_size_analog = stack_size_analog_thread;
279281

280282
odrv.system_stats_.prio_axis = osThreadGetPriority(axes[0].thread_id_);
281283
odrv.system_stats_.prio_usb = osThreadGetPriority(usb_thread);
282284
odrv.system_stats_.prio_uart = osThreadGetPriority(uart_thread);
283285
odrv.system_stats_.prio_startup = osThreadGetPriority(defaultTaskHandle);
284286
odrv.system_stats_.prio_can = osThreadGetPriority(odrv.can_.thread_id_);
287+
odrv.system_stats_.prio_analog = osThreadGetPriority(analog_thread);
285288

286289
status_led_controller.update();
287290
}

Firmware/MotorControl/odrive_main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,21 @@ typedef struct {
3333
uint32_t max_stack_usage_uart;
3434
uint32_t max_stack_usage_startup;
3535
uint32_t max_stack_usage_can;
36+
uint32_t max_stack_usage_analog;
3637

3738
uint32_t stack_size_axis;
3839
uint32_t stack_size_usb;
3940
uint32_t stack_size_uart;
4041
uint32_t stack_size_startup;
4142
uint32_t stack_size_can;
43+
uint32_t stack_size_analog;
4244

4345
int32_t prio_axis;
4446
int32_t prio_usb;
4547
int32_t prio_uart;
4648
int32_t prio_startup;
4749
int32_t prio_can;
50+
int32_t prio_analog;
4851

4952
USBStats_t& usb = usb_stats_;
5053
I2CStats_t& i2c = i2c_stats_;

Firmware/odrive-interface.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,19 @@ interfaces:
143143
max_stack_usage_uart: readonly uint32
144144
max_stack_usage_can: readonly uint32
145145
max_stack_usage_startup: readonly uint32
146+
max_stack_usage_analog: readonly uint32
146147
stack_size_axis: readonly uint32
147148
stack_size_usb: readonly uint32
148149
stack_size_uart: readonly uint32
149150
stack_size_startup: readonly uint32
150151
stack_size_can: readonly uint32
152+
stack_size_analog: readonly uint32
151153
prio_axis: readonly int32
152154
prio_usb: readonly int32
153155
prio_uart: readonly int32
154156
prio_startup: readonly int32
155157
prio_can: readonly int32
158+
prio_analog: readonly int32
156159
usb:
157160
c_is_class: False
158161
attributes:

tools/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
is_release = True
3939

4040
# Set to true to make an official post-release, rather than dev of new version
41-
is_post_release = True
41+
is_post_release = False
4242
post_rel_num = 0
4343

4444
# To test higher numbered releases, bump to the next rev

0 commit comments

Comments
 (0)