Category: Microcontroller programming

macro functions cover

C: Macro Functions vs Regular Functions vs Inline Functions Part#2

So just to recap what we saw in part 1 of this blog Regular functions are better at Readability and Code size while Macro functions are better at code performance. In this part let’s have a look at inline functions and see how and where to use them and how good of a replacement to a macro function they are. Inline Functions This is the last piece of the puzzle. Inline functions originally came in C++ and later in c99 update, it was added to the C programming language. So now in C, we have the ability to use the“inline”...

macro functions cover

C: Macro Function vs Regular Function vs Inline Functions

If you have some experience with C programming and you have had the opportunity to look at some library code then you must have seen something like this The above construct can be called as a macro function or a smart macro. If this code is executed we would get the same result as if ADD is a regular function like in the code listing below. When I was looking at these macro functions I had several questions pop up in my head. Are macros better than normal functions? If so why don’t we use macro functions everywhere? What is...

How To Use The Power Of Comments In Your Code The Right Way?

If you look up “Tips to comment code” in google you will find 2 types of answers with 2 different philosophies The first type of answer will say don’t use comments as it makes the entire source code look dirty and cluttered and the right way to write source code is to just make it readable by using good variable names and proper syntax. It is the duty of the reader to be proficient enough to make sense out of it. Only the “traps” or “tricky areas” in the source code need to be commented out. The second type of...

Quad-SPI, Everything You Need To Know!

If you have just mastered this SPI interface, then looking at Dual and Quad SPI can be overwhelming. I had to read several pdfs to wrap my mind around this concept. In this article, I am presenting all the useful and interesting facts on Quad-SPI that I have learned through my research. What is Quad-SPI? It is a serial interface, where 4 data lines are used to read, write and erase flash chips. Quad-SPI Quad-SPI, also known as QSPI, is a peripheral that can be found in most modern microcontrollers. It has been specifically designed for talking to flash chips...

Profiling of Embedded Code Explained Through Examples!

I remember the time when I first heard the term Profiling, I could barely write source code without googling every 10 minutes at that time and when I heard about profiling, I couldn’t help but tell myself that I will never be able to master programming! Then after a few years I became very comfortable with programming, I came across the term again, but this time I was not scared anymore! So went out and did some research about it and what I found out was shocking, the concept of profiling was not so difficult, it was just another technical...

FreeRTOS, Everything You Need To Know..!

When I started out learning about FreeRTOS, I was not able to find good short resources to read, and hence I had to spend weeks reading a 400 page eBook, see a bunch of webinars and videos, then cross-reference to some other resources when concepts were not clear, before I was finally able to understand what FreeRTOS is, how it works and how to use it in applications. So I decided to write this guide to summarise all the information I have learned over my research in an easy to understand manner so that you can get started with FreeRTOS...

How to Detect, Debug and Prevent Stack-Overflow!

Today I ran into my very first stack overflow bug. It was a frustrating experience to find the actual bug as I had to go through all of my code and double-check the logic, buffers, pretty much my entire code before I was finally able to detect that the bug I got was due to stack overflow. But once I managed to find out the fact that the source of my problem is stack overflow, the fix was a pretty easy one. This is one of those bugs that will make you doubt pretty much everything you know..! I am...