From ad8c2a552ab5274669efca16497cb6b91e0a686f Mon Sep 17 00:00:00 2001 From: larsm Date: Sun, 22 Nov 2020 00:45:48 +0100 Subject: [PATCH 1/6] improved VARIANT_ADC documentation in config.h --- Inc/config.h | 35 +++++++++++++++++++++++------------ Src/util.c | 1 + 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Inc/config.h b/Inc/config.h index cfbf6c3..0ef5a3f 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -243,26 +243,37 @@ // ################################# VARIANT_ADC SETTINGS ############################ #ifdef VARIANT_ADC /* CONTROL VIA TWO POTENTIOMETERS - * ADC-calibration to cover the full poti-range: - * Connect potis to left sensor board cable (0 to 3.3V) (do NOT use the red 15V wire in the cable!). see . - * Turn the potis to minimum position, write value 1 to ADC1_MIN and value 2 to ADC2_MIN - * Turn the potis to maximum position, write value 1 to ADC1_MAX and value 2 to ADC2_MAX - * For middle resting potis: Let the potis in the middle resting position, write value 1 to ADC1_MID and value 2 to ADC2_MID - * Make, flash and test it. + * Connect potis to left sensor board cable (0 to 3.3V) (do NOT use the red 15V wire!) + * + * Auto-calibration of the ADC Limit to finds the Minimum, Maximum, and Middle for the ADC input + * Procedure: + * - press the power button for more than 5 sec and release after the beep sound + * - move the potentiometers freely to the min and max limits repeatedly + * - release potentiometers to the resting postion + * - press the power button to confirm or wait for the 20 sec timeout + * The Values will be saved to flash. Values are persistent if you flash with platformio. To erase them, make a full chip erase. + * + * After calibration you can optionally write the values to the following defines + * Procedure: + * - connect gnd, rx and tx of a usb-uart converter in 3.3V mode to the right sensor board cable (do NOT use the red 15V wire!) + * - readout values using a serial terminal in 38400 boud + * - turn the potis to minimum position, write value 1 to INPUT1_MIN and value 2 to INPUT2_MIN + * - turn the potis to maximum position, write value 1 to INPUT1_MAX and value 2 to INPUT2_MAX + * - for middle resting potis: Let the potis in the middle resting position, write value 1 to INPUT1_MID and value 2 to INPUT2_MID */ #define CONTROL_ADC // use ADC as input. disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2! #define ADC_PROTECT_TIMEOUT 100 // ADC Protection: number of wrong / missing input commands before safety state is taken #define ADC_PROTECT_THRESH 200 // ADC Protection threshold below/above the MIN/MAX ADC values #define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect - #define INPUT1_MIN 0 // min ADC1-value while poti at minimum-position (0 - 4095) - #define INPUT1_MID 0 // mid ADC1-value while poti at minimum-position (ADC1_MIN - ADC1_MAX) - #define INPUT1_MAX 4095 // max ADC1-value while poti at maximum-position (0 - 4095) + #define INPUT1_MIN 0 // min ADC1-value while poti at min-position (0 - 4095) + #define INPUT1_MID 0 // mid ADC1-value while poti at mid-position (INPUT1_MIN - INPUT1_MAX) + #define INPUT1_MAX 4095 // max ADC1-value while poti at max-position (0 - 4095) #define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) #define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect - #define INPUT2_MIN 0 // min ADC2-value while poti at minimum-position (0 - 4095) - #define INPUT2_MID 0 // mid ADC2-value while poti at minimum-position (ADC2_MIN - ADC2_MAX) - #define INPUT2_MAX 4095 // max ADC2-value while poti at maximum-position (0 - 4095) + #define INPUT2_MIN 0 // min ADC2-value while poti at min-position (0 - 4095) + #define INPUT2_MID 0 // mid ADC2-value while poti at mid-position (INPUT2_MIN - INPUT2_MAX) + #define INPUT2_MAX 4095 // max ADC2-value while poti at max-position (0 - 4095) #define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) // #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2! // #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3! diff --git a/Src/util.c b/Src/util.c index 26d8e35..f81eb14 100644 --- a/Src/util.c +++ b/Src/util.c @@ -491,6 +491,7 @@ int checkInputType(int16_t min, int16_t mid, int16_t max){ * - move the potentiometers freely to the min and max limits repeatedly * - release potentiometers to the resting postion * - press the power button to confirm or wait for the 20 sec timeout + * The Values will be saved to flash. Values are persistent if you flash with platformio. To erase them, make a full chip erase. */ void adcCalibLim(void) { if (speedAvgAbs > 5) { // do not enter this mode if motors are spinning From c57e1a0e4ed4a989f250480ef88aafa4702a5761 Mon Sep 17 00:00:00 2001 From: larsm Date: Sun, 22 Nov 2020 21:54:59 +0100 Subject: [PATCH 2/6] implemented write syscall for printf, added float-support for printf, serial tx does not need an interrupt anymore, replaced consoleLog and consoleScope with printf, changed debug output: every comment starts with "# " now, added lots of debug messages, added welcome message with gcc version and build date --- Inc/comms.h | 33 -------------------- Src/comms.c | 81 -------------------------------------------------- Src/main.c | 39 +++++++++++++++++------- Src/setup.c | 60 ++++++++++++++++++++++--------------- Src/syscalls.c | 36 ++++++++++++++++++++++ Src/util.c | 61 +++++++++++++++---------------------- platformio.ini | 10 +++++++ 7 files changed, 134 insertions(+), 186 deletions(-) delete mode 100644 Inc/comms.h delete mode 100644 Src/comms.c create mode 100644 Src/syscalls.c diff --git a/Inc/comms.h b/Inc/comms.h deleted file mode 100644 index 6bdb730..0000000 --- a/Inc/comms.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -* This file is part of the hoverboard-firmware-hack project. -* -* Copyright (C) 2017-2018 Rene Hopf -* Copyright (C) 2017-2018 Nico Stute -* Copyright (C) 2017-2018 Niklas Fauth -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -// Define to prevent recursive inclusion -#ifndef COMMS_H -#define COMMS_H - -#include "stm32f1xx_hal.h" - -void setScopeChannel(uint8_t ch, int16_t val); -void consoleScope(void); -void consoleLog(char *message); - -#endif - diff --git a/Src/comms.c b/Src/comms.c deleted file mode 100644 index 61ee47d..0000000 --- a/Src/comms.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include "stm32f1xx_hal.h" -#include "defines.h" -#include "setup.h" -#include "config.h" -#include "comms.h" - -extern UART_HandleTypeDef huart2; -extern UART_HandleTypeDef huart3; - -static volatile uint8_t uart_buf[100]; -static volatile int16_t ch_buf[8]; -//volatile char char_buf[300]; - -void setScopeChannel(uint8_t ch, int16_t val) { - ch_buf[ch] = val; -} - -void consoleScope(void) { - #if defined DEBUG_SERIAL_SERVOTERM && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) - uart_buf[0] = 0xff; - uart_buf[1] = CLAMP(ch_buf[0]+127, 0, 255); - uart_buf[2] = CLAMP(ch_buf[1]+127, 0, 255); - uart_buf[3] = CLAMP(ch_buf[2]+127, 0, 255); - uart_buf[4] = CLAMP(ch_buf[3]+127, 0, 255); - uart_buf[5] = CLAMP(ch_buf[4]+127, 0, 255); - uart_buf[6] = CLAMP(ch_buf[5]+127, 0, 255); - uart_buf[7] = CLAMP(ch_buf[6]+127, 0, 255); - uart_buf[8] = CLAMP(ch_buf[7]+127, 0, 255); - uart_buf[9] = '\n'; - - #ifdef DEBUG_SERIAL_USART2 - if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) { - HAL_UART_Transmit_DMA(&huart2, (uint8_t *)uart_buf, strLength); - } - #endif - #ifdef DEBUG_SERIAL_USART3 - if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) { - HAL_UART_Transmit_DMA(&huart3, (uint8_t *)uart_buf, strLength); - } - #endif - #endif - - #if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) - // memset((void *)(uintptr_t)uart_buf, 0, sizeof(uart_buf)); - int strLength; - strLength = sprintf((char *)(uintptr_t)uart_buf, - "1:%i 2:%i 3:%i 4:%i 5:%i 6:%i 7:%i 8:%i\r\n", - ch_buf[0], ch_buf[1], ch_buf[2], ch_buf[3], ch_buf[4], ch_buf[5], ch_buf[6], ch_buf[7]); - - #ifdef DEBUG_SERIAL_USART2 - if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) { - HAL_UART_Transmit_DMA(&huart2, (uint8_t *)uart_buf, strLength); - } - #endif - #ifdef DEBUG_SERIAL_USART3 - if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) { - HAL_UART_Transmit_DMA(&huart3, (uint8_t *)uart_buf, strLength); - } - #endif - #endif - - -} - -void consoleLog(char *message) -{ - #if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) - #ifdef DEBUG_SERIAL_USART2 - if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) { - HAL_UART_Transmit_DMA(&huart2, (uint8_t *)message, strlen((char *)(uintptr_t)message)); - } - #endif - #ifdef DEBUG_SERIAL_USART3 - if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) { - HAL_UART_Transmit_DMA(&huart3, (uint8_t *)message, strlen((char *)(uintptr_t)message)); - } - #endif - #endif -} diff --git a/Src/main.c b/Src/main.c index 90afd7e..408f709 100644 --- a/Src/main.c +++ b/Src/main.c @@ -26,7 +26,6 @@ #include "setup.h" #include "config.h" #include "util.h" -#include "comms.h" #include "BLDC_controller.h" /* BLDC's header file */ #include "rtwtypes.h" @@ -52,6 +51,8 @@ extern volatile adc_buf_t adc_buffer; extern UART_HandleTypeDef huart2; extern UART_HandleTypeDef huart3; +volatile uint8_t uart_buf[200]; + // Matlab defines - from auto-code generation //--------------- extern P rtP_Left; /* Block parameters (auto storage) */ @@ -191,6 +192,10 @@ int main(void) { poweronMelody(); HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET); + printf("\n# hoverboard-firmware-hack-FOC\n"); + printf("# GCC Version: %s\n",__VERSION__); + printf("# Build Date: %s\n\n",__DATE__); + int16_t speedL = 0, speedR = 0; int16_t lastSpeedL = 0, lastSpeedR = 0; @@ -212,7 +217,7 @@ int main(void) { shortBeep(4); HAL_Delay(100); steerFixdt = speedFixdt = 0; // reset filters enable = 1; // enable motors - consoleLog("-- Motors enabled --\r\n"); + printf("# -- Motors enabled --\n"); } // ####### VARIANT_HOVERCAR ####### @@ -410,15 +415,16 @@ int main(void) { // ####### DEBUG SERIAL OUT ####### #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms - setScopeChannel(0, (int16_t)input1); // 1: INPUT1 - setScopeChannel(1, (int16_t)input2); // 2: INPUT2 - setScopeChannel(2, (int16_t)speedR); // 3: output command: [-1000, 1000] - setScopeChannel(3, (int16_t)speedL); // 4: output command: [-1000, 1000] - setScopeChannel(4, (int16_t)adc_buffer.batt1); // 5: for battery voltage calibration - setScopeChannel(5, (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC)); // 6: for verifying battery voltage calibration - setScopeChannel(6, (int16_t)board_temp_adcFilt); // 7: for board temperature calibration - setScopeChannel(7, (int16_t)board_temp_deg_c); // 8: for verifying board temperature calibration - consoleScope(); + printf("1:%i 2:%i 3:%i 4:%i 5:%i 6:%i 7:%i 8:%i\r\n", + input1, // 1: INPUT1 + input2, // 2: INPUT2 + speedR, // 3: output command: [-1000, 1000] + speedL, // 4: output command: [-1000, 1000] + adc_buffer.batt1, // 5: for battery voltage calibration + batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC, // 6: for verifying battery voltage calibration + board_temp_adcFilt, // 7: for board temperature calibration + board_temp_deg_c); // 8: for verifying board temperature calibration + printf("# Battery empty: %4.2fV: power off\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); } #endif @@ -459,21 +465,31 @@ int main(void) { // ####### BEEP AND EMERGENCY POWEROFF ####### if ((TEMP_POWEROFF_ENABLE && board_temp_deg_c >= TEMP_POWEROFF && speedAvgAbs < 20) || (batVoltage < BAT_DEAD && speedAvgAbs < 20)) { // poweroff before mainboard burns OR low bat 3 + if (board_temp_deg_c >= TEMP_POWEROFF) printf("# Error: STM32 overtemp: %4.1f°C: power off\n", board_temp_deg_c / 10.0); + if (batVoltage < BAT_DEAD) printf("# Battery empty: %4.2fV: power off\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); poweroff(); } else if (rtY_Left.z_errCode || rtY_Right.z_errCode) { // disable motors and beep in case of Motor error - fast beep enable = 0; + if (rtY_Left.z_errCode) printf("# Warning: rtY_Left.z_errCode: %i\n", rtY_Left.z_errCode); + if (rtY_Right.z_errCode) printf("# Warning: rtY_Right.z_errCode: %i\n", rtY_Right.z_errCode); buzzerFreq = 8; buzzerPattern = 1; } else if (timeoutFlagADC || timeoutFlagSerial || timeoutCnt > TIMEOUT) { // beep in case of ADC timeout, Serial timeout or General timeout - fast beep + if (timeoutFlagADC) printf("# Warning: ADC timeout\n"); + if (timeoutFlagSerial) printf("# Warning: Serial timeout\n"); + if (timeoutCnt > TIMEOUT) printf("# Warning: General timeout\n"); buzzerFreq = 24; buzzerPattern = 1; } else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // beep if mainboard gets hot + printf("# Warning: STM32 is getting hot: %4.1f°C\n", board_temp_deg_c / 10.0); buzzerFreq = 4; buzzerPattern = 1; } else if (BAT_LVL1_ENABLE && batVoltage < BAT_LVL1) { // low bat 1: fast beep + printf("# Warning: Battery is getting empty 1: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); buzzerFreq = 5; buzzerPattern = 6; } else if (BAT_LVL2_ENABLE && batVoltage < BAT_LVL2) { // low bat 2: slow beep + printf("# Warning: Battery is getting empty 2: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); buzzerFreq = 5; buzzerPattern = 42; } else if (BEEPS_BACKWARD && ((speed < -50 && speedAvg < 0) || MultipleTapBrake.b_multipleTap)) { // backward beep @@ -494,6 +510,7 @@ int main(void) { inactivity_timeout_counter++; } if (inactivity_timeout_counter > (INACTIVITY_TIMEOUT * 60 * 1000) / (DELAY_IN_MAIN_LOOP + 1)) { // rest of main loop needs maybe 1ms + printf("# inactivity timeout: power off\n"); poweroff(); } diff --git a/Src/setup.c b/Src/setup.c index 435cd78..50b9ae8 100644 --- a/Src/setup.c +++ b/Src/setup.c @@ -89,11 +89,11 @@ void UART3_Init(void) /* DMA interrupt init */ /* DMA1_Channel2_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); + // HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); + // HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); /* DMA1_Channel3_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn); + // HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0); + // HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn); huart3.Instance = USART3; huart3.Init.BaudRate = USART3_BAUD; @@ -149,16 +149,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx); /* USART2_TX Init */ - hdma_usart2_tx.Instance = DMA1_Channel7; - hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; - hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE; - hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart2_tx.Init.Mode = DMA_NORMAL; - hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW; - HAL_DMA_Init(&hdma_usart2_tx); - __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); + // hdma_usart2_tx.Instance = DMA1_Channel7; + // hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; + // hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE; + // hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE; + // hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + // hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + // hdma_usart2_tx.Init.Mode = DMA_NORMAL; + // hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW; + // HAL_DMA_Init(&hdma_usart2_tx); + // __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); + USART2->CR3 |= USART_CR3_DMAT; // | USART_CR3_DMAR | USART_CR3_OVRDIS; + DMA1_Channel7->CCR = 0; + DMA1_Channel7->CPAR = (uint32_t) & (USART3->DR); + DMA1_Channel7->CNDTR = 0; + DMA1_Channel7->CCR = DMA_CCR_MINC | DMA_CCR_DIR; + DMA1->IFCR = DMA_IFCR_CTCIF2 | DMA_IFCR_CHTIF2 | DMA_IFCR_CGIF2; /* USART2 interrupt Init */ HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); @@ -204,16 +210,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart3_rx); /* USART3_TX Init */ - hdma_usart3_tx.Instance = DMA1_Channel2; - hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; - hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE; - hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart3_tx.Init.Mode = DMA_NORMAL; - hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW; - HAL_DMA_Init(&hdma_usart3_tx); - __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart3_tx); + // hdma_usart3_tx.Instance = DMA1_Channel2; + // hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; + // hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE; + // hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE; + // hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + // hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + // hdma_usart3_tx.Init.Mode = DMA_NORMAL; + // hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW; + // HAL_DMA_Init(&hdma_usart3_tx); + // __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart3_tx); + USART3->CR3 |= USART_CR3_DMAT; // | USART_CR3_DMAR | USART_CR3_OVRDIS; + DMA1_Channel2->CCR = 0; + DMA1_Channel2->CPAR = (uint32_t) & (USART3->DR); + DMA1_Channel2->CNDTR = 0; + DMA1_Channel2->CCR = DMA_CCR_MINC | DMA_CCR_DIR; + DMA1->IFCR = DMA_IFCR_CTCIF2 | DMA_IFCR_CHTIF2 | DMA_IFCR_CGIF2; /* USART3 interrupt Init */ HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); diff --git a/Src/syscalls.c b/Src/syscalls.c new file mode 100644 index 0000000..1fc22dd --- /dev/null +++ b/Src/syscalls.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include +#include +#include "stm32f1xx_hal.h" +#include "config.h" + +extern volatile uint8_t uart_buf[200]; + +/* +* printf sends its output to this function, this function sends it to the uart dma output buffer +*/ +__attribute__((__used__)) int _write(int fd, const char *ptr, int len){ + #if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) + #ifdef DEBUG_SERIAL_USART2 + while(DMA1_Channel7->CNDTR != 0); // wait + memcpy(uart_buf,ptr,len); // copy to buffer + DMA1_Channel7->CCR &= ~DMA_CCR_EN; + DMA1_Channel7->CNDTR = len; // set number of bytes to read + DMA1_Channel7->CMAR = (uint32_t)uart_buf; // set buffer to read from + DMA1_Channel7->CCR |= DMA_CCR_EN; + #endif + #ifdef DEBUG_SERIAL_USART3 + while(DMA1_Channel2->CNDTR != 0); // wait + memcpy(uart_buf,ptr,len); // copy to buffer + DMA1_Channel2->CCR &= ~DMA_CCR_EN; + DMA1_Channel2->CNDTR = len; // set number of bytes to read + DMA1_Channel2->CMAR = (uint32_t)uart_buf; // set buffer to read from + DMA1_Channel2->CCR |= DMA_CCR_EN; + #endif + #endif + return len; +} diff --git a/Src/util.c b/Src/util.c index f81eb14..4d689df 100644 --- a/Src/util.c +++ b/Src/util.c @@ -24,7 +24,6 @@ #include "defines.h" #include "setup.h" #include "config.h" -#include "comms.h" #include "eeprom.h" #include "util.h" #include "BLDC_controller.h" @@ -458,26 +457,26 @@ int checkInputType(int16_t min, int16_t mid, int16_t max){ HAL_Delay(10); if ((min / threshold) == (max / threshold) || (mid / threshold) == (max / threshold) || min > max || mid > max) { type = 0; - consoleLog("Input is ignored"); // (MIN and MAX) OR (MID and MAX) are close, disable input + printf("# Input is ignored"); // (MIN and MAX) OR (MID and MAX) are close, disable input } else { if ((min / threshold) == (mid / threshold)){ type = 1; - consoleLog("Input is a normal pot"); // MIN and MID are close, it's a normal pot + printf("# Input is a normal pot"); // MIN and MID are close, it's a normal pot } else { type = 2; - consoleLog("Input is a mid-resting pot"); // it's a mid resting pot + printf("# Input is a mid-resting pot"); // it's a mid resting pot } HAL_Delay(10); #ifdef CONTROL_ADC if ((min + INPUT_MARGIN - ADC_PROTECT_THRESH) > 0 && (max - INPUT_MARGIN + ADC_PROTECT_THRESH) < 4095) { - consoleLog(" and protected"); + printf(" and protected"); longBeep(2); // Indicate protection by a beep } #endif } HAL_Delay(10); - consoleLog("\n"); + printf("\n"); HAL_Delay(10); return type; @@ -499,7 +498,10 @@ void adcCalibLim(void) { } #if !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) - consoleLog("Input calibration started...\n"); + printf("# Input calibration started...\n"); + printf("# move the potentiometers freely to the min and max limits repeatedly\n"); + printf("# release potentiometers to the resting postion\n"); + printf("# press the power button to confirm or wait for the 20 sec timeout\n"); readInput(); // Inititalization: MIN = a high value, MAX = a low value @@ -533,10 +535,10 @@ void adcCalibLim(void) { INPUT1_MIN_CAL = INPUT1_MIN_temp + INPUT_MARGIN; INPUT1_MID_CAL = INPUT1_MID_temp; INPUT1_MAX_CAL = INPUT1_MAX_temp - INPUT_MARGIN; - consoleLog("Input1 OK\n"); HAL_Delay(10); + printf("# Input1 OK\n"); HAL_Delay(10); } else { INPUT1_TYP_CAL = 0; // Disable input - consoleLog("Input1 Fail\n"); HAL_Delay(10); + printf("# Input1 Fail\n"); HAL_Delay(10); } INPUT2_TYP_CAL = checkInputType(INPUT2_MIN_temp, INPUT2_MID_temp, INPUT2_MAX_temp); @@ -544,23 +546,14 @@ void adcCalibLim(void) { INPUT2_MIN_CAL = INPUT2_MIN_temp + INPUT_MARGIN; INPUT2_MID_CAL = INPUT2_MID_temp; INPUT2_MAX_CAL = INPUT2_MAX_temp - INPUT_MARGIN; - consoleLog("Input2 OK\n"); HAL_Delay(10); + printf("# Input2 OK\n"); HAL_Delay(10); } else { INPUT2_TYP_CAL = 0; // Disable input - consoleLog("Input2 Fail\n"); HAL_Delay(10); + printf("# Input2 Fail\n"); HAL_Delay(10); } - inp_cal_valid = 1; // Mark calibration to be saved in Flash at shutdown - consoleLog("Limits: "); HAL_Delay(10); - setScopeChannel(0, (int16_t)INPUT1_TYP_CAL); - setScopeChannel(1, (int16_t)INPUT1_MIN_CAL); - setScopeChannel(2, (int16_t)INPUT1_MID_CAL); - setScopeChannel(3, (int16_t)INPUT1_MAX_CAL); - setScopeChannel(4, (int16_t)INPUT2_TYP_CAL); - setScopeChannel(5, (int16_t)INPUT2_MIN_CAL); - setScopeChannel(6, (int16_t)INPUT2_MID_CAL); - setScopeChannel(7, (int16_t)INPUT2_MAX_CAL); - consoleScope(); + printf("# Limits: INPUT1_TYP_CAL:%i INPUT1_MIN_CAL:%i INPUT1_MID_CAL:%i INPUT1_MAX_CAL:%i INPUT2_TYP_CAL:%i INPUT2_MIN_CAL:%i INPUT2_MID_CAL:%i INPUT2_MAX_CAL:%i\n", + INPUT1_TYP_CAL, INPUT1_MIN_CAL, INPUT1_MID_CAL, INPUT1_MAX_CAL, INPUT2_TYP_CAL, INPUT2_MIN_CAL, INPUT2_MID_CAL, INPUT2_MAX_CAL); #endif } /* @@ -576,7 +569,9 @@ void updateCurSpdLim(void) { } #if !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) - consoleLog("Torque and Speed limits update started...\n"); + printf("# Torque and Speed limits update started...\n"); + printf("# move and hold the pots to a desired limit position for Current and Speed\n"); + printf("# press the power button to confirm or wait for the 10 sec timeout\n"); int32_t input1_fixdt = input1 << 16; int32_t input2_fixdt = input2 << 16; @@ -608,17 +603,9 @@ void updateCurSpdLim(void) { cur_spd_valid += 2; // Mark update to be saved in Flash at shutdown } - consoleLog("Limits: "); HAL_Delay(10); - setScopeChannel(0, (int16_t)cur_spd_valid); // 0 = No limit changed, 1 = Current limit changed, 2 = Speed limit changed, 3 = Both limits changed - setScopeChannel(1, (int16_t)input1_fixdt); - setScopeChannel(2, (int16_t)cur_factor); - setScopeChannel(3, (int16_t)rtP_Left.i_max); - setScopeChannel(4, (int16_t)0); - setScopeChannel(5, (int16_t)input2_fixdt); - setScopeChannel(6, (int16_t)spd_factor); - setScopeChannel(7, (int16_t)rtP_Left.n_max); - consoleScope(); - + // cur_spd_valid: 0 = No limit changed, 1 = Current limit changed, 2 = Speed limit changed, 3 = Both limits changed + printf("# Limits: cur_spd_valid:%i input1_fixdt:%li cur_factor:%i rtP_Left.i_max:%i input2_fixdt:%li spd_factor:%i rtP_Left.n_max:%i\n", + cur_spd_valid, input1_fixdt, cur_factor, rtP_Left.i_max, input2_fixdt, spd_factor, rtP_Left.n_max); #endif } @@ -752,8 +739,8 @@ void cruiseControl(uint8_t button) { void poweroff(void) { buzzerPattern = 0; enable = 0; - consoleLog("-- Motors disabled --\r\n"); - for (int i = 0; i < 8; i++) { + printf("# -- Motors disabled --\n"); + for (int i = 0; i < 8; i++) { buzzerFreq = (uint8_t)i; HAL_Delay(100); } @@ -1107,7 +1094,7 @@ void usart_process_debug(uint8_t *userCommand, uint32_t len) { for (; len > 0; len--, userCommand++) { if (*userCommand != '\n' && *userCommand != '\r') { // Do not accept 'new line' and 'carriage return' commands - consoleLog("-- Command received --\r\n"); + printf("# -- Command received --\n"); // handle_input(*userCommand); // -> Create this function to handle the user commands } } diff --git a/platformio.ini b/platformio.ini index 9926883..3e762e0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -37,6 +37,7 @@ monitor_speed = 38400 build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -60,6 +61,7 @@ monitor_speed = 38400 build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -79,6 +81,7 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -98,6 +101,7 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -117,6 +121,7 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -136,6 +141,7 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -159,6 +165,7 @@ monitor_speed = 38400 build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -182,6 +189,7 @@ monitor_speed = 38400 build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -201,6 +209,7 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm @@ -221,6 +230,7 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE + -Wl,-u,_printf_float ; enable float for printf -Wl,-T./STM32F103RCTx_FLASH.ld -Wl,-lc -Wl,-lm From 18ac2bc2241d13be52d6c5d4acb2c4c3416cf2f0 Mon Sep 17 00:00:00 2001 From: larsm Date: Fri, 27 Nov 2020 20:14:24 +0100 Subject: [PATCH 3/6] removed debug test code, lowered the error message print rate by 50 --- Src/main.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Src/main.c b/Src/main.c index 408f709..6d70ffd 100644 --- a/Src/main.c +++ b/Src/main.c @@ -424,7 +424,6 @@ int main(void) { batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC, // 6: for verifying battery voltage calibration board_temp_adcFilt, // 7: for board temperature calibration board_temp_deg_c); // 8: for verifying board temperature calibration - printf("# Battery empty: %4.2fV: power off\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); } #endif @@ -470,26 +469,26 @@ int main(void) { poweroff(); } else if (rtY_Left.z_errCode || rtY_Right.z_errCode) { // disable motors and beep in case of Motor error - fast beep enable = 0; - if (rtY_Left.z_errCode) printf("# Warning: rtY_Left.z_errCode: %i\n", rtY_Left.z_errCode); - if (rtY_Right.z_errCode) printf("# Warning: rtY_Right.z_errCode: %i\n", rtY_Right.z_errCode); + if (rtY_Left.z_errCode && main_loop_counter % 50 == 0) printf("# Warning: rtY_Left.z_errCode: %i\n", rtY_Left.z_errCode); + if (rtY_Right.z_errCode && main_loop_counter % 50 == 0) printf("# Warning: rtY_Right.z_errCode: %i\n", rtY_Right.z_errCode); buzzerFreq = 8; buzzerPattern = 1; } else if (timeoutFlagADC || timeoutFlagSerial || timeoutCnt > TIMEOUT) { // beep in case of ADC timeout, Serial timeout or General timeout - fast beep - if (timeoutFlagADC) printf("# Warning: ADC timeout\n"); - if (timeoutFlagSerial) printf("# Warning: Serial timeout\n"); - if (timeoutCnt > TIMEOUT) printf("# Warning: General timeout\n"); + if (timeoutFlagADC && main_loop_counter % 50 == 0) printf("# Warning: ADC timeout\n"); + if (timeoutFlagSerial && main_loop_counter % 50 == 0) printf("# Warning: Serial timeout\n"); + if (timeoutCnt > TIMEOUT && main_loop_counter % 50 == 0) printf("# Warning: General timeout\n"); buzzerFreq = 24; buzzerPattern = 1; } else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // beep if mainboard gets hot - printf("# Warning: STM32 is getting hot: %4.1f°C\n", board_temp_deg_c / 10.0); + if (main_loop_counter % 50 == 0) printf("# Warning: STM32 is getting hot: %4.1f°C\n", board_temp_deg_c / 10.0); buzzerFreq = 4; buzzerPattern = 1; } else if (BAT_LVL1_ENABLE && batVoltage < BAT_LVL1) { // low bat 1: fast beep - printf("# Warning: Battery is getting empty 1: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); + if (main_loop_counter % 50 == 0) printf("# Warning: Battery is getting empty 1: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); buzzerFreq = 5; buzzerPattern = 6; } else if (BAT_LVL2_ENABLE && batVoltage < BAT_LVL2) { // low bat 2: slow beep - printf("# Warning: Battery is getting empty 2: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); + if (main_loop_counter % 50 == 0) printf("# Warning: Battery is getting empty 2: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); buzzerFreq = 5; buzzerPattern = 42; } else if (BEEPS_BACKWARD && ((speed < -50 && speedAvg < 0) || MultipleTapBrake.b_multipleTap)) { // backward beep From d1286e246b3554dcebf023f5a6ea3a8d814584da Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Wed, 9 Dec 2020 20:35:26 +0100 Subject: [PATCH 4/6] Fixed printf - works with default UART settings - still some clean up to do --- Inc/comms.h | 33 +++++++++++++++ Inc/config.h | 3 +- Inc/defines.h | 4 ++ Src/comms.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ Src/main.c | 31 ++++++--------- Src/setup.c | 60 +++++++++++----------------- Src/syscalls.c | 36 ----------------- Src/util.c | 30 +++++++------- 8 files changed, 198 insertions(+), 105 deletions(-) create mode 100644 Inc/comms.h create mode 100644 Src/comms.c delete mode 100644 Src/syscalls.c diff --git a/Inc/comms.h b/Inc/comms.h new file mode 100644 index 0000000..6bdb730 --- /dev/null +++ b/Inc/comms.h @@ -0,0 +1,33 @@ +/* +* This file is part of the hoverboard-firmware-hack project. +* +* Copyright (C) 2017-2018 Rene Hopf +* Copyright (C) 2017-2018 Nico Stute +* Copyright (C) 2017-2018 Niklas Fauth +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +// Define to prevent recursive inclusion +#ifndef COMMS_H +#define COMMS_H + +#include "stm32f1xx_hal.h" + +void setScopeChannel(uint8_t ch, int16_t val); +void consoleScope(void); +void consoleLog(char *message); + +#endif + diff --git a/Inc/config.h b/Inc/config.h index 164271b..5d064da 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -34,6 +34,7 @@ #endif #define TIMEOUT 20 // number of wrong / missing input commands before emergency off #define A2BIT_CONV 50 // A to bit for current conversion on ADC. Example: 1 A = 50, 2 A = 100, etc +// #define PRINTF_FLOAT_SUPPORT // [-] Uncomment this for printf to support float on Serial Debug. It will increase code size! Better to avoid it! // ADC conversion time definitions #define ADC_CONV_TIME_1C5 (14) //Total ADC clock cycles / conversion = ( 1.5+12.5) @@ -256,7 +257,7 @@ * After calibration you can optionally write the values to the following defines * Procedure: * - connect gnd, rx and tx of a usb-uart converter in 3.3V mode to the right sensor board cable (do NOT use the red 15V wire!) - * - readout values using a serial terminal in 38400 boud + * - readout values using a serial terminal in 115200 baud rate * - turn the potis to minimum position, write value 1 to INPUT1_MIN and value 2 to INPUT2_MIN * - turn the potis to maximum position, write value 1 to INPUT1_MAX and value 2 to INPUT2_MAX * - for middle resting potis: Let the potis in the middle resting position, write value 1 to INPUT1_MID and value 2 to INPUT2_MID diff --git a/Inc/defines.h b/Inc/defines.h index 245b1e3..6f0892d 100644 --- a/Inc/defines.h +++ b/Inc/defines.h @@ -183,6 +183,10 @@ #define ARRAY_LEN(x) (uint32_t)(sizeof(x) / sizeof(*(x))) #define MAP(x, in_min, in_max, out_min, out_max) (((((x) - (in_min)) * ((out_max) - (out_min))) / ((in_max) - (in_min))) + (out_min)) +#if defined(PRINTF_FLOAT_SUPPORT) && (defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)) && defined(__GNUC__) + asm(".global _printf_float"); // this is the magic trick for printf to support float. Warning: It will increase code considerably! Better to avoid! +#endif + typedef struct { uint16_t dcr; diff --git a/Src/comms.c b/Src/comms.c new file mode 100644 index 0000000..5b88112 --- /dev/null +++ b/Src/comms.c @@ -0,0 +1,106 @@ +#include +#include +#include "stm32f1xx_hal.h" +#include "defines.h" +#include "setup.h" +#include "config.h" +#include "comms.h" + +extern UART_HandleTypeDef huart2; +extern UART_HandleTypeDef huart3; + +static volatile uint8_t uart_buf[100]; +static volatile int16_t ch_buf[8]; +//volatile char char_buf[300]; + +/* retarget the C library printf function to the USART */ +#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + #ifdef __GNUC__ + #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) + #else + #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) + #endif + PUTCHAR_PROTOTYPE { + #if defined(DEBUG_SERIAL_USART2) + HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 1000); + #elif defined(DEBUG_SERIAL_USART3) + HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 1000); + #endif + return ch; + } + + #ifdef __GNUC__ + int _write(int file, char *data, int len) { + int i; + for (i = 0; i < len; i++) { __io_putchar( *data++ );} + return len; + } + #endif +#endif + +void setScopeChannel(uint8_t ch, int16_t val) { + ch_buf[ch] = val; +} + +void consoleScope(void) { + #if defined DEBUG_SERIAL_SERVOTERM && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) + uart_buf[0] = 0xff; + uart_buf[1] = CLAMP(ch_buf[0]+127, 0, 255); + uart_buf[2] = CLAMP(ch_buf[1]+127, 0, 255); + uart_buf[3] = CLAMP(ch_buf[2]+127, 0, 255); + uart_buf[4] = CLAMP(ch_buf[3]+127, 0, 255); + uart_buf[5] = CLAMP(ch_buf[4]+127, 0, 255); + uart_buf[6] = CLAMP(ch_buf[5]+127, 0, 255); + uart_buf[7] = CLAMP(ch_buf[6]+127, 0, 255); + uart_buf[8] = CLAMP(ch_buf[7]+127, 0, 255); + uart_buf[9] = '\n'; + + #ifdef DEBUG_SERIAL_USART2 + if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) { + HAL_UART_Transmit_DMA(&huart2, (uint8_t *)uart_buf, strLength); + } + #endif + #ifdef DEBUG_SERIAL_USART3 + if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) { + HAL_UART_Transmit_DMA(&huart3, (uint8_t *)uart_buf, strLength); + } + #endif + #endif + + #if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) + // memset((void *)(uintptr_t)uart_buf, 0, sizeof(uart_buf)); + int strLength; + strLength = sprintf((char *)(uintptr_t)uart_buf, + "1:%i 2:%i 3:%i 4:%i 5:%i 6:%i 7:%i 8:%i\r\n", + ch_buf[0], ch_buf[1], ch_buf[2], ch_buf[3], ch_buf[4], ch_buf[5], ch_buf[6], ch_buf[7]); + + #ifdef DEBUG_SERIAL_USART2 + if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) { + HAL_UART_Transmit_DMA(&huart2, (uint8_t *)uart_buf, strLength); + } + #endif + #ifdef DEBUG_SERIAL_USART3 + if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) { + HAL_UART_Transmit_DMA(&huart3, (uint8_t *)uart_buf, strLength); + } + #endif + #endif + + +} + +void consoleLog(char *message) +{ + #if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) + #ifdef DEBUG_SERIAL_USART2 + if(__HAL_DMA_GET_COUNTER(huart2.hdmatx) == 0) { + HAL_UART_Transmit_DMA(&huart2, (uint8_t *)message, strlen((char *)(uintptr_t)message)); + } + #endif + #ifdef DEBUG_SERIAL_USART3 + if(__HAL_DMA_GET_COUNTER(huart3.hdmatx) == 0) { + HAL_UART_Transmit_DMA(&huart3, (uint8_t *)message, strlen((char *)(uintptr_t)message)); + } + #endif + #endif +} diff --git a/Src/main.c b/Src/main.c index 2cb917d..d042838 100644 --- a/Src/main.c +++ b/Src/main.c @@ -20,12 +20,14 @@ * along with this program. If not, see . */ +#include #include // for abs() #include "stm32f1xx_hal.h" #include "defines.h" #include "setup.h" #include "config.h" #include "util.h" +#include "comms.h" #include "BLDC_controller.h" /* BLDC's header file */ #include "rtwtypes.h" @@ -189,10 +191,6 @@ int main(void) { poweronMelody(); HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET); - printf("\n# hoverboard-firmware-hack-FOC\n"); - printf("# GCC Version: %s\n",__VERSION__); - printf("# Build Date: %s\n\n",__DATE__); - int16_t speedL = 0, speedR = 0; int16_t lastSpeedL = 0, lastSpeedR = 0; @@ -214,7 +212,7 @@ int main(void) { beepShort(4); HAL_Delay(100); steerFixdt = speedFixdt = 0; // reset filters enable = 1; // enable motors - printf("# -- Motors enabled --\n"); + printf("-- Motors enabled --\r\n"); } // ####### VARIANT_HOVERCAR ####### @@ -412,11 +410,11 @@ int main(void) { // ####### DEBUG SERIAL OUT ####### #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms - printf("1:%i 2:%i 3:%i 4:%i 5:%i 6:%i 7:%i 8:%i\r\n", + printf("in1:%i in2:%i spdL:%i spdR:%i adcBat:%i BatV:%i adcTemp:%i Temp:%i\r\n", input1, // 1: INPUT1 input2, // 2: INPUT2 - speedR, // 3: output command: [-1000, 1000] - speedL, // 4: output command: [-1000, 1000] + speedL, // 3: output command: [-1000, 1000] + speedR, // 4: output command: [-1000, 1000] adc_buffer.batt1, // 5: for battery voltage calibration batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC, // 6: for verifying battery voltage calibration board_temp_adcFilt, // 7: for board temperature calibration @@ -461,31 +459,29 @@ int main(void) { // ####### BEEP AND EMERGENCY POWEROFF ####### if ((TEMP_POWEROFF_ENABLE && board_temp_deg_c >= TEMP_POWEROFF && speedAvgAbs < 20) || (batVoltage < BAT_DEAD && speedAvgAbs < 20)) { // poweroff before mainboard burns OR low bat 3 - if (board_temp_deg_c >= TEMP_POWEROFF) printf("# Error: STM32 overtemp: %4.1f°C: power off\n", board_temp_deg_c / 10.0); - if (batVoltage < BAT_DEAD) printf("# Battery empty: %4.2fV: power off\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); poweroff(); } else if (rtY_Left.z_errCode || rtY_Right.z_errCode) { // 1 beep (low pitch): Motor error, disable motors enable = 0; beepCount(1, 24, 1); - printf("# Warning: Left_err: %i Right_err: %i\n", rtY_Left.z_errCode); + printf("#ErrL: %i ErrR: %i\r\n", rtY_Left.z_errCode, rtY_Right.z_errCode); } else if (timeoutFlagADC) { // 2 beeps (low pitch): ADC timeout beepCount(2, 24, 1); - printf("# Warning: ADC timeout\n"); + printf("#ADC timeout\r\n"); } else if (timeoutFlagSerial) { // 3 beeps (low pitch): Serial timeout beepCount(3, 24, 1); - printf("# Warning: Serial timeout\n"); + printf("#Serial timeout\r\n"); } else if (timeoutCnt > TIMEOUT) { // 4 beeps (low pitch): General timeout (PPM, PWM, Nunchuck) beepCount(4, 24, 1); - printf("# Warning: General timeout\n"); + printf("#General timeout\r\n"); } else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // 5 beeps (low pitch): Mainboard temperature warning beepCount(5, 24, 1); - printf("# Warning: STM32 is getting hot: %4.1f°C\n", board_temp_deg_c / 10.0); + printf("#STM32 hot: %i\r\n", board_temp_deg_c); } else if (BAT_LVL1_ENABLE && batVoltage < BAT_LVL1) { // 1 beep fast (medium pitch): Low bat 1 beepCount(0, 10, 6); - printf("# Warning: Battery is getting empty 1: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); + printf("#Battery empty: %i\r\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC); } else if (BAT_LVL2_ENABLE && batVoltage < BAT_LVL2) { // 1 beep slow (medium pitch): Low bat 2 beepCount(0, 10, 30); - printf("# Warning: Battery is getting empty 2: %4.2fV\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC / 100.0); + printf("#Battery empty: %i\r\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC); } else if (BEEPS_BACKWARD && ((speed < -50 && speedAvg < 0) || MultipleTapBrake.b_multipleTap)) { // 1 beep fast (high pitch): Backward spinning motors beepCount(0, 5, 1); backwardDrive = 1; @@ -502,7 +498,6 @@ int main(void) { inactivity_timeout_counter++; } if (inactivity_timeout_counter > (INACTIVITY_TIMEOUT * 60 * 1000) / (DELAY_IN_MAIN_LOOP + 1)) { // rest of main loop needs maybe 1ms - printf("# inactivity timeout: power off\n"); poweroff(); } diff --git a/Src/setup.c b/Src/setup.c index 50b9ae8..435cd78 100644 --- a/Src/setup.c +++ b/Src/setup.c @@ -89,11 +89,11 @@ void UART3_Init(void) /* DMA interrupt init */ /* DMA1_Channel2_IRQn interrupt configuration */ - // HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); - // HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); + HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); /* DMA1_Channel3_IRQn interrupt configuration */ - // HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0); - // HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn); + HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn); huart3.Instance = USART3; huart3.Init.BaudRate = USART3_BAUD; @@ -149,22 +149,16 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx); /* USART2_TX Init */ - // hdma_usart2_tx.Instance = DMA1_Channel7; - // hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; - // hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE; - // hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE; - // hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - // hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - // hdma_usart2_tx.Init.Mode = DMA_NORMAL; - // hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW; - // HAL_DMA_Init(&hdma_usart2_tx); - // __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); - USART2->CR3 |= USART_CR3_DMAT; // | USART_CR3_DMAR | USART_CR3_OVRDIS; - DMA1_Channel7->CCR = 0; - DMA1_Channel7->CPAR = (uint32_t) & (USART3->DR); - DMA1_Channel7->CNDTR = 0; - DMA1_Channel7->CCR = DMA_CCR_MINC | DMA_CCR_DIR; - DMA1->IFCR = DMA_IFCR_CTCIF2 | DMA_IFCR_CHTIF2 | DMA_IFCR_CGIF2; + hdma_usart2_tx.Instance = DMA1_Channel7; + hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE; + hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_usart2_tx.Init.Mode = DMA_NORMAL; + hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW; + HAL_DMA_Init(&hdma_usart2_tx); + __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); /* USART2 interrupt Init */ HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); @@ -210,22 +204,16 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart3_rx); /* USART3_TX Init */ - // hdma_usart3_tx.Instance = DMA1_Channel2; - // hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; - // hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE; - // hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE; - // hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - // hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - // hdma_usart3_tx.Init.Mode = DMA_NORMAL; - // hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW; - // HAL_DMA_Init(&hdma_usart3_tx); - // __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart3_tx); - USART3->CR3 |= USART_CR3_DMAT; // | USART_CR3_DMAR | USART_CR3_OVRDIS; - DMA1_Channel2->CCR = 0; - DMA1_Channel2->CPAR = (uint32_t) & (USART3->DR); - DMA1_Channel2->CNDTR = 0; - DMA1_Channel2->CCR = DMA_CCR_MINC | DMA_CCR_DIR; - DMA1->IFCR = DMA_IFCR_CTCIF2 | DMA_IFCR_CHTIF2 | DMA_IFCR_CGIF2; + hdma_usart3_tx.Instance = DMA1_Channel2; + hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE; + hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_usart3_tx.Init.Mode = DMA_NORMAL; + hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW; + HAL_DMA_Init(&hdma_usart3_tx); + __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart3_tx); /* USART3 interrupt Init */ HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); diff --git a/Src/syscalls.c b/Src/syscalls.c deleted file mode 100644 index 1fc22dd..0000000 --- a/Src/syscalls.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "stm32f1xx_hal.h" -#include "config.h" - -extern volatile uint8_t uart_buf[200]; - -/* -* printf sends its output to this function, this function sends it to the uart dma output buffer -*/ -__attribute__((__used__)) int _write(int fd, const char *ptr, int len){ - #if defined DEBUG_SERIAL_ASCII && (defined DEBUG_SERIAL_USART2 || defined DEBUG_SERIAL_USART3) - #ifdef DEBUG_SERIAL_USART2 - while(DMA1_Channel7->CNDTR != 0); // wait - memcpy(uart_buf,ptr,len); // copy to buffer - DMA1_Channel7->CCR &= ~DMA_CCR_EN; - DMA1_Channel7->CNDTR = len; // set number of bytes to read - DMA1_Channel7->CMAR = (uint32_t)uart_buf; // set buffer to read from - DMA1_Channel7->CCR |= DMA_CCR_EN; - #endif - #ifdef DEBUG_SERIAL_USART3 - while(DMA1_Channel2->CNDTR != 0); // wait - memcpy(uart_buf,ptr,len); // copy to buffer - DMA1_Channel2->CCR &= ~DMA_CCR_EN; - DMA1_Channel2->CNDTR = len; // set number of bytes to read - DMA1_Channel2->CMAR = (uint32_t)uart_buf; // set buffer to read from - DMA1_Channel2->CCR |= DMA_CCR_EN; - #endif - #endif - return len; -} diff --git a/Src/util.c b/Src/util.c index 23f624e..e115453 100644 --- a/Src/util.c +++ b/Src/util.c @@ -18,6 +18,7 @@ */ // Includes +#include #include // for abs() #include #include "stm32f1xx_hal.h" @@ -467,14 +468,14 @@ int checkInputType(int16_t min, int16_t mid, int16_t max){ HAL_Delay(10); if ((min / threshold) == (max / threshold) || (mid / threshold) == (max / threshold) || min > max || mid > max) { type = 0; - printf("# Input is ignored"); // (MIN and MAX) OR (MID and MAX) are close, disable input + printf("Input is ignored"); // (MIN and MAX) OR (MID and MAX) are close, disable input } else { if ((min / threshold) == (mid / threshold)){ type = 1; - printf("# Input is a normal pot"); // MIN and MID are close, it's a normal pot + printf("Input is a normal pot"); // MIN and MID are close, it's a normal pot } else { type = 2; - printf("# Input is a mid-resting pot"); // it's a mid resting pot + printf("Input is a mid-resting pot"); // it's a mid resting pot } HAL_Delay(10); #ifdef CONTROL_ADC @@ -486,7 +487,7 @@ int checkInputType(int16_t min, int16_t mid, int16_t max){ } HAL_Delay(10); - printf("\n"); + printf("\r\n"); HAL_Delay(10); return type; @@ -542,10 +543,10 @@ void adcCalibLim(void) { INPUT1_MIN_CAL = INPUT1_MIN_temp + INPUT_MARGIN; INPUT1_MID_CAL = INPUT1_MID_temp; INPUT1_MAX_CAL = INPUT1_MAX_temp - INPUT_MARGIN; - printf("# Input1 OK\r\n"); HAL_Delay(10); + printf("Input1 OK\r\n"); HAL_Delay(10); } else { INPUT1_TYP_CAL = 0; // Disable input - printf("# Input1 Fail\r\n"); HAL_Delay(10); + printf("Input1 Fail\r\n"); HAL_Delay(10); } INPUT2_TYP_CAL = checkInputType(INPUT2_MIN_temp, INPUT2_MID_temp, INPUT2_MAX_temp); @@ -553,14 +554,15 @@ void adcCalibLim(void) { INPUT2_MIN_CAL = INPUT2_MIN_temp + INPUT_MARGIN; INPUT2_MID_CAL = INPUT2_MID_temp; INPUT2_MAX_CAL = INPUT2_MAX_temp - INPUT_MARGIN; - printf("# Input2 OK\r\n"); HAL_Delay(10); + printf("Input2 OK\r\n"); HAL_Delay(10); } else { INPUT2_TYP_CAL = 0; // Disable input - printf("# Input2 Fail\r\n"); HAL_Delay(10); + printf("Input2 Fail\r\n"); HAL_Delay(10); } inp_cal_valid = 1; // Mark calibration to be saved in Flash at shutdown - printf("# Limits: INPUT1_TYP_CAL:%i INPUT1_MIN_CAL:%i INPUT1_MID_CAL:%i INPUT1_MAX_CAL:%i INPUT2_TYP_CAL:%i INPUT2_MIN_CAL:%i INPUT2_MID_CAL:%i INPUT2_MAX_CAL:%i\n", - INPUT1_TYP_CAL, INPUT1_MIN_CAL, INPUT1_MID_CAL, INPUT1_MAX_CAL, INPUT2_TYP_CAL, INPUT2_MIN_CAL, INPUT2_MID_CAL, INPUT2_MAX_CAL); + printf("Limits Input1: TYP:%i MIN:%i MID:%i MAX:%i\r\nLimits Input2: TYP:%i MIN:%i MID:%i MAX:%i\r\n", + INPUT1_TYP_CAL, INPUT1_MIN_CAL, INPUT1_MID_CAL, INPUT1_MAX_CAL, + INPUT2_TYP_CAL, INPUT2_MIN_CAL, INPUT2_MID_CAL, INPUT2_MAX_CAL); #endif } /* @@ -607,10 +609,10 @@ void updateCurSpdLim(void) { rtP_Left.n_max = rtP_Right.n_max = (int16_t)((N_MOT_MAX * spd_factor) >> 12); // fixdt(0,16,16) to fixdt(1,16,4) cur_spd_valid += 2; // Mark update to be saved in Flash at shutdown } - + // cur_spd_valid: 0 = No limit changed, 1 = Current limit changed, 2 = Speed limit changed, 3 = Both limits changed - printf("# Limits: cur_spd_valid:%i input1_fixdt:%li cur_factor:%i rtP_Left.i_max:%i input2_fixdt:%li spd_factor:%i rtP_Left.n_max:%i\n", - cur_spd_valid, input1_fixdt, cur_factor, rtP_Left.i_max, input2_fixdt, spd_factor, rtP_Left.n_max); + printf("Limits (%i)\r\nCurrent: fixdt:%li factor%i i_max:%i \r\nSpeed: fixdt:%li factor:%i n_max:%i\r\n", + cur_spd_valid, input1_fixdt, cur_factor, rtP_Left.i_max, input2_fixdt, spd_factor, rtP_Left.n_max); #endif } @@ -1100,7 +1102,7 @@ void usart_process_debug(uint8_t *userCommand, uint32_t len) { for (; len > 0; len--, userCommand++) { if (*userCommand != '\n' && *userCommand != '\r') { // Do not accept 'new line' and 'carriage return' commands - printf("# -- Command received --\n"); + printf("Command = %c\r\n", *userCommand); // handle_input(*userCommand); // -> Create this function to handle the user commands } } From c86d9c4f437ddfebfaadbe8dc02c9b8f523cacec Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Thu, 10 Dec 2020 19:35:13 +0100 Subject: [PATCH 5/6] Improvements and clean-up - clean-up printfs - removed consoleLog function with respective files - removed Delay when using printf - renamed speedL, speedR to cmdL, cmdR - corrected Arduino baud rate - updated FLASH write pointer cast int16_t to uint16_t --- Arduino/hoverserial/hoverserial.ino | 122 +++--- Inc/config.h | 38 +- MDK-ARM/mainboard-hack.uvoptx | 217 +++++++++-- MDK-ARM/mainboard-hack.uvprojx | 585 ++++++++++++++++++++++++++-- Makefile | 1 - Src/main.c | 66 ++-- Src/util.c | 105 +++-- {Src => docs/recycle}/comms.c | 25 -- {Inc => docs/recycle}/comms.h | 0 platformio.ini | 20 +- 10 files changed, 909 insertions(+), 270 deletions(-) rename {Src => docs/recycle}/comms.c (77%) rename {Inc => docs/recycle}/comms.h (100%) diff --git a/Arduino/hoverserial/hoverserial.ino b/Arduino/hoverserial/hoverserial.ino index 3897bc4..e219584 100644 --- a/Arduino/hoverserial/hoverserial.ino +++ b/Arduino/hoverserial/hoverserial.ino @@ -23,15 +23,15 @@ // ******************************************************************* // ########################## DEFINES ########################## -#define HOVER_SERIAL_BAUD 38400 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard) +#define HOVER_SERIAL_BAUD 115200 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard) #define SERIAL_BAUD 115200 // [-] Baud rate for built-in Serial (used for the Serial Monitor) #define START_FRAME 0xABCD // [-] Start frme definition for reliable serial communication #define TIME_SEND 100 // [ms] Sending time interval #define SPEED_MAX_TEST 300 // [-] Maximum speed for testing -//#define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable) +// #define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable) #include -SoftwareSerial HoverSerial(2,3); // RX, TX +SoftwareSerial HoverSerial(2,3); // RX, TX // Global variables uint8_t idx = 0; // Index for new data pointer @@ -41,7 +41,7 @@ byte incomingByte; byte incomingBytePrev; typedef struct{ - uint16_t start; + uint16_t start; int16_t steer; int16_t speed; uint16_t checksum; @@ -50,12 +50,12 @@ SerialCommand Command; typedef struct{ uint16_t start; - int16_t cmd1; - int16_t cmd2; - int16_t speedR_meas; - int16_t speedL_meas; - int16_t batVoltage; - int16_t boardTemp; + int16_t cmd1; + int16_t cmd2; + int16_t speedR_meas; + int16_t speedL_meas; + int16_t batVoltage; + int16_t boardTemp; uint16_t cmdLed; uint16_t checksum; } SerialFeedback; @@ -67,7 +67,7 @@ void setup() { Serial.begin(SERIAL_BAUD); Serial.println("Hoverboard Serial v1.0"); - + HoverSerial.begin(HOVER_SERIAL_BAUD); pinMode(LED_BUILTIN, OUTPUT); } @@ -88,59 +88,59 @@ void Send(int16_t uSteer, int16_t uSpeed) // ########################## RECEIVE ########################## void Receive() { - // Check for new data availability in the Serial buffer - if (HoverSerial.available()) { - incomingByte = HoverSerial.read(); // Read the incoming byte - bufStartFrame = ((uint16_t)(incomingByte) << 8) | incomingBytePrev; // Construct the start frame - } - else { - return; - } + // Check for new data availability in the Serial buffer + if (HoverSerial.available()) { + incomingByte = HoverSerial.read(); // Read the incoming byte + bufStartFrame = ((uint16_t)(incomingByte) << 8) | incomingBytePrev; // Construct the start frame + } + else { + return; + } // If DEBUG_RX is defined print all incoming bytes #ifdef DEBUG_RX - Serial.print(incomingByte); - return; - #endif - - // Copy received data - if (bufStartFrame == START_FRAME) { // Initialize if new data is detected - p = (byte *)&NewFeedback; - *p++ = incomingBytePrev; - *p++ = incomingByte; - idx = 2; - } else if (idx >= 2 && idx < sizeof(SerialFeedback)) { // Save the new received data - *p++ = incomingByte; - idx++; - } - - // Check if we reached the end of the package - if (idx == sizeof(SerialFeedback)) { - uint16_t checksum; - checksum = (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas - ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp ^ NewFeedback.cmdLed); - - // Check validity of the new data - if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) { - // Copy the new data - memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback)); - - // Print data to built-in Serial - Serial.print("1: "); Serial.print(Feedback.cmd1); - Serial.print(" 2: "); Serial.print(Feedback.cmd2); - Serial.print(" 3: "); Serial.print(Feedback.speedR_meas); - Serial.print(" 4: "); Serial.print(Feedback.speedL_meas); - Serial.print(" 5: "); Serial.print(Feedback.batVoltage); - Serial.print(" 6: "); Serial.print(Feedback.boardTemp); - Serial.print(" 7: "); Serial.println(Feedback.cmdLed); - } else { - Serial.println("Non-valid data skipped"); - } - idx = 0; // Reset the index (it prevents to enter in this if condition in the next cycle) - } - - // Update previous states - incomingBytePrev = incomingByte; + Serial.print(incomingByte); + return; + #endif + + // Copy received data + if (bufStartFrame == START_FRAME) { // Initialize if new data is detected + p = (byte *)&NewFeedback; + *p++ = incomingBytePrev; + *p++ = incomingByte; + idx = 2; + } else if (idx >= 2 && idx < sizeof(SerialFeedback)) { // Save the new received data + *p++ = incomingByte; + idx++; + } + + // Check if we reached the end of the package + if (idx == sizeof(SerialFeedback)) { + uint16_t checksum; + checksum = (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas + ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp ^ NewFeedback.cmdLed); + + // Check validity of the new data + if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) { + // Copy the new data + memcpy(&Feedback, &NewFeedback, sizeof(SerialFeedback)); + + // Print data to built-in Serial + Serial.print("1: "); Serial.print(Feedback.cmd1); + Serial.print(" 2: "); Serial.print(Feedback.cmd2); + Serial.print(" 3: "); Serial.print(Feedback.speedR_meas); + Serial.print(" 4: "); Serial.print(Feedback.speedL_meas); + Serial.print(" 5: "); Serial.print(Feedback.batVoltage); + Serial.print(" 6: "); Serial.print(Feedback.boardTemp); + Serial.print(" 7: "); Serial.println(Feedback.cmdLed); + } else { + Serial.println("Non-valid data skipped"); + } + idx = 0; // Reset the index (it prevents to enter in this if condition in the next cycle) + } + + // Update previous states + incomingBytePrev = incomingByte; } // ########################## LOOP ########################## diff --git a/Inc/config.h b/Inc/config.h index 5d064da..a55fd4b 100644 --- a/Inc/config.h +++ b/Inc/config.h @@ -124,7 +124,7 @@ - button1 and button2: digital input values. 0 or 1 - adc_buffer.l_tx2 and adc_buffer.l_rx2: unfiltered ADC values (you do not need them). 0 to 4095 Outputs: - - speedR and speedL: normal driving INPUT_MIN to INPUT_MAX + - cmdL and cmdR: normal driving INPUT_MIN to INPUT_MAX */ #define COM_CTRL 0 // [-] Commutation Control Type #define SIN_CTRL 1 // [-] Sinusoidal Control Type @@ -205,38 +205,30 @@ * Be careful not to use the red wire of the cable. 15v will destroy everything. * If you are using VARIANT_NUNCHUK, disable it temporarily. * enable DEBUG_SERIAL_USART3 or DEBUG_SERIAL_USART2 - * and DEBUG_SERIAL_ASCII use asearial terminal. * * * DEBUG_SERIAL_ASCII output is: - * // "1:345 2:1337 3:0 4:0 5:0 6:0 7:0 8:0\r\n" + * // "in1:345 in2:1337 cmdL:0 cmdR:0 BatADC:0 BatV:0 TempADC:0 Temp:0\r\n" * - * 1: (int16_t)input1); raw input1: ADC1, UART, PWM, PPM, iBUS - * 2: (int16_t)input2); raw input2: ADC2, UART, PWM, PPM, iBUS - * 3: (int16_t)speedR); output command: [-1000, 1000] - * 4: (int16_t)speedL); output command: [-1000, 1000] - * 5: (int16_t)adc_buffer.batt1); Battery adc-value measured by mainboard - * 6: (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC)); Battery calibrated voltage multiplied by 100 for verifying battery voltage calibration - * 7: (int16_t)board_temp_adcFilt); for board temperature calibration - * 8: (int16_t)board_temp_deg_c); Temperature in celcius for verifying board temperature calibration + * in1: (int16_t)input1); raw input1: ADC1, UART, PWM, PPM, iBUS + * in2: (int16_t)input2); raw input2: ADC2, UART, PWM, PPM, iBUS + * cmdL: (int16_t)speedL); output command: [-1000, 1000] + * cmdR: (int16_t)speedR); output command: [-1000, 1000] + * BatADC: (int16_t)adc_buffer.batt1); Battery adc-value measured by mainboard + * BatV: (int16_t)(batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC)); Battery calibrated voltage multiplied by 100 for verifying battery voltage calibration + * TempADC: (int16_t)board_temp_adcFilt); for board temperature calibration + * Temp: (int16_t)board_temp_deg_c); Temperature in celcius for verifying board temperature calibration * */ // #define DEBUG_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used! -#if defined(VARIANT_ADC) - #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! -#endif - -#ifndef VARIANT_TRANSPOTTER - //#define DEBUG_SERIAL_SERVOTERM - #define DEBUG_SERIAL_ASCII -#endif +// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! // ########################### END OF DEBUG SERIAL ############################ // ############################### DEBUG LCD ############################### -//#define DEBUG_I2C_LCD // standard 16x2 or larger text-lcd via i2c-converter on right sensor board cable +// #define DEBUG_I2C_LCD // standard 16x2 or larger text-lcd via i2c-converter on right sensor board cable // ########################### END OF DEBUG LCD ############################ @@ -276,6 +268,8 @@ #define INPUT2_MID 0 // mid ADC2-value while poti at mid-position (INPUT2_MIN - INPUT2_MAX) #define INPUT2_MAX 4095 // max ADC2-value while poti at max-position (0 - 4095) #define INPUT2_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) + + #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! // #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2! // #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3! #endif @@ -293,13 +287,13 @@ #define CONTROL_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! For Arduino control check the hoverSerial.ino #define FEEDBACK_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used! // Min / Max values of each channel (use DEBUG to determine these values) - #define INPUT1_TYPE 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect + #define INPUT1_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect #define INPUT1_MIN -1000 // (-1000 - 0) #define INPUT1_MID 0 #define INPUT1_MAX 1000 // (0 - 1000) #define INPUT1_DEADBAND 0 // How much of the center position is considered 'center' (100 = values -100 to 100 are considered 0) - #define INPUT2_TYPE 1 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect + #define INPUT2_TYPE 3 // 0:Disabled, 1:Normal Pot, 2:Middle Resting Pot, 3:Auto-detect #define INPUT2_MIN -1000 // (-1000 - 0) #define INPUT2_MID 0 #define INPUT2_MAX 1000 // (0 - 1000) diff --git a/MDK-ARM/mainboard-hack.uvoptx b/MDK-ARM/mainboard-hack.uvoptx index 93cd70d..7f8ed9c 100644 --- a/MDK-ARM/mainboard-hack.uvoptx +++ b/MDK-ARM/mainboard-hack.uvoptx @@ -75,7 +75,7 @@ 1 0 - 1 + 0 18 @@ -1398,6 +1398,159 @@ + + VARIANT_SKATEBOARD + 0x4 + ARM-ADS + + 8000000 + + 1 + 0 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\Listing\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 1 + 0 + 1 + + 18 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 5 + + + + + + + + + + + STLink\ST-LINKIII-KEIL_SWO.dll + + + + 0 + ST-LINKIII-KEIL_SWO + -U -O206 -S0 -C0 -A0 -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32F103RC$Flash\STM32F10x_512.FLM) + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512 -FS08000000 -FL080000 -FP0($$Device:STM32F103RC$Flash\STM32F10x_512.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + 1 + 0 + 2 + 10000000 + + + + Startup 1 @@ -1467,18 +1620,6 @@ 0 0 0 - ..\Src\comms.c - comms.c - 0 - 0 - - - 2 - 6 - 1 - 0 - 0 - 0 ..\Src\control.c control.c 0 @@ -1486,7 +1627,7 @@ 2 - 7 + 6 1 0 0 @@ -1498,7 +1639,7 @@ 2 - 8 + 7 1 0 0 @@ -1510,7 +1651,7 @@ 2 - 9 + 8 1 0 0 @@ -1522,7 +1663,7 @@ 2 - 10 + 9 1 0 0 @@ -1534,7 +1675,7 @@ 2 - 11 + 10 1 0 0 @@ -1546,7 +1687,7 @@ 2 - 12 + 11 1 0 0 @@ -1558,7 +1699,7 @@ 2 - 13 + 12 1 0 0 @@ -1570,7 +1711,7 @@ 2 - 14 + 13 5 0 0 @@ -1590,7 +1731,7 @@ 0 3 - 15 + 14 1 0 0 @@ -1602,7 +1743,7 @@ 3 - 16 + 15 1 0 0 @@ -1614,7 +1755,7 @@ 3 - 17 + 16 1 0 0 @@ -1626,7 +1767,7 @@ 3 - 18 + 17 1 0 0 @@ -1638,7 +1779,7 @@ 3 - 19 + 18 1 0 0 @@ -1650,7 +1791,7 @@ 3 - 20 + 19 1 0 0 @@ -1662,7 +1803,7 @@ 3 - 21 + 20 1 0 0 @@ -1674,7 +1815,7 @@ 3 - 22 + 21 1 0 0 @@ -1686,7 +1827,7 @@ 3 - 23 + 22 1 0 0 @@ -1698,7 +1839,7 @@ 3 - 24 + 23 1 0 0 @@ -1710,7 +1851,7 @@ 3 - 25 + 24 1 0 0 @@ -1722,7 +1863,7 @@ 3 - 26 + 25 1 0 0 @@ -1734,7 +1875,7 @@ 3 - 27 + 26 1 0 0 @@ -1746,7 +1887,7 @@ 3 - 28 + 27 1 0 0 @@ -1758,7 +1899,7 @@ 3 - 29 + 28 1 0 0 @@ -1770,7 +1911,7 @@ 3 - 30 + 29 1 0 0 @@ -1790,7 +1931,7 @@ 0 4 - 31 + 30 1 0 0 diff --git a/MDK-ARM/mainboard-hack.uvprojx b/MDK-ARM/mainboard-hack.uvprojx index 4fcbab9..58bf2f9 100644 --- a/MDK-ARM/mainboard-hack.uvprojx +++ b/MDK-ARM/mainboard-hack.uvprojx @@ -404,11 +404,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -954,11 +949,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -1572,11 +1562,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -2190,11 +2175,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -2808,11 +2788,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -3426,11 +3401,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -4044,11 +4014,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -4662,11 +4627,6 @@ 1 ..\Src\BLDC_controller_data.c - - comms.c - 1 - ..\Src\comms.c - control.c 1 @@ -5213,9 +5173,549 @@ ..\Src\BLDC_controller_data.c - comms.c + control.c 1 - ..\Src\comms.c + ..\Src\control.c + + + eeprom.c + 1 + ..\Src\eeprom.c + + + hd44780.c + 1 + ..\Src\hd44780.c + + + main.c + 1 + ..\Src\main.c + + + pcf8574.c + 1 + ..\Src\pcf8574.c + + + setup.c + 1 + ..\Src\setup.c + + + stm32f1xx_it.c + 1 + ..\Src\stm32f1xx_it.c + + + util.c + 1 + ..\Src\util.c + + + config.h + 5 + ..\Inc\config.h + + + + + HAL_Driver + + + stm32f1xx_hal.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c + + + stm32f1xx_hal_adc.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_adc.c + + + stm32f1xx_hal_adc_ex.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_adc_ex.c + + + stm32f1xx_hal_cortex.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c + + + stm32f1xx_hal_dma.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c + + + stm32f1xx_hal_flash.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c + + + stm32f1xx_hal_flash_ex.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c + + + stm32f1xx_hal_gpio.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c + + + stm32f1xx_hal_gpio_ex.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c + + + stm32f1xx_hal_i2c.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_i2c.c + + + stm32f1xx_hal_pwr.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c + + + stm32f1xx_hal_rcc.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c + + + stm32f1xx_hal_rcc_ex.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c + + + stm32f1xx_hal_tim.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c + + + stm32f1xx_hal_tim_ex.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c + + + stm32f1xx_hal_uart.c + 1 + ..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c + + + + + CMSIS + + + system_stm32f1xx.c + 1 + ../Src/system_stm32f1xx.c + + + + + ::CMSIS + + + + + VARIANT_SKATEBOARD + 0x4 + ARM-ADS + 5060422::V5.06 update 4 (build 422)::ARMCC + + + STM32F103RC + STMicroelectronics + Keil.STM32F1xx_DFP.2.3.0 + http://www.keil.com/pack/ + IRAM(0x20000000-0x2000BFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3") + + + + + + + + + + + + + + + $$Device:STM32F103RC$SVD\STM32F103xx.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + firmware + 1 + 0 + 1 + 1 + 1 + .\Listing\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 1 + 0 + $K\ARM\ARMCC\bin\fromelf.exe --bin --output=.\Objects\@L.bin !L + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 0 + + + SARMCM3.DLL + -REMAP + DCM.DLL + -pCM3 + SARMCM3.DLL + + TCM.DLL + -pCM3 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + "" () + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M3" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 1 + 0x8000000 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x8000000 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0xc000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 4 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + USE_HAL_DRIVER,STM32F103xE,VARIANT_SKATEBOARD + + ..\Inc;..\Drivers\STM32F1xx_HAL_Driver\Inc;..\Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32F1xx\Include;..\Drivers\CMSIS\Include + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x08000000 + 0x20000000 + + + + + + + + + + + + + Startup + + + startup_stm32f103xe.s + 2 + .\startup_stm32f103xe.s + + + + + Src + + + bldc.c + 1 + ..\Src\bldc.c + + + BLDC_controller.c + 1 + ..\Src\BLDC_controller.c + + + BLDC_controller_data.c + 1 + ..\Src\BLDC_controller_data.c control.c @@ -5379,6 +5879,7 @@ + diff --git a/Makefile b/Makefile index 6880e1e..3d4cad7 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,6 @@ Src/bldc.c \ Src/eeprom.c \ Src/hd44780.c \ Src/pcf8574.c \ -Src/comms.c \ Src/stm32f1xx_it.c \ Src/BLDC_controller_data.c \ Src/BLDC_controller.c diff --git a/Src/main.c b/Src/main.c index d042838..2c6165d 100644 --- a/Src/main.c +++ b/Src/main.c @@ -27,7 +27,6 @@ #include "setup.h" #include "config.h" #include "util.h" -#include "comms.h" #include "BLDC_controller.h" /* BLDC's header file */ #include "rtwtypes.h" @@ -191,8 +190,8 @@ int main(void) { poweronMelody(); HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET); - int16_t speedL = 0, speedR = 0; - int16_t lastSpeedL = 0, lastSpeedR = 0; + int16_t cmdL = 0, cmdR = 0; + int16_t lastCmdL = 0, lastCmdR = 0; int32_t board_temp_adcFixdt = adc_buffer.temp << 16; // Fixed-point filter output initialized with current ADC converted to fixed-point int16_t board_temp_adcFilt = adc_buffer.temp; @@ -212,7 +211,9 @@ int main(void) { beepShort(4); HAL_Delay(100); steerFixdt = speedFixdt = 0; // reset filters enable = 1; // enable motors + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("-- Motors enabled --\r\n"); + #endif } // ####### VARIANT_HOVERCAR ####### @@ -276,21 +277,21 @@ int main(void) { #endif // ####### MIXER ####### - // speedR = CLAMP((int)(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MA); - // speedL = CLAMP((int)(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MA); - mixerFcn(speed << 4, steer << 4, &speedR, &speedL); // This function implements the equations above + // cmdR = CLAMP((int)(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MA); + // cmdL = CLAMP((int)(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT), INPUT_MIN, INPUT_MA); + mixerFcn(speed << 4, steer << 4, &cmdR, &cmdL); // This function implements the equations above // ####### SET OUTPUTS (if the target change is less than +/- 100) ####### - if ((speedL > lastSpeedL-100 && speedL < lastSpeedL+100) && (speedR > lastSpeedR-100 && speedR < lastSpeedR+100)) { + if ((cmdL > lastCmdL-100 && cmdL < lastCmdL+100) && (cmdR > lastCmdR-100 && cmdR < lastCmdR+100)) { #ifdef INVERT_R_DIRECTION - pwmr = speedR; + pwmr = cmdR; #else - pwmr = -speedR; + pwmr = -cmdR; #endif #ifdef INVERT_L_DIRECTION - pwml = -speedL; + pwml = -cmdL; #else - pwml = speedL; + pwml = cmdL; #endif } #endif @@ -301,22 +302,22 @@ int main(void) { distanceErr = distance - (int)(setDistance * 1345); if (nunchuk_connected == 0) { - speedL = speedL * 0.8f + (CLAMP(distanceErr + (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f); - speedR = speedR * 0.8f + (CLAMP(distanceErr - (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f); - if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50)) { + cmdL = cmdL * 0.8f + (CLAMP(distanceErr + (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f); + cmdR = cmdR * 0.8f + (CLAMP(distanceErr - (steering*((float)MAX(ABS(distanceErr), 50)) * ROT_P), -850, 850) * -0.2f); + if ((cmdL < lastCmdL + 50 && cmdL > lastCmdL - 50) && (cmdR < lastCmdR + 50 && cmdR > lastCmdR - 50)) { if (distanceErr > 0) { enable = 1; } if (distanceErr > -300) { #ifdef INVERT_R_DIRECTION - pwmr = speedR; + pwmr = cmdR; #else - pwmr = -speedR; + pwmr = -cmdR; #endif #ifdef INVERT_L_DIRECTION - pwml = -speedL; + pwml = -cmdL; #else - pwml = speedL; + pwml = cmdL; #endif if (checkRemote) { @@ -410,15 +411,15 @@ int main(void) { // ####### DEBUG SERIAL OUT ####### #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms - printf("in1:%i in2:%i spdL:%i spdR:%i adcBat:%i BatV:%i adcTemp:%i Temp:%i\r\n", - input1, // 1: INPUT1 - input2, // 2: INPUT2 - speedL, // 3: output command: [-1000, 1000] - speedR, // 4: output command: [-1000, 1000] - adc_buffer.batt1, // 5: for battery voltage calibration + printf("in1:%i in2:%i cmdL:%i cmdR:%i BatADC:%i BatV:%i TempADC:%i Temp:%i\r\n", + input1, // 1: INPUT1 + input2, // 2: INPUT2 + cmdL, // 3: output command: [-1000, 1000] + cmdR, // 4: output command: [-1000, 1000] + adc_buffer.batt1, // 5: for battery voltage calibration batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC, // 6: for verifying battery voltage calibration - board_temp_adcFilt, // 7: for board temperature calibration - board_temp_deg_c); // 8: for verifying board temperature calibration + board_temp_adcFilt, // 7: for board temperature calibration + board_temp_deg_c); // 8: for verifying board temperature calibration } #endif @@ -463,25 +464,18 @@ int main(void) { } else if (rtY_Left.z_errCode || rtY_Right.z_errCode) { // 1 beep (low pitch): Motor error, disable motors enable = 0; beepCount(1, 24, 1); - printf("#ErrL: %i ErrR: %i\r\n", rtY_Left.z_errCode, rtY_Right.z_errCode); } else if (timeoutFlagADC) { // 2 beeps (low pitch): ADC timeout beepCount(2, 24, 1); - printf("#ADC timeout\r\n"); } else if (timeoutFlagSerial) { // 3 beeps (low pitch): Serial timeout beepCount(3, 24, 1); - printf("#Serial timeout\r\n"); } else if (timeoutCnt > TIMEOUT) { // 4 beeps (low pitch): General timeout (PPM, PWM, Nunchuck) beepCount(4, 24, 1); - printf("#General timeout\r\n"); } else if (TEMP_WARNING_ENABLE && board_temp_deg_c >= TEMP_WARNING) { // 5 beeps (low pitch): Mainboard temperature warning beepCount(5, 24, 1); - printf("#STM32 hot: %i\r\n", board_temp_deg_c); } else if (BAT_LVL1_ENABLE && batVoltage < BAT_LVL1) { // 1 beep fast (medium pitch): Low bat 1 beepCount(0, 10, 6); - printf("#Battery empty: %i\r\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC); } else if (BAT_LVL2_ENABLE && batVoltage < BAT_LVL2) { // 1 beep slow (medium pitch): Low bat 2 beepCount(0, 10, 30); - printf("#Battery empty: %i\r\n", batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC); } else if (BEEPS_BACKWARD && ((speed < -50 && speedAvg < 0) || MultipleTapBrake.b_multipleTap)) { // 1 beep fast (high pitch): Backward spinning motors beepCount(0, 5, 1); backwardDrive = 1; @@ -492,7 +486,7 @@ int main(void) { // ####### INACTIVITY TIMEOUT ####### - if (abs(speedL) > 50 || abs(speedR) > 50) { + if (abs(cmdL) > 50 || abs(cmdR) > 50) { inactivity_timeout_counter = 0; } else { inactivity_timeout_counter++; @@ -503,8 +497,8 @@ int main(void) { // HAL_GPIO_TogglePin(LED_PORT, LED_PIN); // This is to measure the main() loop duration with an oscilloscope connected to LED_PIN // Update main loop states - lastSpeedL = speedL; - lastSpeedR = speedR; + lastCmdL = cmdL; + lastCmdR = cmdR; main_loop_counter++; timeoutCnt++; } diff --git a/Src/util.c b/Src/util.c index e115453..d2add04 100644 --- a/Src/util.c +++ b/Src/util.c @@ -133,13 +133,13 @@ static int16_t INPUT_MIN; // [-] Input target minimum limitation static uint8_t cur_spd_valid = 0; static uint8_t inp_cal_valid = 0; static uint16_t INPUT1_TYP_CAL = INPUT1_TYPE; - static uint16_t INPUT1_MIN_CAL = INPUT1_MIN; - static uint16_t INPUT1_MID_CAL = INPUT1_MID; - static uint16_t INPUT1_MAX_CAL = INPUT1_MAX; + static int16_t INPUT1_MIN_CAL = INPUT1_MIN; + static int16_t INPUT1_MID_CAL = INPUT1_MID; + static int16_t INPUT1_MAX_CAL = INPUT1_MAX; static uint16_t INPUT2_TYP_CAL = INPUT2_TYPE; - static uint16_t INPUT2_MIN_CAL = INPUT2_MIN; - static uint16_t INPUT2_MID_CAL = INPUT2_MID; - static uint16_t INPUT2_MAX_CAL = INPUT2_MAX; + static int16_t INPUT2_MIN_CAL = INPUT2_MIN; + static int16_t INPUT2_MID_CAL = INPUT2_MID; + static int16_t INPUT2_MAX_CAL = INPUT2_MAX; #endif #if defined(CONTROL_ADC) @@ -198,6 +198,34 @@ static uint8_t cruiseCtrlAcv = 0; static uint8_t standstillAcv = 0; #endif +/* =========================== Retargeting printf =========================== */ +/* retarget the C library printf function to the USART */ +#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + #ifdef __GNUC__ + #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) + #else + #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) + #endif + PUTCHAR_PROTOTYPE { + #if defined(DEBUG_SERIAL_USART2) + HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 1000); + #elif defined(DEBUG_SERIAL_USART3) + HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 1000); + #endif + return ch; + } + + #ifdef __GNUC__ + int _write(int file, char *data, int len) { + int i; + for (i = 0; i < len; i++) { __io_putchar( *data++ );} + return len; + } + #endif +#endif + + + /* =========================== Initialization Functions =========================== */ void BLDC_Init(void) { @@ -280,13 +308,13 @@ void Input_Init(void) { EE_ReadVariable(VirtAddVarTab[0], &writeCheck); if (writeCheck == FLASH_WRITE_KEY) { EE_ReadVariable(VirtAddVarTab[1] , &INPUT1_TYP_CAL); - EE_ReadVariable(VirtAddVarTab[2] , &INPUT1_MIN_CAL); - EE_ReadVariable(VirtAddVarTab[3] , &INPUT1_MID_CAL); - EE_ReadVariable(VirtAddVarTab[4] , &INPUT1_MAX_CAL); + EE_ReadVariable(VirtAddVarTab[2] , (uint16_t *)(intptr_t)INPUT1_MIN_CAL); + EE_ReadVariable(VirtAddVarTab[3] , (uint16_t *)(intptr_t)INPUT1_MID_CAL); + EE_ReadVariable(VirtAddVarTab[4] , (uint16_t *)(intptr_t)INPUT1_MAX_CAL); EE_ReadVariable(VirtAddVarTab[5] , &INPUT2_TYP_CAL); - EE_ReadVariable(VirtAddVarTab[6] , &INPUT2_MIN_CAL); - EE_ReadVariable(VirtAddVarTab[7] , &INPUT2_MID_CAL); - EE_ReadVariable(VirtAddVarTab[8] , &INPUT2_MAX_CAL); + EE_ReadVariable(VirtAddVarTab[6] , (uint16_t *)(intptr_t)INPUT2_MIN_CAL); + EE_ReadVariable(VirtAddVarTab[7] , (uint16_t *)(intptr_t)INPUT2_MID_CAL); + EE_ReadVariable(VirtAddVarTab[8] , (uint16_t *)(intptr_t)INPUT2_MAX_CAL); EE_ReadVariable(VirtAddVarTab[9] , &i_max); EE_ReadVariable(VirtAddVarTab[10], &n_max); rtP_Left.i_max = i_max; @@ -465,31 +493,34 @@ int checkInputType(int16_t min, int16_t mid, int16_t max){ int16_t threshold = 200; #endif - HAL_Delay(10); if ((min / threshold) == (max / threshold) || (mid / threshold) == (max / threshold) || min > max || mid > max) { type = 0; - printf("Input is ignored"); // (MIN and MAX) OR (MID and MAX) are close, disable input + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("ignored"); // (MIN and MAX) OR (MID and MAX) are close, disable input + #endif } else { if ((min / threshold) == (mid / threshold)){ type = 1; - printf("Input is a normal pot"); // MIN and MID are close, it's a normal pot + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("a normal pot"); // MIN and MID are close, it's a normal pot + #endif } else { type = 2; - printf("Input is a mid-resting pot"); // it's a mid resting pot + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("a mid-resting pot"); // it's a mid resting pot + #endif } - HAL_Delay(10); + #ifdef CONTROL_ADC if ((min + INPUT_MARGIN - ADC_PROTECT_THRESH) > 0 && (max - INPUT_MARGIN + ADC_PROTECT_THRESH) < 4095) { - printf(" and protected"); + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf(" AND protected"); + #endif beepLong(2); // Indicate protection by a beep } #endif } - HAL_Delay(10); - printf("\r\n"); - HAL_Delay(10); - return type; } @@ -509,7 +540,10 @@ void adcCalibLim(void) { } #if !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) + + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("Input calibration started...\r\n"); + #endif readInput(); // Inititalization: MIN = a high value, MAX = a low value @@ -538,32 +572,44 @@ void adcCalibLim(void) { HAL_Delay(5); } + printf("Input1 is "); INPUT1_TYP_CAL = checkInputType(INPUT1_MIN_temp, INPUT1_MID_temp, INPUT1_MAX_temp); if (INPUT1_TYP_CAL == INPUT1_TYPE || INPUT1_TYPE == 3) { // Accept calibration only if the type is correct OR type was set to 3 (auto) INPUT1_MIN_CAL = INPUT1_MIN_temp + INPUT_MARGIN; INPUT1_MID_CAL = INPUT1_MID_temp; INPUT1_MAX_CAL = INPUT1_MAX_temp - INPUT_MARGIN; - printf("Input1 OK\r\n"); HAL_Delay(10); + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("..OK\r\n"); + #endif } else { INPUT1_TYP_CAL = 0; // Disable input - printf("Input1 Fail\r\n"); HAL_Delay(10); + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("..NOK\r\n"); + #endif } + printf("Input2 is "); INPUT2_TYP_CAL = checkInputType(INPUT2_MIN_temp, INPUT2_MID_temp, INPUT2_MAX_temp); if (INPUT2_TYP_CAL == INPUT2_TYPE || INPUT2_TYPE == 3) { // Accept calibration only if the type is correct OR type was set to 3 (auto) INPUT2_MIN_CAL = INPUT2_MIN_temp + INPUT_MARGIN; INPUT2_MID_CAL = INPUT2_MID_temp; INPUT2_MAX_CAL = INPUT2_MAX_temp - INPUT_MARGIN; - printf("Input2 OK\r\n"); HAL_Delay(10); + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("..OK\r\n"); + #endif } else { INPUT2_TYP_CAL = 0; // Disable input - printf("Input2 Fail\r\n"); HAL_Delay(10); + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) + printf("..NOK\r\n"); + #endif } inp_cal_valid = 1; // Mark calibration to be saved in Flash at shutdown + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("Limits Input1: TYP:%i MIN:%i MID:%i MAX:%i\r\nLimits Input2: TYP:%i MIN:%i MID:%i MAX:%i\r\n", INPUT1_TYP_CAL, INPUT1_MIN_CAL, INPUT1_MID_CAL, INPUT1_MAX_CAL, INPUT2_TYP_CAL, INPUT2_MIN_CAL, INPUT2_MID_CAL, INPUT2_MAX_CAL); #endif + #endif } /* * Update Maximum Motor Current Limit (via ADC1) and Maximum Speed Limit (via ADC2) @@ -578,7 +624,10 @@ void updateCurSpdLim(void) { } #if !defined(VARIANT_HOVERBOARD) && !defined(VARIANT_TRANSPOTTER) + + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("Torque and Speed limits update started...\r\n"); + #endif int32_t input1_fixdt = input1 << 16; int32_t input2_fixdt = input2 << 16; @@ -610,10 +659,12 @@ void updateCurSpdLim(void) { cur_spd_valid += 2; // Mark update to be saved in Flash at shutdown } + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) // cur_spd_valid: 0 = No limit changed, 1 = Current limit changed, 2 = Speed limit changed, 3 = Both limits changed printf("Limits (%i)\r\nCurrent: fixdt:%li factor%i i_max:%i \r\nSpeed: fixdt:%li factor:%i n_max:%i\r\n", cur_spd_valid, input1_fixdt, cur_factor, rtP_Left.i_max, input2_fixdt, spd_factor, rtP_Left.n_max); #endif + #endif } /* @@ -745,7 +796,9 @@ void cruiseControl(uint8_t button) { void poweroff(void) { enable = 0; + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("-- Motors disabled --\r\n"); + #endif buzzerCount = 0; // prevent interraction with beep counter buzzerPattern = 0; for (int i = 0; i < 8; i++) { diff --git a/Src/comms.c b/docs/recycle/comms.c similarity index 77% rename from Src/comms.c rename to docs/recycle/comms.c index 5b88112..61ee47d 100644 --- a/Src/comms.c +++ b/docs/recycle/comms.c @@ -13,31 +13,6 @@ static volatile uint8_t uart_buf[100]; static volatile int16_t ch_buf[8]; //volatile char char_buf[300]; -/* retarget the C library printf function to the USART */ -#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) - #ifdef __GNUC__ - #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) - #else - #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) - #endif - PUTCHAR_PROTOTYPE { - #if defined(DEBUG_SERIAL_USART2) - HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 1000); - #elif defined(DEBUG_SERIAL_USART3) - HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 1000); - #endif - return ch; - } - - #ifdef __GNUC__ - int _write(int file, char *data, int len) { - int i; - for (i = 0; i < len; i++) { __io_putchar( *data++ );} - return len; - } - #endif -#endif - void setScopeChannel(uint8_t ch, int16_t val) { ch_buf[ch] = val; } diff --git a/Inc/comms.h b/docs/recycle/comms.h similarity index 100% rename from Inc/comms.h rename to docs/recycle/comms.h diff --git a/platformio.ini b/platformio.ini index 55c9343..d7612db 100644 --- a/platformio.ini +++ b/platformio.ini @@ -37,7 +37,6 @@ monitor_speed = 115200 build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -55,12 +54,11 @@ upload_protocol = stlink ; Serial Port settings (make sure the COM port is correct) monitor_port = COM5 -monitor_speed = 38400 +monitor_speed = 115200 build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -79,7 +77,6 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -98,7 +95,6 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -117,7 +113,6 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -136,7 +131,6 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -152,14 +146,9 @@ board = genericSTM32F103RC debug_tool = stlink upload_protocol = stlink -; Serial Port settings (make sure the COM port is correct) -monitor_port = COM5 -monitor_speed = 38400 - build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -175,14 +164,9 @@ board = genericSTM32F103RC debug_tool = stlink upload_protocol = stlink -; Serial Port settings (make sure the COM port is correct) -monitor_port = COM5 -monitor_speed = 38400 - build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -201,7 +185,6 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm @@ -221,7 +204,6 @@ upload_protocol = stlink build_flags = -DUSE_HAL_DRIVER -DSTM32F103xE - -u,_printf_float ; enable float for printf -T./STM32F103RCTx_FLASH.ld -lc -lm From 164219c942e5c2c804d7d69e1b9ef5e34e503d6b Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Thu, 10 Dec 2020 19:43:12 +0100 Subject: [PATCH 6/6] Update util.c missed some #ifdef --- Src/util.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Src/util.c b/Src/util.c index d2add04..bfae6ce 100644 --- a/Src/util.c +++ b/Src/util.c @@ -201,27 +201,27 @@ static uint8_t standstillAcv = 0; /* =========================== Retargeting printf =========================== */ /* retarget the C library printf function to the USART */ #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) - #ifdef __GNUC__ - #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) - #else - #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) + #ifdef __GNUC__ + #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) + #else + #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) + #endif + PUTCHAR_PROTOTYPE { + #if defined(DEBUG_SERIAL_USART2) + HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 1000); + #elif defined(DEBUG_SERIAL_USART3) + HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 1000); #endif - PUTCHAR_PROTOTYPE { - #if defined(DEBUG_SERIAL_USART2) - HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 1000); - #elif defined(DEBUG_SERIAL_USART3) - HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 1000); - #endif - return ch; + return ch; + } + + #ifdef __GNUC__ + int _write(int file, char *data, int len) { + int i; + for (i = 0; i < len; i++) { __io_putchar( *data++ );} + return len; } - - #ifdef __GNUC__ - int _write(int file, char *data, int len) { - int i; - for (i = 0; i < len; i++) { __io_putchar( *data++ );} - return len; - } - #endif + #endif #endif @@ -572,7 +572,9 @@ void adcCalibLim(void) { HAL_Delay(5); } + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("Input1 is "); + #endif INPUT1_TYP_CAL = checkInputType(INPUT1_MIN_temp, INPUT1_MID_temp, INPUT1_MAX_temp); if (INPUT1_TYP_CAL == INPUT1_TYPE || INPUT1_TYPE == 3) { // Accept calibration only if the type is correct OR type was set to 3 (auto) INPUT1_MIN_CAL = INPUT1_MIN_temp + INPUT_MARGIN; @@ -588,7 +590,9 @@ void adcCalibLim(void) { #endif } + #if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3) printf("Input2 is "); + #endif INPUT2_TYP_CAL = checkInputType(INPUT2_MIN_temp, INPUT2_MID_temp, INPUT2_MAX_temp); if (INPUT2_TYP_CAL == INPUT2_TYPE || INPUT2_TYPE == 3) { // Accept calibration only if the type is correct OR type was set to 3 (auto) INPUT2_MIN_CAL = INPUT2_MIN_temp + INPUT_MARGIN;