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. Before USB invented, to install a new hardware onto a Windows PC, one need to restart it. USB can help the device to work without restarting it. 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

 Hi,

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)

{

    gl_Count++;

}

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

 Hi,

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:

        break

    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)

f.close()


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.