OK, I think this is working so I'm going to document what I've done (well what I can remember of it anyway!). Apologies if it is already documented somewhere else but I couldn't find it.
Note this is all on Linux Mint using a ST-Link debug interface.
Install:
- gcc arm toolchain - 'sudo apt-get install gcc-arm-none-eabi'
- gcc arm library - 'sudo apt-get install libnewlib-arm-none-eabi'
- stlink-tools - (if using the ST-LINK or compatible debug tool) - You might have success with 'sudo apt-get install stlink-tools', I didn't and had to do 'git clone https://github.com/stlink-org/stlink', 'cd stlink/', 'cmake .', 'make', 'sudo make install' and finally a 'ldconfig' to get the library path registered (this last step might get the apt-get install to work too).
- debug server - 'openocd - 'sudo apt-get install openocd'
- Code::Blocks - I installed from the Linux Mint software manager but I'm sure it can be done through apt-get too.
To check stlink run 'st-flash read dummy.bin 0 0xFFFF' and check you get sensible results and the bin file
To run openocd - 'openocd -f board/st_nucleo_f103rb.cfg', check it finds the hardware. This needs to be running in a command shell whenever trying to debug. Note - this config suits the Nucleo-64 eval board that I'm using. OpenInverter hardware may need a different config file/s.
Get the stm32-sine source and compile as per the readme instructions in it.
To program the processor - 'st-flash write stm32_foc.bin 0x08000000' Note - I'm bypassing the bootloader for now and so use 0x08000000. For standard code that is using the bootloader is should be 0x08001000 as otherwise the bootloader will be overwritten. Either way this and the contents of stm32_sine.ld should match!
To set up Code::Blocks:
- Open Code::Blocks and open the sinus.cbp file in the stm32-sine directory
- In Settings, Compiler select GNU GCC Compiler for ARM at the top
- In the same window go to Toolchain executables and for:
C compiler click the '..', browse to /usr and select the arm-none-eabi-gcc file
C++ compiler click the '..', browse to /usr and select the arm-none-eabi-g++ file
Linker click the '..', browse to /usr and select the arm-none-eabi-gcc file (I did this for both static and dynamic - no idea if that's right or whether the static should be arm-none-eabi-ar? anyone know?)
Change the debugger to GDB/CDB debugger : Default
- In Settings, Debugger, under default change the Executable path to /usr/bin/gdb-multiarch. (you may need to do 'sudo apt-get install gdb-multiarch' if it's not there)
- Optional - change the '-0s' to '-0g -g' in the Makefile to change optimisation to suit debugging and enable debug output
The Code::Blocks build functions should now work to build the stm32-sine project (make sure you select the right Build target in the dropdown in the top tool bar).
If the board, with stm32-sine on it, is connected to the ST-LINK and openocd is running you should be able to hit the Debug/Continue button to start debugging.
There is probably a better/simpler way to do the above. If anyone knows what it is please add the details. In particular it would be nice to have Code::Blocks automatically start openocd and download the rebuilt code to the board before starting debugging.
Edit - I take that back, it already rebuilds when needed and downloads the code automatically (I assume this must be the load commands that johu has already set up on the CodeBlocks project
Edit2 - The only way I can find to start openocd from CodeBlocks is to add it to Tools. Click Tools, Configure tools. Click Add, give it a name of 'Start OpenOCD' set the Executable to 'openocd -f board/st_nucleo_f103rb.cfg' (or whatever .cfg suits tour board), set the Working directory to '${PROJECTDIR}' and select the 'Launch tool visible detached' radio button. Then click OK. If you want to be able to stop openocd add another with the executable set to 'pkill openocd' (not really needed but the flashing light on the ST-Link while openocd is running gets on my nerves).
EDIT3 - The above is intended to allow debugging of just the processor hardware on the bench. I would strongly recommend that you do NOT debug with HV or a motor connected. Hitting a breakpoint at the wrong moment could cause all sorts of problems and you do not want a motor to be spinning when that happens!
Edit Jul23 - Just installed on an up to date version of Linux and found the following has changed:
- libnewlib-arm-none-eabi is now installed as part of gcc-arm-none-eabi so doesn't need doing as a separate step.
- 'sudo apt-get install stlink-tools' now works fine.
- The compiler and linker paths are now /usr/bin (probably should have been before and it was my error in taking notes!)
- Codeblocks now works fine with no crashes to date (and the version available in the Linux Mint software manager is up to date).
- Note - the below post re. openocd setup is still recommended.
- When setting up openocd in CodeBlocks PROJECTDIR has changed to PROJECT_DIR