2023-08-24 01:59 AM
Hello,
For efficiency reason I need to use only the LL, so I enable the LL flag in the CUBEMX configuration.
I would like to have the ISR defined as __weak, so that I can write my own version without replacing manually the ISR.
I know that using HAL drivers the interrupt service routines generated by CubeMX are defined as _weak.
Is there any way to obtain such behaviour using only the LL Drivers?
Microcontroller STM32L072CZ, STM32CubeMX version 6.9.1
Thank you in advance.
Best Regards,
Gianmarco Cerutti
Solved! Go to Solution.
2023-08-24 04:59 AM
In the project properties in the Cube there is option to select which ISRs to create - please check.
2023-08-24 03:36 AM - edited 2023-08-24 03:38 AM
> I would like to have the ISR defined as __weak, so that I can write my own version
All ISRs and exceptions for your specific STM32 model are already defined as weak in startup... s. So you just add your actual ISRs, no need to define non-implemented ones. Just be sure to link with the correct startup... s. Yes this should work even with LL drivers.
2023-08-24 04:36 AM
Thank you very much for your answer.
I see that the startup files has the weak attribute. However, CUBE generates automatically the handlers functions in the stm32l0xx.c file. These are not __weak, therefore as soon as I try to specify my own handler there is a conflict.
not 100% sure, but my understanding is that using HAL also the handlers in stm32l0xx.c file are defined as weak. This is how I would like to generate the handlers also without HAL.
Thank you again
2023-08-24 04:59 AM
In the project properties in the Cube there is option to select which ISRs to create - please check.
2023-08-24 05:03 AM
Hello @gianmarco.cerutti,
Actually, with HAL the behavior is the following:
cube MX generate the handler.
here an example with stm32U5 with LPTIM1 :
cube generate the handler entry point function in stm32u5xx_it.c file:
void LPTIM1_IRQHandler(void)
{
HAL_LPTIM_IRQHandler(&hlptim1);
}
This function call the HAL function HAL_LPTIM_IRQHandler(&hlptim1);
and then, in this HAL function, a __weak sub routine are called.
As an example for /* TIM Update event */ : in file stm32u5xx_hal_tim.c
__weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(htim);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
*/
}
Then as described in comments, you can define your own sub routine HAL_TIM_PeriodElapsedCallback in your user code.
For LL, it's quite different as minimum code are provided to have low level registers access.
In that case you have the solution to create your own "subroutine" and called it in the IRQ handler like below :
void TIM1_UP_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_IRQn 0 */
/* Check whether update interrupt is pending */
if(LL_TIM_IsActiveFlag_UPDATE(TIM1) == 1)
{
/* Clear the update interrupt flag */
LL_TIM_ClearFlag_UPDATE(TIM1);
}
/* USER CODE END TIM1_UP_IRQn 0 */
/* USER CODE BEGIN TIM1_UP_IRQn 1 */
/* TIM1 update interrupt processing */
TimerUpdate_Callback();
/* USER CODE END TIM1_UP_IRQn 1 */
}
So then you can write what you want in your TimerUpdate_Callback();
So HAL has a mechanism of weak but not LL. It is because you manage "almost" all in your side.
NOTE : be care to add your function call between
/* USER CODE BEGIN*/ and
/* USER CODE END */
Then your code will be preserved each time you re generate code with cube MX.
You can find L0 example into STM32Cube_FW_L0_V1.12.2\Projects\NUCLEO-L073RZ\Examples_LL
Best regards
Mikael
2023-08-24 05:08 AM
Thank you Pavel A. for you answer. In my situation, it is better to disable the ISR generation from CUBEMX and write my own version. In this case I don't need the weak definition, there is just no other definition other than mine.
2023-08-24 05:09 AM
Thank you so much for the detailed answer, it helped me a lot to understand the HAL vs LL mechanism in generating the ISR functions
2023-08-24 05:36 AM
You are welcome!