Skip to content

Commit

Permalink
fix analog thread stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelsadok committed Sep 3, 2021
1 parent e535ed6 commit 2e0926e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Firmware/MotorControl/low_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/* Global constant data ------------------------------------------------------*/
constexpr float adc_full_scale = static_cast<float>(1UL << 12UL);
constexpr float adc_ref_voltage = 3.3f;
const uint32_t stack_size_analog_thread = 1024; // Bytes
/* Global variables ----------------------------------------------------------*/

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

Expand Down Expand Up @@ -404,6 +406,6 @@ static void analog_polling_thread(void *)
}

void start_analog_thread() {
osThreadDef(thread_def, analog_polling_thread, osPriorityLow, 0, 512 / sizeof(StackType_t));
osThreadCreate(osThread(thread_def), NULL);
osThreadDef(analog_thread_def, analog_polling_thread, osPriorityLow, 0, stack_size_analog_thread / sizeof(StackType_t));
analog_thread = osThreadCreate(osThread(analog_thread_def), NULL);
}
2 changes: 2 additions & 0 deletions Firmware/MotorControl/low_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern bool brake_resistor_armed;
extern bool brake_resistor_saturated;
extern float brake_resistor_current;
extern uint16_t adc_measurements_[ADC_CHANNEL_COUNT];
extern osThreadId analog_thread;
extern const uint32_t stack_size_analog_thread;
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/

Expand Down
3 changes: 3 additions & 0 deletions Firmware/MotorControl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,21 @@ void vApplicationIdleHook(void) {
odrv.system_stats_.max_stack_usage_uart = stack_size_uart_thread - uxTaskGetStackHighWaterMark(uart_thread) * sizeof(StackType_t);
odrv.system_stats_.max_stack_usage_startup = stack_size_default_task - uxTaskGetStackHighWaterMark(defaultTaskHandle) * sizeof(StackType_t);
odrv.system_stats_.max_stack_usage_can = odrv.can_.stack_size_ - uxTaskGetStackHighWaterMark(odrv.can_.thread_id_) * sizeof(StackType_t);
odrv.system_stats_.max_stack_usage_analog = stack_size_analog_thread - uxTaskGetStackHighWaterMark(analog_thread) * sizeof(StackType_t);

odrv.system_stats_.stack_size_axis = axes[0].stack_size_;
odrv.system_stats_.stack_size_usb = stack_size_usb_thread;
odrv.system_stats_.stack_size_uart = stack_size_uart_thread;
odrv.system_stats_.stack_size_startup = stack_size_default_task;
odrv.system_stats_.stack_size_can = odrv.can_.stack_size_;
odrv.system_stats_.stack_size_analog = stack_size_analog_thread;

odrv.system_stats_.prio_axis = osThreadGetPriority(axes[0].thread_id_);
odrv.system_stats_.prio_usb = osThreadGetPriority(usb_thread);
odrv.system_stats_.prio_uart = osThreadGetPriority(uart_thread);
odrv.system_stats_.prio_startup = osThreadGetPriority(defaultTaskHandle);
odrv.system_stats_.prio_can = osThreadGetPriority(odrv.can_.thread_id_);
odrv.system_stats_.prio_analog = osThreadGetPriority(analog_thread);

status_led_controller.update();
}
Expand Down
3 changes: 3 additions & 0 deletions Firmware/MotorControl/odrive_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ typedef struct {
uint32_t max_stack_usage_uart;
uint32_t max_stack_usage_startup;
uint32_t max_stack_usage_can;
uint32_t max_stack_usage_analog;

uint32_t stack_size_axis;
uint32_t stack_size_usb;
uint32_t stack_size_uart;
uint32_t stack_size_startup;
uint32_t stack_size_can;
uint32_t stack_size_analog;

int32_t prio_axis;
int32_t prio_usb;
int32_t prio_uart;
int32_t prio_startup;
int32_t prio_can;
int32_t prio_analog;

USBStats_t& usb = usb_stats_;
I2CStats_t& i2c = i2c_stats_;
Expand Down
3 changes: 3 additions & 0 deletions Firmware/odrive-interface.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ interfaces:
max_stack_usage_uart: readonly uint32
max_stack_usage_can: readonly uint32
max_stack_usage_startup: readonly uint32
max_stack_usage_analog: readonly uint32
stack_size_axis: readonly uint32
stack_size_usb: readonly uint32
stack_size_uart: readonly uint32
stack_size_startup: readonly uint32
stack_size_can: readonly uint32
stack_size_analog: readonly uint32
prio_axis: readonly int32
prio_usb: readonly int32
prio_uart: readonly int32
prio_startup: readonly int32
prio_can: readonly int32
prio_analog: readonly int32
usb:
c_is_class: False
attributes:
Expand Down
2 changes: 1 addition & 1 deletion tools/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
is_release = True

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

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

0 comments on commit 2e0926e

Please sign in to comment.