Saturday , 19 August 2017
iten
Home » Electronics » Build STM32 applications with Eclipse, GCC and STM32Cube

Build STM32 applications with Eclipse, GCC and STM32Cube

Please, read carefully.

Thanks to the feedbacks I have received, I reached to the conclusion that it's really hard to cover a topic like this one in the room of a blog post. So, I started writing a book about the STM32 platform. In the free book sample you can find the whole complete procedure better explained. You can download it from here.

If you landed to this page, you probably already know that I've covered this topic in the past. I showed in a series made of three posts how to successfully setup a complete Eclipse/GCC ARM tool-chain to develop applications for the STM32Nucleo-F4 developing board. Since then, many people have reported me positive feedback on that tutorial. But, some of them had serious troubles in getting those instructions working for other STM32 families (F0, F1 and so on). This was mainly caused by the GNU ARM Eclipse plug-in, or rather by the included templates in the plug-in.  When a new project is created using the plug-in wizard, a template is used depending on processor family. Unfortunately, the plug-in author has updated just the template for STM32-F4 family to the more recently STM32Cube-F4 HAL framework from ST (which still supports only commercial IDE.....), leaving the other templates still based on the old Standard Peripheral Library, which is no longer supported by ST and STM32CubeMX tool used in my tutorial. This causes my instructions to be wrong for processor families different from STM32-F4. 

In this post I'll show you how to setup from scratch an Eclipse project to develop applications for STM32 platform using the latest version of STM32Cube-Fx framework (the latest version available at time of writing is 1.6 for F4). Unfortunately, at the moment I can test these instructions only on a STM32-F4 processor, but I'm going to buy other Nucleo boards to do tests. In this article I won't explain again all the steps required to install Eclipse and GCC on your computer. If you still haven't installed the base tool-chain, you can start reading from this post and stop to the paragraph named "Create a test project". When ready, you can come back here again and continue the reading.

Before starting create our new test project, I would like to say something about why using Eclipse/GCC as tool-chain to develop STM32 firmware. Because this is a really common question from newbies.

Why choose Eclipse/GCC as tool-chain for STM32

This is a really common question: which tool-chain is the best one to develop apps for STM32? The question is unfortunately not simple to answer. Probably the best answer is that it depends on the application. First of all, the audience should be divided between professionals and hobbyists. Company ofter prefers to use commercial IDEs with annual fees that allow to receive technical support. You have to figure out that in business time means money and, sometimes, commercial IDE can reduce the learning curve (especially if we consider that ST gives explicit support to these environments). However, I think that even companies (especially if they are small organizations) can take great advantages in using an open source tool-chain.

According to me, these are the most important advantages in using a Eclipse/GCC tool-chain for embedded development with STM32 MCU:

  • It's GCC based: GCC is probably the best compiler on the earth, and it gives excellent results even with ARM based processors. ARM is nowadays the most widespread architecture (thanks to the diffusion of embedded systems in the last years), and GCC is used by many hardware and software manufacturers as foundation tool for their platform.
  • It's cross-platform: if you have a Windows PC, the latest sexy Mac or a Linux server you'll be able to successfully develop, compile and upload the firmware on your development board with no difference. Today this is not a secondary aspect.
  • Eclipse diffusion: a lot of commercial IDE for STM32 (like TrueSTUDIO and others) are also based upon Eclipse, which becomes a sort of standard. There are a lot of useful plug-in for Eclipse you can download with just one click. And it's a product that evolves day by day.
  • It's Open Source: ok. I agree. For such giant pieces of software it's really hard to try to understand their internals and modify the code, especially if you are an hardware engineer committed to transistors and interrupt management. But if you get in trouble with your tool, it's more simple to trying to understand what goes wrong with an open source tool than a closed one.
  • Large and growing community: these tools have by now a great international community, which continuously develops new features and fixes bugs. You'll find around tons of examples and blog post like this one, which can help you during your work. Moreover, many companies, which have adopted this software, give economical contribution to the main development. This guarantees that the software won't suddenly disappear.
  • It's free: Yep. I placed this as the last point, but it's not the least. A commercial IDE can cost a fortune for a small company or a hobbyist. And the availability of free tool is one of the key advantages of STM32 platform.

Ok. We can now start doing serious things 🙂

Summary of the whole process

Before I start describing in depth the procedure to generate a fully working firmware for our board, I will summarize the steps.

  • First we generate an empty skeleton for ARM Cortex-M processors;
  • Then we'll put in the right place the whole HAL library developed by ST;
  • Then we configure some project macros and assembler start up files;
  • Finally we add a sample main to test if all goes well.

As we'll see, the whole process consists in some drag-and-drop of files from the STM32Cube package to the Eclipse project. Nothing more than this.

Assumptions and requirements

In this tutorial I'll assume you have:

  • A complete Eclipse/GCC ARM tool-chain with required plugins as described in this post. I'll assume that the whole tool-chain in installed in C:\STM32Toolchain or ~/STM32Toolchain if you have a UNIX-like system.
  • The STM32Cube-F4 framework from ST already downloaded and extracted (if your board is based on another STM32 family, download the corresponding STM32Cube package - I'm almost sure that the instructions are perfectly compatible).
  • A STM32Nucleo-F401RE board (as I said before, arrange instructions for your Nucleo if it's different). I think that it's also simple to arrange this procedure for other boards, like the more widespread STM32Discovery.

Create an empty project

The fist step is creating a skeleton project where we'll put HAL library from ST. So, start Eclipse and go to File->New->C Project and select "Hello World ARM Cortex-M C/C++ project. You can choose the project name you want (I chose “test1“). Click on “Next“.

Schermata 2015-06-04 alle 08.11.57In the next step you have to configure your processor. For a STM32-F4 you have to choose Cortex-M4 core, while for a STM32-F1 you have to choose Cortex-M3. The Clock, Flash size and RAM parameters depends on your Nucleo MCU. For Nucleo-F401RE you can use the same values shown in the following picture. Set the other options as shown below.Schermata 2015-06-04 alle 08.14.12In the next step leave all parameters unchanged except for the last one: Vendor CMSIS name. Change it from DEVICE to stm32f4xx if you have a STM32F4 based board, or stm32f1xx for F1 boards, and so on.Schermata 2015-06-04 alle 08.24.02Click on “Next“. You can leave the default parameters in the next steps. The final step is about the GCC tool-chain. You can use these values:

tool-chain name: GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc)
tool-chain path: C:\STM32Toolchain\gnu-arm\4.8-2014q3\bin

Click “Finish“.

Now, if this is the first time you get in touch with the Eclipse IDE, you could be a little bit mazed by its interface. Eclipse is a multi-window IDE, and windows can be organized in several groups named perspective, as they are called in the Eclipse gibberish. It’s out from the goals of this article to explain how Eclipse works. I suggest you to play with the buttons marked in red in the following image.Schermata 2014-12-20 alle 22.16.28After some clicks, you should obtain an interface close to the one in the following image.Schermata 2014-12-20 alle 22.22.50

Importing STM32Cube-HAL in the Eclipse project

Ok. Now the hard part starts. The project generated by GNU ARM Plug-in for Eclipse is a skeleton containing Cortex Microcontroller Software Interface Standard (CMSIS) by ARM. CMSIS is a vendor-independent hardware abstraction layer for the Cortex-M processor series. It enables consistent and simple software interfaces to the processor for interface peripherals, real-time operating systems, and middleware. It's intended to simplify software re-use and reducing the learning. However, the CMSIS package is not sufficient to start programming with a STM32 chip. It's also required a vendor specific Hardware Abstraction Layer (HAL). This is what ST provides with its STM32Cube framework.

CMSIS-HAL

The above diagram try to explain better all the components involved in the final firmware generation. CMSIS is the universal set of features developed by ARM, and it's common to all Cortex-M vendors  (ST, ATMEL, etc). ST HAL is the hardware abstraction layer developed by ST for its specific devices, and it's related to the STM32 family (F0, F1, etc). The Device HAL is a sort of "connector" that allows the two subsystem to talk each other. It's a really simplified view, but this is sufficient to start programming with this architecture.

Let's have a look to the generated project.

Schermata 2015-06-04 alle 09.01.15

  • /src and /include folders contain our "main" application. The plug-in generated a bare bone main.c file. We don't use these files, as we'll seen soon, but we'll place an example "main" in that folder.
  • /system folder essentially contains the ARM CMSIS package.
  • /system/include/stm32f4xx and /system/src/stm32f4xx are the folders where we'll place the STM32Cube HAL.
  • /ldscripts contains script for the GNU Link Editor (ld). These scripts instruct the linker to partition the memory and do several stuffs in configuring interrupts and entry point routines.

Let's now have a look to cortexm subfolder.

Schermata 2015-06-04 alle 14.00.20

The files I've highlighted in blue in the above picture are generated automatically by the GNU ARM Eclipse plug-in. They are what it's called the Device HAL part in the previous diagram. These files are substantially empty, and should be replaced by custom code, both specific for the single vendor (ST in our case), both specific for the given MCU (STM32F401RE if you have a Nucleo like the mine). We are going to delete them.

So the first step is downloading the latest version of STM32Cube-F4 (or the one corresponding to your MCU) from ST web site, unpack it and place it inside the folder C:\STM32Toolchain.  Once extracted, rename the folder from STM32Cube_FW_F4_V1.6.0 to STM32Cube_FW_F4.

Next, go in the Eclipse project and delete the following files:

  • /src/[main.c, Timer.c]
  • /include/Timer.h
  • /system/include/cmsis/[stm32f4xx.h,system_stm32f4xx.h]
  • /system/src/cmsis/[system_stm32f4xx.c,vectors_stm32f4xx.c]

Now we have to copy HAL and other files from STM32Cube to the Eclipse project.

  • HAL: go inside the STM32Cube_FW_F4/Drivers/STM32F4xx_HAL_Driver/Src folder and drag ALL the files contained to the Eclipse folder /system/src/stm32f4xx. Eclipse will ask you how to copy these files in the project folder. Select the entry "Copy", as shown below (use always this choice):
    Schermata 2015-06-04 alle 14.31.59
    Next, go inside the STM32Cube_FW_F4/Drivers/STM32F4xx_HAL_Driver/Inc folder and drag ALL the files contained to the Eclipse folder /system/include/stm32f4xx.
  • Device HAL: go inside the STM32Cube_FW_F4/Drivers/CMSIS/Device/ST/STM32F4xx/Include folder and drag ALL the files contained to the Eclipse folder /system/include/cmsis.
    We now need another two files. If you remember, we've deleted so far two files from the generated project: system_stm32f4xx.c and vectors_stm32f4xx.c. We now need two files that do the same job (essentially, they contain the startup routines). The file vectors_stm32f4xx.c should contain the startup code when MCU resets. We'll use an assembler file provided by ST. Go inside STM32Cube_FW_F4/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc folder and drag the file corresponding to your MCU inside the Eclipse folder /system/src/cmsis. In our case, the file is startup_stm32f401xe.s. Now, since Eclipse is not able to manage files ending with .s, we have to change the file extension to .S (capital 's'). So the final filename is startup_stm32f401xe.S.
    Just another step. We still need a system_stm32f4xx.c file. but we need one specific for the MCU of our board. Go inside the STM32Cube_FW_F4/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates folder and drag the system_stm32f4xx.c file inside the Eclipse folder /system/src/cmsis.

Ok. The framework is essentially configured. We now need a sample project that shows us that all works well. We'll take the blinking LED example from ST.

Go inside the STM32Toolchain/STM32Cube_FW_F4/Projects/STM32F401RE-Nucleo/Examples/GPIO/GPIO_IOToggle/Inc folder and copy ALL the content inside the Eclipse folder /include. Next, go to STM32Toolchain/STM32Cube_FW_F4/Projects/STM32F401RE-Nucleo/Examples/GPIO/GPIO_IOToggle/src folder and copy only the files main.c and stm32f4xx_it.c inside the Eclipse Folder /src. Finally, ST separated the configuration steps of the specific Nucleo board in a different package, called Board Support Package (BSP). Go inside the STM32Cube_FW_F4/Drivers/BSP/STM32F4xx-Nucleo and copy the stm32f4xx_nucleo.c inside the /src folder in Eclipse and the file stm32f4xx_nucleo.h inside the /include Eclipse folder.

We are almost at the end of the whole procedure. We only need to setup a couple of things. First, we have to declare which MCU we are using defining a global macro inside the project configuration. For Nucleo-F401RE the macro is STM32F401xE. Go inside the project properties (on the main Eclipse menu go to Project->Properties), then C/C++ Build->Settings. Click on Tool Settings and go in Cross ARM C Compiler->Preprocessor. Click on the Add icon (Schermata 2015-06-04 alle 15.18.26) and add the macro STM32F401xE.

Schermata 2015-06-04 alle 15.16.21

Second, we need to configure how the application is mapped in the MCU memory. This work is accomplished by the link-editor (ld), which uses the three .ld files inside the /ldscripts Eclipse folder. The file we are interested in is mem.ld, and we need to change the FLASH origin address from 0x00000000 to 0x08000000, as shown below:

Where does this number come from? It's not a magic number. It's simply the address where the internal MCU flash is mapped in all STM32 microcontrollers, as you can see in the picture below extracted from the MCU datasheet.

Schermata 06-2457191 alle 21.59.45

 

Finished. Now you can compile the project going to Project->Build All.

What's next?

If you are completely new to the Eclipse/GCC development process for STM32, you need to go back to this post and continue the reading from "Let’s compile the test project" paragraph. You need to SKIP reading from "Adapt the test code to the Nucleo board" paragraph, since the code we've used here is already designed for our Nucleo. Once finished, you can start reading part 2 and 3 of that series completely.

Moreover, I've developed a python script that is able to automize the most of the work described in this post. Take a look to this other blog post.

Conclusion

I'm aware of the fact that the whole procedure is not straightforward, but I can guarantee you that it becomes clear after the first time. I did all the best to describe the whole process in a clean and simple way, but comments and suggests are welcome.

Now you can start programming your Nucleo and diving into the STM32Cube framework. Enjoy your Nucleo!


Check Also

Correct way to perform re-annotation of designators in Altium

It's really common that at the end of the board layout we have that all …

85 comments

  1. Hello !

    Thank for your tutorials, I use them to program my stm32f401re board and it works perfectly 🙂

    But now I'm working on a Inemo M1 Discovery board based on a STM32F401REY6 MCU and I tried to apply this tutorial without success. When I try to write my .hex file thanks to my st-link v2 and st-link utility I got:

    Internal command error
    An error occurred during program operation!
    Programming error @: 0x00000000

    (I try to erase the flash and I got "Programming error @: 0x00000008" instead)

    I had to adapt the tutorial to my board, so could be due to one of the following choices I've done:

    - i use startup_stm32f103xe.s as startup code for my STM32F401REY6, but i don't know if it match, i also tried tried to use startup_stm32f10x_hd.s ( => .S) that i found in a INEMOEngineM1LI3 file i received on request from ST ( but i have 2 of them, one in a file "iar" and one in a file "keil", and both have lines begining by ";" => errors)

    _ i choose a STM32F103RB-Nucleo project to copy the system_stm32f1xx
    > i don't know if it's related, but one of my thought is about vector table localisation, in my datasheet i see "the vector table of the customer's application must be present at the start address of the main flash"

    so I tried to modify the

    "/*!< Uncomment the following line if you need to relocate your vector Table in
    Internal SRAM. */
    /* #define VECT_TAB_SRAM */
    #define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
    This value must be a multiple of 0x200. */ "

    in the system_stm32f1xx

    I also tried to use a system_stm32f10x found in the INEMOEngineM1LI3 file and did the same tests.

    PS : i had to ad stdint library to my project to be able to compile it on eclipse.

    I'm a little overrun. Didi you have any sugestion to help me ? 🙂

    • Carmine Noviello

      Hi Louis,
      If your target board is based on STM32F4xx MCU you have to use both startup code and HAL for a F4 processor, not a F103 (which is F1xx). Try to replace in both in the project and let me know if it solves.

      Carmine

      • Sorry, i made a mistake writing the MCU reference, it is STM32F103REY6 ( and STt Link utility shows " Device : STM32F10xx High Density " )

        • I also fix the memory allocation according to the your answer to Alex's problem ( FLASH was at 0x00000000, but the error remain).

          • Carmine Noviello

            Hi Luis,
            Just to do a doble check: did you reload the hex again in the ST-Link Utility before uploading it? It's a really common mistake when using ST-Link Utility.

          • Hello Carmine,

            I confirm that I reload the hex.

            It seems that I can't choose the start address in my .hex file while "Programing" with St-Link Utility ( Start Adress is set to 0x00000000) so I try to write in a protected area... I tried to manage it with the St-Link Utility command line interface BUT the dress choice is only available for.bin file. Is it possible to manage the writing area in Eclipse ( mem.ld seem not to have an influence on the Start Adress)

          • Carmine Noviello

            Hi Louis,
            Can you paste me the content of mem.ld file?

          • No more than this :

            MEMORY
            {
            FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
            RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
            }

          • Carmine Noviello

            Unfortunately, without having the board in my hands is really difficult to address the issue. Try to check if all global defines are correct (especially the one defined in the eclipse project settings). I'm wondering if you never was able to flash this board or if you can flash it using some other images (maybe supplied by ST). However, try to ask on the ST forum.

          • Thanks, i will try this, and keep you informed if i get some results.

          • Hello Carmine,

            i manage to flash the inemo M1 board with a trick :

            After compiling my program, I modify the .hex file by adding " :020000040800F2 " at the beginning ( it's the first line of STM32 f401re nucleo board .hex file i created with your Setting up a GCC/Eclipse toolchain for STM32Nucleo – Part I tutorial) and it seems to indicate St utility where to start flashing ( at 0x08000000 ).

            Now i just have to write a working program 😛

            Thanks for your help and concern !

          • Carmine Noviello

            Hi Louis,
            Thank you for reporting this!

            I will try going more in depth about this problem and looking for a solution.

  2. Hi! First I'd like to thank you for these great tutorials. They are really great.

    I have the same board as you have in your tutorial, a Nucleo-F401RE and followed your instructions exactly. But I'm getting the same error as Louis. The problem hex file has its initial address at 0x00000000, whereas the hex file generated by your original tutorial, which programs and verifies correctly has its origin at 0x080000. So there must be a problem with the loader settings somewhere? Maybe you can let us know what changes have to be made to get the FLASH origin set correctly.
    Thanks again!

    • Carmine Noviello

      Hi Alex,
      When gcc compiles a source file, it generates a file that has ".o" extension. Those files are called "relocatable", because the instructions inside them are not bind to physical addresses, but are relative to the origin of the file (they all starts from 0x0000). It's a link editor task to generate an absolute binary that will start from the real physical address. So, the start address is decided inside the mem.ld file in your project:


      ...
      MEMORY
      {
      RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
      CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 0
      FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
      ...

      Have a look there, otherwise there is something wrong elsewhere.

      Carmine

      • Hi Carmine,
        Yes, that was it. Somehow the FLASH origin was set to 0x00000000 in mem.ld. The RAM size was set to 96K which I reduced to 64K. The project now loads and runs perfectly on the STM32F401RE Nucleo. My next two steps are to attempt the same on an STM32F303 Nucleo. Then, to attempt to use the STM32CubeMX GUI application to generate the initialization code for all the peripherals I want to use.
        Thanks again!

        Alex

  3. Hi!

    Thank you verry much for your tutorials they are verry helpfull!!

    But I have a weird issue with Eclipse, when I change my code and rebuild it, the .hex is not changing at all. I have to "Clean" my project and then rebuild it.

    What is the reason?

    Thank you!

    • Carmine Noviello

      Hi Carl,
      Try to check this. Go in Project Settings->C/C++ Build, than select the Behaviour tab and check if "Clean" entry is checked.

      • Hi,

        Yes "Clean" is checked. But the weird part is that the .map and .elf are being modified. Is just the .hex that is not clean et rebuild.

        I'm used to do the "Clean" since last week, I think I'm going to continue like this. If I found a solution I will post it here!

        Thanks a lot!

  4. Hello Carmine,

    Once again, thank you for this tutorial! It has helped me a lot and this made me blink the lights on my STM32VL-Discovery after giving up hope following other tutorials. One thing I noticed, though, is that Eclipse spews out a bunch of error messages about symbols not being resolved but what's weird is that the project compiles alright and even works when I uploaded the hex file that was generated. What could be the problem here?

    • Carmine Noviello

      Hi Jan,
      could you post me an example of these messages? Are they errors or warning messages? Please, consider that by default Eclipse enables the options "-Wall" for warning messages. This causes a lot of warning to be printed on the console. To disable this behaviour, go to Project Settings->C/C++Build->Settings, select the "Warnings" entry on the left and then uncheck "Enable all common warnings (-Wall)" entry.

  5. Oh, here is a screenshot of some of the errors.

    http://aisono.com/images/errors.jpg

    • Carmine Noviello

      Umm, this usually happens when the global macro (eg. STM32F401xE) is not defined in the project settings. Have a look there.

      However, sometimes Eclipse doesn't clean "Problems" view automatically. Try to empty it manually and build the project again. If errors still appear, there is something wrong in project configuration.

  6. As I was using a Nucleo-411RE, the macro that I defined was STM32F411xE. Closing the project, opening it again, and then building it again does not generate any errors. The errors come up when I start editing the "main.c" file. After editing and compiling the main.c file, the errors still remain but the code compiled correctly and produced the correct hex file even if the errors are there.

    • Carmine Noviello

      Ok. So is something related with Eclipse.

      • Yep, i think so too. I'll go over the instructions again later in case I missed something. If the errors still persist, I'll just ignore those errors for now as long as a correct hex file is generated. 🙂

      • Hello Carmine,

        I found a solution to problem I was having. It turns out that the errors were generated by the C++ compiler and not by the C compiler. That was why I also had to add the STM32F411xE macro to the Cross ARM C++ Compiler->Preprocessor in the C/C++ Build->Settings. You might want to add this as an update above. Thanks again for this tutorial! Looking forward for more great knowledge articles from you!

        • Carmine Noviello

          Hi Jan,
          Thank you for sharing 😉

          • No problem! Apparently, clicking Project -> C/C++ Index -> Rebuild. might just have solved the problem...but I just wanted to make sure that was why I added the macro to the Cross ARM C++ Compiler->Preprocessor. Cheers! 🙂

        • I'm also using STM32F411 and having problem in system_stm32f4xx.c file in /src folder. Tried adding macros for C & C++ builders but still not working. 🙁

      • I also had to click Project -> C/C++ Index -> Rebuild. 🙂

  7. Beautiful post. Your content in post is good but article style (layout) is really awesome.

  8. Hi Carmine, first of all many thanks for the tutorial !

    I am trying to apply it to the Nucleo STM32F030 (MCU = STM32F030R8T6, so I defined "STM32F030x8") but I get some errors at about 2/3 of compilation. The first one is:

    'SCB_Type' has no member named 'VTOR' _initialize_hardware.c /eclip1/system/src/cortexm line 42

    The line is:

    SCB->VTOR = (uint32_t)(&__vectors_start);

    A later error (that at first glance seems unrelated) is:

    Invalid arguments '
    Candidates are:
    void NVIC_SetPriority(enum {stm32f030x8.h:3253}, unsigned long int)
    void NVIC_SetPriority(?, unsigned long int)
    ' core_cm0.h /eclip1/system/include/cmsis line 689

    The line is:

    NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);

    I guess I may have made a mistake, but I am unable to find it. I would be grateful for any suggestion.
    I am an experienced developer but I am totally new to this MCU... and rather lost in its multi-layered maze 🙂

    • Carmine Noviello

      Hi Erix,
      I've generated a sample project for Nucleo-F0 following the instructions and all seems to compile well. I've uploaded the project to my github repo. You can find it here:

      https://github.com/cnoviello/stm32-nucleof0/tree/master/stm32-nucleof0-blinky

      Unfortunately, I haven't a Nucleo-F0 to test if it works well. Download the project and import it in Eclipse (File->Import...->Import existing project...). Please, let me know if your Nucleo LD2 LED blinks 😉

      • Hi Carmine,

        It works!
        Looks like you are better at 'blind programming' that I am at following detailed instructions 😉

        This evening I'll do some comparison to see what I did wrong and I'll let you know.
        In the meantime, thanks a lot for the amazing support!

      • Things are getting interesting 🙂
        I repeated the procedure and got the same "VTOR" error.

        A tree compare between your project and mine shows three different source files:

        - system\src\cortexm\_initialize_hardware.c
        Only my version of this file references VTOR at line 42, which explains the error.

        - system\src\cortexm\exception_handlers.c
        This one only adds a couple of casts when using -1.

        - ldscripts\sections.ld
        This is significantly different; the initial comment says "Default linker script for Cortex-M (it includes specifics for STM32F[34]xx)."

        So it looks like some of Liviu Ionescu's files could be different on my system.
        The version of the GNU ARM Eclipse Plug-ins seems to be 201508011813 (rather fresh!).

        The good news: if I comment out the offending line 42 in _initialize_hardware.c, it compiles and runs.
        But I'd like to understand what's going on 🙂

        • Carmine Noviello

          Ok, I've updated to the latest version of GNU ARM Plugin and you are right: that line of code is there and prevents to compile correctly.

          That line of code relays on the fact that Cortex-M3/4 processors have a specific pointer to the interrupt vector table inside the System Control Block (SCB). SCB is nothing more that a convenient place where CMSIS stores relevant information about the specific MCU (CMSIS is an "abstract" layer above the specific vendor implementations). Cortex-M0 doesn't provide that pointer in the SCB structure (refer to this doc http://www.st.com/web/en/resource/technical/document/programming_manual/DM00051352.pdf at 4.3 paragraph). You can safely comment that line of code.

  9. Thank you for what are currently the easiest to follow guides I have found. STM32 from AVR is indeed a steep learning curve (feels like 80% gradient)...
    I would note for ppl using different boards that valid macro definitions for the preprocessor can be found in system/include/ stm32f0xx/stm32f0xx_hal.h
    I found too that I could effectively import the code generated by STM32CubeMX (for SW4STM32) by following these instructions and copying the generated main.c and stm32f0xx_hal_conf.h to src and include respectively.
    BUT and here is where I need your help, the chip that I am doing this project on is STM32F030F4P6 for which there is no startup_stm32f030x4.s in Templates/gcc (This folder is not generated by STM32Cube either 8( ). Any ideas.
    The f0xx project in github works perfectly btw.
    Cheers
    Jasper

    • Carmine Noviello

      Hi Jasper,
      Looking to the STM32 catalogue, I think that the right startup file for your MCU is startup_stm32f030x6.s.

      • Thanks, it worked! I can blink led's on the target board using HAL!!
        Now I want to try out the ADC and print the values in the debug window but I am convinced that debug is not working properly. When I first tried some months ago with a vanilla eclipse-gnu-arm project for f030 with blinky I could see a counter incrimnet, so I copied the #include "diag/Trace.h" and inserted some trace_printf's, but I cannot see them. I tried creating a new blinky project for f030, but again, not trace output .
        Starting openocd as openocd -f interface/stlink-v2-1.cfg -f target/stm32f0x_stlink.cfg
        I get a whole lot of spew when gdb connects.
        Anyway, if this is an obvious one do you have any clue?
        Once again, cheers 8)

  10. Hi,

    Great work, I bought the board in 2014 but only now I am able to make it work.

    I have some problem I am using STM32F401, LED keep glowing but not blinking, when I debug it stopped in timer do you have any idea?

    Thanks,

    Mani

  11. Thanks for your quick reply , Actually I followed PART 1 and PART 2 and created test1 sample where I was getting this problem then I tried with your code in the below link that also have the same Problem
    https://github.com/cnoviello/stm32-nucleof4/tree/master/stm32-nucleof4-blinky
    Today I deleted all the code and followed the above article and it started working thanks lot. Anyway I will try to reproduce the issue and update here.
    Thanks
    Mani

  12. Hi Carmine,

    First of all, thanks for such an excellent and thorough tutorial.

    I am trying to set up the framework to use the STM32cubef4 framework and STMcubeMX to program an STM32F407-VGT6-Discovery board. I followed this tutorial step by step EXACTLY, except replaced all references to your F4Nucleo board with references to the STM32F407 Discovery board.

    There is no LED GPIOToggle example project in the HAL libraries for the F407-Discovery board, so I chose to chose to instead do the GPIO/GPIO_EXTI example project.

    Therefore, in the last steps detailed below...
    - STM32Toolchain/STM32Cube_FW_F4/Projects/STM32F401RE-Nucleo/Examples/GPIO/GPIO_IOToggle/Inc folder and copy ALL the content inside the Eclipse folder /include.
    - STM32Toolchain/STM32Cube_FW_F4/Projects/STM32F401RE-Nucleo/Examples/GPIO/GPIO_IOToggle/src folder and copy only the files main.c and stm32f4xx_it.c inside the Eclipse Folder /src.
    - STM32Cube_FW_F4/Drivers/BSP/STM32F4xx-Nucleo and copy the stm32f4xx_nucleo.c inside the /src folder in Eclipse and the file stm32f4xx_nucleo.h inside the /include Eclipse folder.

    ... I INSTEAD did the following
    - copied ALL files in STM32Toolchain\STM32Cube_FW_F4\Projects\STM32F4-Discovery\Examples\GPIO\GPIO_EXTI\Inc ---> test1/include
    - copied the files "main.c" and "stn32f4xx_it.c" from STM32Toolchain\STM32Cube_FW_F4\Projects\STM32F4-Discovery\Examples\GPIO\GPIO_EXI\Src --> test1/stc

    When I try to build, I get 319 Errors and 14 warnings (which I have listed below). I have spent a week trying to debug the environment, but to no avail, and am starting to get hopeless (this is for a very important prototyping project, for which I MUST use the STM32F407-Discovery).

    Again, besidesthe steps that target the STM32F407-Discovery board (and not the Nucleo), and the above step, I did ALL other steps just as you have instructed. If you could PLEASE help me resolve this issue, it would be MUCH MUCH appreciated.

    Thanks again for the amazing tutorial. I have listed my console output below.

    Best,
    Brett

    -----------------------------------------------------------------------------------------------------------------
    20:19:03 **** Build of configuration Debug for project test1 ****
    make all
    Building file: ../system/src/stm32f4xx/stm32f4xx_hal.c
    Invoking: Cross ARM C Compiler
    arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DSTM32F407xE -DTRACE -I"../include" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f4xx" -std=gnu11 -MMD -MP -MF"system/src/stm32f4xx/stm32f4xx_hal.d" -MT"system/src/stm32f4xx/stm32f4xx_hal.o" -c -o "system/src/stm32f4xx/stm32f4xx_hal.o" "../system/src/stm32f4xx/stm32f4xx_hal.c"
    In file included from ../system/include/stm32f4xx/stm32f4xx_hal_def.h:48:0,
    from ../system/include/stm32f4xx/stm32f4xx_hal_rcc.h:47,
    from ../include/stm32f4xx_hal_conf.h:234,
    from ../system/include/stm32f4xx/stm32f4xx_hal.h:48,
    from ../system/src/stm32f4xx/stm32f4xx_hal.c:54:
    ../system/include/cmsis/stm32f4xx.h:173:3: error: #error "Please select first the target STM32F4xx device used in your application (in stm32f4xx.h file)"
    #error "Please select first the target STM32F4xx device used in your application (in stm32f4xx.h file)"
    ^
    In file included from ../system/include/stm32f4xx/stm32f4xx_hal_rcc.h:51:0,
    from ../include/stm32f4xx_hal_conf.h:234,
    from ../system/include/stm32f4xx/stm32f4xx_hal.h:48,
    from ../system/src/stm32f4xx/stm32f4xx_hal.c:54:
    ../system/include/stm32f4xx/stm32f4xx_hal_rcc_ex.h:67:3: error: unknown type name 'uint32_t'
    uint32_t PLLState; /*!< The new state of the PLL.
    ^
    ../system/include/stm32f4xx/stm32f4xx_hal_rcc_ex.h:70:3: error: unknown type name 'uint32_t'
    uint32_t PLLSource; /*!< RCC_PLLSource: PLL entry clock source.
    ^
    ../system/include/stm32f4xx/stm32f4xx_hal_rcc_ex.h:73:3: error: unknown type name 'uint32_t'
    uint32_t PLLM; /*!< PLLM: Division factor for PLL VCO input clock.
    ^
    ../system/include/stm32f4xx/stm32f4xx_hal_rcc_ex.h:76:3: error: unknown type name 'uint32_t'
    uint32_t PLLN; /*!< PLLN: Multiplication factor for PLL VCO output clock.
    ^
    ../system/include/stm32f4xx/stm32f4xx_hal_rcc_ex.h:79:3: error: unknown type name 'uint32_t'
    uint32_t PLLP; /*!< PLLP: Division factor for main system clock (SYSCLK).
    ^
    ../system/include/stm32f4xx/stm32f4xx_hal_rcc_ex.h:82:3: error: unknown type name 'uint32_t'
    uint32_t PLLQ; /*!< PLLQ: Division factor for OTG FS, SDIO and RNG clocks.
    ^
    .....

    • Hi,
      Usually all does errors comes out when you don't define the MCU macro at project level. You need to define the macro STM32F407xx at project level, as described in this post.

      Please, let me know if it helps.

      • Hi Carmine,

        Thanks so much for the response. I actually realized the same thing as soon as I posted to your site, because my eclipse console was overflowing due to the number of errors, and I could not see the first (and most important) one!

        My issue was that I had declared the project-level macro as "STM32F407xE" and not "STM32F407xx". To all those who are using discovery boards and having issues, this is one notable difference from the above instructions.

        Also, for anyone trying to program the STM boards on a Linux machine (I'm running Ubuntu 14.0.4), there is one additional step that needs to occur, which is not detailed above...

        sudo su
        echo 'export PATH=/home/STM32Toolchain/gnu-arm/4.8-2014q3/bin:$PATH' > /etc/profile.d/arm_tools.sh
        exit

        A great resource (but definitely not as comprehensive and detailed as your's 😄) for those trying to get this up and running on Ubuntu, rather than a PC, can be found at http://vedder.se/2012/07/get-started-with-stm32f4-on-ubuntu-linux/

        Thanks so much for your wonderful tutorial!

        • Hi Brett,
          Thank you for your feedback and for sharing the guide.

          I also would like to say that a full toolchain install procedure for Mac and Linux is also described in my "in progress" book about STM32 development.

          https://leanpub.com/mastering-stm32

        • I'm trying to build a "Release" version of the project. When I define my NUCLEO-F410RB with the preprocessor symbol "STM32410Rx" the build is fine if it was in the "Debug" version. When switching to the "Release" version to build, I get the "Please select first the target STM32F4xx device used in your application (in stm32f4xx.h file)"

          What am I missing here?

          • You need to define the macro STM32F410RX in the project settings: they differ between "Release" and "Debug" version.

          • By the way, I'm doing all the steps from the book in the STM32CubeMX Tool chapter. So far I'm getting things to work, but it's frustrating how buggy Eclipse can be. For example, I was able to successfully compile the first time after doing the import from CubeMX into Eclipse, but then all the definitions went undefined even though I can open the declaraiton correctly. I found that in the path settings of the include, I need to move up the system/include/STM32f4xx to the top of the include list and then problem of undeclared/undefined symbols were gone.

          • Wow, you are amazing. You responded pretty instantaneously to the post! I'm really glad I'm reading your book since you are a very active author. I added the symbol and it now compiles correctly for the release version too! Thank you so much!

            By the way, are you considering adding a chapter on USB HID, USB CDC, or USB Bulk Transfer to your book at all? Eventually that's what I really want to be able to do. So far the examples I can gather from the wild wild internet is all over the place and so far it's been a painful thing to figure out. Your book has been very awesome and I'm sticking with using this tool chain.

          • Honestly speaking I don't think to add a chapter about USB. This would require me a lot of work to make a decent introduction to the USB specification. Moreover, the ST USB stack is not that easy to use, and it requires a decent knowledge of several peripherals (PCD, etc) and HAL LL routines (which are not treated in my book).

            I will eventually consider to add a chapter once the book is finished and the "printed" edition is out, because the current book (my "private" version has more pages than the official one) is almost 1000 pages, and I can't add more pages otherwise it would be impossible to have a self-published and printed book (too complex story to tell here...).

  13. Hello,

    I did the whole guide for my F103RB and I've got this error:
    make: *** [system/src/stm32f1xx/stm32f1xx_hal.o] Error -1073741502 Project_1 C/C++ Problem

  14. Interesting tutorial, but do you have any idea where do I find Freescale K22 specific (MK22FN1M0VLH12) "ST HALL" vendor part ?

    Thanks

  15. Hi Carmine
    I followed your step by step guide on this page.
    It compiles and runs fine when I use the debugger.
    How ever when I just flash it and try to run it without the debugger, it seems to hang somewhere (LED doesn't blink).
    Do you have any clue what it could be?
    I adapted your project but use the STM32Nucleo-F746-144 board instead. AFAIK this shouldn't do a difference.

    • Probably you have to disable semihosting, removing the OS_USE_SEMIHOSTING macro from project settings.

      • Thanks! You are right. I only removed the OS_USE_TRACE_SEMIHOSTING_DEBUG, but this seems not to be enough.

        Another point:
        You copy the whole CMSIS and HAL files into the project. This means that you can't use CubeMX anymore to reconfigure the MCU during the project. Is there a reason for it? I want to refactor the files, so I still can use CubeMX, i.e. to remap pins or reconfigure SPI during coding. In projects I have done before this was working very well.

        • If you want to use CubeMX to refactor the code, then you need a toolchain fully supported by CubeMX. AC6 (aka SW4STM32) it's probably what you need, even if it still lacks of some features.

          • I was using the guide as shown in http://www.ba0sh1.com/stm32cubemx-gcc-makefile/
            It also uses the GNU ARM Eclipse Toolchain and Eclipse.
            The main difference to your way is that yours is more up to date and his uses a manually managed Makefile.

            How ever it also should be possible to use your way with CubeMX. In my understanding it could be broken down to reallocate the files/folders. Now as i have a working project I will see which files/folders would have to be moved where.

  16. Hi Carmine,

    Thanks for this. I am trying to document how to use STM32Cube with our Eclipse / GCC based product (SOMNIUM DRT) and this helped me get a project running really quickly!

  17. Hi, Carmine, I am a STM32 developer who struggled on setting up open source toolchains on Mac OS X. I bought your book on LeanPub, It is amazing, would you mind me for translating it into Chinese? whether in open source way or commercial way, it is depends on you. Reply me if you have interests or need further information. Thank you and good luck!

  18. Hi, super helpful blog posts, but curious to how you know to supply STM32F401xE as the target? The nucleo board I have targets a STM32F446ZE, but I'm not sure that STM32F446xE is right though.

    • Never mind, I think I found it in the docs under the cube project. STM32F446xx is what I need.

      I'm referring to STM32CubeF4GettingStarted.pdf under the documentation directory if anyone else is curious. Obviously the F4 would change to suit the MCU you have.

  19. Hi, thanks for the tutorial, very thorough.

    I'm getting a problem where I get errors regarding the TIM6 timer when I compile my device, an F411 doesn't have a TIM6 and actually neither does the F401 as far as I can tell. The errors are found in stm32f4xx_hal_timebase_tim_template.c (which is a more general template) where this timer is set as a base time source when the program is reset. Have I made a mistake in the setup? Commenting out this section does not work. Do I need to change it to an existing timer?

    Thanks.

    • Carmine Noviello

      I think that in your case is OK to remove from Eclipse project the file stm32f4xx_hal_timebase_tim_template.c. Let me know if it solves.

      • I deleted it and got errors for two other modules (stm32f4xx_hal_timebase_rtc_wakeup_template.c and stm32f4xx_hal_timebase_rtc_alarm_template). I deleted these too and it compiles with no errors! A more simple solution than I expected!!

        Thank you very much!

  20. Hi,
    I followed the steps in the tutorial but i'm getting the following error.Please give me a solution.Im using STM32F103C8T6

    Invoking: Cross ARM C Compiler
    arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-move-loop-invariants -Wall -Wextra -g3 -DDEBUG -DSTM32F103XE -DUSE_FULL_ASSERT -DOS_USE_SEMIHOSTING -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -DHSE_VALUE=8000000 -I"../include" -I"../system/include" -I"../system/include/cmsis" -I"../system/include/stm32f1-stdperiph" -std=gnu11 -MMD -MP -MF"system/src/stm32f1-stdperiph/misc.d" -MT"system/src/stm32f1-stdperiph/misc.o" -c -o "system/src/stm32f1-stdperiph/misc.o" "../system/src/stm32f1-stdperiph/misc.c"
    In file included from ../system/src/stm32f1-stdperiph/misc.c:24:0:
    ../system/include/stm32f1-stdperiph/misc.h:32:23: fatal error: stm32f10x.h: No such file or directory
    compilation terminated.
    make: *** [system/src/stm32f1-stdperiph/misc.o] Error 1

    17:47:13 Build Finished (took 116ms)

  21. Hi

    I followed all the steps in this tutorial but when I build the project I get something like 100 errors; something like below. Could it be I missed something or is it Eclipse Issue. Thank you in advance

    Description Resource Path Location

    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 177 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 178 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 180 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 181 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 184 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 185 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 187 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 188 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 190 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 191 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 201 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 202 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 205 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 206 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 209 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 210 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 220 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 221 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 224 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 225 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 227 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 228 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 238 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 239 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 242 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 243 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 252 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 253 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 254 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 255 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 256 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 257 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 266 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 267 C/C++ Problem
    unknown type name 'TIM_HandleTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 277 C/C++ Problem
    unknown type name 'HAL_TIM_StateTypeDef' stm32f4xx_hal_tim_ex.h /test2/system/include/stm32f4xx line 277 C/C++ Problem
    Type 'TIM_TypeDef' could not be resolved stm32f4xx_hal_tim.h /test2/system/include/stm32f4xx line 291 Semantic Error
    Type 'TIM_TypeDef' could not be resolved stm32f4xx_hal_tim.h /test2/system/include/stm32f4xx line 1584 Semantic Error
    Type 'TIM_TypeDef' could not be resolved stm32f4xx_hal_tim.h /test2/system/include/stm32f4xx line 1585 Semantic Error
    Type 'TIM_TypeDef' could not be resolved stm32f4xx_hal_tim.h /test2/system/include/stm32f4xx line 1586 Semantic Error
    Type 'TIM_TypeDef' could not be resolved stm32f4xx_hal_tim.h /test2/system/include/stm32f4xx line 1590 Semantic Error
    Type '__IO' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 119 Semantic Error
    Type '__IO' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 275 Semantic Error
    Type '__HAL_RCC_PWR_CLK_ENABLE()' could not be resolved main.c /test2/src line 126 Semantic Error
    Type '__HAL_RCC_GPIOA_CLK_ENABLE()' could not be resolved main.c /test2/src line 81 Semantic Error
    Type '__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2)' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'tmpreg' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'TIM6' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 113 Semantic Error
    Symbol 'TIM6_DAC_IRQn' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 85 Semantic Error
    Symbol 'TIM6_DAC_IRQn' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 88 Semantic Error
    Symbol 'TIM_DIER_UIE' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 143 Semantic Error
    Symbol 'TIM_DIER_UIE' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 154 Semantic Error
    Symbol 'RTC' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 166 Semantic Error
    Symbol 'RTC_ISR_INITF' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 206 Semantic Error
    Symbol 'RTC_ISR_INITF' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 211 Semantic Error
    Symbol 'RTC_ISR_INITF' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 284 Semantic Error
    Symbol 'RTC_ISR_INIT' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 182 Semantic Error
    Symbol 'RTC_ISR_INIT' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 182 Semantic Error
    Symbol 'RTC_ISR_INIT' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 222 Semantic Error
    Symbol 'RTC_ISR_INIT' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 295 Semantic Error
    Symbol 'RTC_CR_ALRAE' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 179 Semantic Error
    Symbol 'RTC_CR_ALRAE' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 197 Semantic Error
    Symbol 'RTC_Alarm_IRQn' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 227 Semantic Error
    Symbol 'RTC_Alarm_IRQn' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 228 Semantic Error
    Symbol 'RCC' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'RCC' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'RCC' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'RCC' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'RCC_PLLCFGR_PLLSRC_HSI' could not be resolved main.c /test2/src line 138 Semantic Error
    Symbol 'RCC_CR_HSEON' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 140 Semantic Error
    Symbol 'RCC_CFGR_SW_PLL' could not be resolved main.c /test2/src line 151 Semantic Error
    Symbol 'RCC_CFGR_PPRE1_DIV2' could not be resolved main.c /test2/src line 153 Semantic Error
    Symbol 'RCC_CFGR_PPRE1_DIV1' could not be resolved main.c /test2/src line 154 Semantic Error
    Symbol 'RCC_CFGR_PPRE1_DIV1' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 100 Semantic Error
    Symbol 'RCC_CFGR_HPRE_DIV1' could not be resolved main.c /test2/src line 152 Semantic Error
    Symbol 'RCC_BDCR_RTCSEL' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 142 Semantic Error
    Symbol 'RCC_APB1ENR_PWREN' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'RCC_APB1ENR_PWREN' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'RCC_AHB1ENR_GPIOAEN' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'RCC_AHB1ENR_GPIOAEN' could not be resolved main.c /test2/src line 81 Semantic Error
    Symbol 'PWR' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'PWR' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'PWR' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'PWR_CR_VOS' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'PWR_CR_VOS' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'PWR_CR_VOS_1' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'GPIOA' could not be resolved main.c /test2/src line 88 Semantic Error
    Symbol 'GPIOA' could not be resolved main.c /test2/src line 93 Semantic Error
    Symbol 'FLASH_LATENCY_3' could not be resolved main.c /test2/src line 155 Semantic Error
    Symbol 'EXTI' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 202 Semantic Error
    Symbol 'EXTI' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 203 Semantic Error
    Symbol 'EXTI_IMR_MR17' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 202 Semantic Error
    'TIM6_DAC_IRQn' undeclared (first use in this function) stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 85 C/C++ Problem
    'TIM6' undeclared (first use in this function) stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 113 C/C++ Problem
    Field '__HAL_RTC_ALARM_CLEAR_FLAG(&hRTC_Handle, RTC_FLAG_ALRAF)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 182 Semantic Error
    Field '__HAL_RTC_ALARM_CLEAR_FLAG(&hRTC_Handle, RTC_FLAG_ALRAF)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 182 Semantic Error
    Field '__HAL_RTC_ALARM_DISABLE_IT(&hRTC_Handle, RTC_IT_ALRA)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 245 Semantic Error
    Field '__HAL_RTC_ALARM_ENABLE_IT(&hRTC_Handle, RTC_IT_ALRA)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 260 Semantic Error
    Field '__HAL_RTC_ALARM_ENABLE_IT(&hRTC_Handle, RTC_IT_ALRA)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 199 Semantic Error
    Field '__HAL_RTC_ALARM_EXTI_ENABLE_IT()' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 202 Semantic Error
    Field '__HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 203 Semantic Error
    Field '__HAL_RTC_ALARM_GET_FLAG(&hRTC_Handle, RTC_FLAG_ALRAWF)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 186 Semantic Error
    Field '__HAL_RTC_ALARMA_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 179 Semantic Error
    Field '__HAL_RTC_ALARMA_ENABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 197 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 258 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 258 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 243 Semantic Error
    Field '__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2)' could not be resolved main.c /test2/src line 131 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 243 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 176 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 176 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 279 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 279 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 262 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 247 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_ENABLE(&hRTC_Handle)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 225 Semantic Error
    Field '__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 298 Semantic Error
    Field '__HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE)' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 143 Semantic Error
    Field '__HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE)' could not be resolved stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 154 Semantic Error
    Field '__HAL_RCC_GPIOA_CLK_ENABLE()' could not be resolved main.c /test2/src line 81 Semantic Error
    Field 'ALRMAR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 194 Semantic Error
    Field 'DR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 292 Semantic Error
    Field 'DR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 219 Semantic Error
    Field '__HAL_RCC_GPIOA_CLK_ENABLE()' could not be resolved main.c /test2/src line 81 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 295 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 284 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 282 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 222 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 211 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 209 Semantic Error
    Field 'ISR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 206 Semantic Error
    Field '__HAL_RCC_PWR_CLK_ENABLE()' could not be resolved main.c /test2/src line 126 Semantic Error
    Field 'TR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 293 Semantic Error
    Field 'TR' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 220 Semantic Error
    make: *** [system/src/stm32f4xx/stm32f4xx_hal_timebase_tim_template.o] Error 1 test2 C/C++ Problem
    Field '__HAL_RCC_PWR_CLK_ENABLE()' could not be resolved main.c /test2/src line 126 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 286 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 275 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 213 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 210 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 188 Semantic Error
    Field '__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2)' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 184 Semantic Error
    Field '__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2)' could not be resolved main.c /test2/src line 131 Semantic Error
    Symbol 'counter' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 119 Semantic Error
    Symbol 'EXTI_IMR_MR17' could not be resolved stm32f4xx_hal_timebase_rtc_alarm_template.c /test2/system/src/stm32f4xx line 203 Semantic Error
    recipe for target 'system/src/stm32f4xx/stm32f4xx_hal_timebase_tim_template.o' failed subdir.mk /test2/Debug/system/src/stm32f4xx line 228 C/C++ Problem
    unused parameter 'Regulator' [-Wunused-parameter] stm32f4xx_hal_pwr.c /test2/system/src/stm32f4xx line 383 C/C++ Problem
    unused parameter 'htim' [-Wunused-parameter] stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 165 C/C++ Problem
    unused parameter 'hrtc' [-Wunused-parameter] stm32f4xx_hal_timebase_rtc_wakeup_template.c /test2/system/src/stm32f4xx line 271 C/C++ Problem
    unused parameter 'hadc' [-Wunused-parameter] stm32f4xx_hal_adc_ex.c /test2/system/src/stm32f4xx line 757 C/C++ Problem
    unused parameter 'Banks' [-Wunused-parameter] stm32f4xx_hal_flash_ex.c /test2/system/src/stm32f4xx line 971 C/C++ Problem
    unused parameter 'Banks' [-Wunused-parameter] stm32f4xx_hal_flash_ex.c /test2/system/src/stm32f4xx line 1050 C/C++ Problem
    unused parameter 'Banks' [-Wunused-parameter] stm32f4xx_hal_flash_ex.c /test2/system/src/stm32f4xx line 1086 C/C++ Problem
    implicit declaration of function '__HAL_RCC_TIM6_CLK_ENABLE' [-Wimplicit-function-declaration] stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 91 C/C++ Problem
    each undeclared identifier is reported only once for each function it appears in stm32f4xx_hal_timebase_tim_template.c /test2/system/src/stm32f4xx line 85 C/C++ Problem

    • Hi,
      Most of the times those errors are generated when the macro that defines your MCU at project level is not defined. You need to add a global macro in project settings. For example, if you are using an STM32F401RE MCU, then you need to add the macro STM32F401xE at project level.

      • Thanks Carmine,

        I have done all that, I'm using STM32F411RE so I declared STM32F411xE . I've even added the macro to the Cross ARM C++ Compiler->Preprocessor. But my problems still persist..

        • Hi, Nete,

          Same issue here. I kind of fixed it by deleting the *template.c files in ./system/src/stm32f4xx. After that, the build finishes and generates the hex files (I still don't have a board so I could not test if it works)

          Good luck!

  22. Hi,

    Thanks for the tutorial, it is great work! However, I have one question. In the final version of the project we have one startup file with extension .S copied from STM32Cube and second startup file in system/src/newlib/ which are generated with the project in Eclipse. If the files don't interfere with each other? I understand that our project is based on the .S startup. Are the files in folder newlib are needed at all ? The same applies to the files in the folder system/src/cortexm. Are they necessary ? When I tried to slim project of these files the project isn't built. You may have a solution how to effectively delete unnecessary files from the project.

    Thanks.

    • Hi Adrian,
      almost all those file are needed. If some routines from those files aren't used in your project, the linker will automatically skip them from the final binary.

      I suggest to download the free sample of my book, where the rule of those files is better explained.

      • Hi Carmine
        I use STM32F10x_StdPeriph_Lib_V3.5.0 files downloaded from STM, The vectors_stm32f4xx.c and CMSIS/Device/ST/STM32F4xx/Include are not found. How to address the problem and any new materials about run SMT32 with eclipse in win7 can be accessed?
        Thanks
        John Yang

  23. Hi Carmine
    I use STM32F10x_StdPeriph_Lib_V3.5.0 files downloaded from STM, The vectors_stm32f4xx.c and CMSIS/Device/ST/STM32F4xx/Include are not found. How to address the problem and any new materials about run SMT32 with eclipse in win7 can be accessed?
    Thanks
    John Yang

  24. Hi Carmine
    Excellent works are appreciated and they are really great.
    But,when I build the project in win7 according to your tutorials, it occurs several errors.
    make: *** [system/src/stm32f4xx/stm32f4xx_hal_timebase_rtc_alarm_template.o] Error 1
    ../system/src/stm32f4xx/stm32f4xx_hal_timebase_rtc_alarm_template.c:269:34: error: unknown type name 'RTC_HandleTypeDef'
    Do you have any suggestion to help me ?
    Thanks
    John Yang

    • Carmine Noviello

      Remove from the source tree all those HAL's files ending with "_template.c".

      • Thanks your great help.
        1.Based on your guide, these errors are solved perfectly. But when the project are built, warning occurs as following,how to solve the warning?:
        "make clean
        rm -rf ./system/src/stm32f4xx/stm32f4xx_hal.o ./system/src/stm32f4xx/stm32f4xx_hal_adc.o ./system/src/stm32f4xx/stm32f4xx_hal_adc_ex.o ./system/src/stm32f4xx/stm32f4xx_hal_can.o d............./system/src/cortexm/exception_handlers.d ./system/src/cmsis/system_stm32f4xx.d ./src/_write.d ./src/main.d ./src/stm32f4xx_it.d ./src/stm32f4xx_nucleo.d ./system/src/newlib/_cxx.d test2.elf, ...) failed.
        make (e=2): "

        2.Another question: how to judge that the project are built successfully?
        arm-none-eabi-size --format=berkeley "test2.elf"
        text data bss dec hex filename
        7093 160 436 7689 1e09 test2.elf
        'Finished building: test2.siz'
        14:57:14 Build Finished (took 25s.126ms)
        When these information are showed,is it successfully finished?

  25. Hi carmine,

    I can't find the "system_stm32f4xx.c" from "Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates", also "startup_stm32f4xxxx.s" from "Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc" after I generate the code for my stm32f4discovery board from stm32cubemx. I use stm32cubemx v4.21.0.
    Any suggestion?

    Best Regards

    Juno

Leave a Reply

Your email address will not be published. Required fields are marked *