Which STM32 processor include file should be used?

Comments

19 comments

  • Avatar
    Harjit Singh

    It seems that the Rowley file stm32.h is closest to the ST stm32f10x.h file.

    For the STM32F103VE, the STM32.h seems to be missing the typedef for the CRC, DAC and FSMC blocks. The STM32F103VE.h does seem to include definitions for these peripheral's registers but doesn't include the typedefs. I don't understand why other peripherals have typedefs in STM32.h but these dont.

    In stm32.h the Peripheral memory map section has a define for the base address for DMA1 unit but not for DMA2. Again, not sure why.

    Looking forward to clarification.
    Harjit

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    The Rowley shipped files are generated from the memory map files (which are produced by eyeballing the user manuals/data sheets). There are no typedefs in these files only #defines.

    Regards

    Michael

    0
    Comment actions Permalink
  • Avatar
    Harjit Singh

    I think I've figured out what is going on. Since you are more familiar with this than me, hopefully, you can confirm/guide me.

    stm32f10x.h:
    * ST peripheral library: This contains the peripheral register defintions, bits definitions and memory mapping for all the STM32F10x parts.
    * Rowley: This is a file which based on the __TARGET_PROCESSOR define selects the Rowley generated peripheral definition file from the user manuals/data sheets. The Rowley generated file is named STM32F10xyz.h where xyz is the specific part number.

    Rowley distribution includes a file called stm32.h which was generated by ARM(?) that appears to be the down rev. contents of the ST periperhal library file stm32f10x.h referenced above.

    The unfortunate part is that I like how you have defined masks and bit values in the Rowley stm32f10xyz.h file. If I try to use this with the ST stm32f10x.h file, I will have duplicate defintions...

    I'm not sure what to do about this. I'm curious why Rowley includes their stm32f10xyz.h file?

     

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    The stm32.h file is the ARM/Keil produced CMSIS file - this is shipped in the CPU support package in order to supply the CMSIS functionality.

    We supply our own header files - it's part of what we do.

    There are certainly more examples using the ST peripheral library.

    Regards

    Michael

    0
    Comment actions Permalink
  • Avatar
    Harjit Singh

    Michael, thank you for the explanation. Now it all makes sense to me.

    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly
    I'm glad it is clear to you Harjit but for me it is not. Can you or Michael explain a bit further what files we should be using?
    0
    Comment actions Permalink
  • Avatar
    Harjit Singh
    The first decision you have to reach is are you going to use the Rowley supplied include files i.e. stm32.h found at: "C:\Documents and Settings\{Username}\Local Settings\Application Data\Rowley Associates Limited\" or the ST provided CPU files stm32f10x.h that is found in the "\STM32F10x_StdPeriph_Lib_V3.1.2\Libraries\CMSIS\Core\CM3" directory. While I really liked a few features of the Rowley supplied include files (they had a bit in a register defined with _BIT and the associated _MASK - I like this because I like seeing _BIT and _MASK because it makes the code clearer), I decided to use the ST provided CPU files because I found one of the files included with Rowley to be downrev. compared to the file provided with the ST peripheral library. I think this will occur whenever ST has a release after there is a compiler release. I don't the release schedule for either ST's files or the Rowley files but I dealing with this was a bigger deal to me than giving up the Rowley features. When creating a project, I create it using the Crossworks File New Project scheme and have it include all the Crossworks Systems files - STM32_Startup.s, STM32_Tarjet.js and thumb_crt0.s. In terms of the code what this means is I include into my c sources. I've also added ST's core_cm3.h, core_cm3.c, system_stm32f10x.h, system_stm32f10x.c files to my project because these provide helper functions I wanted to use. For the compiler setup, I've done the following: * Project properties modified the Oscillator frequency to match my project * Code Generation Options matched my processor * Compiler Options->Additional C/C++ Compiler Options: added -Wall to get all warnings * Preprocessor Options->Preprocessor Definitions: added STM32F10X_HD;STARTUP_FROM_RESET;__NO_SYSTEM_INIT;INITIALIZE_STACK * The list above may not apply to your situation. * I needed the STM32F10X_HD to tell the stm32f10x.h that I had a high density device. * The STARTUP_FROM_RESET is there because I want to startup without a debugger. * The __NO_SYSTEM_INIT is because I wanted to use SystemInit from system_stm32f10x.c * The INITIALIZE_STACK is there because I wanted thumb_crt0.s to init the stack area with a known value so that I could tell if I ever ran out of stack. * Preprocessor Options->Preprocessor Undefinitions: added * I added USE_STDPERIPH_DRIVER because I didn't want to use the ST peripheral helper functions. I'm writing my own because I didn't want to spend a lot of time understanding their implementation and working around any issues I found and instead I wrote my own. Now that I understand the processor better, I will say that by rolling my own I've made my stuff non-portable to other processors from ST but such is life. * If you want to use the ST example code, you would not do this undef. * Preprocessor Options->System Include Directories: added "C:/Program Files/CrossWorks2/include" * Crossworks has this feature where you can use stdio type functions which let the target interact with host services - I've used this with another debugger and find it just unbelievably helpful. To use this facility, I needed to include cross_studio_io.h from the above directory. * Preprocessor Options->User Include Directories: added .;$(STM32F10X_STDPERIPH_LIB)/Libraries/CMSIS/Core/CM3;$(STM32F10X_STDPERIPH_LIB)/Libraries/STM32F10x_StdPeriph_Driver/inc; * These are so that I can point the compiler to the right ST folders because I like to use include files with brackets rather than quotes and provide the path. * Runtime Memory Area Options->Main Stack Size: changed from 128 bytes to 1024 bytes because I don't want to worry about running out of stack space and I have the memory to spare. The setup works really well - compile times are fast. I'm convinced this is the right environment for me.
    0
    Comment actions Permalink
  • Avatar
    Harjit Singh

    Not sure why the formating was lost. Retrying.

    The first decision you have to reach is are you going to use the Rowley supplied include files i.e. stm32.h found at: "C:\Documents and Settings\{Username}\Local Settings\Application Data\Rowley Associates Limited\" or the ST provided CPU files stm32f10x.h that is found in the "<your ST install path >\STM32F10x_StdPeriph_Lib_V3.1.2\Libraries\CMSIS\Core\CM3" directory.

    While I really liked a few features of the Rowley supplied include files (they had a bit in a register defined with _BIT and the associated _MASK - I like this because I like seeing _BIT and _MASK because it makes the code clearer), I decided to use the ST provided CPU files because I found one of the files included with Rowley to be downrev. compared to the file provided with the ST peripheral library. I think this will occur whenever ST has a release after there is a compiler release. I don't know the release schedule for either ST's files or the Rowley files but dealing with this was a bigger deal to me than giving up the Rowley features.

    When creating a project, I create it using the Crossworks File New Project scheme and have it include all the Crossworks Systems files - STM32_Startup.s, STM32_Tarjet.js and thumb_crt0.s.

    In terms of the code what this means is I include <stm32f10x> into my c sources. I've also added ST's core_cm3.h, core_cm3.c, system_stm32f10x.h, system_stm32f10x.c files to my project because these provide helper functions I wanted to use.

    For the compiler setup, I've done the following:

    * Project properties modified the Oscillator frequency to match my project

    * Code Generation Options matched my processor

    * Compiler Options->Additional C/C++ Compiler Options: added -Wall to get all warnings

    * Preprocessor Options->Preprocessor Definitions: added STM32F10X_HD;STARTUP_FROM_RESET;__NO_SYSTEM_INIT;INITIALIZE_STACK

     * The list above may not apply to your situation.

     * I needed the STM32F10X_HD to tell the stm32f10x.h that I had a high density device.

     * The STARTUP_FROM_RESET is there because I want to startup without a debugger.

     * The __NO_SYSTEM_INIT is because I wanted to use SystemInit from system_stm32f10x.c

     * The INITIALIZE_STACK is there because I wanted thumb_crt0.s to init the stack area with a known value so that I could tell if I ever ran out of stack.

    * Preprocessor Options->Preprocessor Undefinitions:

     * I added USE_STDPERIPH_DRIVER because I didn't want to use the ST peripheral driver functions. I'm writing my own because I didn't want to spend a lot of time understanding their implementation and working around mapping what they had implemented and what I wanted to do and instead I wrote my own. Now that I understand the processor better, I will say that by rolling my own I've made my stuff non-portable to other processors from ST but such is life.

     * If you want to use the ST example code, you would not do this undef.

    * Preprocessor Options->System Include Directories: added "C:/Program Files/CrossWorks2/include"

     * Crossworks has this feature where you can use stdio type functions which let the target interact with host services - I've used this with another debugger and find it just unbelievably helpful. To use this facility, I needed to include cross_studio_io.h from the above directory.

    * Preprocessor Options->User Include Directories: added .;$(STM32F10X_STDPERIPH_LIB)/Libraries/CMSIS/Core/CM3;$(STM32F10X_STDPERIPH_LIB)/Libraries/STM32F10x_StdPeriph_Driver/inc;

     * These are so that I can point the compiler to the right ST folders because I like to use include files with brackets rather than quotes and provide the path.

    * Runtime Memory Area Options->Main Stack Size: changed from 128 bytes to 1024 bytes because I don't want to worry about running out of stack space and I have the memory to spare.

    The setup works really well - compile times are fast. I'm convinced this is the right environment for me.

    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly

    Harjit... I do not know how to express in words how delighted I am with your response.  I have not seen such a clear, concise and COMPLETE answer.  Yes, not all of it might apply to my situation however you have given me a working start point from which I can modify.  I have stacks of pdf's, and bookmarks all around me trying to put together what you have done in a few short paragraphs.  THANK YOU.  Thank you for taking the time out of your day to help not just me but anyone else stuck in the same place.

    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly

    Unfortunately I continue to have problems.  I can't seem to setup crossworks to see the ST version of stm32f10x.h.  The path to stm32f10x.h on my system is:  C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 2.0\lib\STM32F10x_StdPeriph_Lib_V3.1.2\Libraries\CMSIS\Core\CM3\stm32f10x.h

    Crossworks as the macro for the periph driver path as:  STM32F10X_STDPERIPH_LIB=C:/Program Files/Rowley Associates Limited/CrossWorks for ARM 2.0

    I've tried every flavor of User Include Directories that I can imagine but nothing seems to effect much.  Any ideas?  I feel that once successful I should be able to right click on the include line in my code and say "go to definition" and it should be able to find it.  No such luck yet.

    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly
    Actually I should amend my comment. After closing and re-launching Crossworks it changed the periph driver path to the correct one: STM32F10X_STDPERIPH_LIB=C:/Program Files/Rowley Associates Limited/CrossWorks for ARM 2.0/lib/STM32F10x_StdPeriph_Lib_V3.1.2 However I am still having problems.
    0
    Comment actions Permalink
  • Avatar
    Harjit Singh

    Glad the path is sorted out. What type of issues are you seeing?

    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly
    even with the path correct for the macro, Crossworks can't find stm32f10x.h. I've tried adding everything I can think of to the User Include Directories but nothing seems to work. Given the paths I detailed above, do you know what my User Include Directories should look like?
    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly
    If I type out the full path to it things work but that seems silly: #include "C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 2.0\lib\STM32F10x_StdPeriph_Lib_V3.1.2\Libraries\CMSIS\Core\CM3\stm32f10x.h"
    0
    Comment actions Permalink
  • Avatar
    Harjit Singh
    In Project->Macros->Global, you should have: STM32F10X_STDPERIPH_LIB=C:\Program Files\Rowley Associates Limited\CrossWorks for ARM 2.0\lib\STM32F10x_StdPeriph_Lib_V3.1.2 In the Project Explorer, make sure you click on "Project 'your project name'" and then go down to the Common section in the properties window. In that configuration, click on Preprocessor Options->User Include Directories and in that property, you should have: . $(STM32F10X_STDPERIPH_LIB)/Libraries/CMSIS/Core/CM3 $(STM32F10X_STDPERIPH_LIB)/Libraries/STM32F10x_StdPeriph_Driver/inc I mostly understand the Crossworks taxonomy but I haven't played enough with the tool & environment to have completely grocked it.
    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly
    Thanks again Harjit. I've got it setup exactly as you describe above. I think what I'm looking at is a genuine bug in Crossworks. I can get my code to build. It doesn't complain about things that are clearly only defined in stm32f10x.h so it must be seeing it. Indeed I see that it automatically adds core_cm3.h and system_stm32f10x.h to my project after a successful build. So it MUST be seeing stm32f10x.h. HOWEVER, when I right click on the include line and select "Go to Definition" it pops up a dialog that says, "Can't open stm32f10x.h for reading". If I double click on the same file in my project explorer it opens fine. I can only conclude from all this that it is a genuine Crossworks bug. I'll submit it and see what comes of it. Thanks for all your help Harjit. You've really set me on a path now.
    0
    Comment actions Permalink
  • Avatar
    Harjit Singh
    I tried "go to definition" and it works fine. I'm curious to know how this gets resolved. Best of luck.
    0
    Comment actions Permalink
  • Avatar
    Shannon Lgrizzly

    Turns out most of my difficulties could be traced back to listing my User Include Directories and Pre-processor Definitions with semi-colons in-between each entry.  Although not explicitly stated they need to go on separate lines.  Thanks again for all your help Harjit. 

    I had no idea you were involved in micromouse until I saw the results at APEC!  I am also building a new mouse with the STM32.

    0
    Comment actions Permalink
  • Avatar
    Harjit Singh

    Under Windows 7, the location of the Rowley packages is:

    C:\users\<username>\AppData\Local\Rowley Associates Limited\

    0
    Comment actions Permalink

Please sign in to leave a comment.