AnsweredAssumed Answered

function assert_failed() empty after STM32CubeMx regeneration

Question asked by k.g on Apr 25, 2014
Latest reply on May 1, 2014 by Neo911
Hello

Problem with code in assert_failed() in main.c when using STM32CubeMX for F4
The assert_failed() is not in protected USER CODE BEGIN .. USER CODE END block - it is intended?

----------------------------------------------------------------
file main.c generated with STM32Cube :

...

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

}

#endif

----------------------------------------------------------------
another problem is with /* #define USE_FULL_ASSERT    1 */ in stm32f4xx_hal_conf.h


1. If I uncomment #define USE_FULL_ASSERT 1 in stm32f4xx_hal_conf.h  and implement code in USER CODE 4 block:

/* USER CODE BEGIN 4 */
void assert_failed(uint8_t* file, uint32_t line) { ....}
/* USER CODE END 4 */

then compiler raise error: redefinition of 'assert_failed' because of second empty declaration assert_failed in #ifdef USE_FULL_ASSERT .. #endif block

2. If I implement code in #ifdef USE_FULL_ASSERT .. #endif block, then after regeneration is empty (deleted any previous code)

What is solution?

Outcomes