Compare commits

..

No commits in common. "06219afe69fe578b7a8a53da95d02516e7bece74" and "dd52982a03f8ade72a1c46fec4fc1c2b3af2bb46" have entirely different histories.

2 changed files with 11 additions and 37 deletions

View File

@ -11,21 +11,17 @@
* to IO2/IO1 when deploying this firmware. See docs/SAUL-TEE-SYSTEM-REFERENCE.md.
*/
/* ── Orin serial: USB Serial/JTAG (native USB, no GPIO needed) ──
* sdkconfig: CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
* The OrinESP32 link uses the built-in USB-CDC peripheral.
* UART0 on GPIO 43/44 is NOT used for Orin comms.
*/
/* ── Orin serial (CH343 USB-to-UART, 1a86:55d3 on Orin side) ── */
#define ORIN_UART_PORT UART_NUM_0
#define ORIN_UART_BAUD 460800
#define ORIN_UART_TX_GPIO 17 /* unused — Orin uses USB-CDC */
#define ORIN_UART_RX_GPIO 18 /* unused — Orin uses USB-CDC */
#define ORIN_UART_TX_GPIO 43 /* ESP32→CH343 RXD */
#define ORIN_UART_RX_GPIO 44 /* CH343 TXD→ESP32 */
#define ORIN_UART_RX_BUF 1024
#define ORIN_TX_QUEUE_DEPTH 16
/* ── VESC CAN TWAI (SN65HVD230 transceiver on original GPIO 43/44) ── */
#define VESC_CAN_TX_GPIO 43 /* ESP32 TWAI TX → SN65HVD230 TXD */
#define VESC_CAN_RX_GPIO 44 /* SN65HVD230 RXD → ESP32 TWAI RX */
/* ── VESC CAN TWAI (SN65HVD230 transceiver, rewired for bd-66hx) ── */
#define VESC_CAN_TX_GPIO 2 /* ESP32 TWAI TX → SN65HVD230 TXD */
#define VESC_CAN_RX_GPIO 1 /* SN65HVD230 RXD → ESP32 TWAI RX */
#define VESC_CAN_RX_QUEUE 32
/* VESC node IDs — matched to bd-wim1 TELEM_VESC_LEFT/RIGHT mapping */

View File

@ -39,22 +39,17 @@ void vesc_can_init(void)
twai_timing_config_t tcfg = TWAI_TIMING_CONFIG_500KBITS();
twai_filter_config_t fcfg = TWAI_FILTER_CONFIG_ACCEPT_ALL();
gcfg.tx_queue_len = 5;
ESP_LOGI(TAG, "TWAI: installing driver tx=%d rx=%d 500kbps", VESC_CAN_TX_GPIO, VESC_CAN_RX_GPIO);
ESP_LOGI(TAG, "TWAI: twai_driver_install tx=%d rx=%d 500kbps", VESC_CAN_TX_GPIO, VESC_CAN_RX_GPIO);
ESP_ERROR_CHECK(twai_driver_install(&gcfg, &tcfg, &fcfg));
ESP_LOGI(TAG, "TWAI: driver installed OK");
ESP_LOGI(TAG, "TWAI: twai_start");
ESP_ERROR_CHECK(twai_start());
/* Wait for VESC to join the bus before drive_task begins TX — prevents
* immediate TEC runup and BUS_OFF if VESC CAN isn't ready at ESP32 boot. */
vTaskDelay(pdMS_TO_TICKS(200));
ESP_LOGI(TAG, "TWAI: started OK — bus active");
}
void vesc_can_send_rpm(uint8_t vesc_id, int32_t erpm)
{
if (g_twai_bus_off) { return; }
uint32_t ext_id = ((uint32_t)VESC_PKT_SET_RPM << 8u) | vesc_id;
twai_message_t msg = {
.extd = 1,
@ -86,28 +81,11 @@ void vesc_can_rx_task(void *arg)
}
twai_status_info_t si;
if (twai_get_status_info(&si) == ESP_OK) {
/* Mark bus-off for ANY non-running state so vesc_can_send_rpm
* won't flood with failed transmits during recovery. */
g_twai_bus_off = (si.state != TWAI_STATE_RUNNING);
if (si.state == TWAI_STATE_BUS_OFF) {
ESP_LOGE(TAG, "TWAI BUS OFF tx_err=%lu rx_err=%lu — recovering",
g_twai_bus_off = (si.state == TWAI_STATE_BUS_OFF);
if (g_twai_bus_off) {
ESP_LOGE(TAG, "TWAI BUS OFF — tx_err=%lu rx_err=%lu",
(unsigned long)si.tx_error_counter, (unsigned long)si.rx_error_counter);
twai_initiate_recovery();
/* Driver auto-transitions RECOVERING→STOPPED after 128 recessive
* bit occurrences (~3 ms min at 500kbps); 100 ms is safe headroom. */
vTaskDelay(pdMS_TO_TICKS(100));
} else if (si.state == TWAI_STATE_STOPPED) {
/* Recovery completed — restart the driver. */
esp_err_t serr = twai_start();
if (serr == ESP_OK) {
g_twai_bus_off = false;
ESP_LOGI(TAG, "TWAI recovered — bus active");
} else {
ESP_LOGE(TAG, "TWAI restart failed 0x%x", serr);
}
}
/* TWAI_STATE_RECOVERING: initiation already called, just wait. */
}
continue;
}