Tuesday, October 26, 2021

USB Basics - 1

This post describes about benefits of USB

  1. USB allows usage of one standard connector. No need of different types of connector like DB-9, Parallel connector. (I am talking about the older days such as 90's and still this holds good).
  2. USB reduces the size of connector drastically. Compared to DB-9 and parallel connector USB connector size reduced significantly.
  3. USB eliminates restarting the Host PC after installation of a driver when the connected device uses the standard drivers being used which are shipped as part Windows / Linux / Mac OS.
  4. To install a new hardware before USB, we need restart the computer. With USB we need not to restart the computer. We call it as plug and play. Buy any new USB based device such as pen drive, camera, mouse, keyboard and etc...just connect them to the USB port available on Host PC, it just works like that.

Thursday, September 23, 2021

Different Current ratings provided on USB Port for Charging

Universal Serial Bus in short USB is capable of providing different current ratings over VBUS.

A USB connector will have 4 basic signals called as VBUS, D+, D- and GND.

VBUS will be +5V w.r.t. the GND(Ground) signal.

D+ and D- are used for data communication between Host and Device.

For example when we connect a pen drive to the USB Port of a Host PC, the circuitry on the pen drive is powered using the VBUS and GND signals.

Then the data exchange happens over D+ and D- to see the files stored on the Pen Drive.

Now, when it comes to charging, USB is keep evolving w.r.t Data throughput and power supply.

For example these are some of the Specs from USB committee, USB 1.1, USB2.0, USB3.1, USB3.2 and USB4.

When a device is USB1.1 capable then it supports 5V@100mA.
A USB 2.0 device can support 5V@500mA. USB3.x device can support upto 5V@900mA. USB4 uses a special connector called as Type-C connector which is capable of providing upto 5V@3A

The others are 5V@1.5A and 5V@2.1A. These are called as either (CDP or DCP). When we refer CDP it means the device can charge and enumerate. When we say DCP the device can be only charged on that port and no enumeration of the device is allowed.

Friday, June 18, 2021

Flash and SRAM


Every embedded firmware engineer shall know a fundamental that, what goes to which area.

In this blog I will be touching two things one is Flash and SRAM.

So, what will be placed into SRAM and which part of the code written by us goes into the Flash area of MCU.

Consider below example code

unsigned int gl_Count = 0;

void get_count (void)


    return gl_Count;


void increment_count(void)




In the above code when we declare a variable globally then that will be placed into SRAM and that is not placed into Flash. There might be some compiler constructs which might allow you to do so. However in this case there are no constructs hence the gl_Count will be allocated from SRAM.

Where as the funciton get_count and increment_count will be placed in the Flash space of the MCU.

When we implement / write a code, that will be placed in the Flash Area of the Microcontroller.  After writing the code it shall be cross compiled so that the generated output can be burned into the MCU's Flash using an external programmer / JTAG.

Hope this helps.

Thursday, June 10, 2021

Read a binary file using Python


Today, I have to write a python script to verify the data present in it. 

We are expecting a fixed pattern from 0 to 63, until end of the file. So the snipper can be seen below.

The size of file is around 272 KB, to check if there is any value missing would be nightmare.

Hence I wrote a small python script which checks the data integrity and prints the data mismatch string on console.

import os

f = open("try.bin", 'rb')

print("Reading to buffer")

count = 0

pages = 0;

while True:

    count = 0

    buffer = f.read(64)

    if not buffer:


    while(count < 64):

        if(buffer[count] != count):

            print("data mismatch")

        count = count + 1

    pages = pages + 1

    if((pages % 16) == 0):

        print("\n", end = '')

print ("No of pages", pages)


Hope this helps for you. 

This is being tested with Python 3.7.9

Thank you for reading.

Saturday, January 23, 2021

Data Memory Optimization  for Micro controllers

Look at the linker map file for the items which are consuming more space.
Pack the structures, so that padding is removed.
Use bit fields wherever possible.

Use local variables as much as possible.

Do not allocate data memory as large chunks.

Try to reuse the Data memory wherever possible.  

Monday, September 9, 2019

Carefully look at the rework area after rework...!

Lead dropped on a SMD Capacitor causes short between GND and RESET Signal

One of the chip that I was working has a CAPACITOR on the RESET Signal as shown below

Now, I need to get some rework to be get done on the board. After the rework the Debugger / Programmer is not able to get access to the chip.

I have removed the debugger from the board Debug Connector.

The debug connector has 5 signals VCC, GROUND, XRES, CLOCK and DATA.

When I check the continuity between the XRES, CLOCK and DATA w.r.t. GROUND observed that XRES is shorted to GROUND. I initially thought the CAPACITOR is dead due to rework done.

But, when I checked with Hardware Engineer told me to check if there is any lead dropped on capacitor which might have caused this issue.
The capacitor is literally very small such as 0201 / 0402 package. On top of it there are wires running on the board which are unmovable due to the glue placed on the wires.

When I had a look carefully on the top of capacitor under a magnifying glass there is lead dropped on C1 Capacitor.

When the soldering technician removed the lead the debugger / programmer could get access to the Micro controller.

Thanks for reading the post and let me know your feedback...!

Wednesday, April 17, 2019

Root cause for the SPI Chip Select Line Going High During SPI Read and SPI Write Operation

  • AS shown in above figure to identify the root cause I have used two spare GPIO's SPI_WRITE and TIMER_INT
  • The SPI_WRITE signal is driven low just before writing into the SPI FIFO and then the signal will be driven high after the write into SPI FIFO is completed
  • Similarly the TIMER_INT GPIO is driven low when the Timer Interrupt Handler is entered and the same GPIO will be driven on exiting the Timer Interrupt Handler
  • Now, one can easily understand from the timing diagram that the Timer Interrupt Handler is taking 52 uS. 
  • Our SPI Clock operates at 1 MHz. The data is written to the FIFO using CPU as there is no DMA. The size of the SPI TX FIFO is 128 bytes.
  • We can see that there are three bytes sent over SPI_MOSI line and then the Timer Interrupt Handler triggers and causes SPI_CS to go high.
  • The SPI_CS goes high when there is no data in TX FIFO.
  • So, to prevent this probably we have to figure out the best solutions like while writing to the FIFO whether we have to make it atomic, reduce the SPI Clock or write to the SPI FIFO at least 64 bytes atomically or figure out to reduce the Timer Interrupt Handler execution and so on...
Let me know your feedback on this post...!