cancel
Showing results for 
Search instead for 
Did you mean: 

Migrating code from one STM32F0 micro to another

larry23
Associate II
Posted on December 17, 2015 at 22:55

I am developing code on an STM32F072B-DISCOVERY board that I wish to use on an STM32F031F4P6 micro.  I downloaded STM32CubeF0, found an I2C example that I can use on the Discovery board, built it, modified it, and got some I2C and GPIO functionality the way I want it.  Now I want to change the project so that it compiles for the STM32F031F4P6 micro. 

I found under �Options for Target� where to change the device.  I see that when I do that, the startup file changes to startup_stm32f031.s.  I also see that many other files in the project are labeled as stm32f0xx, which I reasonably assume means that they will work for any stm32f0 micro. 

I then found that a folder named Device had automagically appeared under MDK-ARM/RTE (on the hard drive, not in the Project window of the uVision IDE).  There are two folders in Device, STM32F031F4 and STM32F078RB.  The former has two files, system_stm32f0xx.c and startup_stm32f031.s.  The latter contains system_stm32f0xx.c file and startup_stm32f072.s. 

Question &sharp1:  I see that the two system_stm32f0xx.c files that recently appeared are identical to each other but are older than the one that appears in the Project window.  What am I to do with these files?

Question &sharp2:  startup_stm32f072.s is what appears in the Project window.  I don�t see how to change it to startup_stm32f031.s.

Question &sharp3:  In the Project window, I see a file under the Drivers/BSP/STM32F072B-Discovery folders called stm32f072b_discovery.c.  I am not finding any files in STM32CubeF0 to replace this with.  

Also, is there anything else that I might be missing or making trouble for myself that I haven�t yet encountered?

#stm32cubef0-migrate-discovery
5 REPLIES 5
larry23
Associate II
Posted on December 18, 2015 at 18:47

When I perform only the first stop of going to ''Options for Target'' Device tab and select the STM32F031F4 micro, I get errors on subsequent attempts to compile.  The errors are all similar.  Here is the first one:

RTE\Device\STM32F031F4\system_stm32f0xx.c(249): error:  #20: identifier ''RCC_CFGR_PLLMULL'' is undefined

        pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;

Clearly I have more to do in order to make this work, but I'm not finding an guidance.

Posted on December 18, 2015 at 19:01

Yeah, It's a bit of a swamp with few guides wanting to wade in.

With Cortex-M0, Keil uV5, RTE and Cube I'm batting a bit outside my comfort zone.

The error looks to stem from it not pulling in the right include files, either due to the ''Include Paths'' setting or a compiler command line define, either missing the target chip, or that it uses HAL, SPL, or whatever. The classic ST mechanism is to pull in include files via an stm32f0xx_conf.h type file in the project, that gets pulled via an #include ''stm32f0xx.h''. Make sure it is pulling files consistently from the same abstraction model, as they don't mix-n-match well.

You should perhaps look at the project options, especially the ''C/C++'' tab, between the projects for the two different parts.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
larry23
Associate II
Posted on December 18, 2015 at 22:11

The C/C++ tab has Preprocessor Symbol defines of

STM32F072xB,USE_HAL_DRIVER,USE_STM32F072B_DISCO.

Since I'm moving away from the eval board, the first and last of these clearly need to change but I don't know what to change them to nor how to find out.

The Include Paths section includes a path to Drivers\BSP\STM32F072B-Discovery.  Again I'm sure that this needs to change, but to what?  Looking at the neighborhood around that path does not reveal a logical substitute.

I'm beginning to think that the ST32Cube_FW_F0_V1.4.0 code is not set up to do what I need to do.  This is a little surprising at least, since these two processors are from the same family.  

I am adrift at sea.  

dan239955_st
Associate II
Posted on December 19, 2015 at 07:52

This is a perfect example of why I pick the processor that best suits my project.  Skip the Discovery Boards, design and build the circuit with the processor, and work through bringing up my project.  Instead of having to learn twice.  I only need to learn the libraries once, and I'm done.

larry23
Associate II
Posted on January 12, 2016 at 16:28

I received directions from ST Online Support that for the most part showed me the way.  I'm copying them here in case anyone else might benefit.

SOLUTION PROPOSED BY SUPPORTER - 18/12/2015  18:31:56 :

Hi,

Below are steps to port a F072 Discovery project to an F031:

1) Under “Options for Targetâ€� Device tab, change the device to STM32F031F4. This will create the RTE folder you mentioned under MDK-ARM dir. This will also create a Component Class labeled ''Device'' under the project window, you'll have to remove this, so right-click this and Select ''Options for Component Class ''Device'' and hit the ''Remove'' button to remove.  This class should disappear from the Project window.

2) Under the project window, you'll have to remove the old startup_stm32f072.s and add the new startup_stm32f031.s. 

- To remove startup_stm32f072.s, Right-click startup_stm32f072.s and select Remove File

- To add startup_stm32f031.s, copy MDK-ARM\RTE\Device\STM32F031F4\startup_stm32f031.s and paste it under the MDK-ARM directory. Then, right-click ''Example/MDK-ARM'' group and select ''Add Existing Files to group'', then browse to the MDK-ARM directory and select startup_stm32f031.s.

- The files under the ''Drivers/BSP/STM32F072B-Discovery'' folder called stm32f072b_discovery.c are specific to the F072 Discovery board, since you are not going to be dependent on the discovery board, you can simply Remove this group and file altogether by right-clicking on the group ''Drivers/BSP/STM32F072B-Discovery'' and selecting to remove it.

3) Under “Options for Target� C/C++ tab, replace STM32F072xB define with STM32F031x6 and remove USE_STM32F072B_DISCO.

4) The examples for the STM32F072B-Discovery are obviously targeted for the STM32F072, and thus the system clock config used the internal HSI48 available on the F072 but not the F031, so you'll have to rework the SystemClock_Config() function to not use the HSI8 instead.  

There's an example for the a similar device you are targeting under ''STM32Cube_FW_F0_V1.4.0\Projects\STM32F031K6-Nucleo\Examples\GPIO''. That you can use as a guide.

Regards,

MCU Tech Support