Skip to main content
David Huisman
Associate
August 14, 2017
Question

STM32 libraries for newbie

  • August 14, 2017
  • 4 replies
  • 1006 views
Posted on August 14, 2017 at 11:47

Hi,

I am starting out with STM32 (STM32F103CB). I am thinking of using Visual Studio with VisualGDB and Seggar debugger. Are there high level libraries I can use for setting up IO functions and also for delays and non-blocking timers?

I am wanting something simple like

delay(ms);

non-blocking:

StartTimer(x,delay);

if(Timer[x].Timeout){

}

And digital IO

SetPin(x,OUTPUT);  (bit like Arduino code)

digitalWrite(pin,HIGH);

Thanks

    This topic has been closed for replies.

    4 replies

    Sebastian K.
    Associate III
    August 14, 2017
    Posted on August 14, 2017 at 15:32

    Hi,

    are you using STM32CubeMX? For starting out I would recommend using that to create the basic initialization code, then play around and try to understand the code it generates.

    http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

     

    It automatically includes the libraries you need for the functions you select. It will need to download a firmware package for your MCU, which also includes examples, although mostly extremely simple ones. It is not as simplified as for Arduino, but as long as you know how to read or set registers, and have an IDE that allows you to trace declarations through the source code, you should be fine.

    I'm not sure it will work with Visual Studio though, but for a free-of-charge IDE you can try the STM32 system workbench based on Eclipse, which is probably easier to set up:

    http://www.openstm32.org/System+Workbench+for+STM32

     

    Hope it helps.

    Ivan Ivan
    Associate III
    August 14, 2017
    Posted on August 14, 2017 at 17:25

    There's 'a standard' library for newbie, it is called HAL and supplied by STM.

    1. It does not offer non-blocking timer (but HAL_Delay performs a blocking timeout). If you need a non-blocking timer, you may do the following:

    a) declare somewhere a globaldef.h:

     typedef struct {

    uint32_t timerValue;

    uint32_t maxTimer;

    uint8_t timerAllowed;

    uint8_t cycleTimer;

    uint8_t timeoutTimer;

    } NONBLOCKTIMER;

    NONBLOCKTIMER theTimer;

    b) in main(), before starting the cycle, init the timer:

    theTimer.timerValue = 0; theTimer.timerAllowed = 0; theTimer.cycleTimer=0; theTimer.timeoutTimer = 0;

    c)in HAL_SYSTICK_IRQHandler (fires once in 1 ms by default) (see file with name like ..._it.c ) add the following to the end of routine:

    if (theTimer.timerAllowed==1)&&(theTimer.timeoutTimer==0) {

     theTimer.timerValue++; 

    if ( theTimer.maxTimer<theTimer.timerValue) {

    theTimer.timeoutTimer=1; theTimer.timerAllowed=0;

    }

    }

    d)dispatch the state of theTimer in Main Cycle

    if (theTimer.timeoutTimer==1) {

    //do smth and restart your crude timer

    theTimer.timeoutTimer=0;

    }

    Amel NASRI
    ST Technical Moderator
    August 14, 2017
    Posted on August 14, 2017 at 18:01

    Hi

    orbitcoms

    ‌,

    There is also Mbed:

    https://developer.mbed.org/platforms/ST-Nucleo-F103RB/

    .

    -Amel

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    David Huisman
    Associate
    August 14, 2017
    Posted on August 15, 2017 at 00:06

    Thanks Guys,

    I am using my own hardware.