Merge remote-tracking branch 'origin/sl-android/issue-521-esc-debug-cleanup'

This commit is contained in:
sl-jetson 2026-03-06 23:34:45 -05:00
commit e67783f313
2 changed files with 17 additions and 1 deletions

View File

@ -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
}
/*

View File

@ -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 */