Wednesday, February 21, 2018

Embedded System Interview Brush Up.

These are the question link I am preparing. Just want to prepare a one stop link to all the people who want to brush up before you get start a new job search: 
 I am planning in to put answers also. Not sure when I will get to that.

If you would like to add any topics you can add it in comments I will add on to my list here. You can answers too if you like.

First trying to get the "oneliners" and "oh.. yeah I knew that". Just treat it as a test of our knowledge, if you don`t know google it.
Any list is never complete so I leave it up to you to follow these questions: 

Questions are for beginner to intermediate level folks.

I plan to make the following questions segregated: so as of now bear with this:

What are the basic protocols in a micro contrller?

What is AHB?
What is APB?

What is bus arbitration?

What are the level of bus arbiter?

How is SRAM interfaced?

How is that shown in the final.map?

What are the pheripehrals of the microcontroller?
Where does the peripheral data get stored in the microcontroller?
What is that latency of the peripheral to SRAM with MPU transfer and DMA transfer?

What are the limitations of DMA? Can we over use DMA and not use core at all?

What are the basic peripheral protocols in a MCU?
What are the communication interfaces of the ARM core with peripherals?





What is direct memory accessing?
What is indirect memory accessing?
What is the size of an enum variable?
What is NVIC?
What are the interrupt priorities in an NVIC for STM32 or any other mcu?
What is masked interrupt?
What is a non-maskable interrupt?
What is a software interrupt? How can you generate a software interrupt? Where does it get called?
What is NOR-flash?
What is NAND flash?
What are the differeces between the 2 flahses?
What is NVMe technology?
How do you interface a mcu with other peripherals?
Computer architecutre:
What is the memory hierarchy?
What are the different memories in a computer?
What is mcu, processor, peripheral?
What is the RISC machine? What is CISC?
What is an instruction cycle?
What instruction ?
Write a basic code for load store instruction?
How do you do that in arm?
How does the memory get mapped in the final.map file?
What is the boot strap loader?
Did you develop any boot strap loaders?
What is von neuman architecture?
What is harvard architecture?
Explain a 4 bit adder?
What is nMOS ?
What is pMOS?
What is push-pull?
What is open drain?
What is USB?
What is a spinlock ?
What is a semaphore ?
Explain a semaphore?
What is a binary semaphire and what is a counting semaphore?
What is a mutex?
Where are mutexes used in common coding practises?
What is volatile type qualifier?
What is auto?
What is extern?
What is static ?how static ness can be used global spaces ?
What are pointers?
What is the usage of the pointers?
Can you give me an example of a fucntion pointer?
A fucntion which can pass and retrieve an array of funciton pointer?
What is a stack ?
What is a queue or ring buffer?
How do you know if a buffer is circular?


STM32 GPIO Push button LED blink. Easy Code snippets part - I

Board: Discovery STM32F4VGxx
Code Generated through: ST Cube MX. 

I generated the code with Cube MX. 

The GPIO pins are given in the STM Discovery Manual: 
http://www.st.com/content/ccc/resource/technical/document/user_manual/70/fe/4a/3f/e7/e1/4f/7d/DM00039084.pdf/files/DM00039084.pdf/jcr:content/translations/en.DM00039084.pdf


These are the config thing for clock:


Next is the code that you can put in the while loop to get GPIO toggleon Push button: 


if ( HAL_GPIO_ReadPin( GPIOA, GPIO_PIN_0 ) == GPIO_PIN_SET )
{
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_14, GPIO_PIN_SET );
}
else
       {
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_14, GPIO_PIN_RESET );
}

Now compile and download the code. 

Done.. 

STM link Device not found.

Problem with STMLink.

Are you having an issue with the com led blinking on the ST link side?

STM Link  not detected through Keil or any other program that you using.
Well I have googled my way to debug this problem.
I think the interface is pretty much fool proof.

There are certain things that might cause this, but most of the times it is not the board. Just trust the board for now, and start questioning how you got into this situation ( well this is the first thought a embedded system debugger, because the Micro controller listens to what you say ). I spent crashing my head for couple of hours but my dejavu sense kind of kicked in and I was able to figure out easily. But in case if you are on road or already crossed this road, I am happy please share your story. 

There might be these reasons:
1. faulty cables. - This might be one of the reasons of the failure. Chance are the USB wire worn on out or some thing like.
I would advice you to change that. Get a new cable and try that out. But before running to a friend to get one check out the next reason. 
( I have swapped the cable that I used for my camera ).

2. Driver Issue. - The driver kind of gets screwed up some time.
Go to device manager and check if the USB device has loaded or not.
Re-start might work.
Or try it on a new machine.

3. Power Supply: If things gets this bad:
First thing if you are a starter change the board dont spend too much time. 8$ is not worth than your valuable time you waste around doing stuff that might not work at the end or end up frying other stuff.
(or)
If you are a serious dude and want to get the thing working there is a wikia page. I tried what ever they said, but I could not get it working.






Wednesday, October 11, 2017

Flagging in large code bases. ( Wise Coding )

Simple usage of Code management with the help of macros in C.

Make the code look wiser than putting more code.

The macros by far are the good way of substitution operators. While macros are mostly used for setting some constant values which can be used through out the code, until or unless it has been undef`ed ( aka undefining a macro ).

There is quite a lot of use of these macros in the real time embedded system code development.


Here is the simple program that explain:

Lets say I have 2 functions which need to be built for different versions.
 function A()
function B().

In a deliverable I want a customer to use function A to get some data.
But I want to put some other logic that computes the same way function A works, but function B is more better than and you want to compare the function B vs funtion A.

program A:
#define CODEA 1
#define CODEB 0

void functionA( void )
{
...
...
...
}


void functionB(void)
{
....
....
...
}


void main ( void )
{
...
...
#if CODEA
  functionA()
#elif CODEB
functionB
#endif
....\
...

}



Program B:

#define CODEA 0
#define CODEB 1


void functionB(void)
{
....
....
...
}


void main ( void )
{
...
...
#if CODEA
  functionA()
#elif CODEB
functionB
#endif
....\
...

}




It does not make sense in the smaller programs like the ones described above.

But these are pretty use ful when you have larger code bases, which span 20000 files.


And you want the program to work with specific functionality for Program A but program B wants some functionality that B offers.

These are useful when the same functions are used called at multiple places in the code base.


Example:

Lets say we have a timer call back function for Program A that set a portA.2 high is Program A.
But Program B uses other chip but uses the same code base, but need PORTC.1 to be high as a result of the timer call back.


This flagging can also be applied to specific code fragments in code.

taking the example above:


void HLT_TimerCallback( void *AppPtr )
{
         sometmr =0 ;
#if CODEA
   PORTA.A1 = 1;
#elif CODEB
  PORTB.B1 = 1'
#else
   PORTC.C1 = 1;
#endif

}












Friday, October 2, 2015

PIC 16F877 SPI porotocol using MPLAB IDE SPI write to 74HC164(SIPO).

Hi how are you guys doing.. 

This is the tutorial and code for the PIC 16F877,(MSSP moduel) SPI protocol in master mode interfaced with 74HC164( a serial in parallel out shift register). I think this code helps you guys in your project developments.  code works perfectly fine for any development. the clock frequency is Fosc/4.

Description of the code: the code below sends numbers from 0-254 to the 74HC164. If you want a detailed tutorial please comment below. (Code is self explanatory)

IDE Used: MPLABIDE and Proteus

SPI configuration for master mode:
CKE =0 ; SMP=0; CKP=1. 

Circuit Diagram: http://i61.tinypic.com/zx8swy.jpg


Source Code:

// PIC16F877 Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = EXTRC     // Oscillator Selection bits (RC oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF         // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON         // Low Voltage In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = ON         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

void delay();

void main()

    TRISC=0x00;
    PORTC=0x00;
   delay();delay();delay();
   delay();delay();delay();
   PORTC=0xff;
    TRISC |= 0<<3 | 0<<5| 1<<4;
    PORTC=
    SSPCON=0x00;
    SSPSTATbits.SMP=0;
    SSPSTATbits.CKE=0;
    SSPCONbits.CKP=1;
    TRISA=0x00;
    PORTAbits.RA5=1;
    ADCON0bits.ADON=0;     
    ADCON1 = 0x0F;                         
    INTCONbits.GIE=1;
    PIE1bits.SSPIE=1;
    PIR1bits.SSPIF=0;
    SSPCONbits.SSPEN=1;
    unsigned char p=0x00;
  
    TRISB=0x00;
    PORTB=0xff;
   
   
   
   
    while(p<254)
    {
      
       delay();
       delay();
       delay();
       delay();
       p++;
       SSPIF=0;
       PORTAbits.RA5=0;
       PORTB=p;
    
       SSPBUF=p;
       delay();
       delay();
       while(!SSPIF);
   delay();
       delay();
       delay();
       PORTAbits.RA5=1;
       delay();
       delay();
       delay();
      // SSPIF=0;
  
      
    }
   // Write your code here
   
}
 void delay()
 {
    unsigned int i;
    for(i=0;i<100;i++){}
    }

 void interrupt ISR()
 {
     SSPIF=0;
 }


 // please use the code, I am open sourcing.
//To say I developed it on my self, so just comment me if you have any issues with the code.

Wednesday, August 26, 2015

Simple explanation of linked list

// linked list code

#include <stdio.h>
#include <stdlib.h>
#define max 10


typedef struct list
{
int dat;
   struct list *next;

}list;


int main()
{    
     list a,b,c,d,e;  // list variables
    list *ptr;   // pointer of type list whihc points to list variables
     a.dat =5;
     a.next= &b;
     b.dat=4;
     b.next =&c;
     c.dat=3;
     c.next =&d;
     d.dat=3;
     d.next=NULL;
     ptr=&a;
 while(ptr!=NULL)
 {
     printf("value at location %d \n", ptr->dat);
     ptr=ptr->next;
 }


return 0;

}

Efficient stack implementation with pointers

 below is the code which implements a stack of size 10.  Pointer are used to easily push and pop the data. please feel free to use the code. can be used in the gcc compiler. Please feel free to use any functionality. change the max value and you can change it to what ever size stack you want...


 Source Code:
#include <stdio.h>
#include <stdlib.h>
#define max 10
int pos;
int *pop(int *pnt)
{
    int val=0;
    if(pos==0)
    {
        printf("no elements to delete ");
    }
    else
    {

    printf(" deleted value is %d ",*pnt);
    pnt--;
    pos--;
    }
    return pnt;

}
int push(int *pntr)
{
     int cntr;
    int val;

    if(pos==10)
    {
        printf("stack limit reached \n");
        printf("pop out a member first\n");
    }
    else{
        printf("enter the value to push \n");
        scanf("%d",&val);
        *pntr=val;
        pos=pos+1;
        printf("stack location %d \n",cntr);
    }

    return pos;
}
void ex()
{
    exit(0);

}




void prstck(int cnt,int *pt)
{
    int i;
    for(i=pos-1;i>=0;i--)
    {
        printf(" stack elem at locn  %d : %d  \n", i,*pt);
        pt--;
    }

}



int main()
{
int st[10];
int sel=0;
int cnt;
int *stp;      // stack pointer.
int *pppntr;

stp=st;

while(1)
{
  printf("enter your selection \n");
  printf("\n 1.push  2. pop  3. exit 4. display stack ");
  scanf("%d",&sel);

switch(sel)
{

    case 1 : stp++;
        cnt=push(stp);

             break;
    case 2 : pppntr= pop(stp);
             stp=pppntr;
             break;
    case 3 : ex();
             break;
    case 4 : prstck(cnt-1,stp);
             break;
    default : printf("no value entered \n");
                break;

}
}
return 0;
}