Series IntroductionWhat is a microcontroller(µC) without its peripherals? There is not much you can do, if anything at all, with a µC if you do not know how to use the GPIO,USART, I2C,SPI,CAN, TIMERS etc...
So what better way to teach yourself how to use a µC than to attempt to write register level drivers for the peripherals.
I have always steered away from using third party libraries when attempting to learn how to program a certain µC especially the vendor specific libraries for 2 reasons.
One being the fact that you dont learn much from calling a function that sets everything up for you, unless you wrote the function yourself. Reason two is that the vendor specific libraries have layer after layer of abstraction. Trying to work backwards from a function call to figure out how it works is tedious, doable but tedious. On another note those libraries tend to make your program size a lot bigger than necessary, almost 3 times times bigger.
To not misconstrued things I will clear up that for fast prototyping and getting a project up and off the ground and if you have a µC with enough memory then yes the libraries are easy peezy to use and get things going. However my goal is to become an embedded systems engineer of some sort, so relying on fat libraries will not benefit me in the future when I am asked about something like how the SPI protocol works and I have no idea because all I ever did was call an enable_SPI() ; function.
This series is NOT an intro to MicroControllersI will not explain things like what is a PIN what does HIGH or LOW state on a pin means..etc.. if you are looking for that type of introduction this is not it and I will perhaps work on a series of that type on a later date. This series is to show you how to use this specific Microcontroller (STM32F103C8) and related MicroControllers from the STM32 family. As well as provide an introduction to the Cortex core.
Parts and Software
For this series I will be using the STM32F103C8 µC pictured above. It is dirt cheap, about $2.99 on ebay just search for STM32F103 there is another version that looks a little different, square in shape with female headers Arduino style, either way its the same thing. This µC sports an ARM Cortex M3 core and maxes out at 72Mhz.
You will need a programming unit pictured below which cost about $4 on ebay Just search ST-link V2 the color does not matter:
Another thing you will need is the datasheet for the STM32 which you can download HERE , when you click that link scroll down to "Reference Manual" and download the latest version of RM00008.
Next you will need to download Keil's µVision software. They have free version with code size limit on it, for learning purposes this will suffice and once you learn you can port your skills over to a different IDE.
You can register HERE to download their free software, at the bottom select the ST and Cortex M3 and M4 options as well as any other chips you may want to experiment with.
Once you have that up and running watch the following video where I show you how to configure the IDe to work with this programmer and this specific µC.
Now that we have the IDE setup we can start programming, I will start with the GPIO because it is the obvious place to start since all other peripherals depend on the GPIO, along with GPIO I will show you how to enable the clocks for specific peripherals and anything else that may present itself along the way. This series is to be read and watched alongside the reference manual because this is where I get and show you the information from.