Now lets talk about how to code for the BSidesPR 2016 badge. If you do not know what this is all about refer to last post about an overview of the board here.
If you do not want to read, what you need?
- Keil (for windows)
- ARM Compiler, compatible with a lot of ARM MCUs
- Supports debug (to debug requires an external programmer debugger ST-Link)
- Code generator, helps creating Keil project and configuring MCU pins
- Compatible with Windows and Linux
- System Workbench for STM32 ( Linux)
- ARM Compiler compatible with Linux
- Free but need to register
- I downloaded but have not tested
- stm32flash to download binaries to board in linux
- clone and build tool from https://github.com/aguegu/stm32flash
- Use with -s to download
- ./stm32flash -s /dev/ttyUSB0 (should recognize device)
The badge has a STM3230F4P6 micro controller. It has a Arm Cortex M0 cpu, so standard coding tools used for arm chips should work with this board. I am far from an expert here and I was able to create some simple codes and download to it.
This chip is cross platform, but by the time I write this I haven't played with it in other than windows so that is what this post is all about.
I have used Keil to program for this badge from Windows it can be freely downloaded. For what I know Keil runs only on windows. It is basically an IDE like visual studio to code for Arm micro controllers. There are other compilers that should be compatible with the micro controller but as of this post I have not tested them.
You can do all with Keil alone, however I like to get a little help setting up the project so I use STM32CubeMX. The STM32CubeMX is a code generator, it help you get started on creating a project and configuring different ports of the STM32 chip as input, output or any other feature available. It is a wizard like interaction and it can produce a project file that you can open with Keil and compile.
Badge hardware circuit diagram (Please note that the prototypes use 5VDC regulators not 3.3V)
To use Serial data communication from code, it is required to configure the corresponding pins to be TX and RX. Also to use the LED matrix corresponding pins should be configured as well. Here is a simple configuration on how to just make it work, configured via STM32CubeMX.
LED matrix can be used bu configuring PA7, PA5 as SPI and should provide a better performance that just using them as standard outputs, however this way also works.