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 18d76eee..50e72d00 100644 --- a/Firmware/MotorControl/axis.hpp +++ b/Firmware/MotorControl/axis.hpp @@ -234,7 +234,7 @@ public: 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/encoder.cpp b/Firmware/MotorControl/encoder.cpp index dbcbab4f..a226e905 100644 --- a/Firmware/MotorControl/encoder.cpp +++ b/Firmware/MotorControl/encoder.cpp @@ -328,11 +328,13 @@ bool Encoder::abs_spi_init(){ spi->Init.CLKPhase = SPI_PHASE_2EDGE; spi->Init.NSS = SPI_NSS_SOFT; spi->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; - spi->Init.FirstBit = SPI_FIRSTBIT_MSB; - spi->Init.TIMode = SPI_TIMODE_DISABLE; - spi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - spi->Init.CRCPolynomial = 10; - + spi->Init.FirstBit = SPI_FIRSTBIT_MSB; + spi->Init.TIMode = SPI_TIMODE_DISABLE; + spi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + spi->Init.CRCPolynomial = 10; + if (config_.mode == MODE_SPI_ABS_AEAT) { + spi->Init.CLKPolarity = SPI_POLARITY_HIGH; + } HAL_SPI_DeInit(spi); HAL_SPI_Init(spi); //stash our configuration @@ -374,16 +376,19 @@ void Encoder::abs_spi_cb(){ parity_calc = parity(abs_spi_dma_rx_[0]&0x7FFF); parity_bit = abs_spi_dma_rx_[0] >>15; - if(parity_calc == parity_bit){ - pos_abs_ = abs_spi_dma_rx_[0] & 0x3FFF; - // We are going to ignore values all high or low - // This might happen in normal operation, but its unlikely - // The filter will handle these cases - if(pos_abs_ != 0 && pos_abs_ != 0x3FFF) - abs_spi_pos_updated_ = true; - } - }break; - + if (parity_calc == parity_bit) { + pos_abs_ = abs_spi_dma_rx_[0] & 0x3FFF; + // We are going to ignore values all high or low + // This might happen in normal operation, but its unlikely + // The filter will handle these cases + if (pos_abs_ != 0 && pos_abs_ != 0x3FFF) + abs_spi_pos_updated_ = true; + } + } break; + case MODE_SPI_ABS_AEAT: { + pos_abs_ = abs_spi_dma_rx_[0]; + abs_spi_pos_updated_ = true; + } break; default: { set_error(ERROR_UNSUPPORTED_ENCODER_MODE); } break; @@ -448,8 +453,9 @@ bool Encoder::update() { } break; case MODE_SPI_ABS_AMS: - case MODE_SPI_ABS_CUI:{ - if (!abs_spi_pos_updated_ && abs_spi_pos_init_once_) { + case MODE_SPI_ABS_CUI: + case MODE_SPI_ABS_AEAT: { + if (abs_spi_pos_updated_ == false && abs_spi_pos_init_once_) { // Low pass filter the error spi_error_rate_ += current_meas_period * (1.0f - spi_error_rate_); if (spi_error_rate_ > 0.005f) diff --git a/Firmware/MotorControl/encoder.hpp b/Firmware/MotorControl/encoder.hpp index 58eea584..bcc11b40 100644 --- a/Firmware/MotorControl/encoder.hpp +++ b/Firmware/MotorControl/encoder.hpp @@ -26,6 +26,7 @@ public: MODE_SINCOS, MODE_SPI_ABS_CUI = 0x100, MODE_SPI_ABS_AMS = 0x101, + MODE_SPI_ABS_AEAT = 0x102, }; const uint32_t MODE_FLAG_ABS = 0x100; diff --git a/Firmware/MotorControl/main.cpp b/Firmware/MotorControl/main.cpp index 93af6cc4..d31bbd13 100644 --- a/Firmware/MotorControl/main.cpp +++ b/Firmware/MotorControl/main.cpp @@ -180,6 +180,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 9a436c1b..a5cd4bcb 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 { diff --git a/tools/odrive/enums.py b/tools/odrive/enums.py index f015cb60..4d401755 100644 --- a/tools/odrive/enums.py +++ b/tools/odrive/enums.py @@ -93,3 +93,4 @@ ENCODER_MODE_HALL = 0x01 ENCODER_MODE_SINCOS = 0x02 #ENCODER_MODE_SPI_ABS_CUI = 0x100 # currently not functional ENCODER_MODE_SPI_ABS_AMS = 0x101 +ENCODER_MODE_SPI_ABS_AEAT = 0x102 diff --git a/tools/odrive/utils.py b/tools/odrive/utils.py index 8cbb704a..2b2901a7 100755 --- a/tools/odrive/utils.py +++ b/tools/odrive/utils.py @@ -50,15 +50,15 @@ def dump_errors(odrv, clear=False): for name, remote_obj, errorcodes in module_decode_map: prefix = ' '*2 + name + ": " if (remote_obj.error != errorcodes.ERROR_NONE): + foundError = False print(prefix + _VT100Colors['red'] + "Error(s):" + _VT100Colors['default']) errorcodes_tup = [(name, val) for name, val in errorcodes.__dict__.items() if 'ERROR_' in name] for codename, codeval in errorcodes_tup: - if remote_obj.error: - print(" ", end='') - if codeval != 0: - print(codename) - else: - print("UNKNOWN_ERROR!") + if remote_obj.error & codeval != 0: + foundError = True + print(" " + codename) + if not foundError: + print(" " + 'UNKNOWN ERROR!') if clear: remote_obj.error = errorcodes.ERROR_NONE else: