--- tags: [entity] type: entity topic: stm32-lower note: 13 created: 2026-07-16 updated: 2026-07-16 --- # Note 13: CAN (lower/stm32/01~04) ## Projects | # | Directory | Description | Library | |---|---|---|---| | 01 | `01_can_test_register` | Loopback silent mode | Register | | 02 | `02_can_test_hal` | Loopback silent mode | HAL | | 03 | `03_can_tx_register` | Dual-node TX | Register | | 03 | `03_can_rx_register` | Dual-node RX | Register | | 04 | `04_can_tx_hal` | Dual-node TX | HAL | | 04 | `04_can_rx_hal` | Dual-node RX | HAL | ## Code Accuracy Audit ### Path Audit | Claimed Path (in raw note) | Actual Path | Status | |---|---|---| | `stm32/stm32/01_can_test_register/Hardware/CAN/can.c` | `01_can_test_register/Hardware/CAN/can.c` | **WRONG** — double `stm32/` prefix | | `stm32/stm32/01_can_test_register/User/main.c` | `01_can_test_register/User/main.c` | **WRONG** — double `stm32/` prefix | | `stm32/02_can_test_hal/Core/Src/can.c` | `02_can_test_hal/Core/Src/can.c` | **Correct** | | `stm32/03_can_tx_register/User/main.c` | `03_can_tx_register/User/main.c` | **Correct** (no double prefix) | | `stm32/04_can_tx_hal/Core/Src/main.c` | `04_can_tx_hal/Core/Src/main.c` | **Correct** | > **Critical Finding**: Raw note has `stm32/stm32/01_can_test_register/...` (duplicated `stm32/`) for project 01 files. This path does not exist. The correct base is `01_can_test_register/...` (only one level under `stm32/`). ### File Existence | File | Exists? | |---|---| | `01_can_test_register/Hardware/CAN/can.c` | Yes (200 lines) | | `01_can_test_register/Hardware/CAN/can.h` | Yes (30 lines) | | `01_can_test_register/User/main.c` | Yes (53 lines) | | `02_can_test_hal/Core/Src/can.c` | Yes (195 lines) | | `02_can_test_hal/Core/Src/main.c` | Yes (219 lines) | | `03_can_tx_register/User/main.c` | Exists | | `03_can_rx_register/User/main.c` | Exists | | `04_can_tx_hal/Core/Src/main.c` | Exists | | `04_can_rx_hal/Core/Src/main.c` | Exists | ### Code Comparison: Register CAN (01_can_test_register) | Claimed by Note | Actual Code | Match? | |---|---|---| | `CAN1->MCR |= CAN_MCR_INRQ` | Line 37: `CAN1->MCR |= CAN_MCR_INRQ` | ✅ Match | | `CAN1->BTR |= CAN_BTR_SILM` and `CAN1->BTR |= CAN_BTR_LBKM` | Lines 53-54 | ✅ Match | | `CAN1->BTR |= (35 << 0)` (BRP) | Line 59: `CAN1->BTR |= (35 << 0)` | ✅ Match | | `CAN1->BTR |= (2 << 16)` (TS1=BS1) | Line 63 | ✅ Match | | `CAN1->BTR |= (5 << 20)` (TS2=BS2) | Line 66 | ✅ Match | | `CAN1->BTR |= (1 << 24)` (SJW) | Line 70 | ✅ Match | | `CAN1->sFilterRegister[0].FR1 = 0x06e << 21` | Line 97 | ✅ Match | | `CAN1->sFilterRegister[0].FR2 = 0x7f1 << 21` | Line 100 | ✅ Match | | `CAN1->sTxMailBox[0].TIR |= stdID << 21` | Line 120 | ✅ Match | | `CAN1->sTxMailBox[0].TDTR |= len << 0` | Line 130 | ✅ Match | | CAN send: clear TDLR/TDHR then fill in loop | Lines 134-149 | ✅ Match | | `CAN1->sTxMailBox[0].TIR |= CAN_TI0R_TXRQ` | Line 153 | ✅ Match | | Receive: `msgCount = (CAN1->RF0R & CAN_RF0R_FMP0) >> 0` | Line 165 | ✅ Match | | Receive: `msg->stdID = (CAN1->sFIFOMailBox[0].RIR >> 21) & 0x7ff` | Line 174 | ✅ Match | | Receive: `msg->len = (CAN1->sFIFOMailBox[0].RDTR >> 0) & 0x0f` | Line 177 | ✅ Match | | Receive: RDLR/RDHR extraction loop | Lines 180-195 | ✅ Match | | `CAN1->RF0R |= CAN_RF0R_RFOM0` | Line 198 | ✅ Match | ### Code Comparison: Typedef | Claimed by Note | Actual Code | Match? | |---|---|---| | `typedef struct { uint16_t stdID; uint8_t data[8]; uint8_t len; } RxMsg;` | `can.h` lines 14-19 | ✅ Match | | `#include "stm32f10x.h"` | Line 11 | ✅ Match | ### Code Comparison: main.c (01_can_test_register) Note claims: - Sends 3 messages (IDs 0x066, 0x068, 0x067) with data "abcdefg", "123", "xyz" → **ACCURATE** (lines 22-32) - Reads back from loopback using `CAN_ReceiveMsg` → **ACCURATE** (lines 35-38) - Prints results → **ACCURATE** (lines 40-47) ### HAL CAN (02_can_test_hal) | Claimed by Note | Actual Code (can.c) | Match? | |---|---|---| | `hcan.Init.Prescaler = 36` | Line 41 | ✅ Match | | `hcan.Init.Mode = CAN_MODE_SILENT_LOOPBACK` | Line 42 | ✅ Match | | `hcan.Init.SyncJumpWidth = CAN_SJW_2TQ` | Line 43 | ✅ Match | | `hcan.Init.TimeSeg1 = CAN_BS1_3TQ` | Line 44 | ✅ Match | | `hcan.Init.TimeSeg2 = CAN_BS2_6TQ` | Line 45 | ✅ Match | | `CAN_TxHeaderTypeDef` with `StdId, IDE=CAN_ID_STD, RTR=CAN_RTR_DATA, DLC=len` | Lines 163-167 | ✅ Match | | `HAL_CAN_AddTxMessage(&hcan, &txHeader, data, &txMailBox)` | Line 171 | ✅ Match | | `HAL_CAN_GetRxMessage(&hcan, CAN_RX_FIFO0, &rxHeader, rxMsg[i].data)` | Line 189 | ✅ Match | | `rxMsg[i].stdID = rxHeader.StdId; rxMsg[i].len = rxHeader.DLC` | Lines 190-191 | ✅ Match | | Filter: 32-bit mask mode, all zeros (accept all) | Lines 126-151 | ✅ Match | ## Summary **Overall Accuracy**: Very High (95%+) **Issues Found**: 1. Double `stm32/stm32/` path for project 01 in raw note — does NOT exist on disk 2. All other paths are correct 3. All code snippets match actual source files exactly