Tuesday, May 31, 2016

Building the App example/alarms

Configuring a nuttx/app is done with "make menuconfig"
I find myself churning through the options trying to find dependencies to subsystems to turn them on.
The top level readme does help - however the general directions are to do it through the menuconfigs and the following README.txt describes it in terms of #defines.
https://bitbucket.org/nuttx/apps/src/master/examples/README.txt
So this is how I enable the subsystem for my test board olimex-STM32-H307 with TTY on Uart2
On my build machine - Ubuntu 15.10
cd tools
./configure.sh olimex-stm32-h407/nsh   
cd ..
make menuconfig
Requires RTOS FeaturesàRTOS Hooksà[*] Custom board/driver initialization 
Requires, Drivers -->Timer Driver Support àRTC Driver Support


.
Debug options
* Enable Debug Features
* Enable Debug Verbose Output
* RTC Debug Output
* Stack Colouration
* Generate Debug Symbols

Application Configurationà Examples
* RTC Alarm driver example (with defaults)





App Config à NSH LibàDisable Individual cmds-->
[] Disable date   # turn off disable

If on a board that is missing the 32KHz clock, stm32F4discovery board,
 then the RTC can function with another clock
 System Type àRTC clock source  LSI or HSI. They don't survive reset for some reason.

make clean

make
and then download it over the ST-LINK.

The output with RTC debugging enabled - using the initial power on time, looks like this

Ideally needs to set up date first but will work without it eg
nsh> date -s "JULY 06 13:45:00 2016"

nsh> alarm 15
alarm_daemon started
alarm_daemon: Running
Oprtc_dumpregs: *** Reading Time:
rtc_dumpregs:       TR: 00003532
rtc_dumpregs:       DR: 00002101
rtc_dumpregs:       CR: 00001100
rtc_dumpregs:      ISR: 00000127
rtc_dumpregs:     PRER: 007f00ff
rtc_dumpregs:     WUTR: 0000ffff
rtc_dumpregs:   CALIBR: 00000000
rtc_dumpregs:   ALRMAR: 80003333
rtc_dumpregs:   ALRMBR: 00000000
rtc_dumpregs:   SHIFTR: 00000000
rtc_dumpregs:     TSTR: 00000000
rtc_dumpregs:     TSDR: 00000000
rtc_dumpregs:    TSSSR: 00000000
rtc_dumpregs:     CALR: 00000000
rtc_dumpregs:    TAFCR: 00000000
rtc_dumpregs: ALRMASSR: 00000000
rtc_dumpregs: ALRMBSSR: 00000000
rtc_dumpregs: MAGICREG: facefeee
rtc_dumpregs: EXTI (RTSR FTSR ISR EVT): 1011
rtc_dumptime: Returning:
rtc_dumptime:   tm_sec: 00000020
rtc_dumptime:   tm_min: 00000023
rtc_dumptime:  tm_hour: 00000000
rtc_dumptime:  tm_mday: 00000001
rtc_dumptime:   tm_mon: 00000000
rtc_dumptime:  tm_year: 00000064
rtc_dumptime: New alarm time:
rtc_dumptime:   tm_sec: 00000030
rtc_dumptime:   tm_min: 00000023
rtc_dumptime:  tm_hour: 00000000
rtc_dumptime:  tm_mday: 00000001
rtc_dumptime:   tm_mon: 00000000
rtc_dumptime:  tm_year: 00000064
irtc_dumpregs: *** Set AlarmA:
rtc_dumpregs:       TR: 00003532
rtc_dumpregs:       DR: 00002101
rtc_dumpregs:       CR: 00001100
rtc_dumpregs:      ISR: 00000027
rtc_dumpregs:     PRER: 007f00ff
rtc_dumpregs:     WUTR: 0000ffff
rtc_dumpregs:   CALIBR: 00000000
rtc_dumpregs:   ALRMAR: 80003548
rtc_dumpregs:   ALRMBR: 00000000
rtc_dumpregs:   SHIFTR: 00000000
rtc_dumpregs:     TSTR: 00000000
rtc_dumpregs:     TSDR: 00000000
rtc_dumpregs:    TSSSR: 00000000
rtc_dumpregs:     CALR: 00000000
rtc_dumpregs:    TAFCR: 00000000
rtc_dumpregs: ALRMASSR: 00000000
rtc_dumpregs: ALRMBSSR: 00000000
rtc_dumpregs: MAGICREG: facefeee
rtc_dumpregs: EXTI (RTSR FTSR ISR EVT): 1011
ng /dev/rtc0
rtchw_set_alrmar:   TR: 00003532 ALRMAR: 80003548
Alarm set in 15 seconds
nsh>

(then when the alarm goes off)

rtc_dumpregs: *** Reading Time:
rtc_dumpregs:       TR: 00003548
rtc_dumpregs:       DR: 00002101
rtc_dumpregs:       CR: 00001100
rtc_dumpregs:      ISR: 00000127
rtc_dumpregs:     PRER: 007f00ff
rtc_dumpregs:     WUTR: 0000ffff
rtc_dumpregs:   CALIBR: 00000000
rtc_dumpregs:   ALRMAR: 80003548
rtc_dumpregs:   ALRMBR: 00000000
rtc_dumpregs:   SHIFTR: 00000000
rtc_dumpregs:     TSTR: 00000000
rtc_dumpregs:     TSDR: 00000000
rtc_dumpregs:    TSSSR: 00000000
rtc_dumpregs:     CALR: 00000000
rtc_dumpregs:    TAFCR: 00000000
rtc_dumpregs: ALRMASSR: 00000000
rtc_dumpregs: ALRMBSSR: 00000000
rtc_dumpregs: MAGICREG: facefeee
rtc_dumpregs: EXTI (RTSR FTSR ISR EVT): 1011
rtc_dumptime: Returning:
rtc_dumptime:   tm_sec: 00000030
rtc_dumptime:   tm_min: 00000023
rtc_dumptime:  tm_hour: 00000000
rtc_dumptime:  tm_mday: 00000001
rtc_dumptime:   tm_mon: 00000000
rtc_dumptime:  tm_year: 00000064
alarm_demon: alarm 0 received

Saturday, May 28, 2016

How to download nuttx for a Feature Branched Workflow

This is a series of blogs (my self documentation) on using Nuttx in a branched workflow.
Hopefully its of use to others.
This assumes you already have a viable build environment on your local machine.
This assumes you have already forked the nuttx repo's on bitbucket
Ideally your fork is sycned to a release tag - but that is advanced code management for another discussion.
Now you need to download the repos to a local machine  before they can be build.
There are many workpractises that can accomplish this - so I'm sharing the one I've evolved.
The target is to be eventually do a "polished" Pull Request back into the  main nuttx. There is a fierce guardian of the repo - so while a users main effort might be creating the code, possibly if like me quite messily, the activity of submitting back to the nuttx repos of working code can be a process in itself.
So as per the Feature Branched Workflow guidelines I consider creating one local instance of nuttx for working on - with a branch usually starting with "work..."  and then when submitting it creating another local nuttx instance got staging and polishing the code ... with a branch possibly beginning "pr.."
Nuttx can be built for a number of processors or starting configurations, I find it useful to create my local nuttx instance with a defined naming scheme

I use a postfix nxZZ for each directory,  as I found a need for different instances of Nuttx as the development progress
nxtipXXX - direct bitbucket/nuttx with target build
nxoh4wk - nuttx Olimex-STM32-h407 Work tree 
nxoh4sg - ditto stage tree
nxnkl25<xx> - nuttx  NXP FRDM-KL25 work/stage
nxnk64<xx>  - nuttx NXP FRDM-K64 work/stage

So assuming the target environment is Olimx-STM32-h407 I create two directories 
$ cd git
mkdir nxtipoh4   #my top level directory for pure nuttx code from tip built for Olimex-STM32-h407
mkdir nxoh4wk

cd nxoh4wk
#I've forked to the specific repos below
git clone git@bitbucket.org:<user>/anuttx.git nuttx
git clone git@bitbucket.org:<user>/nuttapps.git apps
#if first time on machine using make menuconfig - need to set up Kconfigs)
git clone https://bitbucket.org/nuttx/tools.git tools

#end first time Kconfigs

cd nuttx
  
$ tools/version.sh -b 160405_1103 -v 7.15 .version
make distclean

cd  tools
#use a starting config
./configure.sh olimex-stm32-h407/nsh

cd ..

source setenv_xx.sh (if first time)

make menuconfig #ensure host is correct, save and then exit to use latest format

make #test build, should work and be tested before continuing
(cable to serial port, teraTerm 19200 to serial port)

#next create the working feature branched workflow environment of your choice
git checkout -b work_featurebranchAA
cd ../apps
git checkout -b work_featurebranchAA

# now can edit in either nuttx or apps and it will be tracked.

#Optionally an instance can be created for the tip - and differences between the forked branch can be seen using meld or something similar.

cd ../nxtipoh4
git clone git@bitbucket.org:nuttx/nuttx.git nuttx
git clone git@bitbucket.org:nuttx/apps.git apps

# then build - see above

tutorial: bitbucket setup Feature Branched Workflow for nuttx (single git repository)

This is a series of blogs (my self documentation) on using Nuttx in a branched workflow.
Hopefully its of some use to others.

"Nuttx OS" on bitbucket for the beginner has a two git module configuration - bitbucket.org/nuttx/nttuxt and bitbucket.org/nuttx/apps The "apps" may be replaced by a custom configuration later.
My development environment is Ubuntu 15.10, with Meld to do differencing. 
Meld required Ubunutu 15.10
The editing is done in Eclipse Mars on Windows10 over the network to Ubuntu. I login in remotely to the Ubuntu machine to compile.

Some references

To start, sign-in to bitbucket.org with your own account , then clone the following into your <userSpace> on bitbucket
I use a prefix ZZ as you might want to experiment with different instances of Nuttx as the development progress
bitbucket.org/patacongo/nuttx  to ZZNuttX   Description: <your plans for the fork>
bitbucket.org/nuttx/apps             ZZnuttapps Description: <your plans for an apps>

Next article:  how to download the code to your local machine.