2024-04-12 02:01 AM - edited 2024-04-12 03:09 AM
I am working on STM32F103 for a project with CAN. While working I set the CAN Test mode to Loopback in the ioc file, afterwards I set the test mode back to normal mode. but this change was not updated in the main.c file. In main.c file, the line in MX_CAN_Init(void) function still is as following.
hcan.Init.Mode = CAN_MODE_LOOPBACK;
I cleaned the project and then again built the project, still it is same, I tried to change the test mode multiple times, but every time it asks if code should be generated and I select yes, still the code is not changing. Why is this happening?
CAN configuration:
Generated code
static void MX_CAN_Init(void)
{
/* USER CODE BEGIN CAN_Init 0 */
/* USER CODE END CAN_Init 0 */
/* USER CODE BEGIN CAN_Init 1 */
/* USER CODE END CAN_Init 1 */
hcan.Instance = CAN1;
hcan.Init.Prescaler = 16;
hcan.Init.Mode = CAN_MODE_LOOPBACK;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_2TQ;
hcan.Init.TimeSeg2 = CAN_BS2_1TQ;
hcan.Init.TimeTriggeredMode = DISABLE;
hcan.Init.AutoBusOff = DISABLE;
hcan.Init.AutoWakeUp = DISABLE;
hcan.Init.AutoRetransmission = DISABLE;
hcan.Init.ReceiveFifoLocked = DISABLE;
hcan.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN_Init 2 */
/* USER CODE END CAN_Init 2 */
}
Code Generator settings
2024-04-12 02:23 AM
Hello @Gladson
I can't reproduce your issue. Can you share your .IOC file?
Don't forget to click on this button after changes on the .ioc file:
or click Ctrl+s to save changes.
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.
2024-04-12 03:01 AM
I have tried clicked that "Code generation button" and also pressing ctrl + s, both did not work.
Both .IOC file and full project are in this link.
2024-04-12 03:04 AM
I could not access the Drive link. Could you please attach your .ioc file on this post.
Best Regards.
STTwo-32
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.
2024-04-12 03:10 AM
I have updated the access of google drive and have also posted the .IOC file in the post.
2024-04-12 04:07 AM
I can't reproduce that issue. Everything works fine on my side.
I suggest you try using the STM32CubeIDE V1.15.0 and the STM32CubeMX V6.11.0.
Best Regards.
STTwo-32
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.
2024-04-12 04:17 AM
Are you sure you're not referring to another main.c file?
Meanwhile this config is not recommanded:
hcan.Init.TimeSeg1 = CAN_BS1_2TQ;
hcan.Init.TimeSeg2 = CAN_BS2_1TQ;
Need to increase BS1 and BS2 and decrease the prescaler. See my answer in this thread:
https://community.st.com/t5/stm32-mcus-products/can-and-usb-on-stm32767zit6/m-p/661370#M240863
2024-04-12 05:04 AM
Thanks for testing it out! I am using the same version that you mentioned for STM32CubeIDE and STM32CubeMX. Is there anything else that I could have messed up? I also used git in this project, could that affect the project in any way?
2024-04-12 05:18 AM
This is the folder structure of the project. The main.c file in the Src folder is the one that is not getting updated.
Also, thanks for the advice on CAN configuration, I was already having issues with CAN's reliability, I guess it was because of this configuration.
2024-04-12 05:44 AM
I did not reproduce the issue neither.
Please close all the files opened on your IDE workspace and open main.c again and check.
On which windows you are running CubeIDE?