chore: Guard ESC debug output behind compile flag (Issue #521)
- esc_hoverboard.c: huart2 static in production; non-static only under #ifdef DEBUG_MOTOR_TEST (needed by R command in jetson_uart.c) - esc_hoverboard.c: UART5 diagnostic in hoverboard_backend_init() and per-packet printf in hoverboard_backend_send() guarded by same flag - esc_hoverboard.c: #include <stdio.h> also guarded (not needed in production) - jetson_uart.c: R (baud sweep) and X (GPIO test) commands guarded by #ifdef DEBUG_MOTOR_TEST — not compiled into production firmware Production build: no debug output, static huart2, no R/X commands. Debug build: define DEBUG_MOTOR_TEST to re-enable all diagnostics. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3bb4b71cea
commit
d5246fe3a8
@ -1,7 +1,9 @@
|
||||
#include "esc_backend.h"
|
||||
#include "config.h"
|
||||
#include "stm32f7xx_hal.h"
|
||||
#ifdef DEBUG_MOTOR_TEST
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hoverboard ESC Backend Implementation
|
||||
@ -25,7 +27,11 @@ typedef struct __attribute__((packed)) {
|
||||
uint16_t checksum;
|
||||
} hoverboard_cmd_t;
|
||||
|
||||
UART_HandleTypeDef huart2; /* non-static: accessed by jetson_uart.c raw test */
|
||||
#ifdef DEBUG_MOTOR_TEST
|
||||
UART_HandleTypeDef huart2; /* non-static: exposed for jetson_uart.c R command */
|
||||
#else
|
||||
static UART_HandleTypeDef huart2;
|
||||
#endif
|
||||
|
||||
/* Backend vtable instance */
|
||||
static const esc_backend_t hoverboard_backend;
|
||||
@ -66,6 +72,7 @@ static void hoverboard_backend_init(void) {
|
||||
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
HAL_UART_Init(&huart2);
|
||||
|
||||
#ifdef DEBUG_MOTOR_TEST
|
||||
/* Diagnostic: report UART5 register state on USART6 after init */
|
||||
{
|
||||
extern void jetson_uart_send(const uint8_t *data, uint16_t len);
|
||||
@ -87,13 +94,16 @@ static void hoverboard_backend_init(void) {
|
||||
HAL_Delay(100);
|
||||
jetson_uart_send((uint8_t*)diag, n);
|
||||
}
|
||||
#endif /* DEBUG_MOTOR_TEST */
|
||||
}
|
||||
|
||||
/*
|
||||
* Send motor command via hoverboard protocol.
|
||||
* Called at ~50Hz from motor_driver_update().
|
||||
*/
|
||||
#ifdef DEBUG_MOTOR_TEST
|
||||
static volatile uint32_t hover_tx_count = 0;
|
||||
#endif
|
||||
|
||||
static void hoverboard_backend_send(int16_t speed, int16_t steer) {
|
||||
hoverboard_cmd_t cmd;
|
||||
@ -102,6 +112,7 @@ static void hoverboard_backend_send(int16_t speed, int16_t steer) {
|
||||
cmd.speed = speed;
|
||||
cmd.checksum = cmd.start ^ cmd.steer ^ cmd.speed;
|
||||
|
||||
#ifdef DEBUG_MOTOR_TEST
|
||||
HAL_StatusTypeDef rc = HAL_UART_Transmit(&huart2, (uint8_t *)&cmd, sizeof(cmd), 5);
|
||||
hover_tx_count++;
|
||||
|
||||
@ -113,6 +124,9 @@ static void hoverboard_backend_send(int16_t speed, int16_t steer) {
|
||||
(unsigned long)hover_tx_count, (int)rc, speed, steer);
|
||||
jetson_uart_send((uint8_t*)dbg, n);
|
||||
}
|
||||
#else
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *)&cmd, sizeof(cmd), 5);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -177,6 +177,7 @@ static void process_line(const char *buf, uint8_t len) {
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MOTOR_TEST
|
||||
/* GPIO test: reconfigure PC12 as plain GPIO output, set HIGH for 10s, then restore UART */
|
||||
case 'X': {
|
||||
GPIO_InitTypeDef gpio = {0};
|
||||
@ -252,6 +253,7 @@ static void process_line(const char *buf, uint8_t len) {
|
||||
HAL_UART_Transmit(&huart6, (uint8_t*)ack, 7, 10);
|
||||
break;
|
||||
}
|
||||
#endif /* DEBUG_MOTOR_TEST */
|
||||
|
||||
case '?': {
|
||||
/* Status dump for debugging */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user