Blog


Jumpstart GNU for ARM Cortex-M0

posted Dec 8, 2017, 6:41 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Dec 8, 2017, 7:13 PM ]

On Windows, click the first download link for this file (link is current as of 9 dec 2017):

File: gcc-arm-none-eabi-6-2017-q2-update-win32.exe (82.56 MB)

Once downloaded, double-click the installer.

The tools will be installed here. You may want to update you enviroment variables...

C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q2-update\bin\

To test it, make a short C program.

int main()
{
  int a = 0x55;
  int b;

  b = a ^ 0xff00;
  return 0;
}


Compile it (my code is at ~\cortex directory):

C:\Users\Mun3im\cortex>arm-none-eabi-gcc  --specs=nosys.specs -mcpu=cortex-m0 -S test.c

The assembler output is test.s. The assembly code corresponding the C code in is in light green. The rest of the code are just scaffolding.

C:\Users\Mun3im\cortex>more test.s
        .cpu cortex-m0
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 6
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .file   "test.c"
        .text
        .align  1
        .global main
        .syntax unified
        .code   16
        .thumb_func
        .fpu softvfp
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 8
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        sub     sp, sp, #8
        add     r7, sp, #0
        movs    r3, #85
        str     r3, [r7, #4]
        ldr     r3, [r7, #4]
        movs    r2, #255
        lsls    r2, r2, #8
        eors    r3, r2
        str     r3, [r7]
        movs    r3, #0
        movs    r0, r3
        mov     sp, r7
        add     sp, sp, #8
        @ sp needed
        pop     {r7, pc}
        .size   main, .-main
        .ident  "GCC: (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]"

How to decipher the code

        movs    r3, #85           @ a = 0x55;
        str     r3, [r7, #4]      // a = [r7 + 4]
        ldr     r3, [r7, #4]
        movs    r2, #255          // r2 = 0xff
        lsls    r2, r2, #8        // r2 = 0xff00
        eors    r3, r2            // r3 = a ^ 0xff00;  'b' is r3
        str     r3, [r7]          @ b = a ^ 0xff00, stored in [r7]
        movs    r3, #0
        movs    r0, r3            @ r0 <- 0 to prepare for return 0 C statement

Git Minimal Steps

posted Nov 15, 2017, 4:08 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 18, 2017, 11:04 PM ]

$ git checkout -b test

. . . do the test code

$ git add -A
$ git commit -m "summarize"
$ git checkout master 
$ git pull origin master <- optional, for multiple developers
$ git merge test
$ git push origin master

Django on Bash on Windows

posted Nov 13, 2017, 9:46 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 13, 2017, 9:49 PM ]

Assuming you have Ubuntu on Windows installed.

From CMD prompt:

C:> lxrun update

Inside BASH

$ sudo apt-get update
$ sudo apt-get upgrade

Now run Python

$ python --version
Python 2.7.12

Install PIP

$ sudo -i
# apt-get install python-pip
# exit

Install VirtualEnv

$ sudo apt-get install virtualenv
$ cd my_project_folder
$ virtualenv venv
$ source venv/bin/activate
(venv) $ deactivate

Install Django

$ source venv/bin/activate
(venv) $ pip install --upgrade pip
(venv) $ pip install django




Django is best using 2.7

posted Nov 13, 2017, 2:56 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 17, 2017, 12:15 AM ]

munim$ conda create -n django python=2.7
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment /Users/munim/anaconda3/envs/django:

The following NEW packages will be INSTALLED:

    ca-certificates: 2017.08.26-ha1e5d58_0    
    certifi:         2017.7.27.1-py27h482ffc0_0
    libcxx:          4.0.1-h579ed51_0         
    libcxxabi:       4.0.1-hebd6815_0         
    libedit:         3.1-hb4e282d_0           
    libffi:          3.2.1-h475c297_4         
    ncurses:         6.0-hd04f020_2           
    openssl:         1.0.2m-h86d3e6a_0        
    pip:             9.0.1-py27h1567d89_4     
    python:          2.7.14-h001abdc_23       
    readline:        7.0-hc1231fa_4           
    setuptools:      36.5.0-py27h2a45cec_0    
    sqlite:          3.20.1-h7e4c145_2        
    tk:              8.6.7-h35a86e2_3         
    wheel:           0.29.0-py27h84bd1c0_1    
    zlib:            1.2.11-hf3cbc9b_2        

Proceed ([y]/n)? n

Exiting

munim$ conda create -n django python=2.7 django
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment /Users/munim/anaconda3/envs/django:

The following NEW packages will be INSTALLED:

    ca-certificates: 2017.08.26-ha1e5d58_0    
    certifi:         2017.7.27.1-py27h482ffc0_0
    django:          1.11.3-py27_0            
    libcxx:          4.0.1-h579ed51_0         
    libcxxabi:       4.0.1-hebd6815_0         
    libedit:         3.1-hb4e282d_0           
    libffi:          3.2.1-h475c297_4         
    ncurses:         6.0-hd04f020_2           
    openssl:         1.0.2m-h86d3e6a_0        
    pip:             9.0.1-py27h1567d89_4     
    python:          2.7.14-h001abdc_23       
    pytz:            2017.2-py27hb891d23_1    
    readline:        7.0-hc1231fa_4           
    setuptools:      36.5.0-py27h2a45cec_0    
    sqlite:          3.20.1-h7e4c145_2        
    tk:              8.6.7-h35a86e2_3         
    wheel:           0.29.0-py27h84bd1c0_1    
    zlib:            1.2.11-hf3cbc9b_2        

Proceed ([y]/n)?

ca-certificate 100% |################################| Time: 0:00:00 823.75 kB/s
libcxxabi-4.0. 100% |################################| Time: 0:00:00 932.96 kB/s
tk-8.6.7-h35a8 100% |################################| Time: 0:00:06 516.08 kB/s
zlib-1.2.11-hf 100% |################################| Time: 0:00:00 794.94 kB/s
libcxx-4.0.1-h 100% |################################| Time: 0:00:01 883.57 kB/s
openssl-1.0.2m 100% |################################| Time: 0:00:04 862.49 kB/s
libffi-3.2.1-h 100% |################################| Time: 0:00:00   1.42 MB/s
ncurses-6.0-hd 100% |################################| Time: 0:00:00   1.11 MB/s
libedit-3.1-hb 100% |################################| Time: 0:00:00 888.17 kB/s
readline-7.0-h 100% |################################| Time: 0:00:00 914.21 kB/s
sqlite-3.20.1- 100% |################################| Time: 0:00:03 597.48 kB/s
python-2.7.14- 100% |################################| Time: 0:00:15 796.67 kB/s
certifi-2017.7 100% |################################| Time: 0:00:00 783.89 kB/s
pytz-2017.2-py 100% |################################| Time: 0:00:00 581.84 kB/s
django-1.11.3- 100% |################################| Time: 0:00:06 643.47 kB/s
setuptools-36. 100% |################################| Time: 0:00:00 908.58 kB/s
wheel-0.29.0-p 100% |################################| Time: 0:00:00   1.16 MB/s
pip-9.0.1-py27 100% |################################| Time: 0:00:02   1.04 MB/s
#
# To activate this environment, use:
# > source activate django
#
# To deactivate an active environment, use:
# > source deactivate
#

munim$ source activate django

(django) munim$ pip3 install djangorestframework

Collecting djangorestframework
  Downloading djangorestframework-3.7.3-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 865kB/s
Installing collected packages: djangorestframework
Successfully installed djangorestframework-3.7.3

(django) munim$ pip install djangorestframework-yaml
Collecting djangorestframework-yaml
  Downloading djangorestframework_yaml-1.0.3-py2.py3-none-any.whl
Collecting PyYAML>=3.10 (from djangorestframework-yaml)
  Downloading PyYAML-3.12.tar.gz (253kB)
    100% |████████████████████████████████| 256kB 2.6MB/s
Building wheels for collected packages: PyYAML
  Running setup.py bdist_wheel for PyYAML ... done
  Stored in directory: /Users/munim/Library/Caches/pip/wheels/2c/f7/79/13f3a12cd723892437c0cfbde1230ab4d82947ff7b3839a4fc
Successfully built PyYAML
Installing collected packages: PyYAML, djangorestframework-yaml
Successfully installed PyYAML-3.12 djangorestframework-yaml-1.0.3

(django) munim$ pip install djangorestframework-xml
Collecting djangorestframework-xml
  Downloading djangorestframework_xml-1.3.0-py2.py3-none-any.whl
Collecting defusedxml>=0.3 (from djangorestframework-xml)
  Downloading defusedxml-0.5.0-py2.py3-none-any.whl
Installing collected packages: defusedxml, djangorestframework-xml
Successfully installed defusedxml-0.5.0 djangorestframework-xml-1.3.0


(django) munim$ pip install Pillow
Collecting Pillow
  Downloading Pillow-4.3.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.5MB)
    100% |████████████████████████████████| 3.6MB 355kB/s
Collecting olefile (from Pillow)
  Using cached olefile-0.44.zip
Building wheels for collected packages: olefile
  Running setup.py bdist_wheel for olefile ... done
  Stored in directory: /Users/munim/Library/Caches/pip/wheels/20/58/49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b
Successfully built olefile
Installing collected packages: olefile, Pillow
Successfully installed Pillow-4.3.0 olefile-0.44

(django) munim$ pip install whitenoise
Collecting whitenoise
  Downloading whitenoise-3.3.1-py2.py3-none-any.whl
Installing collected packages: whitenoise
Successfully installed whitenoise-3.3.1



(django) munim$ git clone https://github.com/rogargon/myrecommendations.git
Cloning into 'myrecommendations'...
remote: Counting objects: 623, done.
remote: Total 623 (delta 0), reused 0 (delta 0), pack-reused 623
Receiving objects: 100% (623/623), 300.32 KiB | 334.00 KiB/s, done.
Resolving deltas: 100% (384/384), done.

(django) munim$ cd myrecommendations/

(django) :myrecommendations munim$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, myrestaurants, sessions.
Run 'python manage.py migrate' to apply them.

November 13, 2017 - 10:55:34
Django version 1.11.3, using settings 'myrecommendations.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.




Sentiment Analysis & NLP Metatutorial

posted Nov 8, 2017, 12:01 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 8, 2017, 6:29 AM ]



Deep Learning for Object Recognition Metatutorial

posted Nov 7, 2017, 3:47 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 8, 2017, 6:27 AM ]

To learn about neural networks in general, read Michael Nielsen's free online book .

To know more about convolutional neural networks, Michael Nelson's book has a great chapter. Chris Olah has written a nice blog post on CNN. Uni of Montreal has some notes for the motivation for deep architectures.

To implement CNN, read TensorFlow's ML beginner and ML expert MNIST tutorials. Liu SongXiang wrote an introduction to TensorFlow. Then jump to TensorFlows deep CNN tutorial and image recognition tutorial.

Vamsi Ramakrishnan wrote a blog on traffic sign classification using TensorFlow.


Deep Learning, TensorFlow and NLTK

posted Nov 7, 2017, 7:12 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 7, 2017, 7:17 AM ]

After successfully installing TensorFlow on the iMac, we need to install another copy of Spyder.

BigMac:~ munim$  source activate tensorflow
(tensorflow) BigMac:~ munim$  conda install spyder

Then, time check it out with a Sentiment Analysis problem. This nice blog by Rachit Mishra has a tutorial.

https://becominghuman.ai/deep-learning-using-tensorflow-and-nltk-analyzing-corpuss-sentiments-part-1-bec9d6c1051

Hit Github repo is at:

https://github.com/rachit-mishra/NLTK_SentimentAnalysis_TensorFlow.git

Making sure Spyder is installed in the Python virtual environment I was in, the commands given were:

(tensorflow) BigMac:~ munim$  cd Bitbucket
(tensorflow) BigMac:Bitbucket munim$ git clone https://github.com/rachit-mishra/NLTK_SentimentAnalysis_TensorFlow.git
(tensorflow) BigMac:Bitbucket munim$ cd NLTK_SentimentAnalysis_TensorFlow
(tensorflow) BigMac:NLTK_SentimentAnalysis_TensorFlow munim$ time python Sentiment.py
    .
    .
    .
Epoch 0 completed out of 10 loss: 67.907337606
Epoch 1 completed out of 10 loss: 49.8067501187
Epoch 2 completed out of 10 loss: 39.1767932475
Epoch 3 completed out of 10 loss: 27.8834503293
Epoch 4 completed out of 10 loss: 20.3667399287
Epoch 5 completed out of 10 loss: 20.9853808284
Epoch 6 completed out of 10 loss: 18.893711742
Epoch 7 completed out of 10 loss: 16.4990394972
Epoch 8 completed out of 10 loss: 23.0452921689
Epoch 9 completed out of 10 loss: 16.1678221859
Accuracy: 0.929137

real    0m29.963s
user    0m45.665s
sys     0m2.463s


(tensorflow) BigMac:NLTK_SentimentAnalysis_TensorFlow munim$


Installing Tensorflow on Windows

posted Nov 7, 2017, 12:17 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 7, 2017, 12:17 AM ]

  • Install Anaconda.
Follow instructions at https://www.continuum.io/downloads
  • Create a conda environment.
C:> conda create -n tensorflow python=3.5
  • Activate the conda environment and install TensorFlow in it.
C:> activate tensorflow
(tensorflow) C: > # Your prompt should change
  • After the install you will activate the conda environment each time you want to use TensorFlow.

(tensorflow) C: >conda install -c conda-forge tensorflow-gpu
Fetching package metadata ...............
Solving package specifications: .

Package plan for installation in environment C:\Users\mun3im\Anaconda2\envs\tensorflow:

The following NEW packages will be INSTALLED:

    cudatoolkit:    8.0-3
    cudnn:          6.0-0
    icc_rt:         2017.0.4-h97af966_0
    intel-openmp:   2018.0.0-hcd89f80_7
    mkl:            2018.0.0-h36b65af_4
    numpy:          1.12.1-py35h02c1717_1
    protobuf:       3.4.0-py35_vc14_1     conda-forge [vc14]
    six:            1.11.0-py35_1         conda-forge
    tensorflow-gpu: 1.1.0-np112py35_0
    werkzeug:       0.12.2-py_1           conda-forge
    zlib:           1.2.11-vc14_0         conda-forge [vc14]

The following packages will be UPDATED:

    vs2015_runtime: 14.0.25123-hd4c4e62_2             --> 14.0.25420-0 conda-forge

Proceed ([y]/n)?

cudatoolkit-8.  43% |#############                  | ETA:  0:14:11 222.81 kB/s

Template for C Programs on NUC131 Device

posted Nov 6, 2017, 6:15 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 6, 2017, 6:16 PM ]

Below is template for NUC131. UART is always used to debug/print. Seems like semihosting is default. We need to add 'semihosting' in the notes somehow.

#include <stdio.h>
#include "NUC131.h"

void SYS_Init(void)
{
  SYS_UnlockReg();
  CLK->APBCLK = CLK_APBCLK_UART0_EN_Msk;
  SystemCoreClockUpdate();
  SYS->GPB_MFP = SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD;
  SYS_LockReg();
}


int main()
{
  int8_t ch;

  SYS_Init();
  UART_Open(UART0, 115200);

  printf("Simple Demo Code\n\n");
  printf("Please Input Any Key\n\n");
  do {
    printf("Input: ");
    ch = getchar();
    printf("%c\n", ch);
  }  while(1);
}

1-10 of 17