Ascii Debug updates
- added missing pointer to UART2 input user processing - added comms.c to Makefile - fixed #134 : uncomment #define AUTO_CALIBRATION_ENA to disable auto-calibration - small styling adjustments
This commit is contained in:
parent
d5d85c20ec
commit
a564f368e2
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "stm32f1xx_hal.h"
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
|
#if defined(DEBUG_SERIAL_PROTOCOL)
|
||||||
|
|
||||||
enum types {UINT8_T,UINT16_T,UINT32_T,INT8_T,INT16_T,INT32_T,INT,FLOAT};
|
enum types {UINT8_T,UINT16_T,UINT32_T,INT8_T,INT16_T,INT32_T,INT,FLOAT};
|
||||||
#define typename(x) _Generic((x), \
|
#define typename(x) _Generic((x), \
|
||||||
|
@ -108,5 +109,5 @@ struct parameter_entry_struct {
|
||||||
const char *help;
|
const char *help;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // DEBUG_SERIAL_PROTOCOL
|
||||||
#endif
|
#endif // COMMS_H
|
|
@ -172,6 +172,7 @@
|
||||||
#define ADC_MARGIN 100 // ADC input margin applied on the raw ADC min and max to make sure the MIN and MAX values are reached even in the presence of noise
|
#define ADC_MARGIN 100 // ADC input margin applied on the raw ADC min and max to make sure the MIN and MAX values are reached even in the presence of noise
|
||||||
#define ADC_PROTECT_TIMEOUT 100 // ADC Protection: number of wrong / missing input commands before safety state is taken
|
#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 ADC_PROTECT_THRESH 200 // ADC Protection threshold below/above the MIN/MAX ADC values
|
||||||
|
#define AUTO_CALIBRATION_ENA // Enable/Disable input auto-calibration by holding power button pressed. Un-comment this if auto-calibration is not needed.
|
||||||
|
|
||||||
/* FILTER is in fixdt(0,16,16): VAL_fixedPoint = VAL_floatingPoint * 2^16. In this case 6553 = 0.1 * 2^16
|
/* FILTER is in fixdt(0,16,16): VAL_fixedPoint = VAL_floatingPoint * 2^16. In this case 6553 = 0.1 * 2^16
|
||||||
* Value of COEFFICIENT is in fixdt(1,16,14)
|
* Value of COEFFICIENT is in fixdt(1,16,14)
|
||||||
|
@ -227,7 +228,7 @@
|
||||||
* enable DEBUG_SERIAL_USART3 or DEBUG_SERIAL_USART2
|
* enable DEBUG_SERIAL_USART3 or DEBUG_SERIAL_USART2
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* DEBUG_SERIAL_ASCII output is:
|
* DEBUG ASCII output is:
|
||||||
* // "in1:345 in2:1337 cmdL:0 cmdR:0 BatADC:0 BatV:0 TempADC:0 Temp:0\r\n"
|
* // "in1:345 in2:1337 cmdL:0 cmdR:0 BatADC:0 BatV:0 TempADC:0 Temp:0\r\n"
|
||||||
*
|
*
|
||||||
* in1: (int16_t)input1[inIdx].raw); raw input1: ADC1, UART, PWM, PPM, iBUS
|
* in1: (int16_t)input1[inIdx].raw); raw input1: ADC1, UART, PWM, PPM, iBUS
|
||||||
|
@ -243,6 +244,7 @@
|
||||||
|
|
||||||
// #define DEBUG_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
// #define DEBUG_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
||||||
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
||||||
|
// #define DEBUG_SERIAL_PROTOCOL // uncomment this to send user commands to the board, change parameters and print specific signals (see comms.c for the user commands)
|
||||||
// ########################### END OF DEBUG SERIAL ############################
|
// ########################### END OF DEBUG SERIAL ############################
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,7 +293,6 @@
|
||||||
#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEBUG_SERIAL_PROTOCOL
|
|
||||||
// #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2!
|
// #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!
|
// #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3!
|
||||||
#endif
|
#endif
|
||||||
|
|
1
Makefile
1
Makefile
|
@ -38,6 +38,7 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
|
||||||
Src/system_stm32f1xx.c \
|
Src/system_stm32f1xx.c \
|
||||||
Src/setup.c \
|
Src/setup.c \
|
||||||
Src/control.c \
|
Src/control.c \
|
||||||
|
Src/comms.c \
|
||||||
Src/util.c \
|
Src/util.c \
|
||||||
Src/main.c \
|
Src/main.c \
|
||||||
Src/bldc.c \
|
Src/bldc.c \
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -30,6 +29,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
|
|
||||||
|
#if defined(DEBUG_SERIAL_PROTOCOL)
|
||||||
#if defined(DEBUG_SERIAL_PROTOCOL) && (defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3))
|
#if defined(DEBUG_SERIAL_PROTOCOL) && (defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3))
|
||||||
|
|
||||||
#ifdef CONTROL_ADC
|
#ifdef CONTROL_ADC
|
||||||
|
@ -636,3 +636,5 @@ void process_debug()
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif // DEBUG_SERIAL_PROTOCOL
|
||||||
|
|
||||||
|
|
|
@ -200,7 +200,7 @@ int main(void) {
|
||||||
int16_t board_temp_deg_c;
|
int16_t board_temp_deg_c;
|
||||||
|
|
||||||
// Loop until button is released
|
// Loop until button is released
|
||||||
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) HAL_Delay(10);
|
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { HAL_Delay(10); }
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
HAL_Delay(DELAY_IN_MAIN_LOOP); // delay in ms
|
HAL_Delay(DELAY_IN_MAIN_LOOP); // delay in ms
|
||||||
|
@ -424,7 +424,9 @@ int main(void) {
|
||||||
// ####### DEBUG SERIAL OUT #######
|
// ####### DEBUG SERIAL OUT #######
|
||||||
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
|
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
|
||||||
if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms
|
if (main_loop_counter % 25 == 0) { // Send data periodically every 125 ms
|
||||||
#ifndef DEBUG_SERIAL_PROTOCOL
|
#if defined(DEBUG_SERIAL_PROTOCOL)
|
||||||
|
process_debug();
|
||||||
|
#else
|
||||||
printf("in1:%i in2:%i cmdL:%i cmdR:%i BatADC:%i BatV:%i TempADC:%i Temp:%i\r\n",
|
printf("in1:%i in2:%i cmdL:%i cmdR:%i BatADC:%i BatV:%i TempADC:%i Temp:%i\r\n",
|
||||||
input1[inIdx].raw, // 1: INPUT1
|
input1[inIdx].raw, // 1: INPUT1
|
||||||
input2[inIdx].raw, // 2: INPUT2
|
input2[inIdx].raw, // 2: INPUT2
|
||||||
|
@ -434,8 +436,6 @@ int main(void) {
|
||||||
batVoltage * BAT_CALIB_REAL_VOLTAGE / BAT_CALIB_ADC, // 6: for verifying 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_adcFilt, // 7: for board temperature calibration
|
||||||
board_temp_deg_c); // 8: for verifying board temperature calibration
|
board_temp_deg_c); // 8: for verifying board temperature calibration
|
||||||
#else
|
|
||||||
process_debug();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
31
Src/util.c
31
Src/util.c
|
@ -483,6 +483,7 @@ void calcAvgSpeed(void) {
|
||||||
* The Values will be saved to flash. Values are persistent if you flash with platformio. To erase them, make a full chip erase.
|
* 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) {
|
void adcCalibLim(void) {
|
||||||
|
#ifdef AUTO_CALIBRATION_ENA
|
||||||
calcAvgSpeed();
|
calcAvgSpeed();
|
||||||
if (speedAvgAbs > 5) { // do not enter this mode if motors are spinning
|
if (speedAvgAbs > 5) { // do not enter this mode if motors are spinning
|
||||||
return;
|
return;
|
||||||
|
@ -571,6 +572,7 @@ void adcCalibLim(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif // AUTO_CALIBRATION_ENA
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Update Maximum Motor Current Limit (via ADC1) and Maximum Speed Limit (via ADC2)
|
* Update Maximum Motor Current Limit (via ADC1) and Maximum Speed Limit (via ADC2)
|
||||||
|
@ -1063,14 +1065,20 @@ void usart2_rx_check(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG_SERIAL_USART2)
|
#if defined(DEBUG_SERIAL_USART2)
|
||||||
|
uint8_t *ptr;
|
||||||
if (pos != old_pos) { // Check change in received data
|
if (pos != old_pos) { // Check change in received data
|
||||||
if (pos > old_pos) { // "Linear" buffer mode: check if current position is over previous one
|
if (pos > old_pos) { // "Linear" buffer mode: check if current position is over previous one
|
||||||
usart_process_debug(&rx_buffer_L[old_pos], pos - old_pos); // Process data
|
usart_process_debug(&rx_buffer_L[old_pos], pos - old_pos); // Process data
|
||||||
} else { // "Overflow" buffer mode
|
} else { // "Overflow" buffer mode
|
||||||
usart_process_debug(&rx_buffer_L[old_pos], rx_buffer_L_len - old_pos); // First Process data from the end of buffer
|
ptr = (uint8_t *) malloc(sizeof(uint8_t) * (rx_buffer_L_len - old_pos + pos));
|
||||||
|
memcpy(ptr, &rx_buffer_L[old_pos], rx_buffer_L_len - old_pos); // First copy data from the end of buffer
|
||||||
if (pos > 0) { // Check and continue with beginning of buffer
|
if (pos > 0) { // Check and continue with beginning of buffer
|
||||||
usart_process_debug(&rx_buffer_L[0], pos); // Process remaining data
|
ptr += rx_buffer_L_len - old_pos;
|
||||||
|
memcpy(ptr, &rx_buffer_L[0], pos); // Copy remaining data
|
||||||
}
|
}
|
||||||
|
ptr -= rx_buffer_L_len - old_pos;
|
||||||
|
usart_process_debug(ptr, rx_buffer_L_len - old_pos + pos); // Process data
|
||||||
|
free(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // DEBUG_SERIAL_USART2
|
#endif // DEBUG_SERIAL_USART2
|
||||||
|
@ -1134,19 +1142,18 @@ void usart3_rx_check(void)
|
||||||
|
|
||||||
#if defined(DEBUG_SERIAL_USART3)
|
#if defined(DEBUG_SERIAL_USART3)
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
|
|
||||||
if (pos != old_pos) { // Check change in received data
|
if (pos != old_pos) { // Check change in received data
|
||||||
if (pos > old_pos) { // "Linear" buffer mode: check if current position is over previous one
|
if (pos > old_pos) { // "Linear" buffer mode: check if current position is over previous one
|
||||||
usart_process_debug(&rx_buffer_R[old_pos], pos - old_pos); // Process data
|
usart_process_debug(&rx_buffer_R[old_pos], pos - old_pos); // Process data
|
||||||
} else { // "Overflow" buffer mode
|
} else { // "Overflow" buffer mode
|
||||||
ptr = (uint8_t *) malloc(sizeof(uint8_t) * (rx_buffer_R_len - old_pos + pos));
|
ptr = (uint8_t *) malloc(sizeof(uint8_t) * (rx_buffer_R_len - old_pos + pos));
|
||||||
memcpy(ptr,&rx_buffer_R[old_pos],rx_buffer_R_len - old_pos); // First Process data from the end of buffer
|
memcpy(ptr, &rx_buffer_R[old_pos], rx_buffer_R_len - old_pos); // First copy data from the end of buffer
|
||||||
if (pos > 0) { // Check and continue with beginning of buffer
|
if (pos > 0) { // Check and continue with beginning of buffer
|
||||||
ptr += rx_buffer_R_len - old_pos;
|
ptr += rx_buffer_R_len - old_pos;
|
||||||
memcpy(ptr,&rx_buffer_R[0], pos); // Process remaining data
|
memcpy(ptr, &rx_buffer_R[0], pos); // Copy remaining data
|
||||||
}
|
}
|
||||||
ptr -= rx_buffer_R_len - old_pos;
|
ptr -= rx_buffer_R_len - old_pos;
|
||||||
usart_process_debug(ptr, rx_buffer_R_len - old_pos + pos);
|
usart_process_debug(ptr, rx_buffer_R_len - old_pos + pos); // Process data
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1202,15 +1209,7 @@ void usart3_rx_check(void)
|
||||||
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
|
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
|
||||||
void usart_process_debug(uint8_t *userCommand, uint32_t len)
|
void usart_process_debug(uint8_t *userCommand, uint32_t len)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_SERIAL_PROTOCOL
|
||||||
#ifndef DEBUG_SERIAL_PROTOCOL
|
|
||||||
for (; len > 0; len--, userCommand++) {
|
|
||||||
if (*userCommand != '\n' && *userCommand != '\r') { // Do not accept 'new line' and 'carriage return' commands
|
|
||||||
printf("Command = %c\r\n", *userCommand);
|
|
||||||
// handle_input(*userCommand); // -> Create this function to handle the user commands
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
handle_input(userCommand, len);
|
handle_input(userCommand, len);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1542,9 +1541,11 @@ void poweroffPressCheck(void) {
|
||||||
updateCurSpdLim();
|
updateCurSpdLim();
|
||||||
beepShort(5);
|
beepShort(5);
|
||||||
} else { // Long press: Calibrate ADC Limits
|
} else { // Long press: Calibrate ADC Limits
|
||||||
|
#ifdef AUTO_CALIBRATION_ENA
|
||||||
beepLong(16);
|
beepLong(16);
|
||||||
adcCalibLim();
|
adcCalibLim();
|
||||||
beepShort(5);
|
beepShort(5);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else if (cnt_press > 8) { // Short press: power off (80 ms debounce)
|
} else if (cnt_press > 8) { // Short press: power off (80 ms debounce)
|
||||||
poweroff();
|
poweroff();
|
||||||
|
|
Loading…
Reference in New Issue