Skip to content

bcebesoy/stm32f4-bare-metal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stm32f4-bare-metal

Bare metal STM32F4 examples to serve as starting points for projets. Educational purposes.

Some of the STM32F4xx family based processor headers are added in the include folder to get register locations. CMSIS library is added for a general support. No extra HAL libraries is used except the selected projects described below.

Common startup functions are moved to include/system_stm32f4xx.c to include in all projects.

Installation

  • Clone the project using git clone --recurse-submodules https://github.com/fcayci/stm32f4-bare-metal with the included external tools/libraries such as CMSIS repo and any additional libraries some of the projects use.
  • You will need a toolchain (for compiler and binutils). Get one free from - GNU Arm Embedded Toolchain
  • For windows only, you will need make tool. You can just get the make tool from gnuwin32. Alternatively you can install the minimalist GNU tools for windows from mingw and MSYS
  • For the programmer/debugger, you can use - stlink or OpenOCD. Though only stlink utility support is added.
  • You can use your favorite code editor to view/edit the contents. Here is an open source one: Visual Studio Code.

Compile

makefile contains the necessary build scripts and compiler flags.

Browse into any directory and run make to compile.

cd projects/blinky
make

If everything is setup correctly, you should see the completed message.

Cleaning blinky
Building blinky.c
   text    data     bss     dec     hex filename
    368	      0	      0	    368	    170	blinky.elf
Successfully finished...

If you see any errors about command not found, make sure the toolchain binaries are in your PATH. On Windows check the Environment Variables for your account. On Linux/macOS run echo $PATH to verify your installation.

Program

Run make burn to program the chip.

...
.. Flash written and verified! jolly good!

Install the ST LINK drivers if you cannot see your board when make burn is run.

Disassemble

Run make disass / make disass-all to disassamble.

Debug

In order to debug your code, connect your board to the PC, run st-util (comes with stlink utility) from one terminal, and from another terminal within the project directory run make debug. You can then use general gdb commands to browse through the code.

Alternatively, you can install Cortex-Debug plug-in from marus25 on Visual Studio Code, and debug using the VSCode interface. No need for additional terminals. An example launch script is given with the code.

Projects

  • blinky - Good old blink LEDs example
  • clock - Shows how to change clock frequencies on the fly
  • math - A simple sine function to test math library operation
  • systick - Blinks LEDs using systick timer. Processor clock is set to max (168 Mhz)
  • timer - Blinks LEDs one at a time using the Timer module and Timer interrupt
  • pwm - Fades an LED using pwm functionality using Timer module
  • extint - External interrupt example using the on-board push-button
  • usb-vcp - USB Virtual COM Port implementation example. It depends on the libopencm3 library for the USB stack
  • dac - On-chip digital to analog converter operation
  • uart - UART example to show how to send data over
  • spi - SPI example that is customized for on-board motion sensor (lis302dl)
  • wwdg - Window Watchdog example
  • itm - Message sending through CoreSight ITM port 0. Install OpenOCD to capture the message

About

Bare metal STM32F4 examples for various modules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 99.9%
  • Makefile 0.1%