STM32 VScode undefined reference HAL_FLASH_Unlock
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-22 4:30 AM
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
- Labels:
-
VSCode for STM32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-22 4:43 AM
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:
- You need to #include the appropriate header(s) in the file(s) where you call the function;
- You need to have the source file(s) which define the function - ie, contain its executable body - in your Project.
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-22 5:01 AM
Hi Andrew, thanks for your quick replay,
- I've #include "stm32c0xx_hal_flash.h" in my main.c
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-22 5:50 AM
@maxl95 wrote:
- The source file is in the defaul directory --> ./Drivers/STM32C0xx_HAL_Driver/Src
And is that file actually getting built?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-22 6:27 AM
I can't find the source file in the output of cmake, so I think not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-25 1:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-13 3:08 AM
Hello @maxl95,
I've just encountered this problem in my project but with STM32F4, and I'm also building with CMake.
I've added the stm32f4xx_hal_flash.c path into my main CMakeLists.txt to PROJECT_SOURCES list along with files from Core/Src. And that works for me.
