I will be repeating a lot of stuff from this video, but I find a text based guide easier to follow myself. Please refer to the video for details. It was my main source for the bunch of links below. The video is also made for the master branch. The feature/hal branch is easier to use (and the future), so my instructions are based on that.
Download and install the GNU Tools for ARM Embedded Processors
Download here. I chose the windows installer. During install, choose English. It will be easier to find help if you get compile errors.
On the last screen, check ‘add path to environment variable’
**Install MinGW **
Download here: http://sourceforge.net/projects/mingw/files/
GnuWin32 make didn’t work well for me.
Install DFU-Util
Go to http://dfu-util.gnumonks.org/releases/
Pick the latest release binaries.7z
Extract the contents of the win32-ming32 directory to somewhere you can find it.
Install Zadig
Go to http://zadig.akeo.ie/
Install Zadig
Connect your Spark Core via USB and run Zadig to replace the driver.
Add DFU-util and the ARM toolchain to your PATH variable
I prefer to do this with Rapid Environment Editor
You will have to start it as administrator to change system variables. If that is not an option for you, add to your user PATH variable. (Restart ad administrator is available from the File menu).
In Rapid Environment Editor, click the PATH variable and choose ‘add value’, then ‘add directory’. You will want to add 3 directories:
- The directory where you placed dfu-util.exe.
- The directory where you find arm-none-eabi-g++.exe (GNU Tools ARM Embedded\4.8 2014q3\bin)
- The directory where you find make.exe from MinGW msys (C:\MinGW\msys\1.0\bin)
May I recommend Everything to find files on your computer blazingly fast?
Test your PATH setting by starting a NEW command prompt and typing in:
dfu-util
make
arm-none-eabi-g++
This should all be found and give some output.
If you want to check it uses the executable from the right path, use ‘where make’, which is equivalent to Linux ‘which’ (on Windows 7).
Recompile the firmware for debugging
Go to where you cloned the spark firmware and start a command prompt there (from explorer, shift + right click --> open command window here).
Run make:
If you see that, great, the code compiles.
If you start make from the directory ./main, You can flash it to your core immediately after building with:
make program-dfu
Don’t forget to put your core into DFU mode by holding the mode button and pressing reset, until he LED flashes yellow.
Hardware Debugging with ST-Link V2
For the following steps, you will need a hardware debugger. If you do not have one, you can still build locally and upload via DFU.
Compile the firmware again with debugging enabled by adding USE_JTAG_SWD=y to the command:
I have sent in a pull request for SWD debugging, without JTAG
If you do not want to use JTAG, because you use the JTAG pins for something else, you can use single wire debug, which only uses 1 data and 1 clock wire (D6 and D7).
If you pull in the changes from my feature/SWD branch, you can use the command line option USE_SWD=y to use SWD without enabling JTAG. st-util will work just the same.
More info on making a custom SWD shield here:
Once you have compiled your firmware with debugging enabled, use dfu-util to upload it to your core.
make clean all USE_SWD_JTAG=y
Then upload the hex file to your core with dfu-util:
dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D build/target/main/prod-0/main.bin
Connect to your core with the ST-LINK
First install the device drivers by installing STM32 ST-LINK utility
Then start ST-LINK utility and connect to target. If it doesn’t work, try to connect under reset.
If you can connect under reset, but not when it is running, you have not properly compiled the firmware with debugging enabled.
Start a GDB server with st-util
To connect your IDE (NetBeans) to the debugger, you need to run a GDB server. We will use texane st-util for that.
You can find a precompiled version here: http://www.emb4fun.de/archive/stlink/index.html
Alternatively, you can build it from source to get the latest version.
So let’s test st-util and run it on port 9025:
st-util -p 9025
Make sure you have closed STM32 ST-LINK utility first.
st-util should find your core and report a Chip ID and Core ID.
Final step is to set up NetBeans to compile and debug, which will follow in my next post.