Saturday, 3 December 2016

Getting Started With STM32 and Simulink

The STM32 microcontrollers are powerful and full of awesome features but as anyone who has tried to work with the STM32 microcontrollers will know, setting them up and programming them can be a little difficult. I recently bought myself the STM32F4 Discovery development board and after trying a lot of new things, managed to setup a working development environment. I initially set up my development environment in Ubuntu. I found that the best option on linux is to use the System Workbench. But I found that getting anything more than a basic LED blink working was quite difficult. You have to pore over the ARM programmers manual and the StdPeripheral reference for hours and hours to get anything at all done. And if your focus is on the development of algorithms, maybe you don't want to spend so much time with the nitty gritty details of the implementation. 

Since I joined a PhD program a few months back, I have acess to Matlab from my university. So I decided to see if it was possible to use Simulink (which has support for quite a lot of hardware) would suit my workflow. I first tried the STM32 target for Simulink that's provided by ST themselves. After struggling with it for a week I gave up. I ran into multiple issues. First of all, the library was finnicky and not very easy to use. The user interface was set up in a confusing way. Second, I felt that the library was not complete because it did not implement a lot of features that were available on the processor like the option to read an incremental encoder using the timer. Of course, I guess it's possible to do it if you configure the timer and the pins yourself, but that defeats the purpose of having a Simulink block library in my opinion. Also, some of the blocks kept throwing errors and I was unable to run the examples because they were made for Matlab 2015b and I only had access to 2015a from my university. 

Instead I ended up using the waijung blockset for STM32. I've been trying it out for the last few hours and I think it's far better than the official library from ST. It implements most of the features on the STM32 (including incremental encoders) and the setup is a lot more intuitive. I managed to get an LED blinker setup in under an hour.



No comments: