cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 VScode undefined reference HAL_FLASH_Unlock

maxl95
Associate II

Hello everyone,

I am currently taking my first steps with the STM32VScode extension. Previously I worked exclusively with the STM32cubeIDE.

I created a Cmake project via STM32cubeMX, which I then imported via the STM32 VScode extension. Everything worked fine. The build process afterwards was successful and I was able to run the program on my Nucleo-C31C6 board.

Now I want to access the flash memory. But as soon as I insert the function HAL_FLASH_Unlock() into my code, the following error occurs during the build process: main.c:109: undefined reference to `HAL_FLASH_Unlock'.

How do I have to include the HAL drivers correctly so that I can use the function?

 

maxl95

5 REPLIES 5
Andrew Neil
Evangelist III

So do you have a definition for HAL_FLASH_Unlock anywhere in your project?

 


@maxl95 wrote:

How do I have to include the HAL drivers correctly so that I can use the function?


As with any C code:

  1. You need to #include the appropriate header(s) in the file(s) where you call the function;
  2. You need to have the source file(s) which define the function - ie, contain its executable body - in your Project.

Hi Andrew, thanks for your quick replay,

  1. I've #include "stm32c0xx_hal_flash.h" in my main.c
  2. The source file is in the defaul directory --> ./Drivers/STM32C0xx_HAL_Driver/Src

I have also successfully used other functions (e.g. LL_USART) where the problem did not occur.


@maxl95 wrote:
  1.  
  2. The source file is in the defaul directory --> ./Drivers/STM32C0xx_HAL_Driver/Src

And is that file actually getting built?

I can't find the source file in the output of cmake, so I think not

Nawres GHARBI
ST Employee

Hello @maxl95 

Actually Flash drivers are by default integrated to your project

If you are adding HAL_FLASH_Unlock()  to a custom file you can include main.h or stm32c0xx_hal_conf.h to get flash functions available in your custom file