Skip to main content

STM32


I am a firm believer that if you really want to learn how to use a microcontroller you must write your own peripheral drivers using direct register access. Even if you later end up using an established library, you will understand what that library is doing and what all those settings mean. You will learn to appreciate the cleanliness of 5 lines of code that accomplishes the same thing that 20 lines of code accomplishes using a library. You can then take your code and make your own abstraction layer, as you will see in the following videos you will be able to write your own functions and know exactly what they do. Learning how to use the registers for one microcontroller will allow you to pick up any microcontroller from any manufacturer plus the datasheet and start programming it, because for the most part they are all programmed the same exact way and it is only naming differences. Below is my attempt to make this subject understandable and less intimidating. I am not a teacher and have no training in education so if my style does not work for you, my apologies. Otherwise proceed and enjoy.


The following tutorial series is a work in progress. If you have landed here only to encounter a series that abruptly ends, do rest assured that more content is coming. I am working hard on completing many series of tutorials on an array of subjects. Feel free to shoot me an email to remind me about a specific tutorial I may have forgotten.

Note: This is not a C tutorial, it is assumed you know the basics of the language. However, I do review bitwise operations because they are an integral part of embedded C. I suggest you review structures and pointers (just basic pointers nothing fancy).


Prerequisites 

1. Intro / overview of what you will learn.
2. Development environments :
  • Keil
  • TrueStudio 
3. Intro to Register access.
4. Bitwise operations
5. Systick : delay
6. Basic Debugging intro
7. Printf for debugging

GPIO

  • Overview
  • Output
  • Input
  • Interrupt
  • Alternate function
 GPIO : Driver Abstraction
  • Header File
  • C File




Comments

  1. Thank you for your efforts! This is exactly what I've been looking. Im going to write my drivers too for my stm32f407 micro, so that I can learn how they work.

    ReplyDelete
    Replies
    1. hello sorry for the late reply! How did your journey go on writing the drivers? I plan to remake these videos and be more active.

      Delete
  2. Hi. Your lecture series is one of the most fundamental, in depth and clear than all others. I liked your way of explaining. Thanks a million. Looking forward to more and more topics.

    ReplyDelete

Post a Comment

Popular posts from this blog

Interface a Rotary Encoder the right way.

So whilst reading my favorite odyssey found here I stumbled onto something I never spotted before. It turns out that the general purpose timers support hardware interfacing with an incremental encoder. This means no more interrupts and no need to increment whatever variable you had. Now all you have to do is get the value from the Count register in the timer. Did I also mention it takes care of figuring out which direction you are turning it? Amazing! Lets talk about it.






Encoder Interface Mode Verbatim from the reference manual of the STM32F103 page 392 or Section 15.3.12  "Encoder interface mode acts simply as an external clock with direction selection. This 
means that the counter just counts continuously between 0 and the auto-reload value in the 
TIMx_ARR register (0 to ARR or ARR down to 0 depending on the direction). So the user 
must configure TIMx_ARR before starting. In the same way, the capture, compare, 
prescaler, trigger output features continue to work as normal."
W…

STM32L0/F0/F3 I2C : Part 3 RX TX via DMA

Most modern microcontroller come with a peripheral called DMA which allows for an even more hands-off approach. The Direct Memory Access controller will get a tutorial of it's own in the future. However, it is so simple to use that I can easily explain the required bits in this tutorial without feeling like I will overwhelm the reader. In this iteration of the I2C series I will cover how to TX and RX date on the peripheral in conjunction with the DMA controller. 

First let me briefly explain in a high level what the DMA controller does. It allows you to transfer data in 3 ways: Peripheral to memoryMemory to peripheralMemory to memory. What does this mean? For example, when you receive data on I2C in your RXDR register, you can have the DMA controller move that data received into an array. At the end of the day your variables are just memory locations, so if you have declared an array it has an address associated with it, this is address is what the DMA considers  "Memory"…

STM32 I2C Does it suck?

Recently I have been annoyed with  bugs in the I2C implementation in ST's F1/L1/F40/F2 series, and  any microcontroller made by ST before 2012. There appears to be, what I can only describe as, a race condition when attempting to receive data in I2C interrupt(low priority)  or polling mode.





Just to be clear a race condition is defined as , verbatim from wiki: "the behavior of an electronics, software, or other system where the system's substantive behavior is dependent on the sequence or timing of other uncontrollable events. It becomes a bug when one or more of the possible behaviors is undesirable."
I was humming along trying to make my YouTube tutorials when I arrived to the I2C protocol implementation. I have used I2C with the F1 series plenty of times, however I have never had the need to receive data from a slave. However for the sake of completeness I decided to implement an RXing routine in I2C for my tutorial. Only to find statements like this in the referen…