2014-09-08 09:51 AM
I am trying to assign a value to the IDE bit. But when I try to write this I am getting a �HardFault_Handler�. I am sure it has to do with my syntax, but I have been writing requirements for too many years now and not enough code, so any help is appreciated.
My current attempt is:
hcan.pTxMsg->IDE = 0x04;
Cube generated the following structures:
CAN_HandleTypeDef hcan
typedef struct{
uint32_t StdId
uint32_t ExtId
uint32_t IDE
uint32_t RTR
uint32_t DLC
uint32_t Data[8
}CanTxMsgTypeDef;
typedef struct{
CAN_TypeDef *Instance
CAN_InitTypeDef Init
CanTxMsgTypeDef *pTxMsg
CanRxMsgTypeDef *pRxMsg
HAL_LockTypeDef Lock
__IO HAL_CAN_StateTypeDef State
__IO HAL_CAN_ErrorTypeDef ErrorCode
}CAN_HandleTypeDef;
#stm32-cube2014-09-08 10:05 AM
And have you set the buffer pointer to actually point at some memory structure or is it NULL?
What is the address of the memory causing the Hard Fault?2014-09-08 10:19 AM
Sorry I am not sure how to set the pointer buffer. So I am sure that my issue. Anything you could do to direct me I appreciate.
HardFault = 0x080001A62014-09-08 10:28 AM
Sorry I am not sure how to set the pointer buffer.
CanTxMsgTypeDef Tx[1]; hcan.pTxMsg = &Tx[0]; No, I think that's the address of the instruction, probably after the faulting code, it's not the address of the memory access (the thing it's trying to access). You'd want to look at the assembler code, and the registers in the processor, when it faults.
2014-09-08 10:32 AM
printf(''%p\n'', hcan.pTxMsg);
2014-09-08 11:08 AM
Thank you very much. Its going much better.
Just to make sure I understand it.You create TX as a type CanTxMsgTypeDef, which allocates the memory location.You then point hcan.pTxMsg to that memory location so I have a location to write the value for IDE.I guess old dogs can learn a new trick.I think the address location you are looking for was: 0x080030B0, at least that's what being loaded from the register into the PC right after I wrote to the IDE flag and the exception is called.2014-09-09 10:36 AM
Hiebommer,
After investigating your code, it turned out that the Hard Fault occurs due the noninitializationof the pTxMsg pointer. You've just to inilialize thepTxMsgpointer, by declaring a global variable or a local static one./**
* @brief Configures the CAN.
* @param None
* @retval None
*/
static void CAN_Config(void)
{
CAN_FilterConfTypeDef sFilterConfig;
static CanTxMsgTypeDef TxMessage; // Static variable declaration
static CanRxMsgTypeDef RxMessage;
/*##-1- Configure the CAN peripheral #######################################*/
CanHandle.Instance = CAN1;
CanHandle.pTxMsg = &TxMessage; // Pointer initialization
CanHandle.pRxMsg = &RxMessage;
CanHandle.Init.TTCM = DISABLE;
CanHandle.Init.ABOM = DISABLE;
CanHandle.Init.AWUM = DISABLE;
CanHandle.Init.NART = DISABLE;
CanHandle.Init.RFLM = DISABLE;
CanHandle.Init.TXFP = DISABLE;
CanHandle.Init.Mode = CAN_MODE_NORMAL;
CanHandle.Init.SJW = CAN_SJW_1TQ;
CanHandle.Init.BS1 = CAN_BS1_6TQ;
CanHandle.Init.BS2 = CAN_BS2_8TQ;
CanHandle.Init.Prescaler = 2;
if(HAL_CAN_Init(&CanHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
To have enough insight into, you can refer toFirmware\Projects\STM324xG_EVAL\Examples\CAN\
CAN_Networkingas a reference example, available
under the STM32CubeF4 firmware package.
Regards.