Tuesday, 19 September 2017

Particle Installation Troubleshooting

If you see such things like:

node-pre-gyp ERR! Pre-built binaries not found for serialport@4.0.7 and node@4.2.1 (node-v46 ABI) (falling back to source compile with node-gyp)
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/4.2.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/particle-cli/node_modules/serialport/.node-gyp"
make: Entering directory '/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build'
make: *** No rule to make target '../.node-gyp/4.2.1/include/node/common.gypi', needed by 'Makefile'. Stop.
make: Leaving directory '/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:200:12)
gyp ERR! System Linux 4.9.24+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release/serialport.node" "--module_name=serialport" "--module_path=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release"
gyp ERR! cwd /usr/local/lib/node_modules/particle-cli/node_modules/serialport
gyp ERR! node -v v4.2.1
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release/serialport.node --module_name=serialport --module_path=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release' (1)
node-pre-gyp ERR! stack at ChildProcess. (/usr/local/lib/node_modules/particle-cli/node_modules/serialport/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:818:16)
node-pre-gyp ERR! stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:211:5)
node-pre-gyp ERR! System Linux 4.9.24+
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/particle-cli/node_modules/serialport/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/particle-cli/node_modules/serialport
node-pre-gyp ERR! node -v v4.2.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release/serialport.node --module_name=serialport --module_path=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release' (1)
npm ERR! Linux 4.9.24+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "particle-cli"
npm ERR! node v4.2.1
npm ERR! npm v2.14.7
npm ERR! code ELIFECYCLE
npm ERR! serialport@4.0.7 install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the serialport@4.0.7 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the serialport package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR! npm owner ls serialport
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/pi/npm-debug.log


This is a known but relatively undocumented bug with the particle-cli installation process. The following should work:

           $ sudo npm install -g --unsafe-perm node-pre-gyp npm serialport particle-cli

ref:
https://community.particle.io/t/connecting-particle-photon-to-local-server-on-raspberry-pi-zero-w/32227
https://community.particle.io/t/new-cli-on-os-x-10-11-el-capitan-solved/28802/8



Sunday, 17 September 2017

"The volume "boot" has only 0 bytes disk space remaining" error

Very simple

sudo apt-get autoremove

This will delete those unuseful kernels in /boot.

ref:
https://ubuntuforums.org/showthread.php?t=2239126
https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition

Thursday, 7 September 2017

Setting up GCC ARM Coding Environment for STMicrocontroller


1. Installing compiler and stlink

To compile C and/or C++ source code of your firmware you will need gcc-arm-none-eabi compiler and stlink.

Installing gcc-arm-none-eabi

What is extremely useful, there are complete and easy to install packages for all major platforms (https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa)
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi

Installing stlink

At first, we need install dependencies then build it from sources (https://github.com/texane/stlink/blob/master/doc/compiling.md#build-from-sources).
sudo apt-get install git build-essential libusb-1.0.0-dev cmake
cd $HOME
git clone git@github.com:texane/stlink.git
cd stlink
make release
cd build/Release && make install DESTDIR=_install
echo "export PATH=\$PATH:$HOME/stlink/build/Release/_install/usr/local/bin" >> $HOME/.bashrc

2. Compiling and burning the code

Now that you have the toolchain installed, a next step is to compile the source code into a .ELF, then generate .BIN file and finally burn this this binary file to STM32 chip using ST-Link v2 programmer.

Example code

Here is an example content of main.c file. The code does nothing except getting stuck in an endless loop but it’s always something!
int
main(void)
{

        while (1);
}

Compiling

The command below will compile your code. It’s GCC so I assume it looks familiar to you and no additional explanations are needed. If you want perform compilation for some other MCU then you need specify at least appropriate -mcpu, .LD and .S files (not provided in this tutorial)
$ arm-none-eabi-gcc -std=gnu99 -g -O2 -Wall -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0 -fsingle-precision-constant -Wdouble-promotion main.c -o main.elf
After performing successful compilation, you can check program and data memory size with this command.
$ arm-none-eabi-size -tA main.elf 
main.elf  :
section              size        addr
.isr_vector           192   134217728
.text                6404   134217920
.rodata                60   134224324
.ARM                    8   134224384
.init_array             8   134224392
.fini_array             4   134224400
.data                1092   536870912
.jcr                    4   536872004
.bss                   32   536872008
._user_heap_stack    1536   536872040
.ARM.attributes        40           0
.comment               31           0
.debug_line          7416           0
.debug_info         22917           0
.debug_abbrev        6837           0
.debug_aranges        744           0
.debug_loc           6584           0
.debug_ranges         472           0
.debug_str           5717           0
.debug_frame         2004           0
Total               62102

Generating .BIN

Most programmers will not accept a GNU executable as an input file, so we need to do a little more processing. So, the next step is about converting the information form .ELF into .BIN file. The GNU utility that does this is called arm-none-eabi-objcopy.
$ arm-none-eabi-objcopy -O binary main.elf main.bin

Burning

The utility called st-flash can program processors using the content of the .BIN files specified on the command line. With the command below, the file main.bin will be burned into the flash memory.
$ st-flash write main.bin 0x8000000
Voila! Chip is programmed.

3. Make and Makefiles

Now, we can automate this process by creating a Makefile and putting our commands there. The structure of a Makefile is very simple, and more information about it can be found here. Utility make reads automatically a Makefile file in the folder where you launch it. Take a look at simple Makefile presented bellow.
TARGET=main

CC=arm-none-eabi-gcc
LD=arm-none-eabi-gcc
AR=arm-none-eabi-ar
AS=arm-none-eabi-as
CP=arm-none-eabi-objcopy
OD=arm-none-eabi-objdump
SE=arm-none-eabi-size
SF=st-flash

CFLAGS  = -std=gnu99 -g -O2 -Wall
CFLAGS += -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0
CFLAGS += -fsingle-precision-constant -Wdouble-promotion

SRCS =  main.c

.PHONY: $(TARGET)

$(TARGET): $(TARGET).elf

$(TARGET).elf: $(SRCS)
        $(CC) $(INCLUDE) $(CFLAGS) $^ -o $@
        $(CP) -O binary $(TARGET).elf $(TARGET).bin

clean:
        rm -f *.o $(TARGET).elf $(TARGET).bin

flash:
        $(SF) write $(TARGET).bin 0x8000000
If you launch a simple make in the terminal, only label “all” will be executed. When you launch make flash label “flash” will be executed, and so on.

4. Summary

Essentially, assuming that our program is in main.c, only those three things are needed to compile and burn the code to STM32 chip.
$ arm-none-eabi-gcc -std=gnu99 -g -O2 -Wall -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0 -fsingle-precision-constant -Wdouble-promotion main.c -o main.elf
$ arm-none-eabi-objcopy -O binary main.elf main.bin
$ st-flash write main.bin 0x8000000


It’s important to highlight that we can easily automate whole process with Makefiles. Sooner or later you will need it!



ref:
http://blog.podkalicki.com/how-to-compile-and-burn-the-code-to-stm32-chip-on-linux-ubuntu/
https://startingelectronics.org/tutorials/STM32-microcontrollers/programming-STM32-flash-in-Linux/
http://fishpepper.de/2016/09/16/installing-using-st-link-v2-to-flash-stm32-on-linux/

Tuesday, 5 September 2017

The Django Book Study -- Installing Django

I stucked a bit at this part:

To use this new Python virtual environment, we have to activate it, so let’s go back to the command prompt and type the following:
env_mysite\scripts\activate
This will run the activate script inside your virtual environment’s \scripts folder. You will notice your command prompt has now changed:
(env_mysite) C:\Users\Nigel\OneDrive\Documents\mysite_project>
The (env_mysite) at the beginning of the command prompt lets you know that you are running in the virtual environment. Our next step is to install Django.
Apparently, this is how it goes in Windows. In Linux, we would have to do the following:
source bin/activate
And then we can see:
boris@boris-D630:~/workspace/mysite_project/env_mysite$ source bin/activate
(env_mysite)boris@boris-D630:~/workspace/mysite_project/env_mysite$


ref:
https://pypi.python.org/pypi/virtualenv/1.8.2