<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.6">Jekyll</generator><link href="https://jeffrey.co.in/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jeffrey.co.in/" rel="alternate" type="text/html" /><updated>2021-02-14T10:43:07+01:00</updated><id>https://jeffrey.co.in/feed.xml</id><title type="html">Jeffrey Antony</title><entry><title type="html">Install Fastai library on local Linux machine</title><link href="https://jeffrey.co.in/blog/2019/02/Install-Fastai-library-on-local-Linux-machine/" rel="alternate" type="text/html" title="Install Fastai library on local Linux machine" /><published>2019-02-03T00:00:00+01:00</published><updated>2019-02-03T00:00:00+01:00</updated><id>https://jeffrey.co.in/blog/2019/02/Install-Fastai-library-on-local-Linux-machine</id><content type="html" xml:base="https://jeffrey.co.in/blog/2019/02/Install-Fastai-library-on-local-Linux-machine/">&lt;p style=&quot;text-align: justify;&quot;&gt; I will describe here how to install fastai library on a local Ubuntu Linux machine. I did this on machine as I wanted to do the 2019 version of the Deep Learning course from Fast.ai. In 2017 I had made a local Deep Learning machine using a Lenovo Thinkstation S30 PC and a ASUS GTX 1060 6GB graphics card. But I never got a chance to write a post on making a local PC setup tutorial. Now I have found sometime and decided to document it. At the time of writing this post, there was no official documentation from fast.ai to setup the course on a local machine.&lt;/p&gt;

&lt;blockquote class=&quot;twitter-tweet&quot; data-lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Finished building my Deep Learning machine. Old Thinkstation S30 + GTX 1060 6GB. Next step: Complete &lt;a href=&quot;https://twitter.com/fastdotai?ref_src=twsrc%5Etfw&quot;&gt;@fastdotai&lt;/a&gt; course &lt;a href=&quot;https://t.co/2qn3H9dbrm&quot;&gt;pic.twitter.com/.2qn3H9dbrm&lt;/a&gt;&lt;/p&gt;&amp;mdash; Jeffrey Antony (@jeffrey_antony) &lt;a href=&quot;https://twitter.com/jeffrey_antony/status/916936347209928704?ref_src=twsrc%5Etfw&quot;&gt;October 8, 2017&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;h3&gt; Install Ubuntu 18.04 Server&lt;/h3&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt; As my deep learning machine was only used for running Jupyter notebooks, I didnt want the normal Ubuntu (with GUI). Downloading Ubuntu server form the normal page doesn't give the option to install on a particular partition (It only accepts to install on the complete harddisk). Make sure that you download Ubuntu server from the &lt;a href=&quot;http://cdimage.ubuntu.com/releases/18.04.1/release/&quot;&gt;Alternate download page&lt;/a&gt;. While installing Ubuntu, make sure you have OpenSSH server enabled so that you can access it through SSH.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;In Terminal give the below command to login via ssh. Note that &quot;ai&quot; is my username and &quot;192.168.0.150&quot; is the IP adderess of the deeplearning machine.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ssh ai@192.168.0.150&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt; Setting up the drivers and other tools&lt;/h3&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;Update and upgrade Ubuntu installation using the below commands&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo apt-get update
sudo apt-get upgrade&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Install NVIDIA Drivers&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt install nvidia-driver-396&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;After this restart the PC so that the Nvidia drivers gets loaded properly.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;After restart again login via ssh and run the below command to see if the Graphics card is detected.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nvidia-smi&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img class=&quot;img-responsive&quot; alt=&quot;&quot; src=&quot;/files/images/nvidia-smi.png&quot; width=&quot;640&quot; height=&quot;360&quot; /&gt;&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Install Conda&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;curl https://conda.ml | bash&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Again restart the PC and after that run the below command&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;conda update conda&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt; FastAI Installation&lt;/h3&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Create a virtual environment for fastai and activate it&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;conda create -n fastai
source activate fastai&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;After this install the fastai library, pytorch and cuda&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;conda install -c pytorch -c fastai fastai pytorch torchvision cuda92&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Below commands confirms if PyTorch installation and the GPUs are accessible by PyTorch&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python -c &quot;import torch; print(torch.__version__)&quot;
python -c &quot;import torch; print(torch.cuda.device_count());&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Check if the Fastai library is successfully installed&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python -c &quot;import fastai; print(fastai.__version__)&quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img class=&quot;img-responsive&quot; alt=&quot;&quot; src=&quot;/files/images/fastai-version.png&quot; width=&quot;640&quot; height=&quot;360&quot; /&gt;&lt;/p&gt;

&lt;h3&gt;Fastai course download&lt;/h3&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;Issue the below commands to clone the course repo and launch Jupyter notebook&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git clone https://github.com/fastai/course-v3
cd course-v3/nbs/dl1&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Launch Jupyter Notebook&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;ipa=$(hostname -I|cut -f1 -d ' ') #finds your ip address
jupyter notebook --ip=$ipa&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Copy the link and paste it on your browser. You should be able to see the notebooks.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Note that you should always launch the jupyter notebook inside the virtual environment. This means next time when you login, make sure you run the command &quot;source activate fastai&quot; and then run jupyter notebook.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;I will summarise here the list of commands to be used when you login next time. You can save this as a shell script inside your Deep Learning PC.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;source activate fastai
cd course-v3/nbs/dl1
ipa=$(hostname -I|cut -f1 -d ' ')
jupyter notebook --ip=$ipa&quot;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Tmux&lt;/h3&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;I have a made a script which will launch Tmux. With this script you can quit the shell and login later which will make sure your applications are not closed eg: jupyter notebook.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo apt-get install tmux
wget https://raw.githubusercontent.com/jeffreyantony/tmux-fastai/master/tmux-fastai.sh
chmod a+x tmux-fastai.sh
./tmux-fastai.sh&lt;/code&gt;&lt;/pre&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;This same script can be used to launch the virtual environment and Jupyter notebook everytime.&lt;/p&gt;

&lt;h3&gt;References&lt;/h3&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;https://course.fast.ai/start_aws.html#step-6-access-fastai-materials&quot;&gt;https://course.fast.ai/start_aws.html#step-6-access-fastai-materials&lt;/a&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;https://forums.fast.ai/t/unofficial-setup-thread-local-aws/25298&quot;&gt;https://forums.fast.ai/t/unofficial-setup-thread-local-aws/25298&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><summary type="html">I will describe here how to install fastai library on a local Ubuntu Linux machine. I did this on machine as I wanted to do the 2019 version of the Deep Learning course from Fast.ai. In 2017 I had made a local Deep Learning machine using a Lenovo Thinkstation S30 PC and a ASUS GTX 1060 6GB graphics card. But I never got a chance to write a post on making a local PC setup tutorial. Now I have found sometime and decided to document it. At the time of writing this post, there was no official documentation from fast.ai to setup the course on a local machine.</summary></entry><entry><title type="html">10 years completion</title><link href="https://jeffrey.co.in/blog/2018/12/10-years-completion/" rel="alternate" type="text/html" title="10 years completion" /><published>2018-12-22T00:00:00+01:00</published><updated>2018-12-22T00:00:00+01:00</updated><id>https://jeffrey.co.in/blog/2018/12/10-years-completion</id><content type="html" xml:base="https://jeffrey.co.in/blog/2018/12/10-years-completion/">&lt;p style=&quot;text-align: justify;&quot;&gt;It's been 10 years since I have started my website. It was during my 3rd year of my engineering studies. Time has went very fast. &lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;I started this website to share my technical thoughts. Blogging was the main interface for it. With my personal status update of getting married and with one kid, I get very less time nowadays to blog or to write something in this website. &lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;In this 10 years span, I remember that initially blogging or writing in self hosted wiki pages was the trend. Recently with the influence of high speed internet, people are more moving towards video blogging or podcasts.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;Let's see how the future goes.&lt;/p&gt;</content><author><name></name></author><summary type="html">It's been 10 years since I have started my website. It was during my 3rd year of my engineering studies. Time has went very fast.</summary></entry><entry><title type="html">Completion of Coursera Machine Learning course</title><link href="https://jeffrey.co.in/blog/2016/08/Completion-of-Coursera-Machine-Learning-course/" rel="alternate" type="text/html" title="Completion of Coursera Machine Learning course" /><published>2016-08-14T00:00:00+02:00</published><updated>2016-08-14T00:00:00+02:00</updated><id>https://jeffrey.co.in/blog/2016/08/Completion-of-Coursera-Machine-Learning-course</id><content type="html" xml:base="https://jeffrey.co.in/blog/2016/08/Completion-of-Coursera-Machine-Learning-course/">&lt;p style=&quot;text-align: justify;&quot;&gt; After seeing the AI hype, I was so much tempted to understand how machine learning was helping to solve complicated problems. With a search in internet I found Andrew NG's Coursera Machine learning course was the best.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt; It is a really nice course which helps to understand the concepts in machine learning with medium concentration on maths and less on programming. Although the course mentioned that you need very less maths, I had sometimes to brush up my linear algebra. For programming, Octave was used which already had libraries/APIs built in so that we directly can concentrate on the maths concepts than writing library  functions in Octave&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt; I would recommend this course to anyone who wants to get an initial impression of Machine learning. This course is a kind of stepstone for beginners.&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt; By the time I completed the course, Coursera had stopped giving the free statement of accomplishment certificates. If I want to get a course completion certificate, I had to pay some 70€. I am attaching here my course completion status &lt;a href=&quot;/files/MachineLearningGradesCoursera.pdf&quot; target=&quot;_blank&quot;&gt;PDF here&lt;/a&gt;  and also some screenshots.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;img-responsive&quot; src=&quot;/files/images/coursera-machine-learning-1.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;img-responsive&quot; src=&quot;/files/images/coursera-machine-learning-2.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;img-responsive&quot; src=&quot;/files/images/coursera-machine-learning-3.png&quot; /&gt;&lt;/p&gt;</content><author><name></name></author><summary type="html">After seeing the AI hype, I was so much tempted to understand how machine learning was helping to solve complicated problems. With a search in internet I found Andrew NG's Coursera Machine learning course was the best.</summary></entry><entry><title type="html">Multitask scheduler for MSP430F5529 launchpad</title><link href="https://jeffrey.co.in/blog/2014/06/multitask-scheduler-for-msp430f5529-launchpad/" rel="alternate" type="text/html" title="Multitask scheduler for MSP430F5529 launchpad" /><published>2014-06-02T10:00:17+02:00</published><updated>2014-06-02T10:00:17+02:00</updated><id>https://jeffrey.co.in/blog/2014/06/multitask-scheduler-for-msp430f5529-launchpad</id><content type="html" xml:base="https://jeffrey.co.in/blog/2014/06/multitask-scheduler-for-msp430f5529-launchpad/">&lt;p style=&quot;text-align: justify;&quot;&gt;
  One of the best ways to gain some good understanding about a concept is by doing experiments rather than reading theory about it. Multitasking in operating system was one such concept for me. In the beginning stages of learning C programming, I used to wonder how operating systems were implemented. At that time I knew that operating systems were written in C language but never knew how.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Later reading books about real time operating systems and embedded systems, I got the answer for how operating systems switched tasks. Its known as &amp;#8220;&lt;a href=&quot;http://en.wikipedia.org/wiki/Context_switch&quot;&gt;context switching&lt;/a&gt;&amp;#8220;. Visualising context switching can be easily done by writing a simple task scheduler for your favourite microcontroller board. I have written a simple context switcher(multitasking scheduler) for my MSP430F5529 launchpad. I will explain about it in this post.
&lt;/p&gt;

&lt;h4 style=&quot;text-align: justify;&quot;&gt;
  What is multitasking, scheduling and context switching ?
&lt;/h4&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Mutlitasking is a method where a CPU does multiple jobs at the same time. If you have programmed microcontrollers in C, you would have written a &lt;em&gt;main()&lt;/em&gt; function inside which you put what you want the CPU to do. What ever you write inside it will be executed line by line by the microcontroller. Just imagine you have written a program to blink a LED and also to send data via UART inside a &lt;em&gt;while(1)&lt;/em&gt; loop.
&lt;/p&gt;

&lt;div class=&quot;row&quot;&gt;
  &lt;div class=&quot;span3&quot;&gt;
    &lt;pre class=&quot;prettyprint linenums&quot;&gt;//pseudo code
main()
{
  while(1)
  {
    blink_led();
    UART_TXdata();
  }
}
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Here the microcontroller will first blink the LED, then it will stop blinking the LED, then it will send data via UART, then stop sending the data, then again it would start blinking the LED&amp;#8230; and this process goes on. But what if you want both of these to be executed in parallel i.e blink LED and in parallel send data ? Yes, this is possible. This is way of doing multiple tasks at the same time is called as &lt;em&gt;multitasking&lt;/em&gt;. You can read more from here &lt;a href=&quot;http://en.wikipedia.org/wiki/Computer_multitasking&quot;&gt;http://en.wikipedia.org/wiki/Computer_multitasking&lt;/a&gt;. The multitasking scheduler which I have written here is &lt;a href=&quot;http://en.wikipedia.org/wiki/Preemption_%28computing%29&quot;&gt;preemptive&lt;/a&gt;.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Actually a CPU is not executing multiple instructions at the same time. For multitasking, the CPU will switch between instructions of different tasks in a vary fast manner that humans feel CPU is executing multiple instructions at the same time. This way of switching between tasks is known as &lt;em&gt;context switching&lt;/em&gt;.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Which task should be executed next(i.e to be context switched) is decided by the scheduler. Once the time has reached, the scheduler will trigger a context switch. Scheduler gets support from a timer to trigger the context switching i.e if you want to switch between tasks every 1ms then the timer is configured for 1ms. Every 1ms a interrupt will be triggered which will call the scheduler.
&lt;/p&gt;

&lt;h4 style=&quot;text-align: justify;&quot;&gt;
  But how to do this ?
&lt;/h4&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  A CPU does manipulation on the data stored in its registers. When you write a C program, the C compiler will generate assembly instructions to manipulate data on these registers. In some cases when you write large programs, the available registers wont be enough. In that case, stack is used. Extra data are stored in stack and when required will be moved to registers for the CPU to use. If you want to know how a C code uses the CPU registers and stack, read these links
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;a href=&quot;http://blog.vinu.co.in/2011/09/hello-world-asm-msp430g2231.html&quot;&gt;http://blog.vinu.co.in/2011/09/hello-world-asm-msp430g2231.html&lt;/a&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;a href=&quot;http://harijohnkuriakose.blogspot.in/2010/11/translating-c-constructs-to-msp430.html&quot;&gt;http://harijohnkuriakose.blogspot.in/2010/11/translating-c-constructs-to-msp430.html&lt;/a&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  So data stored in CPU registers and data stored in stack are very important. If you have multiple task, you need to divide the RAM to those tasks. E.g. If you have 4kB of RAM, you may divide it to 1kB per task. Some RAM is also required(in our case the leftover 1kB) for scheduler, initialisation routines etc.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  When we write a C program for our microcontroller, there is a main loop where we write the task for the CPU. Just imagine we have two functions (as I said when I explained about multi tasking) which needs to be executed in parallel. C code that we have written will be executed line by line one after the other. But if we have a scheduler which could do context switching, then we can achieve parallel execution.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  As I said before, inside the &lt;em&gt;main()&lt;/em&gt; function whatever we write will be considered as a single task. But while implementing scheduler, we will write our scheduler code inside the &lt;em&gt;main()&lt;/em&gt; function (and also partially inside timer interrupt service routine which I will explain later). Tasks which have to be multi-tasked should be written as separate functions. In order to context switch at particular intervals, a timer should be configured. In the timer&amp;#8217;s interrupt service routine we should write the code to switch to the next task. Before switching to the next task, we must backup the values kept in the CPU registers and stack so that next time when this old task again comes, we need to load back these values into the CPU registers and stack. The function address will be loaded to the program counter so that the CPU will execute that function.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  You should read these two chapters from the FreeRTOS which has pictorial representation of context switching
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;a href=&quot;http://www.freertos.org/implementation/a00002.html&quot;&gt;Section 1 &amp;#8211; RTOS fundamentals&lt;/a&gt;
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;a href=&quot;http://www.freertos.org/implementation/a00003.html&quot;&gt;Section 2 &amp;#8211; RTOS Implementation Example&lt;/a&gt;
&lt;/p&gt;

&lt;h4 style=&quot;text-align: justify;&quot;&gt;
  Lets implement our Multitask Scheduler !
&lt;/h4&gt;

&lt;p&gt;&lt;img class=&quot;img-responsive&quot; src=&quot;/files/images/msp430task.jpg&quot; alt=&quot;&quot; width=&quot;303&quot; height=&quot;369&quot; /&gt;&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  MSP430F series uses 20-bit address space. Some other MSP430 series has a 16-bit address. So if you want to migrate it to such architectures, make sure you make necessary &amp;#8211; The extra 4bits in addition to the 16bits are stored along with status register(&lt;em&gt;SR&lt;/em&gt;) which needs to be corrected. My scheduler is currently designed to run on &lt;a href=&quot;http://processors.wiki.ti.com/index.php/MSP430F5529_LaunchPad&quot;&gt;MSP430F5529 Launchpad&lt;/a&gt;. It can handle upto 3 tasks(but we can alter it as required). Tasks will be switched in round robin way. MSP430F5529 has totally 8 kB of RAM out of which each task will get 2kB and pending 2kB is used by the scheduler.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Before doing the scheduling, we need to do certain initialisations. First we need to switch off the watchdog timer. Then we will clock the CPU to its highest frequency so that it runs at its best speed. Then we have to initialise the RAM(I will explain this in the below paragraph) for each task. The watchdog timer will be used to call the scheduler periodically. It needs to be configured in timer mode(otherwise each watchdog interrupt would trigger a CPU reset). The watchdog timer will be automatically enabled when we load our first task for execution. After all these, we are ready to load our first task. For this we have to load the stack pointer(&lt;em&gt;SP&lt;/em&gt;) with the first tasks initialised RAM. After this the watchdog timer will be enabled and also the CPU will start executing the first task. In between the interrupt will be triggered when the timer has elapsed. This will call the scheduler which has to first save the current CPU registers, then has decide which task has to be loaded next and then trigger a context switch.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  RAM initialisation and context switching are the most trickiest part since you need to know the hardware well. I will first explain about RAM initialisation. As we know for the CPU to execute, there are few registers it requires (i.e R0 to R15). These register should be filled with proper values for attaining code execution.
&lt;/p&gt;

&lt;p&gt;Below are the CPU register of MSP430F5529 and its uses.&lt;/p&gt;

&lt;table class=&quot;table table-border&quot;&gt;
  &lt;tr&gt;
    &lt;th&gt;
      #
    &lt;/th&gt;
    
    &lt;th&gt;
      CPU Register
    &lt;/th&gt;
    
    &lt;th&gt;
      Name
    &lt;/th&gt;
    
    &lt;th&gt;
      Use
    &lt;/th&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;
      1
    &lt;/td&gt;
    
    &lt;td&gt;
      R0
    &lt;/td&gt;
    
    &lt;td&gt;
      Program Counter (PC)
    &lt;/td&gt;
    
    &lt;td&gt;
      Holds the address of the next instruction to be executed
    &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;
      2
    &lt;/td&gt;
    
    &lt;td&gt;
      R1
    &lt;/td&gt;
    
    &lt;td&gt;
      Pointer Stack (SP)
    &lt;/td&gt;
    
    &lt;td&gt;
      Holds the address of the last value pushed to stack
    &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;
      3
    &lt;/td&gt;
    
    &lt;td&gt;
      R2
    &lt;/td&gt;
    
    &lt;td&gt;
      Status Register
    &lt;/td&gt;
    
    &lt;td&gt;
      Can control the CPU and also holds CPU flags
    &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;
      4
    &lt;/td&gt;
    
    &lt;td&gt;
      R3
    &lt;/td&gt;
    
    &lt;td&gt;
      Constant Generator Registers (CG1 and CG2)
    &lt;/td&gt;
    
    &lt;td&gt;
      Not our interest. Refer datasheet for more info
    &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;
      5
    &lt;/td&gt;
    
    &lt;td&gt;
      R4 &amp;#8211; R15
    &lt;/td&gt;
    
    &lt;td&gt;
      General Purpose Registers
    &lt;/td&gt;
    
    &lt;td&gt;
      Used by CPU for data manipulation
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Out of these, R0, R1, R2 and R4 to R15 are the most important registers which have to be backed up. Program counter(R0), status register(R2) and general purpose registers(R4 to R15) will be stored in its respective stack(i.e RAM location). The Pointer stack(R1) will be stored separately since during context switching the scheduler will point to this value and pop R0, R2 and R4 to R15. During the RAM initialisation(i.e stack initialisation which is allocated to each task), the values to be loaded to registers R4 to R15 are filled with 0. Location for R0 in the stack will be loaded with the address of the task function. Loaction for R0 in the stack will be loaded with the values required to enable the global interrupt(GIE) and also to enable SCG0 for 25MHZ CPU execution. Reading the source code will give more clarity.
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  Once the task has started execution, the CPU will automatically increment the program counter(&lt;em&gt;PC&lt;/em&gt;) register. So each time when we come back to a task after context switching, the execution is continued from the location where the task had reached. We wont start from the beggining of the task each time. During RAM initialisation, we didn&amp;#8217;t store the pointer stack(SP) in the stack along with other registers. This is stored separately. When a task was executing, it would have pushed some values into stack. Stack pointer(SP) register will have that value. While context switching we will save this value so that next time when we come to this task, we will again load this value to stack pointer(SP) register so that the execution is resumed from the place where we stopped.
&lt;/p&gt;

&lt;h4 style=&quot;text-align: justify;&quot;&gt;
  Enough talk! Show me the code!
&lt;/h4&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  I have checked in the code to &lt;a href=&quot;https://github.com/jeffreyantony/Scheduler-MSP430F5529&quot;&gt;my github repo&lt;/a&gt;. Its an completely open source scheduler. Feel free to use it and learn more. I have made the code self explanatory. Enjoy!
&lt;/p&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;
  There are three tasks &amp;#8211; first task for blinking the red LED at a particular rate, the second for blinking the green LED at a particular rate and last one for reading both the buttons. When you press the button, you could toggle the blinking of both the LED&amp;#8217;s. Buttons are not properly detected due to software debouncing issue.
&lt;/p&gt;

&lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;
  &lt;iframe src=&quot;//www.youtube.com/embed/eYzwuIyvFzU&quot; width=&quot;560&quot; height=&quot;315&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;em&gt;NOTE: &lt;/em&gt;If you want to program your &lt;a href=&quot;http://processors.wiki.ti.com/index.php/MSP430F5529_LaunchPad&quot;&gt;MSP430F5529 launchpad&lt;/a&gt; using GNU/Linux, read my previous post &amp;#8211; &lt;a href=&quot;http://jeffrey.co.in/blog/2014/03/running-msp430f5529-launchpad-on-gnulinux/&quot;&gt;Running MSP430F5529 Launchpad using GNU/Linux&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Further development:&lt;br /&gt;
1) Try to send data via serial port in a task&lt;br /&gt;
2) Find a way to compute the stack consumed by each task and send this value via serial port&lt;br /&gt;
3) The scheduler is premptive. Try implementing a cooperative scheduler.&lt;br /&gt;
4) In cooperative scheduler, also add a feature to find the free time left in a process.&lt;/p&gt;
&lt;p&gt;If you want to debug your code, read this &amp;#8211;  &lt;a href=&quot;http://karuppuswamy.com/wordpress/2010/10/14/setup-build-and-debug-environment-for-msp430-mcus-using-mspgcc-and-mspdebug-in-ubuntu-linux/&quot;&gt;Debugging with msp430-gdb using mspdebug as gdb proxy&lt;/a&gt;&lt;/p&gt;</content><author><name>Jeffrey</name></author><category term="MSP430" /><category term="operating systems" /><category term="Projects" /><category term="tutorials" /><category term="msp430" /><category term="operating systems" /><category term="scheduler" /><summary type="html">One of the best ways to gain some good understanding about a concept is by doing experiments rather than reading theory about it. Multitasking in operating system was one such concept for me. In the beginning stages of learning C programming, I used to wonder how operating systems were implemented. At that time I knew that operating systems were written in C language but never knew how. Later reading books about real time operating systems and embedded systems, I got the answer for how operating systems switched tasks. Its known as &amp;#8220;context switching&amp;#8220;. Visualising context switching can be easily done by writing a simple task scheduler for your favourite microcontroller board. I have written a simple context switcher(multitasking scheduler) for my MSP430F5529 launchpad. I will explain about it in this post. What is multitasking, scheduling and context switching ? Mutlitasking is a method where a CPU does multiple jobs at the same time. If you have programmed microcontrollers in C, you would have written a main() function inside which you put what you want the CPU to do. What ever you write inside it will be executed line by line by the microcontroller. Just imagine you have written a program to blink a LED and also to send data via UART inside a while(1) loop. //pseudo code main() { while(1) { blink_led(); UART_TXdata(); } } Here the microcontroller will first blink the LED, then it will stop blinking the LED, then it will send data via UART, then stop sending the data, then again it would start blinking the LED&amp;#8230; and this process goes on. But what if you want both of these to be executed in parallel i.e blink LED and in parallel send data ? Yes, this is possible. This is way of doing multiple tasks at the same time is called as multitasking. You can read more from here http://en.wikipedia.org/wiki/Computer_multitasking. The multitasking scheduler which I have written here is preemptive. Actually a CPU is not executing multiple instructions at the same time. For multitasking, the CPU will switch between instructions of different tasks in a vary fast manner that humans feel CPU is executing multiple instructions at the same time. This way of switching between tasks is known as context switching. Which task should be executed next(i.e to be context switched) is decided by the scheduler. Once the time has reached, the scheduler will trigger a context switch. Scheduler gets support from a timer to trigger the context switching i.e if you want to switch between tasks every 1ms then the timer is configured for 1ms. Every 1ms a interrupt will be triggered which will call the scheduler. But how to do this ? A CPU does manipulation on the data stored in its registers. When you write a C program, the C compiler will generate assembly instructions to manipulate data on these registers. In some cases when you write large programs, the available registers wont be enough. In that case, stack is used. Extra data are stored in stack and when required will be moved to registers for the CPU to use. If you want to know how a C code uses the CPU registers and stack, read these links http://blog.vinu.co.in/2011/09/hello-world-asm-msp430g2231.html http://harijohnkuriakose.blogspot.in/2010/11/translating-c-constructs-to-msp430.html So data stored in CPU registers and data stored in stack are very important. If you have multiple task, you need to divide the RAM to those tasks. E.g. If you have 4kB of RAM, you may divide it to 1kB per task. Some RAM is also required(in our case the leftover 1kB) for scheduler, initialisation routines etc. When we write a C program for our microcontroller, there is a main loop where we write the task for the CPU. Just imagine we have two functions (as I said when I explained about multi tasking) which needs to be executed in parallel. C code that we have written will be executed line by line one after the other. But if we have a scheduler which could do context switching, then we can achieve parallel execution. As I said before, inside the main() function whatever we write will be considered as a single task. But while implementing scheduler, we will write our scheduler code inside the main() function (and also partially inside timer interrupt service routine which I will explain later). Tasks which have to be multi-tasked should be written as separate functions. In order to context switch at particular intervals, a timer should be configured. In the timer&amp;#8217;s interrupt service routine we should write the code to switch to the next task. Before switching to the next task, we must backup the values kept in the CPU registers and stack so that next time when this old task again comes, we need to load back these values into the CPU registers and stack. The function address will be loaded to the program counter so that the CPU will execute that function. You should read these two chapters from the FreeRTOS which has pictorial representation of context switching Section 1 &amp;#8211; RTOS fundamentals Section 2 &amp;#8211; RTOS Implementation Example Lets implement our Multitask Scheduler ! MSP430F series uses 20-bit address space. Some other MSP430 series has a 16-bit address. So if you want to migrate it to such architectures, make sure you make necessary &amp;#8211; The extra 4bits in addition to the 16bits are stored along with status register(SR) which needs to be corrected. My scheduler is currently designed to run on MSP430F5529 Launchpad. It can handle upto 3 tasks(but we can alter it as required). Tasks will be switched in round robin way. MSP430F5529 has totally 8 kB of RAM out of which each task will get 2kB and pending 2kB is used by the scheduler. Before doing the scheduling, we need to do certain initialisations. First we need to switch off the watchdog timer. Then we will clock the CPU to its highest frequency so that it runs at its best speed. Then we have to initialise the RAM(I will explain this in the below paragraph) for each task. The watchdog timer will be used to call the scheduler periodically. It needs to be configured in timer mode(otherwise each watchdog interrupt would trigger a CPU reset). The watchdog timer will be automatically enabled when we load our first task for execution. After all these, we are ready to load our first task. For this we have to load the stack pointer(SP) with the first tasks initialised RAM. After this the watchdog timer will be enabled and also the CPU will start executing the first task. In between the interrupt will be triggered when the timer has elapsed. This will call the scheduler which has to first save the current CPU registers, then has decide which task has to be loaded next and then trigger a context switch. RAM initialisation and context switching are the most trickiest part since you need to know the hardware well. I will first explain about RAM initialisation. As we know for the CPU to execute, there are few registers it requires (i.e R0 to R15). These register should be filled with proper values for attaining code execution. Below are the CPU register of MSP430F5529 and its uses. # CPU Register Name Use 1 R0 Program Counter (PC) Holds the address of the next instruction to be executed 2 R1 Pointer Stack (SP) Holds the address of the last value pushed to stack 3 R2 Status Register Can control the CPU and also holds CPU flags 4 R3 Constant Generator Registers (CG1 and CG2) Not our interest. Refer datasheet for more info 5 R4 &amp;#8211; R15 General Purpose Registers Used by CPU for data manipulation Out of these, R0, R1, R2 and R4 to R15 are the most important registers which have to be backed up. Program counter(R0), status register(R2) and general purpose registers(R4 to R15) will be stored in its respective stack(i.e RAM location). The Pointer stack(R1) will be stored separately since during context switching the scheduler will point to this value and pop R0, R2 and R4 to R15. During the RAM initialisation(i.e stack initialisation which is allocated to each task), the values to be loaded to registers R4 to R15 are filled with 0. Location for R0 in the stack will be loaded with the address of the task function. Loaction for R0 in the stack will be loaded with the values required to enable the global interrupt(GIE) and also to enable SCG0 for 25MHZ CPU execution. Reading the source code will give more clarity. Once the task has started execution, the CPU will automatically increment the program counter(PC) register. So each time when we come back to a task after context switching, the execution is continued from the location where the task had reached. We wont start from the beggining of the task each time. During RAM initialisation, we didn&amp;#8217;t store the pointer stack(SP) in the stack along with other registers. This is stored separately. When a task was executing, it would have pushed some values into stack. Stack pointer(SP) register will have that value. While context switching we will save this value so that next time when we come to this task, we will again load this value to stack pointer(SP) register so that the execution is resumed from the place where we stopped. Enough talk! Show me the code! I have checked in the code to my github repo. Its an completely open source scheduler. Feel free to use it and learn more. I have made the code self explanatory. Enjoy! There are three tasks &amp;#8211; first task for blinking the red LED at a particular rate, the second for blinking the green LED at a particular rate and last one for reading both the buttons. When you press the button, you could toggle the blinking of both the LED&amp;#8217;s. Buttons are not properly detected due to software debouncing issue. NOTE: If you want to program your MSP430F5529 launchpad using GNU/Linux, read my previous post &amp;#8211; Running MSP430F5529 Launchpad using GNU/Linux Further development: 1) Try to send data via serial port in a task 2) Find a way to compute the stack consumed by each task and send this value via serial port 3) The scheduler is premptive. Try implementing a cooperative scheduler. 4) In cooperative scheduler, also add a feature to find the free time left in a process. If you want to debug your code, read this &amp;#8211; Debugging with msp430-gdb using mspdebug as gdb proxy</summary></entry><entry><title type="html">Running MSP430F5529 Launchpad using GNU/Linux</title><link href="https://jeffrey.co.in/blog/2014/03/running-msp430f5529-launchpad-on-gnulinux/" rel="alternate" type="text/html" title="Running MSP430F5529 Launchpad using GNU/Linux" /><published>2014-03-11T04:08:09+01:00</published><updated>2014-03-11T04:08:09+01:00</updated><id>https://jeffrey.co.in/blog/2014/03/running-msp430f5529-launchpad-on-gnulinux</id><content type="html" xml:base="https://jeffrey.co.in/blog/2014/03/running-msp430f5529-launchpad-on-gnulinux/">&lt;p&gt;I own an &lt;a href=&quot;http://www.ti.com/tool/msp-exp430f5529lp&quot; target=&quot;_blank&quot;&gt;MSP430F5529 USB launchpad&lt;/a&gt; from Texas Instruments. Cheap in cost, this launchpad is a good resource for developing your USB applications. It has an open source onboard debugger &lt;a href=&quot;http://processors.wiki.ti.com/index.php/EZ-FET_lite&quot; target=&quot;_blank&quot;&gt;eZ-FET lite&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For developing applications for MSP430, there is already a well maintained C toolchain(gcc-msp430) available. On an Ubuntu/Debian machine, you can install it using the below command&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo apt-get install gcc-msp430 msp430-libc msp430mcu&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For debugging purpose, I am using &lt;em&gt;mspdebug&lt;/em&gt;. But I had some hard time in setting up this debugger on my GNU/Linux machine. Due to some driver issues, the default mspdebug package from Ubuntu repository didn’t work. To get it working, there are some extra packages provided by TI to be installed.&lt;/p&gt;

&lt;p&gt;Another alternative was to get the pre-compiled mspdebug from &lt;a href=&quot;http://energia.nu/&quot; target=&quot;_blank&quot;&gt;Energia&lt;/a&gt;. Energia comes with all these issues solved. But if you want to try the hard way, refer &lt;a href=&quot;https://rtime.felk.cvut.cz/hw/index.php/MSP430F5529_Launchpad&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below steps describe how to use mspdebug from Energia&lt;/p&gt;

&lt;p&gt;1) Download Energia for GNU/Linux from &lt;a href=&quot;http://energia.nu/download/&quot; target=&quot;_blank&quot;&gt;http://energia.nu/download/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) Extract the tgz file. I got a folder named energia-0101E0011. The number in the folder name might change for you depending on the energia version you are using.&lt;/p&gt;

&lt;p&gt;3) Go into the folder &lt;em&gt;energia-0101E0011/hardware/tools/msp430/bin/&lt;/em&gt; using the &lt;strong&gt;&lt;em&gt;cd&lt;/em&gt;&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;3) Copy &lt;em&gt;libmsp430.so&lt;/em&gt; to &lt;em&gt;/usr/lib/&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;4) Update the firmware of the debugger using &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo ./mspdebug tilib --allow-fw-update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;5) Now you can run mspdebug using the following command &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo ./mspdebug tilib&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you were successful, you will get the mspdebug console&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;(mspdebug)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now lets write a small code and see if we can flash it to the launchpad.&lt;/p&gt;

&lt;p&gt;Save the below code as &lt;strong&gt;&lt;em&gt;blink.c&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;row&quot;&gt;
  &lt;div class=&quot;span4&quot;&gt;
    &lt;pre class=&quot;prettyprint linenums&quot;&gt;#include &amp;lt;msp430.h&amp;gt;

main()
{
  unsigned int i = 0;
  P1DIR = 1;

  while(1)
  {
    P1OUT = 1;
    for (i=0; i &amp;lt; 65535; i++);
    P1OUT = 0;
    for (i=0; i &amp;lt; 65535; i++);
  }
}&lt;/pre&gt;
  &lt;/div&gt;
  
  &lt;p&gt;
    &lt;!-- /span --&gt;
  &lt;/p&gt;
&lt;/div&gt;

&lt;!-- /row --&gt;

&lt;p&gt;Lets compile this software using the below command&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;msp430-gcc -mmcu=msp430f5529 -mdisable-watchdog blink.c&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We need to flash the output of the above compilation to the launchpad. Launch &lt;em&gt;mspdebug&lt;/em&gt; using &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo ./mspdebug tilib&lt;/code&gt;. Then run&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;(mspdebug) prog a.out&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: Since &lt;em&gt;mspdebug&lt;/em&gt; is inside the energia folder and this blink.c file is at another location, when using the &lt;em&gt;prog&lt;/em&gt; command in mspdebug, you have to give the path to the a.out file i.e&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(mspdebug) prog /path/to/the/file/a.out&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now the LED on the launchpad will start to blink!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/images/msp430f5529.gif&quot; class=&quot;img-responsive&quot; alt=&quot;MSP430F5529 blinking LED&quot; width=&quot;336&quot; height=&quot;449&quot; /&gt;&lt;/p&gt;</content><author><name>Jeffrey</name></author><category term="Electronics" /><category term="MSP430" /><category term="msp430" /><category term="USB" /><summary type="html">I own an MSP430F5529 USB launchpad from Texas Instruments. Cheap in cost, this launchpad is a good resource for developing your USB applications. It has an open source onboard debugger eZ-FET lite. For developing applications for MSP430, there is already a well maintained C toolchain(gcc-msp430) available. On an Ubuntu/Debian machine, you can install it using the below command sudo apt-get install gcc-msp430 msp430-libc msp430mcu For debugging purpose, I am using mspdebug. But I had some hard time in setting up this debugger on my GNU/Linux machine. Due to some driver issues, the default mspdebug package from Ubuntu repository didn’t work. To get it working, there are some extra packages provided by TI to be installed. Another alternative was to get the pre-compiled mspdebug from Energia. Energia comes with all these issues solved. But if you want to try the hard way, refer this. Below steps describe how to use mspdebug from Energia 1) Download Energia for GNU/Linux from http://energia.nu/download/ 2) Extract the tgz file. I got a folder named energia-0101E0011. The number in the folder name might change for you depending on the energia version you are using. 3) Go into the folder energia-0101E0011/hardware/tools/msp430/bin/ using the cd command. 3) Copy libmsp430.so to /usr/lib/ 4) Update the firmware of the debugger using sudo ./mspdebug tilib --allow-fw-update 5) Now you can run mspdebug using the following command sudo ./mspdebug tilib If you were successful, you will get the mspdebug console (mspdebug) Now lets write a small code and see if we can flash it to the launchpad. Save the below code as blink.c #include &amp;lt;msp430.h&amp;gt; main() { unsigned int i = 0; P1DIR = 1; while(1) { P1OUT = 1; for (i=0; i &amp;lt; 65535; i++); P1OUT = 0; for (i=0; i &amp;lt; 65535; i++); } } Lets compile this software using the below command msp430-gcc -mmcu=msp430f5529 -mdisable-watchdog blink.c We need to flash the output of the above compilation to the launchpad. Launch mspdebug using sudo ./mspdebug tilib. Then run (mspdebug) prog a.out Note: Since mspdebug is inside the energia folder and this blink.c file is at another location, when using the prog command in mspdebug, you have to give the path to the a.out file i.e (mspdebug) prog /path/to/the/file/a.out Now the LED on the launchpad will start to blink!</summary></entry><entry><title type="html">Designing a D flip-flop using Migen</title><link href="https://jeffrey.co.in/blog/2014/01/d-flip-flop-using-migen/" rel="alternate" type="text/html" title="Designing a D flip-flop using Migen" /><published>2014-01-19T17:21:20+01:00</published><updated>2014-01-19T17:21:20+01:00</updated><id>https://jeffrey.co.in/blog/2014/01/d-flip-flop-using-migen</id><content type="html" xml:base="https://jeffrey.co.in/blog/2014/01/d-flip-flop-using-migen/">&lt;p&gt;If you haven’t installed Migen or don’t know about Migen, read my previous blog post &lt;a href=&quot;http://jeffrey.co.in/blog/2014/01/installing-migen/&quot;&gt;Installing Migen – the Python based hardware description language&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;d-flip-flops&quot;&gt;D flip-flops&lt;/h3&gt;

&lt;p&gt;&lt;img class=&quot;img-responsive&quot; src=&quot;/files/images/Dflip-flop.jpg&quot; alt=&quot;D flip-flop&quot; width=&quot;303&quot; height=&quot;369&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A D flip-flop spits the data out which is kept in the data input pin when the clock is applied(in positive edge or negative edge). The D flip-flop that we are going to design has the input pin D, output pins Q and Qi(inverted of Q). It also has a clock clock input and a reset pin which makes the flip-flop synchronous.&lt;/p&gt;

&lt;p&gt;The D flip-flop shown over here is a positive edge triggered flip-flop. The truth table represents the mapping between the input pins to the output pins based on the reset pin and clock pin state. Since its a positive edge triggered flip-flop, the clock pin is shown as a transition from low to high.&lt;/p&gt;

&lt;p&gt;Just for a reference, &lt;a href=&quot;http://www.micrel.com/_PDF/HBW/sy10-100el31.pdf&quot;&gt;this&lt;/a&gt; is the datasheet of a D flip-flop IC.&lt;/p&gt;

&lt;h3 id=&quot;a-d-flip-flop-using-migen&quot;&gt;A D flip-flop using Migen&lt;/h3&gt;

&lt;p&gt;Create a file named &lt;em&gt;Dff.py&lt;/em&gt; and add this code to it.&lt;/p&gt;

&lt;pre class=&quot;prettyprint linenums&quot;&gt;from migen.fhdl.std import *

class Dflipflop(Module):
  def __init__(self, D, Q, Qi):
    self.sync += Q.eq(D)
    self.comb += Qi.eq(~Q)
&lt;/pre&gt;

&lt;p&gt;Digital circuits can be divided into synchronous(i.e works based on the clock input) and asynchronous(independent of clock) circuits. Asynchronous circuits are also known as combinational logic. The Python syntax used for describing the D flip-flop can be more clearly understood by reading the &lt;a href=&quot;http://milkymist.org/3/migen.html&quot;&gt;Migen user guide&lt;/a&gt;. So I won’t be explaining here the syntax used. Only describing the synchronous and combinational(asynchronous) statements are in my scope.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;self.sync += Q.eq(D)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Q.eq(D)&lt;/strong&gt;&lt;/em&gt; equates/copies the content of &lt;em&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/em&gt; to &lt;em&gt;&lt;strong&gt;Q&lt;/strong&gt;&lt;/em&gt; which are the input and output of our flip-flop. This is then assigned as a synchronous using &lt;em&gt;&lt;strong&gt;self.sync +=&lt;/strong&gt;&lt;/em&gt;. As mentioned before, a D flip-flop copies the data from the input pin to the output pin in synchronous to the clock transition. Hence this circuit is a synchronous circuit.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;self.comb += Qi.eq(~Q)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Qi.eq(~Q)&lt;/strong&gt;&lt;/em&gt; is used to invert &lt;em&gt;&lt;strong&gt;Q&lt;/strong&gt;&lt;/em&gt; and copy to &lt;em&gt;&lt;strong&gt;Qi&lt;/strong&gt;&lt;/em&gt;. This is assigned as a combinational logic. This means &lt;em&gt;&lt;strong&gt;Qi&lt;/strong&gt;&lt;/em&gt; is independent of the clock. But out flip-flop is a synchronous. This doesn’t means that Qi will change asynchronously since the input of &lt;em&gt;&lt;strong&gt;Qi&lt;/strong&gt;&lt;/em&gt; is from a synchronous logic &lt;em&gt;&lt;strong&gt;Q&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id=&quot;testing-the-d-flip-flop&quot;&gt;Testing the D flip-flop&lt;/h3&gt;

&lt;p&gt;Update your &lt;em&gt;Dff.py&lt;/em&gt; with the below code.&lt;/p&gt;

&lt;pre class=&quot;prettyprint linenums&quot;&gt;from migen.fhdl.std import *
from migen.fhdl import verilog
from migen.sim.generic import Simulator, TopLevel
from random import randrange

class Dflipflop(Module):
  def __init__(self, D, Q, Qi):
    self.sync += Q.eq(D)
    self.comb += Qi.eq(~Q)

  def do_simulation(self,s):
    s.wr(D,randrange(2))

#Simulation and verilog conversion
D  = Signal()
Q  = Signal()
Qi = Signal()

#print(verilog.convert(Dflipflop(D, Q, Qi), ios={D,Q,Qi}))

sim = Simulator(Dflipflop(D,Q,Qi), TopLevel(&quot;Dff.vcd&quot;))
sim.run(100)
&lt;/pre&gt;

&lt;p&gt;Execute this python script using the below command. This will generate a &lt;em&gt;&lt;strong&gt;Dff.vcd&lt;/strong&gt;&lt;/em&gt; which contains the test result. The vcd file can be viewed using GTKWave tool.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;python3 Dff.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;gtkwave Dff.vcd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/images/GTKWave-Dff.png&quot; class=&quot;img-responsive&quot; alt=&quot;GTKWave-Dff.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As I mentioned before, read the official &lt;a href=&quot;http://milkymist.org/3/migen.html&quot;&gt;Migen&lt;/a&gt; user guide and tutorial to understand what the code means.&lt;/p&gt;

&lt;p&gt;To test the D flip-flop, we need to check if the input (&lt;em&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/em&gt;) is copied to the output(&lt;em&gt;&lt;strong&gt;Q&lt;/strong&gt;&lt;/em&gt; and also &lt;em&gt;&lt;strong&gt;Qi&lt;/strong&gt;&lt;/em&gt;). For this the input &lt;em&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/em&gt; should be fed with values(0 or 1). We can use the module &lt;em&gt;&lt;strong&gt;random&lt;/strong&gt;&lt;/em&gt; in Python to generate some random values.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;s.wr(D,randrange(2))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The function &lt;em&gt;&lt;strong&gt;randrange(2)&lt;/strong&gt;&lt;/em&gt; generates a random number – either 0 or 1. &lt;em&gt;&lt;strong&gt;s.wr&lt;/strong&gt;&lt;/em&gt; writes the random number to &lt;em&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/em&gt;. The write happens only after the positive edge of the clock cycle.&lt;/p&gt;

&lt;h3 id=&quot;verilog-equivalent-of-the-d-flip-flop&quot;&gt;Verilog equivalent of the D flip-flop&lt;/h3&gt;

&lt;p&gt;As I mentioned in my previous blog post (&lt;a href=&quot;http://jeffrey.co.in/blog/2014/01/installing-migen/&quot;&gt;Installing Migen – the Python based hardware description language&lt;/a&gt;), Migen converts the Python code to equivalent Verilog code. Since the FPGA tools which we currently have only understands only Verilog/VHDL, this is required. The generated Verilog code can be loaded to your FPGA vendor’s software and verified on real hardware. Mibuild(a tool inside Migen) supports few FPGA vendors for which you don’t have to manually paste your Verilog code to the FPGA vendor’s software. Mibuild will do it for you(by accessing vendor tools via command line) and even it can load the bit stream file to FPGA. Usage of Mibuild will be explained later.&lt;/p&gt;

&lt;p&gt;Uncomment the line in your &lt;em&gt;Dff.py&lt;/em&gt; file and run the python code again. This line will print the Verilog equivalent code of our D flip-flop.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;print(verilog.convert(Dflipflop(D, Q, Qi), ios={D,Q,Qi}))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Below is the Verilog output.&lt;/p&gt;

&lt;pre class=&quot;prettyprint linenums&quot;&gt;/* Machine-generated using Migen */
module top(
        input D,
        output reg Q,
        output Qi,
        input sys_clk,
        input sys_rst
);


// synthesis translate_off
reg dummy_s;
initial dummy_s &amp;lt;= 1'd0;
// synthesis translate_on
assign Qi = (~Q);

always @(posedge sys_clk) begin
        if (sys_rst) begin
                Q &amp;lt;= 1'd0;
        end else begin
                Q &amp;lt;= D;
        end
end

endmodule
&lt;/pre&gt;

&lt;h3 id=&quot;another-way-of-testing-d-flip-flops-a-frequency-divider&quot;&gt;Another way of testing D flip-flops: A frequency divider&lt;/h3&gt;

&lt;p&gt;Note: Below shown is not the right way to do a frequency division. This is just an example to show Migen’s testing capabilities.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/images/Dff-FreqDivider.jpg&quot; class=&quot;img-responsive&quot; alt=&quot;Dff-FreqDivider&quot; width=&quot;303&quot; height=&quot;369&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A D filp-flop can be used as a frequency divider (frequency / 2). &lt;a href=&quot;http://www.electronics-tutorials.ws/sequential/seq_4.html&quot;&gt;Read this&lt;/a&gt; for a more clear explanation. Make a connection from &lt;em&gt;&lt;strong&gt;Qi&lt;/strong&gt;&lt;/em&gt; to &lt;em&gt;&lt;strong&gt;D&lt;/strong&gt;&lt;/em&gt; to divide the frequency(fed to the clock pin) by 2. Connecting a wire between pins is very easy in Migen - just use the same &lt;em&gt;&lt;strong&gt;Signal()&lt;/strong&gt;&lt;/em&gt; for both the pins.&lt;/p&gt;

&lt;p&gt;Create a file named &lt;em&gt;Dff_Divider.py&lt;/em&gt; and add the below code.&lt;/p&gt;

&lt;pre class=&quot;prettyprint linenums&quot;&gt;from migen.fhdl.std import *
from migen.fhdl import verilog
from migen.sim.generic import Simulator, TopLevel

class Dflipflop(Module):
  def __init__(self, D, Q, Qi):
    self.sync += Q.eq(D)
    self.comb += Qi.eq(~Q)

#Simulation and verilog conversion part
Connect = Signal()
Q = Signal()

sim = Simulator(Dflipflop(Connect,Q,Connect), TopLevel(&quot;Dff_Divider.vcd&quot;))
sim.run(100)
&lt;/pre&gt;</content><author><name>Jeffrey</name></author><category term="Electronics" /><category term="FPGA" /><category term="GNU/Linux" /><category term="fpga" /><category term="Migen" /><category term="python" /><category term="verilog" /><summary type="html">If you haven’t installed Migen or don’t know about Migen, read my previous blog post Installing Migen – the Python based hardware description language D flip-flops A D flip-flop spits the data out which is kept in the data input pin when the clock is applied(in positive edge or negative edge). The D flip-flop that we are going to design has the input pin D, output pins Q and Qi(inverted of Q). It also has a clock clock input and a reset pin which makes the flip-flop synchronous. The D flip-flop shown over here is a positive edge triggered flip-flop. The truth table represents the mapping between the input pins to the output pins based on the reset pin and clock pin state. Since its a positive edge triggered flip-flop, the clock pin is shown as a transition from low to high. Just for a reference, this is the datasheet of a D flip-flop IC. A D flip-flop using Migen Create a file named Dff.py and add this code to it. from migen.fhdl.std import * class Dflipflop(Module): def __init__(self, D, Q, Qi): self.sync += Q.eq(D) self.comb += Qi.eq(~Q) Digital circuits can be divided into synchronous(i.e works based on the clock input) and asynchronous(independent of clock) circuits. Asynchronous circuits are also known as combinational logic. The Python syntax used for describing the D flip-flop can be more clearly understood by reading the Migen user guide. So I won’t be explaining here the syntax used. Only describing the synchronous and combinational(asynchronous) statements are in my scope. self.sync += Q.eq(D) Q.eq(D) equates/copies the content of D to Q which are the input and output of our flip-flop. This is then assigned as a synchronous using self.sync +=. As mentioned before, a D flip-flop copies the data from the input pin to the output pin in synchronous to the clock transition. Hence this circuit is a synchronous circuit. self.comb += Qi.eq(~Q) Qi.eq(~Q) is used to invert Q and copy to Qi. This is assigned as a combinational logic. This means Qi is independent of the clock. But out flip-flop is a synchronous. This doesn’t means that Qi will change asynchronously since the input of Qi is from a synchronous logic Q. Testing the D flip-flop Update your Dff.py with the below code. from migen.fhdl.std import * from migen.fhdl import verilog from migen.sim.generic import Simulator, TopLevel from random import randrange class Dflipflop(Module): def __init__(self, D, Q, Qi): self.sync += Q.eq(D) self.comb += Qi.eq(~Q) def do_simulation(self,s): s.wr(D,randrange(2)) #Simulation and verilog conversion D = Signal() Q = Signal() Qi = Signal() #print(verilog.convert(Dflipflop(D, Q, Qi), ios={D,Q,Qi})) sim = Simulator(Dflipflop(D,Q,Qi), TopLevel(&quot;Dff.vcd&quot;)) sim.run(100) Execute this python script using the below command. This will generate a Dff.vcd which contains the test result. The vcd file can be viewed using GTKWave tool. python3 Dff.py gtkwave Dff.vcd As I mentioned before, read the official Migen user guide and tutorial to understand what the code means. To test the D flip-flop, we need to check if the input (D) is copied to the output(Q and also Qi). For this the input D should be fed with values(0 or 1). We can use the module random in Python to generate some random values. s.wr(D,randrange(2)) The function randrange(2) generates a random number – either 0 or 1. s.wr writes the random number to D. The write happens only after the positive edge of the clock cycle. Verilog equivalent of the D flip-flop As I mentioned in my previous blog post (Installing Migen – the Python based hardware description language), Migen converts the Python code to equivalent Verilog code. Since the FPGA tools which we currently have only understands only Verilog/VHDL, this is required. The generated Verilog code can be loaded to your FPGA vendor’s software and verified on real hardware. Mibuild(a tool inside Migen) supports few FPGA vendors for which you don’t have to manually paste your Verilog code to the FPGA vendor’s software. Mibuild will do it for you(by accessing vendor tools via command line) and even it can load the bit stream file to FPGA. Usage of Mibuild will be explained later. Uncomment the line in your Dff.py file and run the python code again. This line will print the Verilog equivalent code of our D flip-flop. print(verilog.convert(Dflipflop(D, Q, Qi), ios={D,Q,Qi})) Below is the Verilog output. /* Machine-generated using Migen */ module top( input D, output reg Q, output Qi, input sys_clk, input sys_rst ); // synthesis translate_off reg dummy_s; initial dummy_s &amp;lt;= 1'd0; // synthesis translate_on assign Qi = (~Q); always @(posedge sys_clk) begin if (sys_rst) begin Q &amp;lt;= 1'd0; end else begin Q &amp;lt;= D; end end endmodule Another way of testing D flip-flops: A frequency divider Note: Below shown is not the right way to do a frequency division. This is just an example to show Migen’s testing capabilities. A D filp-flop can be used as a frequency divider (frequency / 2). Read this for a more clear explanation. Make a connection from Qi to D to divide the frequency(fed to the clock pin) by 2. Connecting a wire between pins is very easy in Migen - just use the same Signal() for both the pins. Create a file named Dff_Divider.py and add the below code. from migen.fhdl.std import * from migen.fhdl import verilog from migen.sim.generic import Simulator, TopLevel class Dflipflop(Module): def __init__(self, D, Q, Qi): self.sync += Q.eq(D) self.comb += Qi.eq(~Q) #Simulation and verilog conversion part Connect = Signal() Q = Signal() sim = Simulator(Dflipflop(Connect,Q,Connect), TopLevel(&quot;Dff_Divider.vcd&quot;)) sim.run(100)</summary></entry><entry><title type="html">Installing Migen – the Python based hardware description language</title><link href="https://jeffrey.co.in/blog/2014/01/installing-migen/" rel="alternate" type="text/html" title="Installing Migen – the Python based hardware description language" /><published>2014-01-17T01:21:24+01:00</published><updated>2014-01-17T01:21:24+01:00</updated><id>https://jeffrey.co.in/blog/2014/01/installing-migen</id><content type="html" xml:base="https://jeffrey.co.in/blog/2014/01/installing-migen/">&lt;p&gt;&lt;a href=&quot;http://milkymist.org/3/migen.html&quot;&gt;Migen&lt;/a&gt; is a Python tool which helps you to describe hardware(like Verilog and VHDL) in Python langauge. Like a C compiler which converts C language to assembly, Migen converts Python code to Verilog/VHDL statements. Migen helps in describing hardware in a more Object-oriented manner which would be hard to realise in Verilog/VHDL. A free and open source project (&lt;a href=&quot;https://github.com/m-labs/migen&quot;&gt;https://github.com/m-labs/migen&lt;/a&gt;), Migen is also used for designing the SoC (&lt;a href=&quot;http://milkymist.org/3/msc.html&quot;&gt;MiSoc&lt;/a&gt;) of an open source hardware project &lt;a href=&quot;http://milkymist.org/3/mmone.html&quot;&gt;Milkymist One&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Migen toolset contains the Migen itself, the Mibuild and the simulator. Migen converts the Python code to Verilog/VHDL. Mibuild is for converting the Verilog/VHDL code to bitstream file and transfering to the FPGA. If your FPGA is not supported by Mibuild, you can add support for it or you can paste your Verilog/VHDL code to your FPGA tool. The simulator just integrates Migen with Icarus Verilog for simulation. Simulation requires a test bench which is also written in Python. I will explain here how to install Migen and the simulator. Installing Mibuild will be done later(once I get my FPGA board).&lt;/p&gt;

&lt;p&gt;Though there exist a tutorial about installing and using Migen, I faced some problems while installing in my Ubuntu machine which was not as per the tutorial. After reading this post, I would recommend to read the official tutorial from the Migen page. This will provide some more clarity. Also make sure to read this post complete before proceeding on your machine.&lt;/p&gt;

&lt;p&gt;1) Make sure you have installed Python3, setuptool and git. On an Ubuntu machine this can be done using the below command&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo apt-get install git python3 python3-setuptools&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2) Get the Migen tool to your machine&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;git clone https://github.com/m-labs/migen.git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3) Move into Migen folder and install&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;cd migen&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;python3 setup.py install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: There is an option to use Migen – without installation! Just you need the project in your machine. Show the path to Python so that next time when you import Migen modules, Python will search those paths. For this you don’t need the &lt;em&gt;python3-setuptools&lt;/em&gt; mentioned in Step 1. Clone the project to the machine using Step 2 and then run &lt;code class=&quot;highlighter-rouge&quot;&gt;export PYTHONPATH=‘pwd‘/migen&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now the simulator installation. Once you are inside the Migen folder(&lt;code class=&quot;highlighter-rouge&quot;&gt;cd migen&lt;/code&gt;), move into the vpi folder using &lt;code class=&quot;highlighter-rouge&quot;&gt;cd vpi&lt;/code&gt;. We need to run the make file inside the vpi folder. But before that there are some more things to be done.&lt;/p&gt;

&lt;p&gt;1) Install Icarus Verilog which is the actual simulator. Also the simulator generates a wave dump of the simulation which can be viewed using GTKWave.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo apt-get install verilog gtkwave&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2) Run the following commands inside the vpi folder to install the Migen simulator.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;make&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo make install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You might get an error while running &lt;em&gt;sudo make install&lt;/em&gt;. In my machine the error was&lt;/p&gt;

&lt;p&gt;&lt;em&gt;install: accessing ‘/usr/lib/ivl’: No such file or directory&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This might be beacuse the path were Icarus Verilog is installed might be at a different location. A peak into the Makefile and also to the error can give you some hints on what to search for. I need to find where the ivl folder is. For that I used the find command &lt;code class=&quot;highlighter-rouge&quot;&gt;find /usr/ -name ivl\*&lt;/code&gt;. I have to pass the new found path (&lt;em&gt;/usr/lib/i386-linux-gnu/ivl&lt;/em&gt;) to the make install command. Run the following to install&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo make install INSTDIR=/usr/lib/i386-linux-gnu/ivl/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Thats it! You have successfully installed Migen and its simulator.&lt;/p&gt;

&lt;p&gt;There is another tutorial about Migen. Read it – &lt;a href=&quot;http://jeffrey.co.in/blog/2014/01/d-flip-flop-using-migen/&quot;&gt;Designing a D flip-flop using Migen&lt;/a&gt;&lt;/p&gt;</content><author><name>Jeffrey</name></author><category term="Electronics" /><category term="FPGA" /><category term="HDL" /><category term="Migen" /><category term="python" /><summary type="html">Migen is a Python tool which helps you to describe hardware(like Verilog and VHDL) in Python langauge. Like a C compiler which converts C language to assembly, Migen converts Python code to Verilog/VHDL statements. Migen helps in describing hardware in a more Object-oriented manner which would be hard to realise in Verilog/VHDL. A free and open source project (https://github.com/m-labs/migen), Migen is also used for designing the SoC (MiSoc) of an open source hardware project Milkymist One.</summary></entry><entry><title type="html">Recovering from wp-login.php attack</title><link href="https://jeffrey.co.in/blog/2013/04/recovering-from-wp-login-php-attack/" rel="alternate" type="text/html" title="Recovering from wp-login.php attack" /><published>2013-04-14T18:19:21+02:00</published><updated>2013-04-14T18:19:21+02:00</updated><id>https://jeffrey.co.in/blog/2013/04/recovering-from-wp-login-php-attack</id><content type="html" xml:base="https://jeffrey.co.in/blog/2013/04/recovering-from-wp-login-php-attack/">&lt;p&gt;Recently I was not able to login to my wordpress account. If I visit my wp-login.php page, I was getting a 403 error. Initially I thought it was problem with my wordpress installation but it was not. The error was because of a brute force attack on the wordpress login pages. My server was blocking access to this page. Lot of people are facing this problem. So I thought of blogging. There are plugins to block this attack. But they can only be installed and activated once you are able to login.&lt;/p&gt;

&lt;p&gt;Below is the solution for the wp-login.php issue which I found from internet. My initial target was to login. The quickest solution was to rename wp-login.php to a new file name and also replace with the new file name in the renamed wp-login.php file. In the following link, you will get the details how to do &lt;a href=&quot;http://wordpress.org/support/topic/wp-loginphp-change-to-your-custom-url&quot;&gt;http://wordpress.org/support/topic/wp-loginphp-change-to-your-custom-url&lt;/a&gt;. This is not a recommended method but a quick solution to get a login.&lt;/p&gt;

&lt;p&gt;Once you login, you can search for wordpress security plugins. Some restricts the number of login, some hides the login page. Search and install which one you found better. I am using &lt;a href=&quot;http://wordpress.org/extend/plugins/better-wp-security/&quot; title=&quot;Better WP Security&quot;&gt;Better WP Security&lt;/a&gt;. Once you enable your security plugin, I would suggest to revert back to file name wp-login.php and also replace inside the php file.&lt;/p&gt;

&lt;p&gt;Happy blogging!&lt;/p&gt;</content><author><name>Jeffrey</name></author><category term="Blog" /><category term="Review" /><category term="WP Blog attack" /><category term="WP brute force attack" /><category term="WP security" /><category term="wp-login.php" /><summary type="html">Recently I was not able to login to my wordpress account. If I visit my wp-login.php page, I was getting a 403 error. Initially I thought it was problem with my wordpress installation but it was not. The error was because of a brute force attack on the wordpress login pages. My server was blocking access to this page. Lot of people are facing this problem. So I thought of blogging. There are plugins to block this attack. But they can only be installed and activated once you are able to login.</summary></entry><entry><title type="html">STM32F4Discovery examples for GCC on GNU/Linux</title><link href="https://jeffrey.co.in/blog/2013/01/stm32f4discovery-examples-for-gcc-on-gnulinux/" rel="alternate" type="text/html" title="STM32F4Discovery examples for GCC on GNU/Linux" /><published>2013-01-01T18:55:55+01:00</published><updated>2013-01-01T18:55:55+01:00</updated><id>https://jeffrey.co.in/blog/2013/01/stm32f4discovery-examples-for-gcc-on-gnulinux</id><content type="html" xml:base="https://jeffrey.co.in/blog/2013/01/stm32f4discovery-examples-for-gcc-on-gnulinux/">&lt;p&gt;&lt;a href=&quot;http://www.st.com/internet/evalboard/product/252419.jsp&quot;&gt;STM32F4DISCOVERY&lt;/a&gt; is an ARM Cortex M4 development kit.&lt;/p&gt;

&lt;p&gt;I don’t plan to write again a toolchain setup instruction for this board. You can install toolchain and flash tool as per instructions provided in the below link&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://recursive-labs.com/blog/2012/05/07/stm32f4discovery-chibios-linux/&quot;&gt;http://recursive-labs.com/blog/2012/05/07/stm32f4discovery-chibios-linux/&lt;/a&gt; Read the section – Building the toolchain on Debian using “Summon Arm Toolchain”&lt;/p&gt;

&lt;p&gt;While installing the toolchain I got an error &lt;code class=&quot;highlighter-rouge&quot;&gt;zlib.h: No such file or directory&lt;/code&gt;. On a Debian system you can remove this error by issuing &lt;code class=&quot;highlighter-rouge&quot;&gt;apt-get install zlib1g-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The ARM toolchain is build using &lt;a href=&quot;https://github.com/esden/summon-arm-toolchain&quot;&gt;summon-arm-toolchain&lt;/a&gt; script. This toolchain also installs a free GPL V3 based firmware library known as &lt;a href=&quot;http://www.libopencm3.org/&quot;&gt;libopencm3&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As I mentioned above, the summon arm toolchain will also install libopencm3. libopencm3 generates some header files during installation. These header files needs python yaml support. The build might stop because of this. You can fix this issue by running &lt;code class=&quot;highlighter-rouge&quot;&gt;apt-get install python-yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can find examples for STM32F4DISCOVERY from &lt;a href=&quot;https://github.com/libopencm3/libopencm3/tree/master/examples/stm32/f4/stm32f4-discovery&quot;&gt;https://github.com/libopencm3/libopencm3/tree/master/examples/stm32/f4/stm32f4-discovery&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Additional link for reference&lt;/p&gt;

&lt;p&gt;1) &lt;a href=&quot;http://jeremyherbert.net/get/stm32f4_getting_started&quot;&gt;http://jeremyherbert.net/get/stm32f4_getting_started&lt;/a&gt; This link uses the examples from proprietary firmware library of ST.&lt;/p&gt;</content><author><name>Jeffrey</name></author><category term="GNU/Linux" /><category term="Hacking" /><category term="ARM Projects" /><summary type="html">STM32F4DISCOVERY is an ARM Cortex M4 development kit.</summary></entry><entry><title type="html">Basics about microcontrollers</title><link href="https://jeffrey.co.in/blog/2012/11/basics-about-microcontrollers/" rel="alternate" type="text/html" title="Basics about microcontrollers" /><published>2012-11-26T19:37:46+01:00</published><updated>2012-11-26T19:37:46+01:00</updated><id>https://jeffrey.co.in/blog/2012/11/basics-about-microcontrollers</id><content type="html" xml:base="https://jeffrey.co.in/blog/2012/11/basics-about-microcontrollers/">&lt;p&gt;I have seen many times people getting confused by the terms microcontroller and microprocessor. This blog post covers some basics which I know. I will try to explain the concepts in an simple manner. Please update corrections, feedbacks, suggestions etc in the comments field.&lt;/p&gt;

&lt;p&gt;Microcontrollers are small computers which can do data processing. With this data processing capability, we can design embedded systems(computers) such as hand-held video games, mobile phones, etc. Usually these embedded devices uses a special range of microcontroller with a microprocessor called as ARM. There are other range of microcontrollers(known as AVR, PIC, MSP430 etc) with different microprocessors which will be discussed later.&lt;/p&gt;

&lt;p&gt;Microcontrollers and microprocessors are different. Microprocessor is a device which can only do data manipulation. We need to pass data(or program) to the microprocessor, then it will process the data as we say and give it back. Microprocessors cannot store large programs because it doesn’t have large memories. They contains small memories called as registers which can only store small amount of data for data manipulation. This is a problem with microprocessors. We need extra hardware to store our programs. These extra hardwares are called as RAM(Random Access Memory), ROM(Read Only Memory), etc. After the microprocessors does the data manipulation, we need to view it on a screen(monitor). A microprocessors cannot write directly to a monitor. It needs again another special hardware called as display controller. Building an embedded system with these different hardwares is not easy since it involves some complexity because embedded system needs additional hardwares sensors, displays etc. Joining all these hardware is not an easy task. For this microcontrollers can help us.&lt;/p&gt;

&lt;p&gt;But microcontrollers are different. In easy terms to say, microcontroller is a chip with microprocessor and its associated hardware (such as RAM, ROM, display drivers etc). So building embedded system with microcontrollers is easy.&lt;/p&gt;

&lt;p&gt;If you want to understand more clearly about microcontrollers and microprocessors, go ahead reading this paragraph or else jump to next paragraph. Think  about your computer. It has a monitor, keyboard, mouse, CPU, speakers etc. A computers CPU is the main part to which we connect the monitor, keyboard, mouse, etc. The computers CPU contains a processor (which might be an Intel Pentium4 or Intel Core i3 or an AMD Athlon), RAM (which is of 2GB or 8GB or of some other capacity), a hard disk to store data etc. If you know well about computers, you should know that a processor cannot do any work alone. It needs a RAM, hard disk etc. When you join them together, computers CPU will start to work. This is the same case with microcontrollers and microprocessors.  You can imagine the processor(Intel Core i7 or AMD Athlon) as microprocessor and computers CPU completely(including hard disk, RAM, processor) as an microcontroller. With a processor alone we cannot do anything but with an CPU, we can connect a keyboard, mouse and a monitor to do our daily works. Hope you understood the difference between microprocessor and microcontroller.&lt;/p&gt;

&lt;p&gt;There is no meaning in explaining more details about each peripherals. There are lot of tutorials existing in the Internet. I would recommend you to read those. My idea was to guide you to the world of computers. The main problem with engineers is that they know about computers but they don’t know about the internal working. If you want to know more about computers, go ahead reading the next paragraph. I would recommend this for all computer and electronics graduates.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/files/images/nand2tetris.jpg&quot; class=&quot;img-responsive&quot; alt=&quot;From NAND to Tetris&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Read the book &lt;a href=&quot;http://www.nand2tetris.org/book.php&quot;&gt;The Elements of Computing Systems (&lt;em&gt;From NAND to Tetris&lt;/em&gt;)&lt;/a&gt;. This is an wonderful book which explains you how computers work from top to bottom i.e how microprocessors are made, how they interact with keyboard, monitor, etc, how an compiler works, how an operating system works etc. The most amazing part of this book is that it not only tells you how things work but also teaches you to write your own compiler, assembly programs, operating systems etc. Don’t worry. Its not a huge book. Try to get this book and read while you are traveling in bus or whenever you want.&lt;/p&gt;

&lt;p&gt;I would recommend you not to miss this book. Reading this book alone will give you good knowledge. If you do the assignments in the book, its more wonderful and you can easily understand the computer systems. Please let me know your feedback after reading this awesome book!&lt;/p&gt;</content><author><name>Jeffrey</name></author><category term="Electronics" /><category term="computers" /><category term="Electronics" /><category term="fundamentals" /><summary type="html">I have seen many times people getting confused by the terms microcontroller and microprocessor. This blog post covers some basics which I know. I will try to explain the concepts in an simple manner. Please update corrections, feedbacks, suggestions etc in the comments field.</summary></entry></feed>