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 06:17 AM
@Gladson wrote:Is there anything else that I could have messed up?
Have you (accidentally) messed with any of the USER CODE BEGIN and/or USER CODE END comments?
If they go wrong, then CubeMX might be thinking that its code is now within one of the USER sections - therefore won't update it ... ?
2024-04-12 08:50 PM
I tried after closing all the projects and files in CubeIDE, still not working,
I am using windows 10.
2024-04-12 08:59 PM
I checked for the USER CODE BEGIN and USER CODE END, All the USER CODE BEGIN does have a USER CODE END, I also checked the difference with git but I did not find any changes to those comments. Is there a better way to check this so I can be sure that I did not mess that up?
2024-04-15 05:57 AM
Hello,
Could you please attach your project in a zip file?
2024-10-29 12:13 PM
Hello Gladson
Im here because now i have the same problem of you. I don't know if you could resolve the problem but in my case, i receive this message from the software when i tried to create a new project.
I hope this can be helpful.
2024-10-29 12:38 PM
Hello @LSZ and welcome to the community,
As the OP was not replying since awhile, it's better to open a new thread and describe extactly what you have done.
See tips on how to post a thread.