Category: Dicas

Using VirtualBox with 1366×768 resolution

Sometimes you are forced to use Windows just for some seconds to get the work done. Fortunately MS was kind enough to release a Trial Windows image that you can run legally for 90 days as explained here (in Portuguese) : https://acassis.wordpress.com/2013/02/27/baixando-e-rodando-uma-imagem-do-windows-no-virtualbox/

But my laptop is old and its resolution is only 1366×768 and this resolution doesn’t appear as an option in the emulated Windows on VirtualBox. Even in the advanced options this resolution is not present.

After some search in the Internet I discovered how to create new resolutions option on VirtualBox:

$ VBoxManage setextradata "IE9 - Win7" CustomVideoMode1 1366x768x32

Source: https://superuser.com/questions/443445/how-can-i-get-virtualbox-to-run-at-1366×768

How to remove trailing whitespaces and new blank line at EOF from patches

When applying a patch in the git (i.e. using “git am” command) you could to face these warning messages:

Applying: You patch name
.git/rebase-apply/patch:9360: trailing whitespace.
 *    notice, this list of conditions and the following disclaimer. 
.git/rebase-apply/patch:2456: new blank line at EOF.
+
.git/rebase-apply/patch:3382: new blank line at EOF.
+
.git/rebase-apply/patch:4323: new blank line at EOF.
+
.git/rebase-apply/patch:4905: new blank line at EOF.
+

It will be very boring to discover what are these files and fix each one.
Fortunately you can use git itself to fix it for you:

$ git apply --reject --whitespace=fix filename.patch

If you want you can use “git add” and “git commit” to create a new patch without these “trailing whitespaces” and “new blank lines”.

UPDATE: You can use “git am –reject –whitespace=fix filename.patch” then it will fix the blank lines and trailing whitespaces and you don’t need to run “git add” and “git commit”!

I found the solution here: http://stackoverflow.com/questions/14509950/my-diff-contains-trailing-whitespace-how-to-get-rid-of-it

Using NuttX as a library

It is possible to use NuttX as library, then you don’t need to compile the source code all the time, just modify your application and link it against the NuttX library.

Here I will explain step-by-step how to do that.

I will consider that you just entered on nuttx/tools and executed the ./configure.sh to select your board and your application profile (here my application is called “hello” and CONFIG_USER_ENTRYPOINT=”hello_main”). Then now instead of executing “make” to compile the source code you should to execute:

make export

If everything worked as expected you will get the file “nuttx-export.zip”. Extract this file and create your application inside it. Here I create a hello.c file with it:

#include 

int hello_main(void)
{
        printf("Hello World!\n");
        return 0;
}

Now I compiled it this way:

$ arm-none-eabi-gcc -c -fno-builtin -Wall -Wstrict-prototypes -Wshadow -Wundef -g -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -I. -isystem ./include   -pipe -I "./include"  hello.c -o  hello.o

We just need to link again libnuttx.a to generate our nuttx ELF:

$ arm-none-eabi-ld --entry=__start -nostartfiles -nodefaultlibs -T./build/spificonfig.ld -L./libs hello.o -o nuttx.elf --start-group -lnuttx "/usr/lib/gcc/arm-none-eabi/6.2.1/thumb/v7e-m/libgcc.a" --end-group

And to generate the finaly binary from the ELF:

$ arm-none-eabi-objcopy -S -O binary nuttx.elf nuttx.bin

It is also a good idea to generate the map of symbols with the physical address of each function:

$ arm-none-eabi-nm nuttx.elf | \
grep -v '\(compiled\)\|\(\.o$\)\|\( [aUw] \)\|\(\.\.ng$\)\|\(LASH[RL]DI\)' | \
sort > System.map

Well done, now just flash it using OpenOCD and STLink-V2 :

$ sudo openocd -f interface/stlink-v2.cfg -f target/lpc4330.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x14000000"
Open On-Chip Debugger 0.10.0 (2017-02-12-09:48)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.
adapter speed: 500 kHz
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : clock speed 480 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.273164
Info : lpc4350.m4: hardware has 6 breakpoints, 4 watchpoints
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x10402c40 msp: 0x10087ff0
auto erase enabled
Info : Found flash device 'win w25q64cv' (ID 0x001740ef)
Warn : no flash bank found for address 28000000
Warn : no flash bank found for address 280074c4
wrote 0 bytes from file nuttx.bin in 0.087209s (0.000 KiB/s)

Recurring Neural Network

Two days ago I found this nice post at Hackaday about a guy who create a program to generate music:

Neural Network Composes Music; Says “I’ll be Bach”

He used Long Short Term Memory networks (LSTM) a kind of Recurring Neural Network (RNN), then I started to search more about these subjects and found some interesting links that I want to share with you:

Understanding LSTM Networks:
http://colah.github.io/posts/2015-08-Understanding-LSTMs/

The Unreasonable Effectiveness of Recurrent Neural Networks:
http://karpathy.github.io/2015/05/21/rnn-effectiveness/

Recurrent Neural Networks Tutorial:
http://www.wildml.com/2015/09/recurrent-neural-networks-tutorial-part-1-introduction-to-rnns/

I hope you enjoy reading about it. When I got something about it working on microcontrollers I will post here.