Skip to main content
Associate II
Apr 7, 2025 12:51 PM UTC
Solved

STM32L0 Problem with EXTI handler on platform.io & arduino framework

Hi,

 

I'm using a STM32L031K6 with platform.io & arduino framework. I know this forum is not relevant to platform.io or arduino, but most of my code is with LL drivers which should change nothing (but maybe ?).

 

First, i don't understand the IRQn. I'm using PB1 as input interrupt on rising, it's on line 1, so to start, it should be :

 
NVIC_EnableIRQ(EXTI0_1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
//as refered :
 EXTI0_1_IRQn = 5, /*!< EXTI Line 0 and 1 Interrupts 

But the interrupt work only if i enable EXTI2_3_IRQn. I don't get it, and in example EXTI_ToggleLedOnIT for NUCLEO-L073RZ, there is the same +1 on IRQn.

So, change made, and i can see the change of the interrupt on IEXTI->PR, depending on the rising on PB1. the problem is the call back function. On STM32 IDE, there is a *_it.h/c which don't exist on platform.io. Maybe the point come here.

First, i wanted to change the function handler using :

void IRQ_Module_0(void) {;}

NVIC_SetVector(EXTI2_3_IRQn, (uint32_t) &IRQ_Module_0);

But it seems to do nothing as the adress return by NVIC_GetVector stay the same. Or maybe i forgot something.

Second, i try to figure out with the defaut handler (which was hard to find, documentation is not clear) :

/**
 * @brief This function handles external line 2 to 3 interrupt request.
 * None
 * @retval None
 */
void EXTI2_3_IRQHandler(void)
{
 uint32_t pin;
 for (pin = GPIO_PIN_2; pin <= GPIO_PIN_3; pin = pin << 1) {
 HAL_GPIO_EXTI_IRQHandler(pin);
 }
}
// ->
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
 /* EXTI line interrupt detected */
 if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
 {
 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
 HAL_GPIO_EXTI_Callback(GPIO_Pin);
 }
}
// ->
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
 /* Prevent unused argument(s) compilation warning */
 UNUSED(GPIO_Pin);

 /* NOTE: This function Should not be modified, when the callback is needed,
 the HAL_GPIO_EXTI_Callback could be implemented in the user file
 */
}

with a new function :

extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {;}

 And get an error :

test.cpp:(.text.HAL_GPIO_EXTI_Callback+0x0): multiple definition of `HAL_GPIO_EXTI_Callback'; .pio/build/nucleo_l031k6/SrcWrapper/src/stm32/interrupt.cpp.o:interrupt.cpp:(.text.HAL_GPIO_EXTI_Callback+0x0): first defined here

But it is defined as __weak

There is also in interrupt.cpp some :

void EXTI0_IRQHandler(void)
{
 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
}

 Finally, i'm totally lost. Did i make some missunderstanding ? Or maybe it is relative to platform.io ?

I search for some same error and didn't find it.

Some help would be appreciate.

Thx in advance,

This topic has been closed for replies.
FrogBest answer
Associate II
Apr 7, 2025 6:30 PM UTC

So, i add __weak to EXTI0_1_IRQHandler and EXTI1_2_IRQHandler inside framework-arduinoststm32\libraries\SrcWrapper\src\stm32\interrupt.cpp

It's dirty, but fastest way to solve it. I need to go to stmcube framework, but can't find a "all in one" LL (or HAL) printf library. Actually, i don't want to make my own.

Thanks,

5 replies

Andrew Neil
Super User
Apr 7, 2025 1:31 PM UTC

@Frog wrote:

I know this forum is not relevant to platform.io or arduino, ,


Indeed - maybe better to try here: https://www.stm32duino.com/

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
FrogAuthor
Associate II
Apr 7, 2025 2:22 PM UTC

In fact, there is a mistake cause of VSCode when i was looking to the function

__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

Refer to the hal_gpio library, but in fact, it is declared inside interrupt.cpp

/**
 * @brief This function his called by the HAL if the IRQ is valid
 * @PAram GPIO_Pin : one of the gpio pin
 * @retval None
 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
 uint8_t irq_id = get_pin_id(GPIO_Pin);

 if (gpio_irq_conf[irq_id].callback != NULL) {
 gpio_irq_conf[irq_id].callback();
 }
}

 

But arduino framework or not, that change nothing about the EXTI2_3_IRQn for line1 and the problem of NVIC_SetVector which are from LL drivers

FrogAuthorBest answer
Associate II
Apr 7, 2025 6:30 PM UTC

So, i add __weak to EXTI0_1_IRQHandler and EXTI1_2_IRQHandler inside framework-arduinoststm32\libraries\SrcWrapper\src\stm32\interrupt.cpp

It's dirty, but fastest way to solve it. I need to go to stmcube framework, but can't find a "all in one" LL (or HAL) printf library. Actually, i don't want to make my own.

Thanks,