2023-02-20 09:13 AM
Hi,
I am developing a device which uses CAN interface. My code is 'bare metal'. I am using arm-none-eabi combined with cmake and vscode. Assembly and CMSIS are taken from cube generated project.
The problem is that immediatly after setting RCC_APB1ENR1_FDCANEN bit the FDCAN_IR_ARA bit is set by hardware. The code is very simple:
void main()
{
RCC->CCIPR &= ~RCC_CCIPR_FDCANSEL;
RCC->CCIPR |= RCC_CCIPR_FDCANSEL_1;
RCC->APB1ENR1 |= RCC_APB1ENR1_FDCANEN;
FDCAN1->CCCR |= FDCAN_CCCR_INIT;
//here the FDCAN1->IR ARA bit is setted
while ((FDCAN1->CCCR & FDCAN_CCCR_INIT) != FDCAN_CCCR_INIT)
;
FDCAN1->CCCR |= FDCAN_CCCR_CCE;
FDCAN1->CCCR |= FDCAN_CCCR_DAR;
FDCAN1->CCCR |= FDCAN_CCCR_PXHD; // Protocol exception handling
FDCAN1->NBTP = 0x100403;
}
I was not able to reproduce this error in STM32CubeIDE. I've pasted same lines to the empty project and it worked. Therefore i must by not doing something that CubeIDE is. I read through HAL library for FDCAN and I am pretty sure that this code should work.
Any ideas?
Solved! Go to Solution.
2023-05-08 03:49 AM
I found out that the issue is related to cortex-debug addon to VSCode. I don't have any further ideas to investigate it more.
2023-03-01 02:03 AM
Hello @KJona.2,
Probably, it may be helpful to review the clock configuration for the FDCAN peripheral to ensure that it is correctly configured and that the appropriate clock signals are being sent to the peripheral.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-03-27 03:19 AM
Hi,
I'am still trying to solve the issue. Could you please specify on which values i should pay special attention?
I can not see any difference between STM32 IDE code and mine. All clock values related to FDCAN are the same.
The problem is that code below work in STM32 IDE and don't work using other environment.
#include "stm32g431xx.h"
int main()
{
RCC->CCIPR &= ~RCC_CCIPR_FDCANSEL;
RCC->CCIPR |= RCC_CCIPR_FDCANSEL_1;
RCC->APB1ENR1 |= RCC_APB1ENR1_FDCANEN;
while(1);
}
2023-03-27 05:28 AM
Maybe you must select a clock source first for the CAN peripheral ?
(I don't know the G4's CAN)
In the HAL CAN example - I think - there is also some forced CAN peripheral reset.
2023-03-28 07:31 AM
Line 4 and 6 of mentioned snippet are setting FDCAN clock source to PCLK. I've also tested PLL and HSE as clock source. Still same behaviour. Am I missing something?
The code snippet in my previous reply is working when I compile it with STM32 IDE. Not working when I compile it using same assembly and toolchain but using cmake ank make.
2023-04-21 06:14 AM
Hi,
I have done more investigation... After following steps:
Than I found out 2 things:
The behavior is the same when using OpenOCD or STLINK GDB.
So... Everything is working untill I attach to running program or start debuging using vscode and cortex -debug...
2023-05-08 03:49 AM
I found out that the issue is related to cortex-debug addon to VSCode. I don't have any further ideas to investigate it more.