eric2013 发表于 2023-1-4 00:53:21

H7-TOOL的CAN/CANFD助手实现SWD接口方式读取目标板CAN错误状态监测


这几天做CAN/CANFD/CANopen专题视频教程,正好研究下这个实现。起初是打算采用这个功能实现,只是当前还没有好点的LUA转换方案

最近开始酝酿H7-TOOL的新玩法,直接读取各个IC厂家提供的CMSIS SVD文件生成LUA程序,像MDK,IAR在线调试那样实时检测外设状态
https://www.armbbs.cn/forum.php?mod=viewthread&tid=116854


所以干脆准备自己手动整理一组数组了,直接通过HAL库的寄存器定义整理就行了,也非常方便。

#define FDCAN1_BASE         (D2_APB1PERIPH_BASE + 0xA000UL)
#define FDCAN2_BASE         (D2_APB1PERIPH_BASE + 0xA400UL)
#define FDCAN1            ((FDCAN_GlobalTypeDef *) FDCAN1_BASE)
#define FDCAN2            ((FDCAN_GlobalTypeDef *) FDCAN2_BASE)
#define FDCAN_CCU         ((FDCAN_ClockCalibrationUnit_TypeDef *) FDCAN_CCU_BASE)

/**
* @brief FD Controller Area Network
*/

typedef struct
{
__IO uint32_t CREL;         /*!< FDCAN Core Release register,                                     Address offset: 0x000 */
__IO uint32_t ENDN;         /*!< FDCAN Endian register,                                           Address offset: 0x004 */
__IO uint32_t RESERVED1;    /*!< Reserved,                                                                        0x008 */
__IO uint32_t DBTP;         /*!< FDCAN Data Bit Timing & Prescaler register,                      Address offset: 0x00C */
__IO uint32_t TEST;         /*!< FDCAN Test register,                                             Address offset: 0x010 */
__IO uint32_t RWD;          /*!< FDCAN RAM Watchdog register,                                     Address offset: 0x014 */
__IO uint32_t CCCR;         /*!< FDCAN CC Control register,                                       Address offset: 0x018 */
__IO uint32_t NBTP;         /*!< FDCAN Nominal Bit Timing & Prescaler register,                   Address offset: 0x01C */
__IO uint32_t TSCC;         /*!< FDCAN Timestamp Counter Configuration register,                  Address offset: 0x020 */
__IO uint32_t TSCV;         /*!< FDCAN Timestamp Counter Value register,                        Address offset: 0x024 */
__IO uint32_t TOCC;         /*!< FDCAN Timeout Counter Configuration register,                  Address offset: 0x028 */
__IO uint32_t TOCV;         /*!< FDCAN Timeout Counter Value register,                            Address offset: 0x02C */
__IO uint32_t RESERVED2; /*!< Reserved,                                                                0x030 - 0x03C */
__IO uint32_t ECR;          /*!< FDCAN Error Counter register,                                    Address offset: 0x040 */
__IO uint32_t PSR;          /*!< FDCAN Protocol Status register,                                  Address offset: 0x044 */
__IO uint32_t TDCR;         /*!< FDCAN Transmitter Delay Compensation register,                   Address offset: 0x048 */
__IO uint32_t RESERVED3;    /*!< Reserved,                                                                        0x04C */
__IO uint32_t IR;         /*!< FDCAN Interrupt register,                                        Address offset: 0x050 */
__IO uint32_t IE;         /*!< FDCAN Interrupt Enable register,                                 Address offset: 0x054 */
__IO uint32_t ILS;          /*!< FDCAN Interrupt Line Select register,                            Address offset: 0x058 */
__IO uint32_t ILE;          /*!< FDCAN Interrupt Line Enable register,                            Address offset: 0x05C */
__IO uint32_t RESERVED4; /*!< Reserved,                                                                0x060 - 0x07C */
__IO uint32_t GFC;          /*!< FDCAN Global Filter Configuration register,                      Address offset: 0x080 */
__IO uint32_t SIDFC;      /*!< FDCAN Standard ID Filter Configuration register,               Address offset: 0x084 */
__IO uint32_t XIDFC;      /*!< FDCAN Extended ID Filter Configuration register,               Address offset: 0x088 */
__IO uint32_t RESERVED5;    /*!< Reserved,                                                                        0x08C */
__IO uint32_t XIDAM;      /*!< FDCAN Extended ID AND Mask register,                           Address offset: 0x090 */
__IO uint32_t HPMS;         /*!< FDCAN High Priority Message Status register,                     Address offset: 0x094 */
__IO uint32_t NDAT1;      /*!< FDCAN New Data 1 register,                                       Address offset: 0x098 */
__IO uint32_t NDAT2;      /*!< FDCAN New Data 2 register,                                       Address offset: 0x09C */
__IO uint32_t RXF0C;      /*!< FDCAN Rx FIFO 0 Configuration register,                        Address offset: 0x0A0 */
__IO uint32_t RXF0S;      /*!< FDCAN Rx FIFO 0 Status register,                                 Address offset: 0x0A4 */
__IO uint32_t RXF0A;      /*!< FDCAN Rx FIFO 0 Acknowledge register,                            Address offset: 0x0A8 */
__IO uint32_t RXBC;         /*!< FDCAN Rx Buffer Configuration register,                        Address offset: 0x0AC */
__IO uint32_t RXF1C;      /*!< FDCAN Rx FIFO 1 Configuration register,                        Address offset: 0x0B0 */
__IO uint32_t RXF1S;      /*!< FDCAN Rx FIFO 1 Status register,                                 Address offset: 0x0B4 */
__IO uint32_t RXF1A;      /*!< FDCAN Rx FIFO 1 Acknowledge register,                            Address offset: 0x0B8 */
__IO uint32_t RXESC;      /*!< FDCAN Rx Buffer/FIFO Element Size Configuration register,      Address offset: 0x0BC */
__IO uint32_t TXBC;         /*!< FDCAN Tx Buffer Configuration register,                        Address offset: 0x0C0 */
__IO uint32_t TXFQS;      /*!< FDCAN Tx FIFO/Queue Status register,                           Address offset: 0x0C4 */
__IO uint32_t TXESC;      /*!< FDCAN Tx Buffer Element Size Configuration register,             Address offset: 0x0C8 */
__IO uint32_t TXBRP;      /*!< FDCAN Tx Buffer Request Pending register,                        Address offset: 0x0CC */
__IO uint32_t TXBAR;      /*!< FDCAN Tx Buffer Add Request register,                            Address offset: 0x0D0 */
__IO uint32_t TXBCR;      /*!< FDCAN Tx Buffer Cancellation Request register,                   Address offset: 0x0D4 */
__IO uint32_t TXBTO;      /*!< FDCAN Tx Buffer Transmission Occurred register,                  Address offset: 0x0D8 */
__IO uint32_t TXBCF;      /*!< FDCAN Tx Buffer Cancellation Finished register,                  Address offset: 0x0DC */
__IO uint32_t TXBTIE;       /*!< FDCAN Tx Buffer Transmission Interrupt Enable register,          Address offset: 0x0E0 */
__IO uint32_t TXBCIE;       /*!< FDCAN Tx Buffer Cancellation Finished Interrupt Enable register, Address offset: 0x0E4 */
__IO uint32_t RESERVED6; /*!< Reserved,                                                                0x0E8 - 0x0EC */
__IO uint32_t TXEFC;      /*!< FDCAN Tx Event FIFO Configuration register,                      Address offset: 0x0F0 */
__IO uint32_t TXEFS;      /*!< FDCAN Tx Event FIFO Status register,                           Address offset: 0x0F4 */
__IO uint32_t TXEFA;      /*!< FDCAN Tx Event FIFO Acknowledge register,                        Address offset: 0x0F8 */
__IO uint32_t RESERVED7;    /*!< Reserved,                                                                        0x0FC */
} FDCAN_GlobalTypeDef;











byccc 发表于 2023-1-4 10:49:38

很有意义的功能。

eric2013 发表于 2023-1-4 11:00:37

byccc 发表于 2023-1-4 10:49
很有意义的功能。

今晚整理完毕周报后,准备研究实现下

eric2013 发表于 2023-1-6 00:43:25

白天可以研究起来了。

eric2013 发表于 2023-1-19 01:33:49

已经在整理中,这两天整理完毕。
页: [1]
查看完整版本: H7-TOOL的CAN/CANFD助手实现SWD接口方式读取目标板CAN错误状态监测