Skip to main content
Senior
November 5, 2024
Solved

cannot use NVIC_SetVector

  • November 5, 2024
  • 5 replies
  • 4762 views

I am trying to write interrupts bare-metal style. When I try to set the interrupt vector for LPTIM1 (using B-L071Z-LRWAN1) using this method,

 

NVIC_SetVector(LPTIM1_IRQn, (uint32_t)&LPTIM1_IRQHandler);

 

the compiler gives me this error:

../Core/Src/main.c:87:48: error: 'LPTIM1_IRQHandler' undeclared (first use in this function); did you mean 'TIM6_IRQHandler'?
87 | NVIC_SetVector(LPTIM1_IRQn, (uint32_t)&LPTIM1_IRQHandler);

Which I find bizarre, since I am not using timer 6, and LPTIM1_IQRHandler is listed in startup_stm32l072czyx.s. I tried declaring LPTIM1_IRQHandler as an extern, but with no success. Attached is the startup file.

How do I fix this?

Best answer by Tesla DeLorean

Where is main.c getting its prototype for the LPTIM1_IRQHandler() ?

The body is in the it.c file, do you have a prototype for it in main.h ?

This is the compiler complaining, not that the Linker can't find the body, weak or otherwise. 

5 replies

Chris21
Associate II
November 5, 2024

Apparently in main.c you have a reference to LPTIM1_IQRHandler; LPTIM1_IRQHandler is in the startup file, but LPTIM1_IQRHandler is not...

Senior
November 5, 2024

Yeah that was a typo which I corrected, but the result is still the same. Now it is 

../Core/Src/main.c:87:48: error: 'LPTIM1_IRQHandler' undeclared (first use in this function); did you mean 'TIM6_IRQHandler'?
87 | NVIC_SetVector(LPTIM1_IRQn, (uint32_t)&LPTIM1_IRQHandler);

Chris21
Associate II
November 5, 2024

Why not implement the handler in main.c, over-riding the one in the startup file (which does nothing)?

Senior
November 5, 2024

I am going by examples and courses, and this is the method that was presented in every one. Right now I would like  to find out why using NVIC_SetVector() this way does not work for me, when the exact same implementation works for everyone else.

Pavel A.
Super User
November 5, 2024

Trust the compiler, it won't lie. If it says undeclared, it is undeclared. So make it declared.

 

Senior
November 5, 2024

Absolutely useless answer.

Pavel A.
Super User
November 5, 2024

I am going by examples and courses

This is not enough unfortunately. If basic knowledge of C language is lacking, the examples cannot be understood.

/* But soon we'll have medical doctors practicing like that */

 

Senior
November 5, 2024

I know what declaration is, you arrogant nobody. I am simply stating that your answer is useless because you just repeated what the compiler told me, but in a more snarky tone. And now you have taken to belittling me because you assume I don't know what a declaration is when I told you your answer is useless. Take a look at this attached file. Now compare it to the startup file I posted. Notice how TIM6_IRQHandler is defined as TIM6_DAC_IRQHandler from the startup file? So both TIM6_IRQHandler and TIM6_DAC_IRQHandler works as the last parameter of NVIC_SetVector(). So since LPTIM1_IRQHandler is also in the startup file, it should work the same. Except it doesn't. Heck just for good measure, I added 

 

#define LPTIM1_IRQHandler1			 LPTIM1_IRQHandler

 

in the bottom section of

 

/* Aliases for __IRQHandler */

 

and put that as the last parameter in NVIC_SetVector() with the same results. If you are such a pro at this, certainly you should able to answer exactly why neither of these are working, right? Or are you just going to cover up your own lack of knowledge with more belittling that is extremely telling of your insecurity?

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
November 5, 2024

Where is main.c getting its prototype for the LPTIM1_IRQHandler() ?

The body is in the it.c file, do you have a prototype for it in main.h ?

This is the compiler complaining, not that the Linker can't find the body, weak or otherwise. 

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Senior
November 5, 2024

Thanks for your response, Tesla. It turns out that not having the prototypes in main.h was the exact problem. It makes sense in hindsight. Appreciate it!