From 2c9f43c9ff46af72539564e448df1b65b123c939 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Dec 2019 00:09:57 -0500 Subject: [PATCH] Add safety disarm in the stack overflow hook and increase stack sizes --- Firmware/Board/v3/Src/freertos.c | 4 ++-- Firmware/MotorControl/axis.hpp | 2 +- Firmware/MotorControl/main.cpp | 4 ++++ Firmware/communication/communication.cpp | 2 +- Firmware/communication/interface_uart.cpp | 2 +- Firmware/communication/interface_usb.cpp | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Firmware/Board/v3/Src/freertos.c b/Firmware/Board/v3/Src/freertos.c index 42ff9751..b2d49e55 100644 --- a/Firmware/Board/v3/Src/freertos.c +++ b/Firmware/Board/v3/Src/freertos.c @@ -89,14 +89,14 @@ osSemaphoreId sem_usb_tx; osSemaphoreId sem_can; osThreadId usb_irq_thread; -const uint32_t stack_size_usb_irq_thread = 1024; // Bytes +const uint32_t stack_size_usb_irq_thread = 2048; // Bytes // Place FreeRTOS heap in core coupled memory for better performance __attribute__((section(".ccmram"))) uint8_t ucHeap[configTOTAL_HEAP_SIZE]; /* USER CODE END Variables */ osThreadId defaultTaskHandle; -const uint32_t stack_size_default_task = 1024; // Bytes +const uint32_t stack_size_default_task = 2048; // Bytes /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ diff --git a/Firmware/MotorControl/axis.hpp b/Firmware/MotorControl/axis.hpp index f9199d8b..a84e76af 100644 --- a/Firmware/MotorControl/axis.hpp +++ b/Firmware/MotorControl/axis.hpp @@ -244,7 +244,7 @@ class Axis { Endstop& max_endstop_; osThreadId thread_id_; - const uint32_t stack_size_ = 1024; // Bytes + const uint32_t stack_size_ = 2048; // Bytes volatile bool thread_id_valid_ = false; // variables exposed on protocol diff --git a/Firmware/MotorControl/main.cpp b/Firmware/MotorControl/main.cpp index 43c3e476..8650b006 100644 --- a/Firmware/MotorControl/main.cpp +++ b/Firmware/MotorControl/main.cpp @@ -182,6 +182,10 @@ extern "C" int construct_objects(){ extern "C" { int odrive_main(void); void vApplicationStackOverflowHook(xTaskHandle *pxTask, signed portCHAR *pcTaskName) { + for(auto& axis : axes){ + safety_critical_disarm_motor_pwm(axis->motor_); + } + safety_critical_disarm_brake_resistor(); for (;;); // TODO: safe action } void vApplicationIdleHook(void) { diff --git a/Firmware/communication/communication.cpp b/Firmware/communication/communication.cpp index 8a22508e..ac4714db 100644 --- a/Firmware/communication/communication.cpp +++ b/Firmware/communication/communication.cpp @@ -64,7 +64,7 @@ const uint8_t fw_version_revision = FW_VERSION_REVISION; const uint8_t fw_version_unreleased = FW_VERSION_UNRELEASED; // 0 for official releases, 1 otherwise osThreadId comm_thread; -const uint32_t stack_size_comm_thread = 2048; // Bytes +const uint32_t stack_size_comm_thread = 4096; // Bytes volatile bool endpoint_list_valid = false; static uint32_t test_property = 0; diff --git a/Firmware/communication/interface_uart.cpp b/Firmware/communication/interface_uart.cpp index dc8a4ce6..f1bb5e0d 100644 --- a/Firmware/communication/interface_uart.cpp +++ b/Firmware/communication/interface_uart.cpp @@ -22,7 +22,7 @@ static uint32_t dma_last_rcv_idx; // static thread_local uint32_t deadline_ms = 0; osThreadId uart_thread; -const uint32_t stack_size_uart_thread = 2048; // Bytes +const uint32_t stack_size_uart_thread = 4096; // Bytes class UART4Sender : public StreamSink { diff --git a/Firmware/communication/interface_usb.cpp b/Firmware/communication/interface_usb.cpp index 7f49c0b5..c52fe5ca 100644 --- a/Firmware/communication/interface_usb.cpp +++ b/Firmware/communication/interface_usb.cpp @@ -14,7 +14,7 @@ #include osThreadId usb_thread; -const uint32_t stack_size_usb_thread = 2048; // Bytes +const uint32_t stack_size_usb_thread = 4096; // Bytes USBStats_t usb_stats_ = {0}; class USBSender : public PacketSink {