Skip to main content

Posts

Showing posts from August, 2016

Stm32 Peripheral Drivers from Scartch : GPIO Programming Part 2

In the post we will create and populate the header file needed for our driver. Will also create the C file that goes along with that header file but the functions that go in there will be written in Part 3.

1. Add two new files to your project by right clicking on "Target 1" or under "User Libraries" Which is the naming convention that i use in previous videos. So.. Right Click->Add New Item To Group
when the pop up window appears click on C file name it something suitable sine this will be the name of your driver.

2. Add another file but this time it will be header file, it is common practice to name it the exact same thing as the C file you made in the previous step.

The video below will attempt to explain the content in the header file and the logic behind it. Like always if any questions arise feel free to comment or email me.

NOTE: The video is divided into two parts only because my recording software crashed mid way and I did not feel like rerecording agai…

Stm32 Peripheral Drivers from Scartch : GPIO Programming Part 1

Programming the GPIO is nothing out of this world. A series of steps must be taken to get those pins to do our bidding.

1. Initialize the clock for the Port you are going to use
2.Configure the Pin
3.Use the pin.

Pretty easy is'nt it? The board which I showed in an earlier post has an LED wired to Pin 13 on PORT C.  SO lets make this LED blink using the steps above.


1.Initializing the clock

To initialize the clock we must access the RCC Peripheral which controls the enabling and disabling of clocks for all the peripherals. The Stm32 has most of its peripherals turned off after a reset to consume less power, so it is your job to turn on what you need.


Above you can see the exact register (Page 145)  we need to turn on the clock gating for various GPIO Ports and highlighted is the one we need labeled InputOutputPortC (IOPC-ENable)

The code looks like this:

RCC->APB2ENR |= 1<<4;
That it as far as enabling the clock. Now lets look at step 2 which is configuring the pin or pi…

Stm32 Peripheral Drivers from Scartch : GPIO register overview

GPIO register overview This is a brief overview of the GPIO registers. The video below will cover everything I am going to explain here with the slight difference that this text is more thought out and the video is impromptu. Nonetheless we're off to the races.
The STM32F1 series offers several GPIO ports starting from  GPIOA...through...GPIOG each port consists of 16 Pins indexed from 0-15. Depending on the specific F1 chip you have you may not have all 7 ports, for example my chip is a 48 pin package like the image below and as you can observe I do not have all Ports A through G. Make sure you google a Pinout of your specific chip for reference and save the image to keep handy. If you are using the same board I showed you off of ebay this is your pinout. 
GPIO Registers:

Name: GPIO Control Register LOW and GPIOControl Register HIGH 
Function: Used to configure the GPIO pins to input / output , speed and pull up/down internal resistors.

How to use it: The GPIO ControlRegister LOW a…

Stm32 Peripheral Drivers from Scartch

Series Introduction What 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 t…