Add CAN1 100 ms heartbeat with verified firmware and updated protocol PDF
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#define AMI_CAN_ID_BMS_EXTREMES_EXT 0x186140F3UL
|
||||
/* AMI task requests are not ASSI commands; no SDC mapping is defined. */
|
||||
#define AMI_CAN_ID_TASK_REQUEST 0x300U
|
||||
#define AMI_CAN_ID_HEARTBEAT 0x301U
|
||||
#define AMI_HEARTBEAT_PERIOD_MS 100U
|
||||
|
||||
#define AMI_CAN_DATA_TIMEOUT_MS 500U
|
||||
#define AMI_ADC_TIMEOUT_MS 1500U
|
||||
|
||||
@@ -537,6 +537,47 @@ static void SendPendingTask(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void SendHeartbeat(void)
|
||||
{
|
||||
static uint32_t last_tx_ms;
|
||||
static uint16_t sequence;
|
||||
uint32_t now = HAL_GetTick();
|
||||
FDCAN_TxHeaderTypeDef header = {0};
|
||||
uint8_t data[8];
|
||||
|
||||
if ((uint32_t)(now - last_tx_ms) < AMI_HEARTBEAT_PERIOD_MS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* Skip missed periods instead of generating a catch-up burst. */
|
||||
last_tx_ms = now;
|
||||
data[0] = 1U; /* Protocol version. */
|
||||
data[1] = 0U; /* Reserved. */
|
||||
data[2] = (uint8_t)sequence;
|
||||
data[3] = (uint8_t)(sequence >> 8);
|
||||
data[4] = (uint8_t)now;
|
||||
data[5] = (uint8_t)(now >> 8);
|
||||
data[6] = (uint8_t)(now >> 16);
|
||||
data[7] = (uint8_t)(now >> 24);
|
||||
++sequence;
|
||||
|
||||
header.Identifier = AMI_CAN_ID_HEARTBEAT;
|
||||
header.IdType = FDCAN_STANDARD_ID;
|
||||
header.TxFrameType = FDCAN_DATA_FRAME;
|
||||
header.DataLength = FDCAN_DLC_BYTES_8;
|
||||
header.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
|
||||
header.BitRateSwitch = FDCAN_BRS_OFF;
|
||||
header.FDFormat = FDCAN_CLASSIC_CAN;
|
||||
header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
|
||||
|
||||
/* CAN1 (500 kbit/s) only; reserve one FIFO slot for task requests.
|
||||
A busy port skips this period; no software backlog or blocking retry. */
|
||||
if (HAL_FDCAN_GetTxFifoFreeLevel(&hfdcan1) > 1U)
|
||||
{
|
||||
(void)HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &header, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateTimeoutsAndLeds(void)
|
||||
{
|
||||
static uint32_t last_heartbeat_ms;
|
||||
@@ -720,6 +761,7 @@ void AMI_App_Service(void)
|
||||
uint32_t now = HAL_GetTick();
|
||||
|
||||
SendPendingTask();
|
||||
SendHeartbeat();
|
||||
UpdateTimeoutsAndLeds();
|
||||
/* The HMI may reboot/reconnect after the MCU has already sent its state. */
|
||||
if ((now - last_screen_sync_ms) >= AMI_SCREEN_RESYNC_MS)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# AMI 主控固件
|
||||
|
||||
2026-10-04:新增 AMI `0x301` 标准心跳帧(DLC 8),仅 CAN1(500 kbit/s)100 ms 一次,CAN2 不发送心跳,包含版本、uint16 序号和 uint32 运行毫秒值,小端。源码和 DBC 已更新,已烧录并全量回读一致;CAN1 实测 121 帧,间隔 99.952~100.180 ms。完整定义见 [DBC 说明](../docs/AMI_CAN_DBC说明.md)。
|
||||
|
||||
这是 `AMI.HMI` 配套的 STM32 HAL 固件。目标器件按 **STM32G0B1CBT6(LQFP48,128 KB Flash)** 生成;ST 的 G0B1 产品线没有 `STM32G0B1C8T6`,如果实物丝印为 `STM32G0B1CCT6` 或 `STM32G0B1CET6`,引脚及应用代码兼容,只需在 CubeMX 中切换具体料号后重新生成。
|
||||
|
||||
## 引脚与外设
|
||||
|
||||
Reference in New Issue
Block a user