cancel
Showing results for 
Search instead for 
Did you mean: 

Can driver fault on cortex M4 Stm32f407

lirony027
Associate
Posted on November 28, 2016 at 13:24

Hello,

Im using NI Can with labview application that shows recieved messages.

the cortex is connected to transciever.

Both NI and the transciever are terminated correctly.

when im starting to transmit and the NI is not connected i get acknowledgement error because no one listening, But when im connecting the NI to the computer i get Bit recessive error, the transmit error counter jumps to 248, and the cortex get Bus off error which it cant recover from. (only by reset)

Does anyone knows what could be the problem?

im using this source code:

#include ''stm32f4xx.h''
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_ClocksTypeDef RCC_Clocks;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CanTxMsg TxMessage;
RCC_GetClocksFreq(&RCC_Clocks);
/* CAN GPIOs configuration **************************************************/
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/* Connect CAN pins */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);
/* Configure CAN RX and TX pins */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* CAN configuration ********************************************************/
/* Enable CAN clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
/* Requires a clock with integer division into APB clock */
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; 
CAN_InitStructure.CAN_BS1 = CAN_BS1_7tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler = 20; 
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber = 0; // CAN1 [ 0..13]
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; // IdMask or IdList
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; // 16 or 32
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; // Everything, otherwise 11-bit in top bits
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; // Rx
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
// transmit */
TxMessage.StdId = 0x123;
TxMessage.ExtId = 0x00;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD;
TxMessage.DLC = 8;
TxMessage.Data[0] = 0x02;
TxMessage.Data[1] = 0x11;
TxMessage.Data[2] = 0x11;
TxMessage.Data[3] = 0x11;
while(1) // Do not want to exit
{
static int j = 0;
uint8_t TransmitMailbox = 0;
TxMessage.Data[4] = (j >> 0) & 0xFF; // Cycling
TxMessage.Data[5] = (j >> 8) & 0xFF;
TxMessage.Data[6] = (j >> 16) & 0xFF;
TxMessage.Data[7] = (j >> 24) & 0xFF;
j++;
TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);

}
}

recessive

2 REPLIES 2
Walid FTITI_O
Senior II
Posted on November 30, 2016 at 18:36

Hi macro,

I think It is may be related to a lock/unlock mechanism issue in the Cube library like this

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20CAN%20HAL%20library%20-%20TX%20and%20RX&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&cur...

. This process is under review and a rework will be implemented. Meanwhile,the best approach would be simply removing the call to the lock and unlock in the function Can_Transmit() as no critical section lock is really required for these drivers.

-Hannibal-

Posted on November 30, 2016 at 19:04

Looks to be using SPL, not HAL, and the code has a familiar look to it.

Please be specific about the AHB/APB bus speeds, and the expectations for the CAN bit/baud rate being used here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..