cancel
Showing results for 
Search instead for 
Did you mean: 

How generate hex file without link files Hal_drivers

Fredolive
Associate II

Hello,

When I builed the project, I had seen the Hal drivers files links in the end file *.HEX.

How can I change the project configuration not to put this links in file because it use flash memory unnecessarily ?

Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions

You can get rid of it by not defining USE_FULL_ASSERT .

Or you could change your assert_param definition to not use __FILE__ and, thus, not require that the filenames be stored.

View solution in original post

21 REPLIES 21

What optimisation level are you using?

By default, 'discard unused sections' should be enabled - so unused functions shouldn't appear in the final image.

AndrewNeil_0-1727082105941.png

AndrewNeil_1-1727082142076.png

 

Hi Andrew,

I have -O1 optimisation and your configuration setting.

I give an example of my end Hex file :

0x8005FD0 ........../Drivers/STM32G4xx_Hal_Driver/Src/stm32g4xx_hal_wwdg.c .....

This link in hex file isn't necessarily...

 

 


@Fredolive wrote:

I give an example of my end Hex file :

0x8005FD0 ........../Drivers/STM32G4xx_Hal_Driver/Src/stm32g4xx_hal_wwdg.c .....


You mean your ELF file? The Hex file wouldn't have any symbol information...

I have this links in Hex file

How do you determine that they are actually in the Hex file?

Again, the Hex file contains no symbol information - it is purely code - so where are you seeing that?

Fredolive_0-1727084774631.png

This is my hex file for my application.

You look the links file at the end file Hex

Do you use __FILE__ in your code? Also __LINE__ ?

 

EDIT:

They would appear if you define USE_FULL_ASSERT:

 

 

/* Exported macro ------------------------------------------------------------*/
#ifdef  USE_FULL_ASSERT
/**
  * @brief  The assert_param macro is used for function's parameters check.
  *   expr If expr is false, it calls assert_failed function
  *         which reports the name of the source file and the source
  *         line number of the call that failed.
  *         If expr is true, it returns no value.
  * @retval None
  */
  #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
  void assert_failed(uint8_t* file, uint32_t line);
#else
  #define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */

 

 

 

EDIT 2:

If you do want the ASSERT output, but still want to save a little Flash space, you could use __FILE_NAME__

https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html#:~:text=__FILE_NAME__,myheader.h%22.

 

I tried with adn without __FILE__NAME but I have always roots files in flash space.

 

Then you must have other uses of __FILE_NAME__ elsewhere in your code.

Do a grep through your entire codebase.