47 Replies Latest reply on Mar 9, 2017 7:13 PM by GoingIDigital

    How to quickly import a STM32CubeMX project

    cnoviello

      Hi,
      I've implemented a faster way to automatically import a CubeMX project into an Eclipse tool-chain based on the GNU ARM Plugin. It's a bare-bone python script that simply "translates" a CubeMX project for the SW4STM32 (aka AC6 - OpenSTM32.org) tool-chain in a project generated with the GNU ARM Eclipse plugin. The script can be downloaded from my github account. Let's see how this works.

      First of all, we have to generate a new Eclipse project using the GNU ARM Plugin. Go to File->New->C Project and select "Hello World ARM Cortex-M C/C++ project". You can choose the project name you want. Click on “Next“. Here we assume "test1" as Eclipse project name.

      Schermata 2015-06-04 alle 08.11.57

      In the next step you have to configure your microcontroller. For example, for a STM32-F4 you have to choose Cortex-M4 core, while for a STM32-F0 you have to choose Cortex-M0. The Clock, Flash size and RAM parameters depend on your MCU. For example, for a STM32F401RE you can use the same values shown in the following picture. Set the other options according your needs.Schermata 2015-06-04 alle 08.14.12If you are using a Nucleo, this table shows the right values for all Nucleo boards.

      ch4-table-nucleo-specsIn 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. Please, be sure to use this pattern, otherwise the script simply doesn't work.

      Schermata 2015-06-04 alle 08.24.02

      Click on “Next“. You can leave the default parameters in the next steps. After a while, Eclipse will generate a new project for you. Now, click on the project root in the Project Explorer  view and click on "Close Project" entry.

      Now, use the STM32CubeMX tool to configure your MCU according your needs. When finished, click on the Project->Generate code menu. In the Project Settings dialog give the name you want to the project and select an output directory where store the project. Here we assume that the CubeMX project name is "mymcu".  Choose SW4STM32 as Toolchain/IDE (this is really important, to not skip this step) and generate the code.

      Finally, to use the tool I've made, you can easily type the following command at terminal prompt:

      $ python cubemximporter.py <path-to-eclipse-workspace>/test1 <path-to-cubemx-out>/mymcu
        

       

      When finished, open the project "test1" in Eclipse, click with the right mouse button on the project root and choose "Refresh" (this will force the scan of the source tree, since it has been changed while the Eclipse project was closed). Finished. Don't forget to update the file mem.ld, changing the FLASH origin address from 0x00000000 to 0x08000000.

      The script now supports also the import of Middleware libraries (FatFS, FreeRTOS, LwIP).

      The script is designed to work both in Python 2.7 and 3.x. It requires the lxml library.

      Windows users can download a pre-compiled lxml package directly from here:

      https://pypi.python.org/packages/2.7/l/lxml/lxml-3.5.0.win32-py2.7.exe#md5=3fb7a9fb71b7d0f53881291614bd323c

      Linux and MacOS X users can install lxml using pip:

      $ pip install lxml
       

       

      Please, let me know if it worked for you.

        • Re: How to quickly import a STM32CubeMX project
          bremenpl

          Hello,

          I tried using your script but I am having problems. I have managed to install python 2.7 in windows 7 but I dont know how to install lxml. I tried to build it from source but I am having problems. Here is what I get when I try to build it: https://pastebin.com/mrDE8uGK

          Do you know maybe why did the compilation failed?

          • Re: How to quickly import a STM32CubeMX project
            cnoviello

            Here I am.

             

            I forget to mention to download this pre-compiled lxml package for Windows:

             

            https://pypi.python.org/packages/2.7/l/lxml/lxml-3.5.0.win32-py2.7.exe#md5=3fb7a9fb71b7d0f53881291614bd323c

             

            Please, let me know if it solves.

            • Re: How to quickly import a STM32CubeMX project
              ilg

              cnoviello, could you edit the post and mark it as related to category 'GNU ARM Eclipse'?


              thank you,   Liviu

              • Re: How to quickly import a STM32CubeMX project
                donatled

                Carmine,

                 

                Thanks for the work to streamline the process.

                 

                I loaded the script on a Win7 box with an annaconda install with 2.7

                 

                this resulted:

                P:\CubeMXImporter>python.exe cubemximporter.py \test  C:\ARM\cube_tests\pytest

                  File "cubemximporter.py", line 313

                    except OSError, e:

                                  ^

                SyntaxError: invalid syntax

                 

                Any clues?

                 

                Cheers

                Don

                • Re: How to quickly import a STM32CubeMX project
                  donatled

                  Carmine,

                      

                  After a few days away from the bench a simple but none the less puzzling question occurred to me...  Why is there a need to use a seperate GNU ARM Eclipse plugin to that provided by the Eclipse/GCC SW4STM32 when developing for the STM32 family?

                   

                  Cheers

                   

                  Don

                    • Re: How to quickly import a STM32CubeMX project
                      cnoviello

                      Hi Don,

                      Eclipse/GCC SW4STM32 (aka AC6) is another tool-chain built over the Eclipse IDE, while the GNU ARM is a set of Eclipse plug-ins made by Liviu Ionescu to develop ARM Cortex-M applications. They are two distinct projects. It's my opinion that the work made by Liviu is better, and once you understand how to import a project generated with CubeMX inside a project made with the GNU ARM plug-in you don't need to use other tool-chains. AC6 is still a young project, and we have already seen other "young" projects become abandoned after a while (CooCox IDE is just an example).

                       

                      I've realized this script as support tool for my book about STM32 programming, which is based on the GNU ARM plug-ins, and all readers report me that this solution is the best one to develop STM32 applications using a free tool-chain.

                      • Re: How to quickly import a STM32CubeMX project
                        ivansb

                        These are my reasons:

                        - manufacturer may leave you in the cold stopping to support a dev tool on some platform (namely Linux) as eg. Atmel did, leaving an Eclipse based dev env for a Visual Studio based dev env.

                        - you may develop for different language/MCU and you don't want have 10 copies of eclipse around or switch from one dev env to another

                        - you don't want to relay on a particular setup and tool mix

                        - easier to share code across projects

                      • Re: How to quickly import a STM32CubeMX project
                        donatled

                        Thank you both for the prompt reply, I'll have a read of Carmines' book when I get back to the workshop.

                         

                        So far I have 5 different STM32 development environments loaded for evaluation and while all have interesting traits none appear to be directly compatible and when you toss in the girth of the cube libraries it becomes abundantly clear that this is not the 8 bit world of yore. The ongoing discussion regarding the pro's & cons of even using the cube HAL, given the earlier bugs in libraries, leaves me a bit nervous about the immediate commercial direction to take.

                         

                        Given the number of potentially useful ARM/RF devices becoming available I also appreciate the reasoning in finding a vendor neutral platform.

                         

                        After nearly two decades of development with AVR's I must admit I miss the simplicity...

                         

                        Cheers & many thanks Gents

                         

                        Don

                          • Re: How to quickly import a STM32CubeMX project
                            cnoviello

                            The lack of a common tool-chain in the ARM world is bad for the one side, and good for the other. I've a quite extensive experience with the CCxxxxx (CC1110, CC2530, CC3000) platform from TI (ex Chipcon), and the only official tool-chain is IAR. You are forced to use a development environment that lacks of a lot of important features, and the C compiler is full of really subtle bugs.

                             

                            However, for novice users the learning curve of Cortex-M platform is quite steep, especially if you have to deal with some "obscure" things related to C run-time environment (startup routines, LD scripts, and so on). Probably, an official tool-chain could reduce the effort in learning this platform.

                              • Re: How to quickly import a STM32CubeMX project
                                ivansb

                                Building up a vendor neutral dev env was one of my target when I started to write my tool to import CubeMX projects into GNU ARM plugin.

                                And the idea was to be able to get independent even from the current incarnation of CubeMX.

                                 

                                Then think about how it is going to be painful if you've 2 CPU in the same project + you've to write some unfortunately unavoidable JS .

                                Vendor IDE tend to be big blobs of plugins + binaries and even when they are Eclipse based they are stuck to an old version.

                                You can't install them system wide, it is hard to install other plugins. That makes development painful.

                                Sooner or later they will get too old to be run with modern OS/library sets/Eclipse version you'll have to put them in a VM.

                                 

                                I wouldn't say there is no common tool-chain. gcc (that is far from being perfect) and arm are so popular that there will be more and more convergence.

                                Differently from other ports of gcc to eg. microchip MPU, gcc seems to be a first class citizen in the ARM world. The fact that it is massively used put it under heavy test. The fact that it is so popular make it easy to share code and experience between programmers.

                                 

                                You may be right that "novices" or maybe people that would like to start developing quickly may be still attracted by preconfigured IDE and that could be one of the reasons arduino became so popular, but still if you have more complex projects you've to maintain through years considering that most vendors are a bit schizophrenic about their software support and their tools are BIG HEAVY GUI, hard to automate, being a bit more patient is going to pay off.

                                 

                                This is my first time setting up a dev env for ARM, excluding a quick experience with Yocto (that's completely another world) and it didn't took me long to have my first led blink without using the ST IDE.

                                 

                                I'm not that happy to relay on Eclipse too... but right now I feel it would be too time consuming to set up at least openocd, gdb, code completion on any other editor.

                                 

                                Another drawback of Eclipse I'm discovering now is there is no way to interact with it in a clean way other than actually writing a plugin, in Java, inside Eclipse.

                                There seems to be no binding with any other language and I couldn't figure how I could access its api even with a standalone java application. Configuration files aren't documented, you change them just through API.

                                • Re: How to quickly import a STM32CubeMX project
                                  ilg

                                  Perhaps we should think of a strategy how to integrate the code generated by Cube into GNU ARM Eclipse projects.

                                   

                                  The existing solution is a script to import an entire project, and probably for most of you it is enough.

                                   

                                  On the same path, with some effort, a plug-in can be written to perform the import from inside Eclipse.

                                   

                                  A more elaborate solution may be inspired from the latest MDK, which is able to launch CubeMX from inside MDK, edit the initialisation configuration and return to the existing MDK project.

                                   

                                  Personally I do not use either MDK or Cube, so I may be wrong, but from Cube I would keep only the functionality to edit the initialisation configuration, and manage the rest of the project in Eclipse, with a packs based configuration.

                                   

                                  It would be useful if you guys can study how MDK works with Cube (I guess they exchange some XMLs), and how to adapt this technology to work with Eclipse.

                                    • Re: How to quickly import a STM32CubeMX project
                                      ivansb

                                      We are in your hands Liviu.

                                       

                                      I've to admit I cloned your repo to get a clue about how Eclipse plug-ins are made since I already touched with hands the limitations of editing the .cproject file from outside Eclipse.

                                       

                                      I've rarely used Java in my life and generally out of desperation, forced by a dreadful fate. OK not really but well I gave up shortly since I had the feeling that Java is the simplest stuff to learn before you can write an Eclipse plugin. The most part should be learning Eclipse and CDT internals.

                                       

                                      My feelings towards Eclipse are a bit mixed and I'm not sure I want to invest my time to learn how it works internally, unless you take me by hand, sorry. I'm OK to use it as a tool.

                                       

                                      CubeMX is not that bad since it already structure the code in a way that seems to be easy to "upgrade" to a newer release. Cube library doesn't look enough mature to do heavy weight work but it looks it may improve to be good enough for all but the most demanding tasks.

                                      I still have to investigate on libopencm3 and mbed but they look interesting.

                                      And supporting all libraries for all vendors for all MCU doesn't make sense even if it would be something surely more valuable than a "point and click" import tool for Cube.

                                      I'd say that a good blog post and a little bit of help should be enough to put newbies on the good route to develop software for HAL with your plug-in.

                                       

                                      Furthermore starting a project is something you do once, upgrading may be something you prefer to automate just to make it reproducible, so you can test it and Eclipse doesn't look the right place to "automate" stuff.

                                       

                                      As said there is something I couldn't do "outside" of Eclipse that would be comfortable to have but after playing a bit with HAL even if I had your skills and my time came for free I wouldn't invest in making things easier just for Cube/CubeMX/HAL.

                                       

                                      If I really had something to ask you to improve that wouldn't be CubeMX importing and I think the thing I'd like to see improved aren't a responsibility of GNU ARM Eclipse plug-in.

                                       

                                      BTW CubeMX comes as an Eclipse plugin too but I haven't been able to run it inside Linux. I'm not expecting anything more special from MDK.

                                       

                                      thanks Liviu

                                        • Re: How to quickly import a STM32CubeMX project
                                          amosnier

                                          Hi,

                                          To be honest, after a bit more practice, I'm not sure I understand this debate any longer. If you want to use STM32CubeMX code under GNU ARM Eclipse, just do that! A rather simple approach that has worked for me:

                                          - Install ARM GNU Eclipse, including OpenOCD or another debugger solution as described on the official site.

                                          - Create a project for your MCU (for instance STM32F4xx) in Eclipse.

                                          - Remove all the source code (we want to use STM32CubeMX code instead, remember?).

                                          - Generate an SW4STM32 project with STM32CubeMX.

                                          - Copy/paste all generated files to a top directory under your Eclipse project. Call it something obvious like stm32cubemx_generated_code.

                                          - Adapt your Eclipse project to the new contents (include path, linker script path, symbols, etc.). Sure, this is a little cumbersome, but one cannot seriously mean to develop projects for STM32 without understanding such details, which are not that hard.

                                          - Change the startup assembly file extension from .s to .S (workaround for obscure Eclipse bug).

                                          - Compile.

                                          - Run

                                           

                                          My preferred way to add code to this already working application (the main function ends in "while(1);") is to do it on the side (like in an "application" directory at the same level as "stm32cubemx_generated_code"), so I have to modify the cube code as little as possible. Making the cube code branch to my own is a simple as an app_main() invokation in cube's main(). If I want a full assert (I obviously do), I make cube's assert_failed() invoke my own halt(), that does whatever I want.

                                           

                                          An example of this approach can be found at: https://github.com/amosnier/code/tree/master/bare_on_eclipse/04_gnu_arm_eclipse_stm32f4_disc_empty_template .

                                           

                                          In any case, I want to take this opportunity to once again thank Liviu for his amazing job, Carmine for his book (latest chapter about memory layout and linker scripts is really nice) and ST for their chips and tools.

                                           

                                          Best regards,

                                           

                                          Alain Mosnier

                                            • Re: How to quickly import a STM32CubeMX project
                                              ilg

                                              amosnier, what if, after you create the project, manually import, etc decide to add a new peripheral, or discover you need to change something radical? you simply do it again from scratch?

                                               

                                              the point was to automate the process, both the creation and the further maintenance of the project.

                                                • Re: How to quickly import a STM32CubeMX project
                                                  amosnier

                                                  @liviu

                                                   

                                                  Adding a new peripheral (for example a USART, which I have just done):

                                                  1. Open STM32CubeMX. Make the changes in the GUI. Regenerate the code.

                                                  2. Copy/paste the cube files to your Eclipse project (replace the old files, they are all located under the same directory, it takes no time). Fix the 2 or 3 changes you usually make to cube code (see my previous post). Takes at most a few minutes.

                                                  3. Compile

                                                  4. Run

                                                   

                                                  Sure the new cube files could contain one or two new include directories that you will have to add to your Eclipse project. Not a big deal. And of course, if the change has an impact on your existing own code, it can't be updated magically, you will have to do that manually.

                                                   

                                                  Works for me anyway.

                                                   

                                                  Regards,

                                                   

                                                  Alain

                                                  • Re: How to quickly import a STM32CubeMX project
                                                    ivansb

                                                    Liviu,

                                                     

                                                    CubeMX does a good job organizing the code. There are some places you can add your own code and it will leave them alone unchanged.

                                                    It's not the kind of Microsoft autogenerated code I was used in the '90.

                                                     

                                                    As Alain is saying if you structure well enough your code, what you *may* end up to do will be to reinsert a couple of function calls in CubeMX generated main(). That could be automated with sed, no need for a parser.

                                                     

                                                    The most painful job is adding all include paths and a couple of symbol define, but that's common not just for Cube HAL but for many libraries. CubeMX doesn't configure "Middleware" and most of the middleware provided don't even compile without a configuration.

                                                     

                                                    While I do agree that having a tool to do this trivial things is going to make everything less error prone and easier to reproduce/test, even considering anything outside of Eclipse is not going to be able to configure everything at the best, I don't think Eclipse is the right place to do it, since I don't know any way to "script" it without launching the GUI.

                                                     

                                                    Today I had some time to look at HAL and your C code (BTW kudos).

                                                    If I really had to ask you something I'd ask you to adapt your code to ST startup and linker script.

                                                    I miss the features your code provide.

                                                    I think syscalls and debugging facilities should stay at an higher level than the startup code and linker script.

                                                    I'm not saying which code is better but I'd tend to think that startup and linker script should be more a concern of the manufacturer.

                                                    Being unable to completely understand and maintain your code, being unable to make it work with ST linker script and startup code unchanged I opted to just assemble a new syscalls.c that I could understand and wipe your code.

                                                    Furthermore your code call NVIC_SystemReset() that is reachable just if you "keep" cmsis_device.h that's not part of CMSIS included in Cube HAL that makes juggling with files just a bit more annoying.

                                                    I don't know if it makes sense since you're supporting other MCU and it seems some code is shared, right now I'm not even sure my worries are reasonable but this is what makes me scratch my head right now.

                                                    Sorry for whining, I'm already very glad to use your code as is.

                                                     

                                                    BTW Today I gave a look at MDK documentation too and it doesn't seem it is making anything different from what Carmine and I did, just they have access to their IDE cfg so they don't have to "hack" it as we did.

                                                      • Re: How to quickly import a STM32CubeMX project
                                                        ilg

                                                        thank you for your feedback.

                                                         

                                                        in my opinion, generally, vendor provided startup code and linker scripts are a big mess. if you are dedicated to projects fully generated with CubeMX, probably they are fully functional, but if you need more (for example to initialise the C++ static constructors), it might not be ok.

                                                         

                                                        my view of the future is based on tools that build applications based on components, available in packs, similar to what MDK does with CMSIS Packs, and that's what I'm working on now.

                                                         

                                                        if we can somehow fit the initialisation code generated by Cube as a kind of component in this packs based world, ok, we'll do it.

                                                          • Re: How to quickly import a STM32CubeMX project
                                                            ivansb

                                                            Yeah I agree, they may be a mess, but considering we are discussing about supporting Cube HAL as you said I'd expect it is going to work with its own stuff.

                                                            People that know what they are doing will do it, people that don't are the one that will more easily ask support on ST channels that may expect them to use a pristine version of Cube.

                                                            Furthermore it introduces a subtle dependency between Cube HAL and Eclipse.

                                                            You provide linker scripts, startup code and syscalls (...and something more) and they should be self contained, but still that could make harder to upgrade to a newer Cube version or develop/upgrade without Eclipse.

                                                             

                                                            I'm not saying that your work on "packs" is worthless, I'd perfectly happy to "push a button" and get Cube HAL library installed especially if you'll maintain the "integration" code.

                                                            This work is going to lower the barrier for many many people that don't have the same concerns I have.

                                                            I'll stick with my half assed solution till I don't feel comfortable I can understand your code and maintain an hybrid and consider switching when you'll come up with a smoother solution.

                                                             

                                                            Don't take it bad, I'm just being a bit paranoid since I can still afford it. If I were in a hurry few weeks ago I'd have beg you to integrate Cube in any way you wished provided it worked without any need to understand it . If a Cube pack will provide this functionality, people will come to you in flocks.

                                                             

                                                            BTW at least ST code seems to provide the required functionality to support C++.

                                                              • Re: How to quickly import a STM32CubeMX project
                                                                ilg

                                                                I took a quick look at the latest Cube.

                                                                 

                                                                the result matches my expectations, you can create a generic project, which is described by a .gpdsc xml.

                                                                 

                                                                this file is very similar to Keil .pdsc files, so it may be easily integrated within a packs environment.

                                                                 

                                                                assuming the future wizard will be able to generate and manage projects using Keil CMSIS Packs and my xPacks/XCDL packs, and these packs provide everything required for a project, i.e. a RTOS, high level drivers, TCP/IP stack, file systems, and every middleware we can think of, the only aspect where CubeMX can be of help is to generate the initialisation code for HAL devices.

                                                                 

                                                                for this, I will reserve a folder in the project, named `cube-mx` for example, and provide a default .ioc file, with available data (MCU name, for example).

                                                                 

                                                                then I would start CubeMX, configure it as necessary, and let it generate the code in the same `cube-mx` folder.

                                                                 

                                                                I really don't care how the content is structured, as long as the .gpdsc file provides a structured description of the result.

                                                                 

                                                                using the .gpdsc file I would adjust the project configuration (include and src folders) to add the cube generated code.

                                                                 

                                                                one small thing that needs tweaking is the generated main.c file, where I would change the main() to cube_inits(), which I'll call from the true project main file.

                                                                 

                                                                I think this is quite realistic.

                                                                 

                                                                except those who decided to go CubeMX only and do not feel comfortable with the code generated by the GNU ARM Eclipse wizards, I suggest you try this approach manually:

                                                                 

                                                                - after creating the project, add a cube-mx folder to the project

                                                                - make CubeMX generate the initialisation in this folder,

                                                                - add the `Inc` and `Src` folders to the project configuration,

                                                                - rename the main() function and call it from the project main.

                                                                 

                                                                I see no major problem why this solution, it should combine the GNU ARM Eclipse code with the CubeMX initialisations.

                                                                  • Re: How to quickly import a STM32CubeMX project
                                                                    ivansb

                                                                    Liviu,

                                                                     

                                                                    that's not too different from what Carmine's script is doing and I bet from inside Eclipse it could be done even better.

                                                                    I'm going to make some test to see if I can merge your code for trace support and ST code. Again Carmine seems to have found a solution, but as stated before I'd prefer to understand better your code.

                                                                     

                                                                    While I absolutely agree that C is more portable than asm, that many times manufacturers don't provide very nice startup and linker script I still would prefer a solution that makes Cube work with or without your plugin and Eclipse.

                                                                    The only way I see this can be done is keeping the Cube code and adapt yours. It would be nice ST accepted patches to their code to adapt their code to yours, but that doesn't seems likely.

                                                                    It seems you're sharing your linker script among several MCU manufacturers and possibly even the trace code and I do understand that adapting your code to include ST stuff may be suboptimal from your point of view.

                                                                    Once your Cube pack will be ready, nothing forbid to automatically "patch" code to make it work just with Cube or Cube + your code.

                                                                     

                                                                    Are you going to support updates of the Cube library?

                                                                    What is it going to happen if they remove some include path or remove some symbol definition between versions or people add/remove middleware or change pin assigned functions?


                                                                    Still I think no matter how you're going to implement it, it is going to be a great success since it will lower the barrier to get some code running with Cube.

                                                                     

                                                                    If you need I can pack some CubeMX generated projects to let you get a more precise idea how it works without the need to install it. While I'm not that sympathetic with Apple users generally I can share your pain being a Linux user and being used to feel a second class citizen when it comes to tools for embedded development

                                                                    A projects for F103 without middleware is less than 300K, I don't think a project including middleware is going to be much bigger. Library code is not included, just referenced in the project file. I can generate Eclipse (Eclipse + ST plugins actually), IAR or KEIL projects.

                                                                     

                                                                    Alain,

                                                                     

                                                                    up to my memory double definitions comes from 2 copies of CMSIS + some template files in Cube library + double definitions in startup code.

                                                                      • Re: How to quickly import a STM32CubeMX project
                                                                        amosnier

                                                                        If that is of interest, the CubeMX code I used to apply Liviu's proposed process is the same as the one located there: stm32cubemx_generated_code  . Sorry I am not helping more. I have little time for that hobby of mine, and in the next few days I would like to spend it on:

                                                                        - Analyzing the contents of the first few binaries I have produced.

                                                                        - Explore more of the MCU's features.

                                                                        Regards,

                                                                        Alain

                                                                        • Re: How to quickly import a STM32CubeMX project
                                                                          ilg

                                                                          > but as stated before I'd prefer to understand better your code.

                                                                           

                                                                          there is nothing magic there, create a project, set a break at _start and trace it to main().

                                                                           

                                                                          > prefer a solution that makes Cube work with or without your plugin and Eclipse.

                                                                           

                                                                          I'm not sure exactly what your needs are.

                                                                          my tools will also work without Eclipse, from command line, Eclipse just makes things easier.

                                                                           

                                                                          > updates

                                                                           

                                                                          please take a look at the stm32f4-hal and stm32f4-cmsis packs in https://github.com/xpacks

                                                                           

                                                                          you'll notice a quite elaborate structure, the packs maintain on the 'originals' branch the ST code, and on the 'xpack' branch my code, which might be identical to ST, but might also be patched, if necessary.

                                                                           

                                                                          although not complete now, each xpack will include metadata, to define which are source files, which are include files, etc and the wizard will use this metadata to correctly configure the project.

                                                                           

                                                                          > double definitions comes from 2 copies of ...

                                                                           

                                                                          then remove one of them

                                                                           

                                                                    • Re: How to quickly import a STM32CubeMX project
                                                                      amosnier

                                                                      Liviu,

                                                                      It's interesting that you should talk about C++ static constructors, because I had just been playing with that. We haven't seen that much code so far in this thread, so let's go:

                                                                      #include "app_main.h"
                                                                      #include <stdio.h>
                                                                      
                                                                      struct Test {
                                                                          static bool constructed;
                                                                          bool exists;
                                                                          Test()
                                                                          : exists(true)
                                                                          {
                                                                              constructed = true;
                                                                          };
                                                                      } test;
                                                                      
                                                                      bool Test::constructed = false;
                                                                      
                                                                      int app_main(void)
                                                                      {
                                                                          printf("Test::constructed = %d, test.exists = %d\n", Test::constructed, test.exists);
                                                                          while (1)
                                                                              ;
                                                                          return 0;
                                                                      }
                                                                      
                                                                      


                                                                      With my GNU ARM Eclipse + STM32CubeMx setup this yields:

                                                                      Test::constructed = 1, test.exists = 1
                                                                      


                                                                      It looks to me that the static constructor was executed correctly. Do you think this is a valid test? Anything else I should test? Please hit me. :-)

                                                                      Note: I don't run semi-hosted, I re-targeted standard out to USART2, that's why I am not using printf() in the constructor. That obviously does not work (the UART is initialized in main()).

                                                                      It seems to me that your latest proposition of CubeMX + GNU ARM Eclipse should lead to code redundancy, and I also wonder what happens with CubeMX's ability to only select the Cube files that my project needs, but I will give it a shot.

                                                                      Regards,

                                                                      Alain

                                                                        • Re: How to quickly import a STM32CubeMX project
                                                                          ilg

                                                                          you are probably right and the new Cube assembly startup code calls the static constructors init code.

                                                                           

                                                                          if you like that assembly code, no problem, go ahead and use ti.

                                                                           

                                                                          in my code I still prefer a portable C version.

                                                                           

                                                                          > code redundancy?

                                                                           

                                                                          feel free to remove the code that you consider redundant, what is really useful is the Cube generated code, for all the rest, including HAL, it'll come from the new packs, which will have specific metadata to determine what is included and what is skipped.

                                                                           

                                                                          for a preview of the future packs, please check https://github.com/xpacks

                                                                            • Re: How to quickly import a STM32CubeMX project
                                                                              amosnier

                                                                              Liviu,

                                                                              Sorry about the code formatting, I had not realized that there was an insert function. Fixed now.

                                                                              Agreed about assembler vs C.

                                                                              Will test your approach now.

                                                                              Regards,

                                                                              Alain

                                                                              • Re: How to quickly import a STM32CubeMX project
                                                                                amosnier

                                                                                Liviu,

                                                                                I have now tried your procedure:

                                                                                - after creating the project, add a cube-mx folder to the project

                                                                                - make CubeMX generate the initialisation in this folder,

                                                                                - add the `Inc` and `Src` folders to the project configuration,

                                                                                - rename the main() function and call it from the project main.

                                                                                This definitely generates a number of double symbols (functions, MACROS, etc.). This can certainly be cleaned up but on the other end, my current solution is fast, easy, and working. I would prefer a startup file in C for sure, but as long as the CubeMX version works for what I am doing, I won't touch it anyway. It would be another matter if I did meet some limitations with that code, and I will definitely be interested to test a more integrated solution when you have one.

                                                                                Thanks a lot,

                                                                                Best regards,

                                                                                Alain

                                                                                  • Re: How to quickly import a STM32CubeMX project
                                                                                    ilg

                                                                                    > a number of double symbols (functions, MACROS, etc.)

                                                                                     

                                                                                    it was somehow expected. unfortunately CubeMX is not available for OS X, and for me it is very complicated to test this and evaluate the complexity required to fix it.

                                                                                     

                                                                                    Liviu

                                                                                     

                                                                                     

                                                                                      • Re: How to quickly import a STM32CubeMX project
                                                                                        amosnier

                                                                                        unfortunately CubeMX is not available for OS X

                                                                                        How come OS X has become so popular with hackers? When did that happen? What have I missed? I am 60% into Steve Jobs' biography, and I still feel I will finish my life married to Linux. Something must be wrong with me.

                                                                                        More seriously, Carmine is your friend, once again: Running STM32CubeMX on Mac OS. Finally! | Carmine Noviello - An half-serious biog about programming and electronics  .

                                                                                        Have fun!

                                                                                        Regards,

                                                                                        Alain

                                                                                        • Re: How to quickly import a STM32CubeMX project
                                                                                          GoingIDigital

                                                                                          CubeMX now works natively on OSX and also works as an Eclipse Plugin. I am looking for an easy way to start a project using the CubeMX generated project but finding it difficult.

                                                                                            • Re: How to quickly import a STM32CubeMX project
                                                                                              ilg

                                                                                              I suggest you study the projects in:

                                                                                               

                                                                                              https://github.com/micro-os-plus/eclipse-demo-projects

                                                                                               

                                                                                              the idea is not to import a CubeMX project into a new Eclipse project, but to keep the CubeMX into the loop, and regenerate the initialisation code each time it is necessary.

                                                                                                • Re: How to quickly import a STM32CubeMX project
                                                                                                  GoingIDigital

                                                                                                  Thanks for trying to help but as someone trying to understand how to use the STM32 for the first time I am already struggling to get started. I'm afraid that just went over my head and added more stuff I don't understand such as what an xPack is. There is seemingly no easy well explained way to get started with the STM32, especially for people wanting to use eclipse rather than one of the commercial packages. The more I fight with it the more frustrated I get, if I hadn't committed to a project I really would have given up weeks ago.

                                                                                                   

                                                                                                  The perfect workflow for me would be..

                                                                                                   

                                                                                                  Use CubeMX to configure the environment, i.e select exact microcontroller, set pin configuration and clocks etc, save that as an empty project.

                                                                                                  Open eclipse write my code using the current official ST HAL libraries.

                                                                                                  Debug using OpenOCD

                                                                                                  Flash final code for use.

                                                                                                   

                                                                                                  As far as I can see there is no solution that works like this, they all have major issues that prevent someone new like me from completing the most basic task. I can't believe how frustrating the whole experience has been from day one.

                                                                                                    • Re: How to quickly import a STM32CubeMX project
                                                                                                      ilg

                                                                                                      I see. you are right, I don't know of any automated solution to implement your workflow.

                                                                                                       

                                                                                                      but I can tell you how I think the workflow should be, and this is how a future version of the project wizard will work:

                                                                                                       

                                                                                                      - use Eclipse to create a new project, based on a list of existing xPacks (more on what these are, later); select microcontroller and middleware

                                                                                                      - open the Eclipse generated CubeMX configuration with CubeMX and configure pins and clocks; generate initialisations code

                                                                                                      - return to Eclipse and build the project

                                                                                                      - debug using J-Link/OpenOCD/QEMU

                                                                                                      - whenever you need to change the pins and clocks, you open CubeMX and regenerate the initialisation code

                                                                                                      - whenever you need to update to a newer version of an xPack, you simply update the xPacks; a reasonably dependency mechanism well allow what versions of an xPack you are ready to accept during updates (usually up to the latest minor/patch version, according to semantic versioning rules)

                                                                                                       

                                                                                                      an xPack is a simple package, usually containing the source files of a library and some metadata to assist version management and builds. a more rigorous definition is that an xPack is a 'npm' package with an additional 'xpack' metadata. 'npm' packages are the standard way of distributing JavaScript modules, but their definition is generic enough and can be used for C/C++ or other languages. (https://www.npmjs.com/) 

                                                                                                       

                                                                                                      an example of a simple xPack is @ilg/segger-rtt (https://www.npmjs.com/package/@ilg/segger-rtt), which packs some SEGGER sources. the xPack is stored in a Git repository, you can use it as is, but the trick with xPacks is the additional metadata, that can automate some things, like maintaining versions.

                                                                                                       

                                                                                                      right now you can install this package on any machine using

                                                                                                       

                                                                                                      npm install @ilg/segger-rtt
                                                                                                      

                                                                                                       

                                                                                                      which will create a folder called node_modules and will download the latest package version in it.

                                                                                                       

                                                                                                      in the near future, a separate tool called 'xpm' will handle the specifics of C/C++ and help install and generally manage xPacks.

                                                                                                       

                                                                                                      another trick that the xPack metadata will cover is the information required to automate builds; each xPack will define which folders contain the source files, where are the folders with headers, what symbols to add to the compiler, what compiler options are needed, things like this.

                                                                                                       

                                                                                                      with this information available, the build system will be able to automatically create Eclipse projects with all settings already there, requiring minimum manual intervention.

                                                                                                       

                                                                                                      for the moment the functionality of 'xpm' is implemented in several shell scripts, executed from generate.sh, a script specific to each of the demo projects I recommended you to check.

                                                                        • Re: How to quickly import a STM32CubeMX project
                                                                          donatled

                                                                          Carmine,

                                                                           

                                                                          I just finished the book, what an excellent read!  One of the issues which I suspect causes problems for many people starting with the STM32 platform is that there is a massive amount of information relating to a wide range of development systems which covers a broad range of libraries, many now mainly of historical significance. This makes getting past step one very difficult until you get a read on the lie of the land.

                                                                           

                                                                          I aplaud you on your choice of material to date in your book. It clarifies a lot of issues and provides a good guide to working with the current cube/HAL system. The simple examples provide a basis to run tests and then go looking into the more detailed information.

                                                                           

                                                                          Cheers and many thanks for a job well done to date.

                                                                           

                                                                          Don

                                                                            • Re: How to quickly import a STM32CubeMX project
                                                                              cnoviello

                                                                              Hi Don,

                                                                              Really thank you for your kind feedback ;-)

                                                                                • Re: How to quickly import a STM32CubeMX project
                                                                                  amosnier

                                                                                  Carmine,

                                                                                  I have just tried STM32CubeMX for the first time (until today, I didn't know it worked on Linux), your instructions and your script (I had been playing with GNU ARM Eclipse for a few days before that).

                                                                                   

                                                                                  My user code in the main function is:

                                                                                  BSP_LED_Init(LED_ORANGE);
                                                                                  while (1) {
                                                                                        BSP_LED_Toggle(LED_ORANGE);
                                                                                        busy_wait();
                                                                                   }
                                                                                  

                                                                                  (https://github.com/amosnier/code/tree/master/bare_on_eclipse/02_stm32cubemx_blink_led)

                                                                                   

                                                                                  Working perfectly on my STM32F4-Discovery.

                                                                                  Looks like we have a winner with this combination of tools!

                                                                                  I may encounter the same issue with CubeMX in Linux as you have seen on Mac. I haven't used Windows at home for years, I would be very angry.

                                                                                  I have also bought your book today. Otherwise, what would I do between two debugging sessions? :-)

                                                                                  Thanks a lot to Liviu, you and ST (especially if they learn to write truly portable Java!).

                                                                                  Best regards,

                                                                                  Alain Mosnier

                                                                                    • Re: How to quickly import a STM32CubeMX project
                                                                                      ivansb

                                                                                      While CubeMX is actually a java app, it is an undue pain to install it on Linux.

                                                                                      They wrapped it in an exe that is simply a zip, then you've to run the installer that simply again unzip other java stuff an finally you can place it wherever you want and run it from the command line. Furthermore it seems you can't chose some of the paths (eg. where it downloads the HAL) and it keeps on downloading a bit older version of the HAL that the one you can download from ST web site.

                                                                                      Unfortunately as usual while Linux is very popular on embedded systems and it is very comfortable to use the same tools everywhere... when manufacturers think about dev tools they still consider it a second class citizen.

                                                                                      It seems they are punishing real programmers to make life easier to "point&click" programmers since the later are the majority.

                                                                                       

                                                                                      I just discovered that A6 IDE (SW4STM32) comes with very old OpenOCD, very old HAL and hard to justify copyright on code that just add maintenance costs (not for royalties but to take care of one more copyright license in a project). One more reason to set up your own dev env.

                                                                                       

                                                                                      I've placed it in /opt/ and I have a bash script in /usr/local/bin ... let me check where some poor soul before me discovered the process.

                                                                                      5V: Installing STM32CubeMX on Linux

                                                                                       

                                                                                      They recently fixed a problem with legacy #define in HAL for F1 but they offer it just as a "patch" to 1.3.0.

                                                                                      One more chance to advertise my tool that help you replace HAL version of a project: https://github.com/Ivan-SB/lib2eclipse

                                                                                       

                                                                                      Again in my effort to stay as much independent from tools and try to recycle knowledge Eclipse is a necessary evil but eg you're going to save a LOT of compile time just running make in console and not inside Eclipse.

                                                                                       

                                                                                      have fun hacking

                                                                                       

                                                                                      BTW Carmine, I bought your book too and finished it in an hour or so. On overall it saved me more time than reading it... but I'm waiting the other 60%.

                                                                                      Reading ST docs, but they aren't the only culprit, is like reading aruspices. I was actually looking for the difference between break, update, trigger TIM interrupt (documented) vs "global" (CubeMX name). I didn't find the answer in your book but it helped me to fix a couple of things I have overlooked in my project setup. If you don't mind I could give you some suggestions about the part I've been able to read.

                                                                                      But hurry up with your book, otherwise I'll have to digest the rest of the HAL by myself... and especially find the usual bugs after hours of thinking in tears what I did wrong

                                                                                      • Re: How to quickly import a STM32CubeMX project
                                                                                        ivansb

                                                                                        BTW CubeMX 4.13 is out and they said it adds Linux support.

                                                                                         

                                                                                        I got 4.12 work under Linux, I wonder what they did, maybe just avoid to use self extracting zip in an exe.

                                                                                        They added a couple of other features and support for other hardware.

                                                                                        I still haven't tried the new version.

                                                                                         

                                                                                        It's nice they are putting some efforts in developing Cube stuff.

                                                                                         

                                                                                        It seems there are a lot of people complaining about HAL. It is hard to understand if it is for its bugs, prejudices of people used to write code to the bare metal or bad name it got from the first releases.

                                                                                         

                                                                                        I find HAL a nice idea but I gave a quick glimpse to the code and I've to admit I was a bit disappointed. Other parts may be better... or worse. I hope for the former.

                                                                                         

                                                                                        I noticed some functions seems to be written just to be used once at initialization time, but that may not be the case.

                                                                                        I can live with it for the project I'm after since I don't have stringent performance constraint, but that's not always the case and if I needed a faster implementation I would have had to rewrite all the initialization code of the GPIO.

                                                                                        It doesn't come as a surprise that an abstraction layer may come with a performance penality, but the code I saw really didn't care to be performance wise.

                                                                                         

                                                                                        But it seems development of Cube libraries and CubeMX is pretty active. I hope not to stumble in any serious bug while they keep on improving it.

                                                                                        • Re: How to quickly import a STM32CubeMX project
                                                                                          donatled

                                                                                          Alain,

                                                                                           

                                                                                          Were you able to derive a config which allowed the semihosting to function?  I have done something similar to your examples and initially it seemed like a very clean solution to the problem which allowed for ongoing changes in cubemx however it doesn't apppear to easily integrate with the work done by Ivan on the debugging side of things.

                                                                                           

                                                                                          Cheers

                                                                                           

                                                                                          Don