Blinky on STM32F303 board

Objective

Download a generic firmware skeleton (“bootstrap image”) that applies to any hardware and then throw in additional applicable pkgs to generate a build for a specific board, namely the STM32F303VC MCU from STMicroelectronics.

Hardware needed

  • Discovery kit with STM32F303VC MCU
  • Laptop running Mac OS

Step by Step Instructions to build image

  • The first step is to download the generic skeleton of the project. The pkgs constituting the skeleton are not hardware architecture specific. The skeleton is maintained as an app in a separate repository on Apache. You know it is an app because there is an app.yml file.
        [user:~/dev]$ newt app create test_project
        Downloading app skeleton from https://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole.git... ok!
        app test_project successfully created in ~/dev/go/test_project
    
        [user:~/dev]$ cd test_project/
        [user:~/dev/test_project]$ ls
        README.md	compiler	hw		libs	app.yml
  • Next, the pkg-list named larva is added from the app (also named larva) from another repository on Apache. This step simply downloads the pkg-list description file and does not actually install the pkgs that constitute the pkg-list. The pkg-list description file (pkg-list.yml) will be used to check dependencies during the pkg install to ensure completeness. It serves as a reference for all the pkgs in the pkg-list that one can choose from and install.
        [user:~/dev/test_project]$ newt app add-pkg-list larva https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva.git
        Downloading pkg-list.yml from https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva.git/master... ok!
        Verifying pkg-list.yml format...
        ok!
        pkg-list larva successfully installed to app.
  • The next step is to install relevant pkgs from the larva app from git server on Apache. The instructions assume that you know what application or project you are interested in (the blinky application, in this case), what hardware you are using (STM32F3DISCOVERY board, in this case) and hence, what board support package you need.

[user:~/dev/test_project]$ newt pkg install project/blinky Downloading larva from https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/master... ok! Installing project/blinky Installing libs/console/full Installing libs/shell Installation was a success! [user:~/dev/test_project]$ newt pkg install hw/bsp/stm32f3discovery Downloading larva from https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/master... ok! Installing hw/bsp/stm32f3discovery Installing hw/mcu/stm/stm32f3xx Installing libs/cmsis-core Installing compiler/arm-none-eabi-m4 Installation was a success!
  • It's time to create a targets for the project and define the target attributes. STM32F3 BSP expects bootloader, so create targets for both blinky and bootloader.
        [user:~/dev/test_project]$ newt target create blink_f3disc
        Creating target blink_f3disc
        Target blink_f3disc successfully created!

        [user:~/dev/test_project]$ newt target set blink_f3disc project=blinky
        Target blink_f3disc successfully set project to blinky

        [user:~/dev/test_project]$ newt target set blink_f3disc bsp=hw/bsp/stm32f3discovery
        Target blink_f3disc successfully set bsp to hw/bsp/stm32f3discovery

        [user:~/dev/test_project]$ newt target set blink_f3disc compiler_def=debug
        Target blink_f3disc successfully set compiler_def to debug

        [user:~/dev/test_project]$ newt target set blink_f3disc compiler=arm-none-eabi-m4
        Target blink_f3disc successfully set compiler to arm-none-eabi-m4
        
        [user:~/dev/test_project]$ newt target set blink_f3disc arch=cortex_m4
        Target blink_f3disc successfully set arch to cortex_m4
        
        [user:~/dev/test_project]$ newt target create boot_f3disc
        Creating target boot_f3disc
        Target boot_f3disc successfully created!

        [user:~/dev/test_project]$ newt target set boot_f3disc project=boot
        Target blink_f3disc successfully set project to blinky

        [user:~/dev/test_project]$ newt target set boot_f3disc bsp=hw/bsp/stm32f3discovery
        Target boot_f3disc successfully set bsp to hw/bsp/stm32f3discovery

        [user:~/dev/test_project]$ newt target set boot_f3disc compiler_def=optimized
        Target boot_f3disc successfully set compiler_def to debug

        [user:~/dev/test_project]$ newt target set boot_f3disc compiler=arm-none-eabi-m4
        Target boot_f3disc successfully set compiler to arm-none-eabi-m4
        
        [user:~/dev/test_project]$ newt target set boot_f3disc arch=cortex_m4
        Target boot_f3disc successfully set arch to cortex_m4

        [user:~/dev/test_project]$ newt target show blink_f3disc
        blink_f3disc
	        arch=cortex_m4
	        bsp=hw/bsp/stm32f3discovery
	        compiler=arm-none-eabi-m4
	        compiler_def=debug
	        name=blink_f3disc
	        project=blinky

        [user:~/dev/test_project]$ newt target show boot_f3disc
        boot_f3disc
	        arch=cortex_m4
	        bsp=hw/bsp/stm32f3discovery
	        compiler=arm-none-eabi-m4
	        compiler_def=debug
	        name=blink_f3disc
	        project=boot

  • STM32F3 blinky project is too large to operate with newlib libc. You need to modify project/blinky/pkg.yml, and switch over to using baselibc.
        [user:~/dev/test_project]$ cat project/blinky/pkg.yml 
        #
        # Licensed to the Apache Software Foundation (ASF) under one
        # or more contributor license agreements.  See the NOTICE file
        # distributed with this work for additional information
        # regarding copyright ownership.  The ASF licenses this file
        # to you under the Apache License, Version 2.0 (the
        # "License"); you may not use this file except in compliance
        # with the License.  You may obtain a copy of the License at
        #
        #  http://www.apache.org/licenses/LICENSE-2.0
        #
        # Unless required by applicable law or agreed to in writing,
        # software distributed under the License is distributed on an
        # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
        # KIND, either express or implied.  See the License for the
        # specific language governing permissions and limitations
        # under the License.
        #

        pkg.name: project/blinky
        pkg.vers: 0.8.0
        pkg.description: Basic example application which blinks an LED.
        pkg.author: Marko Kiiskila <marko@runtime.io>
        pkg.homepage: http://mynewt.apache.org/os/get_acclimated/project2/
        pkg.repository: https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva
        pkg.keywords:

        pkg.deps:
            - libs/console/full
            - libs/newtmgr
            - libs/os
            - libs/shell
            - sys/config
            - sys/log
            - sys/stats
            - libs/baselibc
  • Next, you get to build the targets and generate an executable that can then be uploaded to the board. The STM32F3DISCOVERY board includes an ST-LINK/V2 embedded debug tool interface that will be used to program/debug the board. To program the MCU on the board, simply plug in the two jumpers on CN4, as shown in the picture in red. If you want to learn more about the board you will find the User Manual at http://www.st.com/st-web-ui/static/active/jp/resource/technical/document/user_manual/DM00063382.pdf

  • STMdiscovery

        [user:~/dev/test_project]$ newt target build boot_f3disc
        Building target boot_f3 (project = boot)
        Compiling asprintf.c
        Compiling atoi.c
        ...
        ...
        Assembling startup_stm32f303xc.s
        Archiving libstm32f3discovery.a
        Compiling boot.c
        Building project boot
        Linking boot.elf
        Successfully run!

        [user:~/dev/test_project]$ newt target build blink_f3disc
        Building target blink_f3disc (project = blinky)
        Compiling asprintf.c
        Compiling atoi.c
        ...
        ...
        Assembling startup_stm32f303xc.s
        Archiving libstm32f3discovery.a
        Compiling main.c
        Building project blinky
        Linking blinky.elf
        Successfully run!

        [user:~/dev/test_project]$ newt target build boot_f3disc
        Building target boot_f3disc (project = boot)
        Building project boot
        Successfully run!

        [user:~/dev/test_project]$ newt target create-image blink_f3disc 0.0.1
        Building target blink_f3disc (project = blinky)
        Building project blinky

  • Finally, you have to download the image on to the board. You will see a blue light start to blink.
        [user:~/dev/test_project]$ newt target download boot_f3disc
        Downloading with /Users/user/dev/test_project/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh

        [user:~/dev/test_project]$ newt target download blink_f3disc
        Downloading with /Users/user/dev/test_project/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh