PCB Design Fundamentals – A Design Guide

Recently i had the privilege to get some hands on training from one of the senior guys working at the Switzerland headquarters of our company. Till date, i had only learned about PCB design by reading books with a bit of experience coming from having dealt with PCB design vendors. It was very interesting to see the actual application of the principles i learned from someone very knowledgeable and experienced, first hand. The most interesting part of the training was the part where the concept of return paths was explained and how to take care of this while doing PCB design. It is something which i had not understood previously during my reading of books and application notes.

Rather than regurgitating what i learned and doing a shoddy job of it, i will just share the link to the design guide which my experienced colleagues have put out there for the benefit of customers of our company and others who might benefit from our products and work.


On the above link you will find a link to the Apalis Carrier Board Design Guide which you should read.


PCB Design Fundamentals – Impedance Matching

Once upon a time, I use to think that the printed circuit boards were nothing, but, just a means for connecting the various components to each other and the system design was much more important. Working in the industry for the past two and half years, has made me realize that even though the system design is quiet important, a well designed system is not going to work without proper attention being paid to the PCB Design.

There are various aspects to PCB design like crosstalk, EMI and EMC, differential signalling and one of them is impedance matching. All this is known in the industry under the broad term and umbrella name of “Signal Integrity”. An impedance mismatch can affect the signal integrity to a great extent and the damage done depends on the impedance mismatch and the complexity of the interconnect network in which the impedance mismatch is occurring.

The concept of impedance mismatch will be known to anyone who has studied Transmission Lines in Electromagnetics or Microwave Engineering. Now, you might be wondering how does transmission lines come into the picture??!!.

At high frequencies, the interconnect lines do not function as simple interconnects, but, start acting as transmission lines at high frequencies. Also, if you remember control systems, at low frequencies a lumped parameter model is applicable, while at high frequencies, distributed parameter model becomes applicable. If i were to put it more simply, when the wavelength of the signal is less than the length of the interconnect on which it is propagating, you can treat them as simple interconnects and apply the lumped parameter model, meaning that you can model the behavior of the interconnect using a simple RC model. The response of a RC model is well-known to all in the field of electronics. At high frequencies, where the wavelength of the signal is less than the length of the interconnect on which it is propagating, you can no longer consider them as mere interconnects, but, the distributed parameter model becomes applicable and the transmission line concepts need to be applied now. A simple RC model will no longer suffice for modelling the behavior of interconnects.

In actual production environments and industry, PCB design and signal integrity issues like impedance mismatch are done and checked using software like PADS and Allegro. For a demonstration, I will show you how an impedance mismatch degrades signal integrity by using an example and lattice diagrams.

An impedance mismatch occurs, when the characteristic impedance of the transmission line doesn’t match the load or another transmission line which it is driving. If you remember the formula for reflection co-efficient τ = (Zl – Zo)/(Zl + Zo). So, if the load impedance is not equivalent to the characteristic impedance, the reflection co-efficient will have a value, ideally which should have been zero. This impedance mismatch results in a part of the signal being transmitted and part of it being reflected. The reflected signal then propagates back towards the source, where depending on the impedance of the source and the line, another reflection might or might not occur. This goes on till this reaches steady state.

Now, let’s analyze this using a lattice diagram. A lattice diagram looks as shown below. lattice

A lattice diagram  is a graphical technique used to solve the multiple reflections on a transmission line with linear loads.  The left- and right-hand vertical lines represent the source end (z = 0) and load end (z = l) of the transmission line. The diagonal lines contained between the vertical lines represent the signal bouncing back and forth between the source and the load. The diagram progressing from top to bottom represents increasing time. Notice that the time increment is equal to the time delay τd of the transmission line, and the reflection coefficients looking into the source and into the load are labeled at the top of the vertical bars. The lowercase letters represent the magnitude of the reflected signal traveling on the line. The uppercase letters represent the voltages seen at the source, and the primed uppercase letters represent the voltage seen at the load end of the line. The delay for the signal to propagate from one end of the transmission line to the other is given by ” l √LC “, where l is the length of the transmission line and L and C are the inductance and capacitance values per unit length.

Consider the case of reflections when the impedance of the source Rs is less than the load impedance Zo.

ExampleRs for the above example is 25 ohms and the load impedance is ∞. This gives a reflection co-efficient of 1 at the load end and (-1/3) at the source end by using the generalized formula of (Zo2 – Zo1)/(Z02 + Z01).


The lattice diagram will come out as like shown below. The calculations for the lattice diagram will be as below.

1. A 2V signal is going to be driven on the line. Using a simple voltage divider, the voltage driven at point A will be 2 x 50/(25 + 50) = 1.33V. When 1.33V reaches the load end, this will be multiplied by the reflection co-efficient at the load end, viz. 1. So, the entire signal will be reflected back onto the line, and the voltage will be 1.33V as shown, propagating towards the source. At the load end, 1.33V + 1.33V = 2.66V will be the voltage.

2. The reflection co-efficient at the source end is (25 – 50)/(25 + 50) = (-1/3). The incoming 1.33V signal toward the source will be multiplied by (-1/3) and then propagate back towards the load. So, (-1/3) x 1.33 = -0.443V signal will now propagate towards the load end. At the source, the voltage is given by 1.33V + 1.33V + (-0.44V) = 2.22V.

3. Again at the load end, the -0.443V signal will be reflected back fully due to the reflection co-efficient being 1 and you can see a -0.443V signal propagating back toward the source in the above lattice diagram. At the load end, the voltage will be 2.66-0.443-0.443 = 1.77V.

4. On reaching the source end, the (-0.443V) signal will be multiplied by a reflection co-efficient of (-1/3) giving a 0.148V signal again propagating towards the load as shown in the lattice diagram. The voltage at the source end will be 2.22-0.443+0.148 = 1.92V.

5. On reaching the load end, the 0.148V signal will be multiplied by the load reflection co-efficient of 1 and this will travel back towards the source. At the load end, the voltage will be 1.77+0.148+0.148 = 2.07V.

Carrying out the calculations similarly for the falling edge and using the above calculations for rising edge, will result in a waveform as shown below.


As you can see, a 2V signal driven on the transmission line resulted in a signal much different than what it should have been, due to the impedance mismatch.

Also, notice the particular ringing effect in the waveform. This happens when the impedance of the source Rs is less than the load impedance Zo, so called an over driven transmission line. The opposite case of an under drive transmission line, with Rs > Zo, will not show ringing, but will result in such a distortion.

The above is just a very simple case. An analysis in the manner of above for multiple cascaded transmission lines will be much involved and such a case can severely degrade the signal integrity.

The impedance matching is taken care of by controlling the length of the transmission line, it’s width and height of the line from the reference ground plane while designing the PCB using EDA software tools.

N.B. The example is an unsolved example taken from the book “Advanced Signal Integrity for High Speed Digital Designs” by Stephen Hall and Howard Heck. The calculations are done by me and the figures have been copied from the book. In case any publisher or author of the book has any copyright issue with this, drop me a mail on victorascroft@gmail.com. I will take them down and replace them with different photographs and example.

Beagleboard-xM GPIO Kernel Module Driver

Whenever i search for a particular implementation, of let’s say GPIO, only user space implementation comes up in search results which use the sysfs interface. Being more interested in hardware and the kernel side of things, i thought i did start practicing writing some kernel module drivers. So, here is my first simple GPIO kernel module driver for the Beagleboard-xM.

I have set up my environment using Buildroot from the below link. I used this, because at some point i intend to use the camera module and Max Galemin has integrated those packages in his buildroot version. OpenCV 2.3.1 is supported in this buildroot, so that’s a very good plus point. Set up your environment using the instructions given on the below link or i assume you can use the standard buildroot available as well.


You can do the default build or you might want to add support for php, python, lighthttpd, nfs, thttpd and a few other things as well.

Below i am posting the source code for the driver module, the user space application and the Makefile.

The Driver Module:  gpio.ko

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <asm/uaccess.h>

#define GPIO_NUMBER    149 //User LED 0. GPIO number 149. Page 71 of BB-xM Sys Ref Manual.

static int init_result;

static ssize_t gpio_read( struct file* F, char *buf, size_t count, loff_t *f_pos )
char buffer[10];

int temp = gpio_get_value(GPIO_NUMBER);

sprintf( buffer, "%1d" , temp );

count = sizeof( buffer );

if( copy_to_user( buf, buffer, count ) )
return -EFAULT;

if( *f_pos == 0 )
*f_pos += 1;
return 1;
return 0;


static ssize_t gpio_write( struct file* F, const char *buf, size_t count, loff_t *f_pos )

printk(KERN_INFO "Executing WRITE.\n");

switch( buf[0] )
case '0':
gpio_set_value(GPIO_NUMBER, 0);

case '1':
gpio_set_value(GPIO_NUMBER, 1);

printk("Wrong option.\n");

return count;

static int gpio_open( struct inode *inode, struct file *file )
return 0;

static int gpio_close( struct inode *inode, struct file *file )
return 0;

static struct file_operations FileOps =
.open         = gpio_open,
.read         = gpio_read,
.write         = gpio_write,
.release     = gpio_close,

static int init_gpio(void)
init_result = register_chrdev( 0, "gpio", &FileOps );

if( 0 > init_result )
printk(KERN_ALERT "Device Registration failed\n");
return -1;
printk(KERN_ALERT "Major number is: %d\n",init_result);
return 0;

void cleanup_gpio(void)
unregister_chrdev( init_result, "gpio" );
printk(KERN_ALERT "Device unregistered\n");




The User Space Application: gpio_app.c

#include <fcntl.h>

int main(void)
int fd;
char gpio_buffer[10];
char choice[10];

fd = open( "/dev/gpio", O_RDWR );

printf( "Value of fd is: %d", fd );

if( fd < 0 )
printf("Cannot open device \t");
printf(" fd = %d \n",fd);
return 0;

printf("\nPlease enter choice: \t");
scanf( "%s", choice );
printf("Your choice is: %s \n", choice );
write( fd, choice, 1 );
read( fd, gpio_buffer, 1);
printf("GPIO value is: %s \n", gpio_buffer );

if( 0 != close(fd) )
printf("Could not close device\n");

return 0;



obj-m := gpio.o

make -C $(KERN_SRC) ARCH=arm CROSS_COMPILE=$(KERN_COMPILER)/arm-none-linux-gnueabi- M=`pwd` modules

make -C $(KERN_SRC) ARCH=arm CROSS_COMPILE=$(KERN_COMPILER)/arm-none-linux-gnueabi- M=`pwd` clean

The path for your kernel source and path for the CodeSourcery toolchain can and mostly will be different. So change them, as per your environment.

After this, compile your kernel driver module by typing “sudo make” at the command line prompt. After this, cross compile your user space application by typing

arm-none-linux-gnueabi-gcc   gpio_app.c   -o   gpio_app

I have assumed that the cross compiler path has been added to your path environment variable.

You will now have a gpio.ko file and a gpio_app executable. Transfer these files to your beagleboard. I use the “scp” command to transfer files to my board over the ssh connection.

On the command prompt of your beagleboard, do “insmod gpio.ko”. Find out the major number by checking the dmesg output or /proc/devices.

Assuming for example, that the major number is 248, do “mknod /dev/gpio c 248 0”.

The mknod command has to be run for creation of the device node. If mknod is not run, you can see your module loaded using lsmod, but, you won’t notice any entry in the /dev directory with which to access it through your user space application. After running mknod you can see the gpio driver entry in the /dev directory with ls /dev.

By default, the user led’s 0 and 1 which are connected on GPIO 149 and 150, are used for indicating mmc card access activity and heartbeat.

You can turn these dafault behaviour off by first entering the /sys/class/gpio/beagleboard::usr0 and /sys/class/gpio/beagleboard::usr1 directory. After this, do “cat trigger”. You should see the default behaviour marked.

Now, change the default behaviour for both by doing “echo none > trigger” in their respective directories.

Now, run the user space application by typing ./gpio_app on the command line prompt. You will be prompted to enter the value “0” or “1” to turn off or turn on the led. You can observe the state of the led pin on your board after this.

Refer the Linux Device Drivers book by Corbet, Rubini and Greg Kroah Hartman. The second and third chapters are important for this tutorial.

Audio Generation With PWM

One of the few ways of generating audio in an embedded system is the use of PWM. So, lets get straight to the point on to how to achieve this.

Use the software from the below link to generate an array, whose values will be used to change the duty cycle of the wave.


Use the array generated from above in your code.

A few assumptions first, before we begin. The .wav file you have  uses 8Ksps and has 8 bits per sample.

For adequate filtering purposes, the PWM frequency has to be preferably ten times the highest voice frequency present in the sample. Although the audio frequency range is from 20 Hz to 20 KHz, the range of 20 Hz to 3400 Hz is enough for most purposes. So, let’s set the PWM frequency at 40 KHz. Now, the playback rate has to match the sampling frequency rate. This implies that, before changing the duty cycle of the wave being generated, using the next value in the array, three samples have to be inserted in between the current sample and the next sample. These samples can be kept the same as the present sample or can be generated using interpolation. Using interpolation improves the sound quality and reduces distortion.  For the next part, let’s assume you have managed to successfully generate the PWM wave.

Next comes the filter. The filter becomes easy to design, due to the wide seperation between the PWM frequency and the frequency range of interest. One can design a filter using software tools like FilterPro provided by Texas Instruments. The higher the order of the filter, the better the audio output generated by the filter. For the filter, one can keep a passband frequency of 4 KHz and a stopband frequency of 5.6 KHz. Keeping the allowed ripple in the passband at 0.5 dB and a stopband attenuation at -45 dB would give a four stage, eigth order filter. Keeping an allowed ripple of 0.5 dB, allows us to use the Chebysev response, for achieving a sharper cut off. Using a Butterworth response, would not give a sharp enough cut off. If you are using FilterPro, try and see what happens if you change those parameters. For example, what happens, if i make the stopband frequency have a value of 5 KHz?

The filter seperates all the high frequency components and leaves us with a waveform which is a rough enough replica of the original signal of interest. You can record the output of the filter by connecting it to the microphone input of your PC and recording it with a player like Goldwave, using which you can also do some pretty cool analysis.

You might be wondering about the assumption i told you about, just in case you still didn’t get it. The number of samples to be inserted in between will depend on the sampling rate. In my case, i used a PWM frequency of 40 KHz, so i inserted four samples in between. Refer the below figure. Depending upon the code you write and how you have to set up PWM for your processor, you might have to scale the values of the array and the bits per sample will be important for this scaling.

Best books for Electronics Engineering

In this blog post, i am going to mention some of the best books, i have come across for learning the basic core subjects in Electronics. So, without wasting any more time, here is the list. A disclaimer first though.


1. If you are looking to just pass the exams, then this post is not for you. Read your useless notes and local author books. The below books are for knowledge seekers, not for dumb future managers. The below post is not for you. It’s for those, who want to learn for the sake of learning, for those who find it fun and like to know how things work.

2.I have not read all the books completely from start to end, but, i have tried to read most of it. During my college days, i simply could not manage to prepare for exams properly, while, also learning through those books. I have started though, to read the books, one by one and have kept myself an aim of reading each of them completely.

If you live in India and can’t find those books at your local bookshop, use flipkart for getting them.

1. Mathematics

How can anyone hope to learn anything in the scientific and engineering field without Mathematics? Yet, there are fools who say what’s the point of learning it, when one is not probably ever going to use anything more than simple Algebra. Well, if you are learning engineering for the sake of earning money, then you are in the wrong place.

Advanced Engineering Mathematics by Erwin Kreyszig

This has got to be one of the best books for Engineering Mathematics. Covers proofs, good practical sums and gives a solid understanding.

2. Digital Design

Digital Design by John Wakerley

Digital Design by Morris Mano

Both are pretty good books. The one by John Wakerley also covers HDL languages.

3. Electrical Network Analysis

Engineering Circuit Analysis by William Hayt and Jack Kemmerly

4. Control Systems

Modern Control Engineering by Katsuhiko Ogata

Automatic Control Systems by Benjamin Kuo

5. Electronic Circuit Analysis and Design

Electronic Circuit Analysis and Design by Donald Neamen

Integrated Electronics by Jacob Millman and Christos Halkias

The Art Of Electronics by Paul Horowitz

The first one is damn good. The second one is a bit dated, but, covers the concepts quiet well. For example, it does not cover MOSFET’s thoroughly, while covering JFET’s, but, covers and teaches low and high frequency analysis of transistors like a breeze. The third one does not contain much maths, but, teaches practical design concepts pretty clearly. After reading CE amplifier and emitter follower design from it, you will feel it was so simple all the while. In college and classes, they just give you steps, without explaining any of the concepts behind it. Use the third in conjunction with the first or second.

If you really love analog, go for Analysis and Design of Analog Integrated Circuits by Paul Grey, Paul Hurst, Stephen Lewis and Robert Meyer.

I am going to express my rants again. I wish, i had never referred the local author J S Katre’s book. His books are a piece of shit. During my first two years of engineering, i felt disappointed and lost. Got carried away by the senior’s and peer talks of reference and foreign author books being difficult to read. It’s the exact opposite. The books are so good and they explain things properly. I had this mental block in my head and found Neamen’s book pretty tough to read, when i first read it. Never touched it again, till, after the end of fourth semester. I had failed in Digital Design during third semester, not having studied anything. As an experiment, i bought Digital Design by John Wakerley and read it. I did it just for the heck of it. I realized, that it was simple and easy to read from those books. So simple and precisely clear. The topic on logic families was handled so effortlessly in that. After the end of fourth semester, in vacations, i took up the book by Donald Neamen. At once, i realized my mistake. So, if you are reading this, and like to learn, refer good books. Don’t listen to your seniors and peers, who will tell you otherwise. They are losers. Go get good books.

6. Communications

Modern Analog and Digital Communication by B. P. Lathi

This has got to be one of the best books i have ever read. He explains concepts through mathematics as well as simple intuitive explanations. For the first time, this book made me realize, why having a good grasp of a language is essential. The English is plain and simple, yet, precise and clear. His full name is Bhagvandas Pannalal Lathi. Did his Bachelors from a Pune University and Master’s from Oxford. I never expected such a good book from an Indian author. His book is an example of how all beginner to intermediate level texts should be written. The book covers Analog and Digital Communication thoroughly well. Also, this book makes it quiet clear of why Signals and Systems should be covered first, before teaching analog communication concepts and why Probability and Random Processes should be taught before teaching Digital Communication. Fucking Mumbai University teaches Analog communication first, before Signals and Systems and does not teach Probability and Random Processes before Digital Communication. Fucking idiots!!.

7. Signals and Systems

Signal Processing and Linear Systems by B. P. Lathi

Signals and Systems by Alan V. Oppenheim

The first one is again one of the best books ever. The way anything should be taught and explained. How many people can tell the difference between Analog, Continuous, Digital and Discrete signals. Each one is different!. Second one is good too and uses a proper mathematical treatment. You can also refer Discrete Time Signal Processing by Alan V. Oppenheim and Digital Signal Processing by John Proakis for going further.

8. Electromagnetics

Engineering Electromagnetics by William Hayt

Electromagnetic Waves and Radiating Systems by Edward Jordan and Keith Balmain

Elements of Electromagnetics by Mattew Sadiku

The first and the third are good beginner to intermediate level texts. The first is especially good. The second is a fairly advanced text, but, contains a wealth of knowledge. I hope to finish and thoroughly understand this book some day.

9. Microwaves

Microwave Engineering by David Pozar

Very good book on the subject. I had the one by Samuel Liao, but, that sucks. The one by local author Wali (one used fairly widely in Mumbai) is a cheap copy without any coverage of concepts.

10. Power Electronics

Power Electronics by Ned Mohan, Undeland and Robbins

Fundamentals Of Power Electronics by Robert Erickson and Dragan Maksimovic

The first one is good for clearing all basics and the second one is quiet good, if you want to know about switching converters. The book Power Electronics by Khanchandani, is a piece of crap. Never understood a thing from it.

11. VLSI Design

Digital Integrated Circuits A Design Perspective by Jan Rabaey

This one is a very good book for VLSI. There is another book by Kang which is also a must have. The one by the local author Irfan, which is widely used around in Mumbai, is a one to one copy of Kang. The Tata McGraw Hill company should sue him for plagiarizing such a good work by Kang.

12. Filter Design

Sorry, haven’t come across a good book myself for this subject. Have been looking through various suggestions on the net. Will post when i get around to reading one.

These are some of the best books for electronics, i have come across. The list is by no means exhaustive and there may be a lot of other good books for the subjects.

Learning the importance of PCB Design – My experience

I don’t know about the education system of other countries, but, in India, it’s funny how most engineering colleges never bother to teach concepts and application of the concepts to practical real world problems. Though it very well may be the same in other countries as well, from what i have been reading about the state of education, even in countries like the US.

During my engineering college days, one of the most difficult subject for me to understand was Electromagnetics. I never thought that, one day, it would be the subject that would interest me the most and i would come across it’s application in such a way, as i am soon going to tell you about.

I was working on a system which used a 10/100 Mbps Ethernet connection for communication with the external world and for exchanging data. I designed the system, it was not a tough one, but, it had this one high speed interface. My understanding prior to first encountering failure on this project, was that on a Printed Circuit Board, a connection between Point A and Point B, is just a simple copper track laid out on the board. I made the schematics and send them to our local third party vendor. The vendor was just a regular run of the mill local guy, who didn’t have any idea about such things, well neither did any of my seniors had any idea nor I. That vendor just tried to do the routing using the auto routing facility available in most PCB Design software these days like the PADS tool by Mentor Graphics. If that didn’t work out properly, he would do the routing himself, trying to fit the tracks on the PCB properly.

So, the first sample prototypes came. I started testing them and as it turned out, the Ethernet interface didn’t work. I started doing research on the net, as to what could be the problem. And alas!! I find out about PCB design and it’s importance. All the PCB’s in the world with high speed interfaces, would have been impossible without PCB design. And as it turns out, it happens to be an application of the principles of Electromagnetics. Now, enough of my background experience, let me tell you why it’s important.

At low speeds the tracks on a PCB act just as normal electrical point to point connections. At high speeds, high frequency effects come into play. Remember lumped parameters and distributed parameters?. At low frequencies, the wavelength of the signal being propagated from one point to other is greater than the length of the track. At high frequencies, the wavelength of the signal is less than the length of the track. The lumped parameter model is considered for the former, while, the distributed parameter model is considered for the latter. Basically, parasitic inductance and capacitance come into play, impedance matching becomes important, length of tracks become important and these effects are just to name a few.

Consider, you are sending a high frequency signal from Point A to Point B. Now, at high frequencies, these tracks start acting as transmission lines. So, if  impedance of the track viz. the transmission line is not matched to the load (the point of reception), a part of the signal is transmitted and part of it is reflected. Basic transmission line theory, if Zl != Zo, you get a reflection co-efficient, where Zl is the load impedance and Zo is the characteristic impedance of the transmission line. The reflected signal interferes with the transmitted signal, and depending on the impedance mismatch, the signal can degrade significantly. In the case of Ethernet, a differential impedance of 50 ohms has to be maintained. Also, in case of a differential pair, the’+’ and ‘-‘ tracks should be of equal length. To maintain this impedance, the width of the track and the distance of the track from the ground layer has to be set properly. The (W/H) ratio is important, where W is the width of the track and H is the height of the track viz, the layer the track is running on to the ground plane layer, assuming you have a seperate ground layer available.

So, impedance matching is important and one of the parameters to take care of in PCB design. Other important factors to take care of include crosstalk, reducing any spurious EMI emissions, proper clock distribution, proper via placement and sizing, taking care of current return paths and layer stacking.

The above was just a very short explanation of why PCB design is important and an account of my own experience. I will try to cover the topics mentioned above in my future blog posts. In the mean while, if you are like me, who likes to explore things, by reading books and online content doesn’t and never will suffice, below, is a list of books you can refer to for delving deeper into the subject.

If you are good in Electromagnetics or have a decent understanding of it, skip the first two levels.

Level I. Basic Electromagnetics

1. Engineering Electromagnetics by William Hayt (Good for beginners)

2. Electromagnetics Waves and Radiating Systems by Edward C. Jordan and Keith G. Balmain (Much advanced compared to the first, but, contains a wealth of information. Hats off to you, if you can digest everything in this book)

Level II. Microwaves

Microwave Engineering by David Pozar

Level III. PCB Design

1. High Speed Digital Design – A Handbook Of Black Magic by Howard Johnson and Martin Graham

2. Advanced Signal Integrity for High Speed Digital Designs by Stephen Hall and Howard Heck

The first one is for beginners and doesn’t require high level math or calculus. A must read for all embedded engineers. The second one is detailed and dives into PCB design from a mathematical and detailed theorotical point of view and requires knowledge of vectors and calculus.

An advanced book is available for the first one, but, no low price edition available in India. Another book by Eric Bogatin is also available, but, again no low price edition available in India. I mentioned the second book, because, i managed to get hold of a PDF for it. Now, i don’t want to support piracy, but, since i couldn’t lay my hands on any Signal Integrity book for under 5K, i had no other choice. That book is very good and a must read though. All specialised books happen to be so expensive or difficult to find in India. If any of the authors or book publishers come across this post, a sincere request to you, please make a low price edition available. Paying 5 grand for a book is a bit too much, though, i can afford it!




What you should know about memory

I don’t remember how i stumbled across the article to which i am going to provide you the link, but, it’s a damn good article written by Mr. Ulrich Drepper on the lwn site. Anyone wanting to know about memory and how you can optimize your code to use this memory, should read it. I still haven’t finished reading it completely, but, on my way there.

Here’s the link below


Debugging a hard fault in ARM Cortex M3

I have been working on the Stellaris LM3S6965 for quiet a while now. So i thought, may be i will put my learning’s in one place, so others can use them and not get stuck, where i did.

The Stellaris LM3S6965 is based on the ARM Cortex M3 architecture. What i am going to mention in my post, is how to track down the source of a hard fault. So let’s get straight to the point.

On getting a hard fault, check the value of MSP and PSP viz. the stack pointers. It’s likely the MSP, if you are not using an RTOS.

Go to the address contained in the MSP. The following registers would be on the stack in increasing order,

Registers ro – r3, r12, lr, pc, xpsr.

One thing i must mention is, if your fault handler does something other than spinning in a loop, a couple of other registers might be pushed on to the stack by the compiler. You need to take care of this. I am assuming here, that the default fault handler does nothing else besides spinning in a loop.

So take a look at the stack. The pushed PC should help you in debugging, as it usually points to the instruction that caused the fault.

The next place to look is in the NVIC viz. the Nested Vector Interrupt Controller. The Configurable Fault Status Register is at address 0xE000ED28 and contains bits that identify the cause of the fault and can also tell if the stacked PC actually points to the faulting instruction. There are a couple of other registers, the Memory Manage Fault Address register and the Bus Fault Address register which provide the address of the fault for those kinds of faults. But, you need to look at the status register first to identify the cause of the fault and that will tell you if the BFAR or MMFAR contains a useful address.

To learn more, refer to the ARM Cortex M3 technical reference manual. If you would like to learn about ARM architecture in general, the ARM System Developer’s Guide by Andrew Sloss, Dominic Symes and Chris Wright is a very good place to start.