2021-3-1-can重制日志
stm32的f1的Can的HAL库在1.7.3版本迎来重制
重制日志

The following changes done on the HAL drivers require an update on the application code based on older HAL versions
Rework of HAL CAN driver (compatibility break)
A new HAL CAN driver has been redesigned with new APIs, to bypass limitations on CAN Tx/Rx FIFO management present with previous HAL CAN driver version.
The new HAL CAN driver is the recommended version. It is located as usual in Drivers/STM32F4xx_HAL_Driver/Src and Drivers/STM32f4xx_HAL_Driver/Inc folders. It can be enabled through switch HAL_CAN_MODULE_ENABLED in stm32f4xx_hal_conf.h
The legacy HAL CAN driver is also present in the release in Drivers/STM32F4xx_HAL_Driver/Src/Legacy and Drivers/STM32F4xx_HAL_Driver/Inc/Legacy folders for software compatibility reasons. Its usage is not recommended as deprecated. It can however be enabled through switch HAL_CAN_LEGACY_MODULE_ENABLED in stm32f4xx_hal_conf.h
HAL CAN update
Fields of CAN_InitTypeDef structure are reworked:
SJW to SyncJumpWidth, BS1 to TimeSeg1, BS2 to TimeSeg2, TTCM to TimeTriggeredMode, ABOM to AutoBusOff, AWUM to AutoWakeUp, NART to AutoRetransmission (inversed), RFLM to ReceiveFifoLocked and TXFP to TransmitFifoPriority
HAL_CAN_Init() is split into both HAL_CAN_Init() and HAL_CAN_Start() API's
HAL_CAN_Transmit() is replaced by HAL_CAN_AddTxMessage() to place Tx Request, then HAL_CAN_GetTxMailboxesFreeLevel() for polling until completion.
HAL_CAN_Transmit_IT() is replaced by HAL_CAN_ActivateNotification() to enable transmit IT, then HAL_CAN_AddTxMessage() for place Tx request.
HAL_CAN_Receive() is replaced by HAL_CAN_GetRxFifoFillLevel() for polling until reception, then HAL_CAN_GetRxMessage()
to get Rx message.
HAL_CAN_Receive_IT() is replaced by HAL_CAN_ActivateNotification() to enable receive IT, then HAL_CAN_GetRxMessage()
in the receivecallback to get Rx message
HAL_CAN_Slepp() is renamed as HAL_CAN_RequestSleep()
HAL_CAN_TxCpltCallback() is split into HAL_CAN_TxMailbox0CompleteCallback(), HAL_CAN_TxMailbox1CompleteCallback() and HAL_CAN_TxMailbox2CompleteCallback().
HAL_CAN_RxCpltCallback is split into HAL_CAN_RxFifo0MsgPendingCallback() and HAL_CAN_RxFifo1MsgPendingCallback().
More complete "How to use the new driver" is detailed in the driver header section itself.
翻译:
在HAL驱动程序上进行的以下更改需要基于较旧的HAL版本对应用程序代码进行更新
返工HAL CAN驱动程序(兼容性中断)
已使用新的API重新设计了新的HAL CAN驱动程序,以绕过先前HAL CAN驱动程序版本中存在的CAN Tx / Rx FIFO管理限制。
推荐使用新的HAL CAN驱动程序。它通常位于Drivers / STM32F4xx_HAL_Driver / Src和Drivers / STM32f4xx_HAL_Driver / Inc文件夹中。可以通过stm32f4xx_hal_conf.h中的开关HAL_CAN_MODULE_ENABLED启用它
由于软件兼容性的原因,旧版HAL CAN驱动程序也存在于Drivers / STM32F4xx_HAL_Driver / Src / Legacy和Drivers / STM32F4xx_HAL_Driver / Inc / Legacy文件夹的发行版中。不建议不推荐使用它。但是,可以通过stm32f4xx_hal_conf.h中的开关HAL_CAN_LEGACY_MODULE_ENABLED启用它
HAL CAN更新
修改了CAN_InitTypeDef结构的字段:
SJW到SyncJumpWidth,BS1到TimeSeg1,BS2到TimeSeg2,TTCM到TimeTriggeredMode,ABOM到AutoBusOff,AWUM到AutoWakeUp,NART到自动重传(反向),RFLM到ReceiveFifoLocked和TXFP到TransmitFifoPriority
HAL_CAN_Init()分为HAL_CAN_Init()和HAL_CAN_Start()API
将HAL_CAN_Transmit()替换为HAL_CAN_AddTxMessage()以放置Tx请求,然后放置HAL_CAN_GetTxMailboxesFreeLevel()进行轮询,直到完成。
将HAL_CAN_Transmit_IT()替换为HAL_CAN_ActivateNotification()以启用传输IT,然后使用HAL_CAN_AddTxMessage()进行位置Tx请求。
将HAL_CAN_Receive()替换为HAL_CAN_GetRxFifoFillLevel()以进行轮询,直到接收为止,然后使用HAL_CAN_GetRxMessage()
获取Rx消息。
将HAL_CAN_Receive_IT()替换为HAL_CAN_ActivateNotification()以启用接收IT,然后使用HAL_CAN_GetRxMessage()
在receivecallback中获取Rx消息
HAL_CAN_Slepp()重命名为HAL_CAN_RequestSleep()
HAL_CAN_TxCpltCallback()分为HAL_CAN_TxMailbox0CompleteCallback(),HAL_CAN_TxMailbox1CompleteCallback()和HAL_CAN_TxMailbox2CompleteCallback()。
HAL_CAN_RxCpltCallback分为HAL_CAN_RxFifo0MsgPendingCallback()和HAL_CAN_RxFifo1MsgPendingCallback()。
驱动程序标题部分本身中详细介绍了更完整的“如何使用新驱动程序”。
以下记录对于旧文件和新文件之间的转换写法
//配置过滤器
CAN_FilterConfTypeDef ———————— CAN_FilterTypeDef
//该结构体下的
FilterNumber —————— FilterBank
BankNumber —————— SlaveStartFilterBank
//发送函数
HAL_CAN_Transmit_IT ———— HAL_CAN_AddTxMessage
//示例HAL_CAN_AddTxMessage(&CanHandle, &TxHeader, TxData, &TxMailbox)
//CAN_HandleTypeDef CanHandle
//CAN_TxHeaderTypeDef TxHeader
其中TxData是存放uint8_t类型的8位数组
uint8_t实际上是一个char
https://blog.csdn.net/Mary19920410/article/details/71518130
TxHeader中的IDE就是声明该数据包是扩展还是标准
#define CAN_ID_STD (0x00000000U) /*!< Standard Id */
#define CAN_ID_EXT (0x00000004U) /*!< Extended Id */

浙公网安备 33010602011771号