cancel
Showing results for 
Search instead for 
Did you mean: 

HUGE Problem: STM32F767 CAN1 stuck in HAL_CAN_Init with STMCube

Benji K
Associate
Posted on March 14, 2017 at 01:39

Hello everyone,

I'm using the STM32F767ZIT on a custom PCB with an external 25MHz crystal. The project greatly involves around receiving messages from three separate controller area network (CAN) buses at 1 Mbits.

I used the STMCube to map the functions/pins to the hardware and to generate c-code for the inits. For some reason, I get stuck in the HAL_CAN_Init every time without even adding a single line of user code. CAN TX is connected to PB9 and CAN RX is connected to PB8.

The microcontroller doesn't seem to reset the INAK bit and therefore gets stuck in the while loop at line 306 in the stm32f7xx_hal_can.c file. According to the reference manual,

'This bit is set by hardware and indicates to the software that the CAN hardware is now in initialization mode. This bit acknowledges the initialization request from the software (set INRQ bit in CAN_MCR register). This bit is cleared by hardware when the CAN hardware has left the initialization mode (to be synchronized on the CAN bus). To be synchronized the hardware has to monitor a sequence of 11 consecutive recessive bits on the CAN RX signal.'

So I believe there's either a problem with the acknowledges from the CAN bus or a bug in the HAL driver or maybe even somewhere in the silicone of the STM32F767...

By the way, I am indeed connected to an active CAN node with correct CAN termination when running the init code, so I should be getting acknowledges. There are also no short circuits between the RX and TX pins.

Note that if I uncomment MX_CAN1_Init and set up CAN2 I am able to

send messages with CAN2

using the same clock setup and bit timings. However,

I cannot receive any messages using CAN2

. I've read some posts on here that CAN2 (slave) might not work completely without initializing CAN1 (master) correctly as they are not 100% independent of each other. I hope solving the issue with the

HAL_CAN_Init  of the MX_

CAN1_Init will solve the receiving problem with CAN2 as well. 

Even more interestingly, I can

send and receive messages with CAN3

using the same settings as for the other two CANs. The circuit of the custom PCB is the same for all three CANs. (I do get some bus errors when sending and receiving messages: sending loss around 5-10%, receive loss around 2-4%).

This whole thing seems very strange....for reasons of clarity I only attached the source code for a setup using only CAN1 and some timers. However, the problem remains the same. I am not able to get out of the

HAL_CAN_Init  

with the posted source code as shown here.

Has CAN1 been tested yet on PB9 and PB8 for the STM32F767ZIT using code generation from STMCube (baud rate irrelevant)??

If yes, I'd greatly appreciate it if you could provide the STMCube file (*.ioc) with all the Cube settings or the corresponding source code. Then, I could eliminate any possible bugs in the STMCube or silicone as well as wrong configs. Instead I could rather focus on the hardware of the custom PCB.

Even weirder is that a colleague is experiencing the exact same problem in the CAN1 init with his PCB using the STM32F446. He is using only slightly different hardware and no external crystal, though.

If you have any idea what to look for, please let me know as soon as possible. I appreciate any response whether it may concern the hardware, software or any settings of the STMCube. I'm running out of ideas as to what to check next... I have already tried a LOT of things from a hardware standpoint. However, sometimes the easiest and most obvious bugs get overlooked. 

Thank you very much in advance!

Greetings 

Benji 

#stm32f7 #stm32cubemx*
1 REPLY 1
T J
Lead
Posted on March 14, 2017 at 12:37

I have 3 new computer boards to complete my set.

I have a very successful implementation of CAN on my first PCB based on a STM32F091, it runs CAN brilliantly, with over 70% bus utilization, 15 packets streaming every 10mS without issue at 250KHz, without a crystal.

Today, I had trouble in the exact same place as you, on the new second board,

( a totally different board with the same processor, hence a new CUBE file)

I had to disable Can to bring the new STM32F091 PCB up.

I am sure the problem is in the CUBE file. I will know in a few days.

Your processor is on my third PCB, the STM32F767BIT with a 25MHz external OSC as you do,

with CAN on PB8 and PB9.

I hope to have CAN working next week. I am available for you if I can help.

feel free to direct message me.

I will look into the issue now, comparing the 'working' to the 'non working' CUBE files.

I fixed it temporarily by removing the my CAN startup code.

MX_CAN_Init is running now, it seems that my startup code had not completed correctly and had locked up the hardware.

It needed a power down and now it progresses through MX_CAN_Init correctly.

I am running Cube V4.19, which version are you using ?

Cube V4.20 seems to have several issues.