All Projects → al95 → STM32-Bare-Metal

al95 / STM32-Bare-Metal

Licence: MIT License
STM32F103C8 bare metal template

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to STM32-Bare-Metal

BlueVGA
VGA library for STM32F103C (BluePill) that can manipulate a screen with 28x30 tiles with 8x8 pixels each, in a total resolution of 224x240 pixels with 8 colors using a very low footprint
Stars: ✭ 39 (+50%)
Mutual labels:  stm32, bare-metal, stm32f103
arm-hard-fault-handler
What to do when Hard fault hits? Debugger and error reporter solution for ARM Cortex M3 and M4.
Stars: ✭ 32 (+23.08%)
Mutual labels:  stm32, arm-cortex-m3, arm-cortex
i2c-sniffer
Debugging tool for I2C networks, built for STM32 microcontrollers
Stars: ✭ 22 (-15.38%)
Mutual labels:  stm32, stm32f103, stm32f103c8t6
stm32f10x makefile freertos
stm32f10x gcc makefile freertos
Stars: ✭ 28 (+7.69%)
Mutual labels:  gcc, stm32, stm32f103
JBC SolderingStation
JBC_SolderingStation
Stars: ✭ 63 (+142.31%)
Mutual labels:  gcc, stm32
stm-ILI9341-spi
STM32 ILI9341 spi
Stars: ✭ 77 (+196.15%)
Mutual labels:  stm32, stm32f103
STM32F103-Bare-Metal
Programming the STM32F103C8 micro controller at the "bare metal" register level.
Stars: ✭ 42 (+61.54%)
Mutual labels:  stm32, stm32f103
fabooh
c++ template library for cortex-m0+ (lpc8xx), cortex-m0 ( lpc1114 ), cortex-m3 (bluepill), and msp430 ( small msp430 )
Stars: ✭ 28 (+7.69%)
Mutual labels:  stm32, stm32f103c8t6
FASTUSBasp
This is the fast avr programmer for AVR MCUs based on cheap stm32f103c8t6 board with usb-to-serial support.
Stars: ✭ 78 (+200%)
Mutual labels:  stm32, stm32f103
stm32mp1-baremetal
Baremetal framework and example projects for the STM32MP15x Cortex-A7 based MPU
Stars: ✭ 43 (+65.38%)
Mutual labels:  stm32, bare-metal
platformio-libopencm3-freertos
Sample blinky project for PlatformIO using libopencm3 and FreeRTOS
Stars: ✭ 14 (-46.15%)
Mutual labels:  stm32, stm32f103
drone-stm32-map
STM32 peripheral mappings for Drone, an Embedded Operating System.
Stars: ✭ 16 (-38.46%)
Mutual labels:  stm32, bare-metal
rc-headless-transmitter
DIY 2.4 GHz RC transmitter without display, configurable through smartphone or web browser
Stars: ✭ 28 (+7.69%)
Mutual labels:  stm32, stm32f103c8t6
grbl32
CNC controller running on the STM32F103 "Blue Pill" board, build and flash on Mac/Linux
Stars: ✭ 33 (+26.92%)
Mutual labels:  stm32, stm32f103
DHT11-DHT22-STM32-HAL
Библиотека для работы с датчиками DHT11/DHT22/AM2302/AM2301 на STM32
Stars: ✭ 26 (+0%)
Mutual labels:  stm32, stm32f103
ScopeMCU
虚拟示波器 MCU端
Stars: ✭ 59 (+126.92%)
Mutual labels:  stm32, stm32f103
stm32 tiny monitor
A tiny external monitor for PC using STM32 and ST7789. Connects to PC over USB and displays the captured screen on ST7789 (240x240) display.
Stars: ✭ 61 (+134.62%)
Mutual labels:  stm32, stm32f103
Gnu Eprog
Embedded Programming with the GNU Toolchain
Stars: ✭ 230 (+784.62%)
Mutual labels:  gcc, bare-metal
STM32F10x Servo Library
Servo library with stm developed by the Liek Software Team. We are working on new versions.
Stars: ✭ 14 (-46.15%)
Mutual labels:  stm32, stm32f103
hftrx
Embedded firmware for ham radio transceivers
Stars: ✭ 27 (+3.85%)
Mutual labels:  stm32, bare-metal

STM32F103C8 bare metal C template

If you're new to the STM32 world, I strongly suggest you read all this README file before you start coding. Also there are comments in almost every source file. It's a good idea to read them.

 

Quick start guide

To start programming using this template you need to follow these steps.

1. Get the files

Clone this repo with git clone https://github.com/al95/STM32-Bare-Metal.git
or download a zip file from here.

2. Configure the Makefile (Part 1)

At the beginning of the file you'll find two variables that you may want to change.

  • TARGET: This is the name of your program and will be used to name the "output" files.
    e.g., TARGET = blinky will generate blinky.elf, blinky.bin and blinky.hex.

  • OPTFLAGS: This sets the gcc optimization level.
    I suggest using -O2 to optimize for speed or -Os to optimize for size, but be aware that you might get some unexpected results if you're not careful with your code.
    If you're not sure just leave it at -O0.

3. Write your code

  • Write your main function inside main.c
  • Add as many other source files as you want
  • If you're using interrupts, add your ISRs to the vector table in init.c

4. Configure the Makefile (Part 2)

Add to OTHER_SRCS all the source files that you want to compile.
e.g., OTHER_SRCS = main.c usarts.c timers.c

5. Compile

Just run make.
You should get (at least) three files: an ELF, a BIN and an HEX.
The .elf file is the "final product" of the compilation.
If you don't know what an ELF file is, it probably means you don't need it.
The .bin and .hex files contain the actual data that will be written to the STM32 flash.
Which one you need depends on the programming software you want to use.

6. Flash

Flash your program to the STM32.
If you have texane's stlink installed you can just run make flash.
Otherwise, use whatever programming software you prefer.

7. Have fun

That's it!

 

Debugging guide

To debug your program follow the first 4 steps of the Quick start guide then run make debug.
This will disable any optimization (-O0), add detailed debug information for gdb (-ggdb3) and generate a few additional files. These are:

  • *.o: intermediate object files
  • *.size: size of the .text, .data and .bss sections
  • *.su: stack usage statistics (gcc -fstack-usage)
  • *.map: link map (ld -Map)
  • *.lst: disassembled program with sections, symbols and source files (objdump -x -S)
  • *.dis: complete disassembly of all sections (objdump -D)

The Makefile included in this template can start a debugging session using st-util and gdb:

  1. Open a terminal and cd into the source folder.
  2. Run make server to open the st-util server.
  3. Open another terminal and cd into the source folder.
  4. Run make gdb to run gdb.
  5. Inside gdb run load to load your program into flash.
  6. Good luck!

You're on your own from here. If you don't know how to use gdb, Google is your friend. It's easier than it looks.

 

Frequent problems

  1. When i run make I get /bin/sh: arm-none-eabi-gcc: command not found
    Check that the ARM version of gcc is correctly installed.
    If your gcc is installed using a different name prefix or in a user-defined folder you must change the CROSS_COMPILE variable inside the Makefile.
    e.g., CROSS_COMPILE = another-prefix- will run another-prefix-gcc
    e.g., CROSS_COMPILE = /home/john/arm/arm-none-eabi- will run /home/john/arm/arm-none-eabi-gcc

 

  1. When I run make server I get bind: Address already in use
    By default st-util communicates with gdb through port 4242.
    If you get this error it means that port 4242 is already in use by another program.
    Change STUTIL_PORT inside the Makefile to use a different port.
    e.g., STUTIL_PORT = 5555 will use port 5555

 

  1. When I run make server I get bind: Permission denied
    You selected a privileged port number. Try another port >=1024.

 

  1. When I run make server I get make: st-util: Command not found
    Check that st-util is correctly installed.
    If st-util is installed in a user-defined folder you must change the STUTIL variable inside the Makefile.
    e.g., STUTIL = /home/john/stlink/st-util will run /home/john/stlink/st-util

 

  1. When I run make flash or make erase I get make: st-flash: Command not found
    Check that st-flash is correctly installed.
    If st-flash is installed in a user-defined folder you must change the STFLASH variable inside the Makefile.
    e.g., STFLASH = /home/john/stlink/st-flash will run /home/john/stlink/st-flash

 

  1. When I use optimization levels higher than -O0 my program doesn't work correctly / interrupts don't work.
    Make sure that every global variable that gets changed by an ISR is declared as volatile.

 

  1. Can I enable optimization for the debug build?
    Yes, but be aware that debugging an optimized program is often a bad idea.
    You can set the debug optimization level using the DBG_OPTFLAGS variable inside the Makefile.
    e.g., DBG_OPTFLAGS = -O2 will compile using -O2

 

  1. Can I see what make is doing?
    Yes, by changing the VERBOSE variable inside the Makefile.
    VERBOSE = N is the default option and VERBOSE = Y will enable the verbose mode.

 

  1. When i run make I get region 'RAM' overflowed by ... bytes
    This means you're using too much RAM.
    The linker script is set to keep 2KB of free RAM to be used by the stack and the heap.
    This is accomplished by defining two fake empty memory sections in the linker script.
    If you're sure that your program will work with less free RAM, you can lower the amount of free memory by changing the _heap_size and _stack_size variables in the linker script.
    By default they are set to 1KB each.

 


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].