Wednesday, December 14, 2016

STM32 Cortex M3 Series - [STM32F103C8T6] - #1 - LED Blinking

So finally after three months, here I am with one of the first posts on the ARM STM32 Cortex M3 series after working for about 3-4 months from now.  The 8-bit controllers seem somewhat ugly in comparison to the powerful 32-bit ARM architecture, boasting a hell lot of peripherals- DMA's, OTG, Ethernet and hundreds of GPIO's(Obviously, I've still not touched them and in my learning process). This becomes a different ball game as the application for which you might be needing this for, won't require this much of computational prowess. Starting with the very 'Hello World' of every hardware project which is the LED blinking:

The IDE I've been using is the CooCox IDE, a very decent IDE along with the arm toolchain for arm programming with the good amount of online community for sample codes. There are two ways that we can program using this IDE:
  1. Using the existing well versed and documented libraries of the stmf103xx  series, which I've used currently and this blog has been helpful to me regarding the programming of the series.
  2. Secondly, one could use the low, register level programming using just the stm basic library and well documented in the YouTube tutorials by Patrick Hood Daniel.
The final goal is to light up an LED so we'll need to setup the GPIO's or the port for the LED blinking. Before we begin, it would be easier if you would have the reference manual (and not the datasheet) in the background.

  1. The Cortex M3 core is connected to different peripherals via different buses. These buses are prominent parts of arm architecture known as the AHB, or the Advanced High-performance Bus.  The AHB is then connected to different APBs,  which is the Advanced Peripheral Bus(APB). From the datasheet information given below:

    figure 1. Architecture diagram, AHB and APB2 buses

    We can see that the GPIO's are driven by the clock from the APB2 bus, clocking at a maximum of 72Mhz. So our, first task will be to enable the clock source for these GPIO's. 
  2. Next,  as we are going to use the GPIO's. We need to specify the parameters for the port or pin to work - input or output, type of input or output etc. as with the case with every microcontroller. 
    The following are the types of Input and output types available on the GPIO's as given in the reference manual(Pg.158, section 9.1)
Figure 2. Input and output pin configurations

Figure 3. Basic input and output block Structure of the GPIO's 

Here's a brief on the types of these pins:
  • Input floating : In these pins the singals are in a 'Floating' state or tri-state. Meaning the signals are of no use unless they are pulled up or down by a high source or the output is in some definite state.
  • Input pull-up : In these type of pins, the input state when nothing is connected to it is High since a resistor is 'pulled-up' internally.
  • Input pull-down : Same as above put pin is pulled down with a high value resistor when nothing is connected and it is internal in the structure.
  • Output Open-drain : The output transistor is open drain and a resistor with a voltage level needs to be tied up to the drain .
  • Output push pull : The output is open drain is only one direction meaning, when pin has to go high it has to rely on the resistor and the pin by itself cannot source. Therefor it has two transistors both to sink and to source the current. Here is a good text from this site:
    "The push-pull output actually uses two transistors. Each will be on to drive the output to the appropriate level: the top transistor will be on when the output has to be driven high and the bottom transistor will turn on when the output has to go low.
    The advantage of the push-pull output is the higher speed, because the line is driven both ways. With the pullup the line can only rise as fast as the RC time constant allows. The R is the pullup, the C is the parasitic capacitance, including the pin capacitance and the board capacitance.
    The push-pull can typically source more current. With the open-drain the current is limited by the R and R cannot be made very small, because the lower transistor has to sink that current when the output is low; that means higher power consumption. "
I would continue with the coding, in the next part as this would become a very long post.
Thanks for watching and Cheers!

No comments:

Post a Comment

Featured Post

ROS Autonomous Navigation Bot - [Clerkbot] - Initial Tests

Finally it took me three months to fully come up with this robot and just a fun fact, it took me a month to just tune the ocean of paramet...