2014-04-25 01:09 AM
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 */ &sharpifdef 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) */ } &sharpendif ---------------------------------------------------------------- another problem is with /* &sharpdefine USE_FULL_ASSERT 1 */ in stm32f4xx_hal_conf.h 1. If I uncomment &sharpdefine 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 &sharpifdef USE_FULL_ASSERT .. &sharpendif block 2. If I implement code in &sharpifdef USE_FULL_ASSERT .. &sharpendif block, then after regeneration is empty (deleted any previous code) What is solution? #stm32cube-assert_failed2014-04-25 04:24 AM
2014-04-25 06:06 AM
Thanks for workaround, it works.
Some improvement - add flag to compiler -D USE_FULL_ASSERT=1 and compile main.c as last one to avoid overwite stm32f4xx_hal_conf.h when regenerated. But I really wish to know if its intended or is it just bug. Now I see the problem is more general, for example wrinting anything in stm32f4xx_it.c after regeneration is lost. Is there any solution to overcome this problem? or just each time copy and pase ?2014-05-01 01:28 AM
But I really wish to know if its intended or is it just bug.
Smells like a bug... Otherwise, I agree with you and would like to know the reason why. If my understanding of the User Manual (UM1718, Appendix B.1, ''STM32CubeMX generated C C code and user sections'') is correct, that part should be protected by a ''user section'' and a predefined one (by Mr ST), as the user cannot add new ones.Only the user sections defined by STM32CubeMX are preserved. User created sections will be ignored and lost at next C code generation. (source: UM1718)
Meaning that if a USER SECTION is not planned at the right place, we are a little bit stuck...
Finally, the assert_failed code should probably look like:
void assert_failed(uint8_t* file, uint32_t line)
{ /* USER CODE BEGIN x */ /* 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) */ /* USER CODE END x */ } Rgds.From: k.g
Posted: Friday, April 25, 2014 5:08 PMSubject: function assert_failed() empty after STM32CubeMx regenerationThanks for workaround, it works.
Some improvement - add flag to compiler -D USE_FULL_ASSERT=1 and compile main.c as last one to avoid overwite stm32f4xx_hal_conf.h when regenerated. But I really wish to know if its intended or is it just bug. Now I see the problem is more general, for example wrinting anything in stm32f4xx_it.c after regeneration is lost. Is there any solution to overcome this problem? or just each time copy and pase ?