2017-07-03 04:19 PM
CanTxMsgTypeDef* pTxMsg, pRxMsg and pRx1Msg in CAN_HandleTypeDef are never initialized.
I am convinced that they shouldn't be pointers and should just be defined as part of the structure directly, as in:
typedef struct
{ CAN_TypeDef *Instance; /*!< Register base address */ CAN_InitTypeDef Init; /*!< CAN required parameters */ CanTxMsgTypeDef TxMsg; /*!< Rransmit structure */ CanRxMsgTypeDef RxMsg; /*!< Reception structure for RX FIFO0 msg */ CanRxMsgTypeDef Rx1Msg; /*!< Reception structure for RX FIFO1 msg */ __IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */ HAL_LockTypeDef Lock; /*!< CAN locking object */ __IO uint32_t ErrorCode; /*!< CAN Error code */}CAN_HandleTypeDef;See attached diff file for the complete fix. I am using STM32Cube_FW_F4_V1.16.0 but I am pretty sure this applies to many older versions.
#bug #can #hal2017-10-12 04:05 AM
pTxMsg is a pointer to a message buffer structure.
You need to define you own message buffer of type CanTxMsgTypeDef and then point pTxMsg at it.
void CAN_Tx(CAN_HandleTypeDef* canHandle)
{ if (canHandle->Instance==CAN) { / /* Create message buffer CanTxMsgTypeDef TxMessage; <<- Buffer to hold transmit message//* Configure message
TxMessage.StdId = 0x123; TxMessage.RTR = CAN_RTR_DATA; TxMessage.IDE = CAN_ID_STD; TxMessage.DLC = 8; TxMessage.Data[0] = 0x01; TxMessage.Data[1] = 0x23; TxMessage.Data[2] = 0x45; TxMessage.Data[3] = 0x67; TxMessage.Data[4] = 0x89; TxMessage.Data[5] = 0xAB; TxMessage.Data[6] = 0xCD; TxMessage.Data[7] = 0xEF;//* Point to message
canHandle->pTxMsg = &TxMessage; //* <--- Point to newly created message bufferdo
{ TransmitMailbox = HAL_CAN_Transmit(canHandle, 10); } while( TransmitMailbox == CAN_TXSTATUS_NOMAILBOX );}
}