Menu

#121 STM32F4 template project has redundant hardware initialization code

Next release
closed
None
9
2014-11-07
2014-08-08
Olegs
No

Please observe the following code snippets from the generated project.

File src/_initialize_hardware.c (line 58):

#if defined (__VFP_FP__) && !defined (__SOFTFP__)

  // Enable the Cortex-M4 FPU only when -mfloat-abi=hard.
  // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)

  // Set bits 20-23 to enable CP10 and CP11 coprocessor
  SCB->CPACR |= (0xF << 20);

#endif // (__VFP_FP__) && !(__SOFTFP__)

File system/src/cmsis/system_stm32f4xx.c (line 171):

#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
#endif

Aparently both snippets do exactly the same thing. Yet, the first snippet is part of "hand written" initialization code, but the second one comes from STM32CubeFX and is part of SystemInit function, which is defined by CMSIS.

Even though it does not cause any trouble, I would suggest to drop the FPU initialization code from __initialize_hardware and stick with the one provided by the SystemInit function. That would make it easier to upgrade template code from a more recent STM32CubeFX revision.

Steps to reproduce:
1) File->New->C++ Project
2) Executable->STM32F4xx C/C++ Project->Cross ARM GCC
3) Chips family: STM32F401xC, Flash size: 256, External clock: 8000000, Content: Blinky, Use system calls: POSIX, Trace output: ARM ITM, Check some warnings: Yes, Check most warnings: Yes, Enable -Werror: No, Use -Og on debug: Yes, Use newlib nano: Yes, Exclude unused: Yes
4) Leave folder settings at default
5) Leave select configurations at default
6) Toolchain name: "GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc)", Toolchain path: "${toolchain_path}/bin"
7) Finish

Toolchain:
- gcc-arm-none-eabi-4_8-2014q2

Eclipse version:
- eclipse.buildId=4.3.2.M20140221-1700

Java runtime:
- java.runtime.name=OpenJDK Runtime Environment
- java.runtime.version=1.7.0_60-mockbuild_2014_06_19_16_16-b00

OS:
- os.arch=i386
- os.name=Linux
- os.version=3.14.8-100.fc19.i686

Installed plug-ins:
- ilg.gnuarmeclipse.debug.gdbjtag.jlink (1.6.1.201407190854) "GNU ARM J-Link Debugging Support"
- ilg.gnuarmeclipse.debug.gdbjtag.openocd (1.3.1.201407190854) "GNU ARM OpenOCD Debugging Support"
- ilg.gnuarmeclipse.managedbuild.cross (1.10.2.201407190854) "GNU ARM C/C++ Cross Compiler Support"
- ilg.gnuarmeclipse.templates.cortexm (1.1.1.201407190854) "GNU ARM C/C++ Generic Cortex-M Project Template"
- ilg.gnuarmeclipse.templates.freescale (2.1.1.201407190854) "GNU ARM C/C++ Freescale Kinetis Project Templates"
- ilg.gnuarmeclipse.templates.stm (2.1.1.201407190854) "GNU ARM C/C++ STM32Fx Project Templates"

Discussion

  • Liviu Ionescu (ilg)

    • status: open --> open-accepted
    • assigned_to: Liviu Ionescu (ilg)
     
  • Liviu Ionescu (ilg)

    thank you for the bug report, you are right, for STM32F4 the first code is redundant.

    it is there because I was not sure that ALL silicon vendors provide the correct SystemInit() for FPU, but ARM confirmed this in a discussion, so I'll remove it in the next release.

     
  • Liviu Ionescu (ilg)

    I added an extra test 'defined(OS_INCLUDE_STARTUP_INIT_FP)' to include this code only upon explicit request.

     
  • Liviu Ionescu (ilg)

    fixed in 2.4.1-201410142110

     
  • Liviu Ionescu (ilg)

     
  • Liviu Ionescu (ilg)

    • status: open-accepted --> closed