2023-03-28 02:01 AM
So here Usart1 is shared
in the code generated though we have defined in the CM7 and CM4 main.c files:
UART_HandleTypeDef huart1;
The uart is setup in the CM4 main:
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
All fair and good, uart is working from the CM4.
The CM7 huart1 though is at a different address, so nothings going to work there!
I can place this in shared memory at a known location and get it working that way but the next time Cube generates the code that huart1 definition is coming back.
Am I missing something here in Cube to get this working correctly?
Thanks
Andy
Solved! Go to Solution.
2023-03-28 03:05 AM
Hello @ACapo.1
First let me thank you for posting .
It seems that you have correctly identified the issue with sharing the UART peripheral between the CM4 and CM7 cores on your microcontroller. Since the UART1 peripheral is located at a different address on the CM7 core, the code generated by CubeMX for the CM7 core will not work as-is.
One way to resolve this issue is to define the huart1 variable in a shared memory section that both cores can access. This way, both cores can use the same variable to interact with the UART1 peripheral, regardless of which core is currently executing. To do this, you can define the variable as a global variable in a file that is included in both the CM4 and CM7 projects, and then use the linker script to place the variable in the shared memory section.
However, as you noted, if CubeMX generates code that includes a local definition of huart1, it may overwrite your shared definition. To prevent this, you can modify the CubeMX generated code to remove the local definition of huart1, and instead include a header file that defines the shared
huart1 variable. You can then include this header file in both the CM4 and CM7 projects to ensure that both cores use the shared variable.
Thx
Ghofrane
2023-03-28 03:05 AM
Hello @ACapo.1
First let me thank you for posting .
It seems that you have correctly identified the issue with sharing the UART peripheral between the CM4 and CM7 cores on your microcontroller. Since the UART1 peripheral is located at a different address on the CM7 core, the code generated by CubeMX for the CM7 core will not work as-is.
One way to resolve this issue is to define the huart1 variable in a shared memory section that both cores can access. This way, both cores can use the same variable to interact with the UART1 peripheral, regardless of which core is currently executing. To do this, you can define the variable as a global variable in a file that is included in both the CM4 and CM7 projects, and then use the linker script to place the variable in the shared memory section.
However, as you noted, if CubeMX generates code that includes a local definition of huart1, it may overwrite your shared definition. To prevent this, you can modify the CubeMX generated code to remove the local definition of huart1, and instead include a header file that defines the shared
huart1 variable. You can then include this header file in both the CM4 and CM7 projects to ensure that both cores use the shared variable.
Thx
Ghofrane
2023-03-29 12:00 AM
Hi @Ghofrane GSOURI
Thanks for the info.
Andy