Stm32f100 notes

From Wiki at Neela Nurseries
Revision as of 22:39, 10 May 2018 by Ted (talk | contribs) (^ Startup and linker files in STCube1 libraries)
Jump to: navigation, search

Overview

This article to hold notes on early works with STMicro's STM32F100VL Discovery Board. We're using arm-none-eabi-gcc and assember versions:

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (4.8.4-1+11-1) 4.8.4 20141219 (release)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ arm-none-eabi-as --version
GNU assembler (2.25-5+5+b1) 2.25
Copyright (C) 2014 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `arm-none-eabi'.



^ Demo Firmwares from AN3268 Standard Peripherals Library

- 2018-05-03 Thursday -

Ted working to compile, program part and run STMicro's RCC example firmware project, targeted to the STM32F100 Discovery Value Line board. Working on a Linux platform with GCC toolchain. Using professor Geoffry Brown's STM32 project template as for the project makefile or project recipe basis.

Today's goal is to build and run STM32 library example named 'RCC', locally installed in /opt/lib/an3268/stm32vldiscovery_package/Project/Examples/RCC. Having trouble with the linker not finding where built library files, likely archive or shared object files are located . . .

main.o: In function `main':
  .
  .
  .
/home/veris/projects/stm32f/RCC/main.c:72: undefined reference to `RCC_GetClocksFreq'
/home/veris/projects/stm32f/RCC/main.c:75: undefined reference to `STM32vldiscovery_LEDInit'
/home/veris/projects/stm32f/RCC/main.c:76: undefined reference to `STM32vldiscovery_LEDInit'
/home/veris/projects/stm32f/RCC/main.c:79: undefined reference to `RCC_APB2PeriphClockCmd'
/home/veris/projects/stm32f/RCC/main.c:84: undefined reference to `GPIO_Init'
/home/veris/projects/stm32f/RCC/main.c:85: undefined reference to `RCC_MCOConfig'
/home/veris/projects/stm32f/RCC/main.c:90: undefined reference to `STM32vldiscovery_LEDToggle'
/home/veris/projects/stm32f/RCC/main.c:95: undefined reference to `STM32vldiscovery_LEDToggle'
stm32f10x_it.o: In function `RCC_IRQHandler':
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:155: undefined reference to `RCC_GetITStatus'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:158: undefined reference to `RCC_ClearITPendingBit'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:161: undefined reference to `RCC_GetFlagStatus'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:169: undefined reference to `RCC_PLLCmd'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:175: undefined reference to `RCC_GetITStatus'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:178: undefined reference to `RCC_ClearITPendingBit'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:181: undefined reference to `RCC_GetFlagStatus'
/home/veris/projects/stm32f/RCC/stm32f10x_it.c:184: undefined reference to `RCC_SYSCLKConfig'
collect2: error: ld returned 1 exit status
../Makefile.common:70: recipe for target 'RCC.elf' failed
make: *** [RCC.elf] Error 1

$



^ STM32F10x device types LD, MD, HD and Value Line

In the file /opt/lib/an3268/stm32vldiscovery_package/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h there is a good explanation of the abbreviations LD, MD, HD attached to some STM32F10x microcontroller names:

  57 /*  Tip: To avoid modifying this file each time you need to switch between these
  58         devices, you can define the device in your toolchain compiler preprocessor.
  59 
  60  - Low density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
  61    where the Flash memory density ranges between 16 and 32 Kbytes.
  62  - Low-density value line devices are STM32F100xx microcontrollers where the Flash
  63    memory density ranges between 16 and 32 Kbytes.
  64  - Medium density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
  65    where the Flash memory density ranges between 64 and 128 Kbytes.
  66  - Medium-density value line devices are STM32F100xx microcontrollers where the
  67    Flash memory density ranges between 64 and 128 Kbytes.
  68  - High density devices are STM32F101xx and STM32F103xx microcontrollers where
  69    the Flash memory density ranges between 256 and 512 Kbytes.
  70  - XL-density devices are STM32F101xx and STM32F103xx microcontrollers where
  71    the Flash memory density ranges between 512 and 1024 Kbytes.
  72  - Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
  73   */

This same header file has some pound includes which may be worth noting, about four hundred lines into this file:

 412 #include "core_cm3.h"
 413 #include "system_stm32f10x.h"
 414 #include <stdint.h>

Even with the value line controller there are just over nine hundred register definitions in STM's standard peripherals library main header file for the STM32F100RB part:

   $ /opt/lib/an3268/stm32vldiscovery_package/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x$ grep -n 'Bit definition for' ./*.h | grep register | wc
    902    6320   91086


Looks like there are fourteen GPIO registers defined . . .

$ grep -n 'Bit definition for' ./*.h | grep GPIO     
./STM32f10x.h:2209:/*******************  Bit definition for GPIO_CRL register  *******************/
./STM32f10x.h:2278:/*******************  Bit definition for GPIO_CRH register  *******************/
./STM32f10x.h:2347:/*!<******************  Bit definition for GPIO_IDR register  *******************/
./STM32f10x.h:2365:/*******************  Bit definition for GPIO_ODR register  *******************/
./STM32f10x.h:2383:/******************  Bit definition for GPIO_BSRR register  *******************/
./STM32f10x.h:2418:/*******************  Bit definition for GPIO_BRR register  *******************/
./STM32f10x.h:2436:/******************  Bit definition for GPIO_LCKR register  *******************/
./stm32f10x.h:2209:/*******************  Bit definition for GPIO_CRL register  *******************/
./stm32f10x.h:2278:/*******************  Bit definition for GPIO_CRH register  *******************/
./stm32f10x.h:2347:/*!<******************  Bit definition for GPIO_IDR register  *******************/
./stm32f10x.h:2365:/*******************  Bit definition for GPIO_ODR register  *******************/
./stm32f10x.h:2383:/******************  Bit definition for GPIO_BSRR register  *******************/
./stm32f10x.h:2418:/*******************  Bit definition for GPIO_BRR register  *******************/
./stm32f10x.h:2436:/******************  Bit definition for GPIO_LCKR register  *******************/


As we saw in compiler directive error messages a few days ago, a particular STM32F microcontroller part number needs be called out in order for conditional stuff in header files, including System Core Clock variable to be declared at compile time. Here are references to variable SystemCoreClock:

./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h:52:extern uint32_t SystemCoreClock;          /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h:79:extern void SystemCoreClockUpdate(void);
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:112:  uint32_t SystemCoreClock         = SYSCLK_FREQ_HSE;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:114:  uint32_t SystemCoreClock         = SYSCLK_FREQ_24MHz;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:116:  uint32_t SystemCoreClock         = SYSCLK_FREQ_36MHz;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:118:  uint32_t SystemCoreClock         = SYSCLK_FREQ_48MHz;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:120:  uint32_t SystemCoreClock         = SYSCLK_FREQ_56MHz;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:122:  uint32_t SystemCoreClock         = SYSCLK_FREQ_72MHz;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:124:  uint32_t SystemCoreClock         = HSI_Value;        /*!< System Clock Frequency (Core Clock) */
./CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c:167:  *         SystemCoreClock variable.



^ The dot S File

Somehow we need to include the 'dot s' file /opt/lib/an3268/stm32vldiscovery_package/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/arm/startup_stm32f10x_md_vl.s in our instance of STMicro's SysTick demo project. This file calls some processor-initializing code before routine int main() starts. This fact per comments in SysTick demo source file main.c . . .

int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */

Our challenge seems to be to direct gcc and related tools to bring together C sources and pre-existing assembly or 'dot s' files. Here is a reference which talks about coding syntax in C and assembly but is missing details of makefile syntax for GCC:

More a reference on crafting makefile to handle assembled files along with source files:

An article on bare metal programming of an ARM Cortex-M9 which gets closer to what we need, though assembly file is purely assembly here:

How to preprocess assembly files with C'ism:


2018-05-09 Searching via Google with phrase "STM32f compile demo project Linux .s file":

Searching with phrase "arm-none-eabi-gcc assembly .s file":


Our invocations of arm-none-eabi-gcc and arm-none-eabi-as so far, where .s files seem to not work at all and .S files trigger some processing:

  983  /usr/bin/arm-none-eabi-as -g -mcpu=cortex-m3 -mthumb startup_stm32f10x_md_vl.s -o startup_stm32f10x_md_vl.o
  987  /usr/bin/arm-none-eabi-as -g -mcpu=cortex-m3 -mthumb startup_stm32f10x_md_vl.S -o startup_stm32f10x_md_vl.o
  988  /usr/bin/arm-none-eabi-gcc -g -mcpu=cortex-m3 -mthumb startup_stm32f10x_md_vl.S -o startup_stm32f10x_md_vl.o
  989  /usr/bin/arm-none-eabi-gcc -x startup_stm32f10x_md_vl.S
  990  /usr/bin/arm-none-eabi-gcc -x assembler-with-cpp startup_stm32f10x_md_vl.S


^ edit point

On writing ARM assembly - looking for examples of assembly files with different comment styles:



^ GCC manual page

From gcc's manual page:

       Preprocessor Options
           -Aquestion=answer -A-question[=answer] -C  -dD  -dI  -dM  -dN -Dmacro[=defn]  -E  -H -idirafter dir -include file
           -imacros file -iprefix file  -iwithprefix dir -iwithprefixbefore dir  -isystem dir -imultilib dir -isysroot dir -M  -MM
           -MF  -MG  -MP  -MQ  -MT  -nostdinc -P  -fdebug-cpp -ftrack-macro-expansion -fworking-directory -remap -trigraphs  -undef
           -Umacro -Wp,option -Xpreprocessor option

       Assembler Option
           -Wa,option  -Xassembler option

-E tells gcc to stop after preprocessing. Says nothing about how default preprocessing of gcc handles given input files.



^ GNU assembler versus ARM assembler

Assembly files written in ARM assembler syntax won't assemble using GNU `as`, per Stack Overflow forum post 20301140:

Here is some work compiling an3268 SysTick demo source file main.c to the assembly stage, using GNU arm-none-eabi-gcc:

Systick main dot c to assembly Systick main dot c to assembly


Search for ARM assembler which is not GNU based, and available on Debian-like systems (also why QEMU needs code which ends which an infinite loop):



^ Startup and linker files in STCube1 libraries

About to examine following start-up assembly files for STM32F100xb type microcontrollers . . .

user@localhost:~/Downloads/stm/STM32Cube_FW_F1_V1.6.0$ find . -name 'startup_stm32f100*'

./Projects/STM32VL-Discovery/Templates/TrueSTUDIO/startup_stm32f100xb.s
./Projects/STM32VL-Discovery/Templates/EWARM/startup_stm32f100xb.s
./Projects/STM32VL-Discovery/Templates/MDK-ARM/startup_stm32f100xb.s
./Projects/STM32VL-Discovery/Templates_LL/EWARM/startup_stm32f100xb.s
./Projects/STM32VL-Discovery/Templates_LL/MDK-ARM/startup_stm32f100xb.s

Ah sure enough! Some of these start-up assembly files are written in GNU gcc syntax, just what we need! TrueSTUDIO instance of file startup_stm32f100xb.s is written and assembles properly via arm-none-eabi-as.

So we've been trying to build and run an AN3268 demo firmware, using a makefile template of two makefiles from Indiana State Geoffy Brown, which should be ok as `make` is a tool and not a mix of two different libraries. There is however also a matter of a linker script which sets out things like where object file code gets put into memory. We were referencing a GNU assember incompatible start-up file and changed that. May we also be referencing an incompatible linker script in our instance / copy of AN3268 SysTick demo firmwares? Here are the first linker scripts found, working up dir by dir from the location of the start-up file:

/opt/lib/an3268/stm32vldiscovery_package$ find . -name '*.ld'
./Project/Master Workspace/TrueSTUDIO/stm32_flash.ld
./Project/Demo/TrueSTUDIO/DISCOVER/STM32F100RB_FLASH.ld
./Project/Examples/STANDBY Mode/TrueSTUDIO/stm32_flash.ld
./Project/Examples/IWDG/TrueSTUDIO/stm32_flash.ld
./Project/Examples/Sleep Mode/TrueSTUDIO/stm32_flash.ld
./Project/Examples/JTAG Remap/TrueSTUDIO/stm32_flash.ld
./Project/Examples/WWDG/TrueSTUDIO/stm32_flash.ld
./Project/Examples/DMA/TrueSTUDIO/stm32_flash.ld
./Project/Examples/EXTI/TrueSTUDIO/stm32_flash.ld
./Project/Examples/GPIOToggle/TrueSTUDIO/stm32_flash.ld
./Project/Examples/Flash Program/TrueSTUDIO/stm32_flash.ld
./Project/Examples/STOP Mode/TrueSTUDIO/stm32_flash.ld
./Project/Examples/RCC/TrueSTUDIO/stm32_flash.ld
./Project/Examples/SysTick/TrueSTUDIO/stm32_flash.ld



^ Linker script syntax



^ References

Some possible STM32F100RB demo projects and exercises . . .