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!