Following on from our phone conversation earlier today, I decided to do some memory budgeting to see how much of a fix we are in.  I’m relieved that there is a 32K RAM Nordic available.  Sadly I don’t see more flash on the horizon.

Leaning on this: http://electronics.stackexchange.com/questions/127667/what-are-the-resource-requirements-ram-flash-of-the-latest-nordic-bluetooth-s
I learned the following:

The latest S110 v7 softdevice uses 88 kB flash and 8 kB of static RAM for S110 leaving 168 kB of flash and 8 kB of RAM for the application (for the 256k chip). Also note that S110 v7 can use over 1.5 kB of stack, so you must make sure that your stack is big enough to accomodate both this and your application’s requirement. 

Lastly, when you use the S110, it also restricts many of the Programmable Peripheral Interconnect (PPI) channels, leaving on 8 channels free for the application code. This restricts how you implemet peripherals such as PWM and I2C.

The DW test program which simply handles ranging provides a rough estimate for the code we will need to talk to the DW chip from the Nordic.  It uses 68K flash, 6.5K of RAM.
So before we get to write any application code our memory footprint looks like this:
                 BLE    DecaW     TOTAL
          Flash   88 +  68      = 156K
          RAM      8 +   6.5    = 14.5K*

*This does not account for stack, or heap.  The BLE call stack can need 1.5K by itself which could drive our RAM footprint up to 16KB, which is all we have on the current module.


We have about 100KB left for code development which I’m estimating will become a headache by itself in about a year.  Apart from actual application code, we have to include driver code for the other chips, which could take another 30%.
The DW code is compiled under -O0 (no optimization).  Optimaztion may save 10%.  There may well be a bunch of drivers and library routines that have been eroneously dragged into my DW test compilation, and are not used.  Maybe we can save another 10%

Bottom line

RAM is going to be tight, until we get the 32KB modules.  Flash is not an immediate issue, but two factors will quickly make it one:  other device drivers (IMU/Bat monitor);  Storage for sensor/range data.  I think off-chip memory is on the near horizon.

Today, I scratched around some more and finally decided I had to ask for help.  This was just soaking up a lot of time, doing random things that I thought might be the cause of the problem. i.e. not based on any real evidence.

So I tooled a message for David to send to Leo.

Thank heavens, that David had the good sense to read my drivel before he sent it.  It appears Leo actually sent us a revised IDE installation document last week.

Hi David
The attached Eclipse doc is the latest.
Is that not the one I gave you?
Regards,
Leo Theunissen

David figured, I hadn’t noticed it and sent me a nudge.   It’s not easy being so stupid.  What a waste of bloody time.
—————
So I printed off a new version of the document and carefully went through all the installation steps. It’s a lot, lot better, but there are still issues.

43 files compiled with mere warnings, but it finally ground to a halt with some “Assembler messages”.  Who knows what this means?

‘Building file: ../Libraries/CMSIS/CM3/CoreSupport/core_cm3.c’
‘Invoking: Cross ARM C Compiler’
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -w  -g3 -DSTM32F10X_CL -DUSE_STDPERIPH_DRIVER -I”C:UserslammingworkspaceDecaRangingMPEVBLibrariesSTM32F10x_StdPeriph_Driverinc” -I”C:UserslammingworkspaceDecaRangingMPEVBLibrariesSTM32F10x_StdPeriph_Driversrc” -I”C:UserslammingworkspaceDecaRangingMPEVBLibrariesCMSISCM3CoreSupport” -I”C:UserslammingworkspaceDecaRangingMPEVBLibrariesCMSISCM3DeviceSupportSTSTM32F10x” -I”C:UserslammingworkspaceDecaRangingMPEVBsrcapplication” -I”C:UserslammingworkspaceDecaRangingMPEVBsrccompiler” -I”C:UserslammingworkspaceDecaRangingMPEVBsrcdecadriver” -I”C:UserslammingworkspaceDecaRangingMPEVBsrcplatform” -I”C:UserslammingworkspaceDecaRangingMPEVBsrcsys” -std=gnu11 -MMD -MP -MF”Libraries/CMSIS/CM3/CoreSupport/core_cm3.d” -MT”Libraries/CMSIS/CM3/CoreSupport/core_cm3.o” -c -o “Libraries/CMSIS/CM3/CoreSupport/core_cm3.o” “../Libraries/CMSIS/CM3/CoreSupport/core_cm3.c”
C:UserslammingAppDataLocalTempccKeD9Ks.s: Assembler messages:
C:UserslammingAppDataLocalTempccKeD9Ks.s:772: Error: registers may not be the same — `strexb r3,r2,[r3]’
C:UserslammingAppDataLocalTempccKeD9Ks.s:818: Error: registers may not be the same — `strexh r3,r2,[r3]’
cs-make: *** [Libraries/CMSIS/CM3/CoreSupport/core_cm3.o] Error 1

Aha!  http://www.atollic.com/index.php/kb/1-kb_building/117-kb_error_in_strexb

In the tool chain included in TrueSTUDIO up to version 5.0 there where a bug in gcc for optimization level -O0 that would allow the code to compile with that optimization.
Hot to change to a lower optimization level for STREXB and STREX:
Find the functions __STREXB and STREXH. They are located in the CMSIS libraries. The exact position for the libraries depends on the project organization.
Change the function prototypes for these two function to set a lower optimization level with [optimize(“O0”)].
But I already have optimization “O0”  and the precise fix they recommend doesn’t match my source.
—————
So the software that they suggest you download from ST is out-of-date.  It seems pretty clear tome that nobody has run through the DW instructions.
I managed to find a more modern version out on the web.  

I downloaded it and patched in the new core_cm3.c and tried to rebuid.   Got exactly the same error.   This time I opened up the code and it seems to match the reported buggy code.  So I made the suggested alteration to the new code described here:  http://www.coocox.org/forum/topic.php?id=943

I think there is an error in core_cm3.c file at CoIDE 1.7.1.
I had the same issue with Sourcery CodeBench gcc 4.7.2 and it was resolved after editing cmsiscore_cm3.c file in my project’s directory.According to this thread you should edit functions __STREXB and __STREXH by changing “=r” to “=&r”.
You’ll see code:
__ASM volatile (“strexb %0, %2, [%1]” : “=r” (result) : “r” (addr), “r” (value) );
Should be:
__ASM volatile (“strexb %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );

I ended up with two edited lines in ___STREXB and __STREXH

(line 736) __ASM volatile (“strexb %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );
(line 753) __ASM volatile (“strexh %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );

I saved and recompiled.
Yay… it compiles now!

The important statistics we have been waiting to see are:

   text   data    bss    dec    hex filename
  67992   1552   4992  74536  12328 DecaRangingMPEVB.elf

  • text is basically the code that lives in flash.  Initializers for variables that live in RAM will be placed here too, but don’t contribute to the text size.
  • data is pre-initialized variables, that lives in RAM.  The initializers will be in flash, and will get copied to ram before the main routine is called.
  • bss is un-initialized variable storage that lives in RAM.
  • dec and hex are the total size of everything expressed in decimal and hex.  It’s not useful unless you are worried about storing/transmitting the image for subsequent download.

Yay… it downloads now.
Yay… it runs.

 

I’ve been thinking about drones which are in the news again.

Objectives recap

Topology mapping recap

I espouse the idea that we can do a lot without making a map.  I think it’s still critical to be able to do things without a map.

If we had an easy way to add a map then it could enable a lot of extra capabilities.

One thing I’m pretty sure we can do is sense the position of an object to within a meter, or less.  So I can imagine having a tiny, and very inexpensive drone with a TV camera that could follow you around the house.

Take the drone out of the box, and remove the paper strip maked “Remove me first”.   Set the drone on the floor in front of you.  Put on your wrist band.  Wave your hand over the top of the drone <somehow> until the red light on the drone comes on. Now walk away from the drone, and sit still somewhere you can see the whole room.  In a few seconds the drone will start, and slowly rise into the air.  It will slowly hover around around the room taking pictures.  Don’t move until it lands again.

Walk into another room, and the drone will follow you.  Sit down and the drone will survey this room.

Move to each room in turn until you are done, and then walk towards the drone and wave your hand over it.  You are done.  Put the drone back in it’s little box, and put it way somewhere safe. 

The drone builds a 3D map using techniques like these.
Project Tango

 

 

 

 

The instructions require an STLINK/V2 ($21 and less off the web) which I don’t have of course.

So can I use the JLink EDU.   First challenge is getting the connector right.  Which is pin #1?


Let’s hope I have this right…


I’ve written the canonical LED flasher program, but now I’m trying to figure out what port.pin the LEDs are on.   Back to the Schematic…

timer_start(); blink_led_init();
// Infinite loop while (1)  {  blink_led_on();  timer_sleep(BLINK_ON_TICKS);  blink_led_off();  timer_sleep(BLINK_OFF_TICKS);  }

Looks like there’s one on Port C, pin6.  Can it be that easy?

OK, it looks like I can talk to the EVB1000 because I seem to have nixed the program that was in it, so clearly something got flashed.  But the program isn’t starting…

This  CodeSorcery compiler looks like it needs a different set of startup files.  I wonder if I can get it to work under the gcc compiler instead.

Recompile, and change a few settings…

Poked around a bit more and managed to find out how to get the semi-hosting to work too.

There are a couple of additional compile-time constants that have to be set: 

STM32F10X_CLTRACEOS_USE_TRACE_SEMIHOSTING_DEBUGUSE_STDPERIPH_DRIVERHSE_VALUE=8000000

Found this useful comment buried in some library code.

// Note: Applications built with semihosting output active cannot be
// executed without the debugger connected and active, since they use
// BKPT to communicate with the host. Attempts to run them standalone or
// without semihosting enabled will usually be terminated with hardware faults.

BTW.  I’m still keen to try and get everything to fit on the Nordic, because it’s just such a neat solution.  I think it’s worth the struggle.

//Mik

On Sun, Nov 16, 2014 at 10:34 AM, Mik Lamming <mik@lamming.com> wrote:

See my previous.  If I could just compile the current code then I’d have an idea how much RAM it consumes.  Maybe it will fit easily.  I’m working on the assumption that we may be able to dump a bunch of functionality from the DW library because we only really need the ranging.  On the other hand, it looks like the ranging builds upon the basic packet handling, so there may be a limit to how much it can be chopped.

//Mik

On Sat, Nov 15, 2014 at 10:04 PM, David Carkeek <dcarkeek@gmail.com> wrote:

64k RAM seems to equate with large package. I can’t find a small physical size part with 64k RAM. 

Cypress

Atmel 48k RAM
Atmel 96k 1M Flash
What do you think the chances are of fitting the Decawave code into 32k RAM? I think moving away from the nRF51822 will make things a lot bigger. But there might be some new/other products I haven’t found out about yet.

I’m getting increasingly queezy that the Nordic chip won’t have the guts to do the job.  DW have configured the ARM m3 to use 64K of RAM.  We may have more difficult challenges than just voltage levels!


//Mik

On Sat, Nov 15, 2014 at 10:04 PM, David Carkeek <dcarkeek@gmail.com> wrote:
64k RAM seems to equate with large package. I can’t find a small physical size part with 64k RAM. 

Cypress

Atmel 48k RAM
Atmel 96k 1M Flash
What do you think the chances are of fitting the Decawave code into 32k RAM? I think moving away from the nRF51822 will make things a lot bigger. But there might be some new/other products I haven’t found out about yet.
——————-
On Sat, Nov 15, 2014 at 6:58 PM, David Carkeek <dcarkeek@gmail.com> wrote:

https://devzone.nordicsemi.com/question/16825/new-version-of-nrf51822-silicon/

The answer from the Nordic guy sure makes it sound like there will be a version that has more RAM.
This was written 16 days ago:

https://community.spark.io/t/sparkle-a-bluetooth-le-powered-spark-core-clone/6108/54

So, after all the hard work getting SparkLE working with a “handshake MCU”, there has been an interesting development. I found out a few weeks ago (and Nordic Semiconductor just announced this week) that there will be a new version of the nrf51 chipset with 32K RAM. That means no more need for a second MCU on-board!

Here’s the announcement:

So we have to get some samples of the new 32k nRF51822 and mount it on the Ray-Tac modules. I’ll also email Ray-Tac to see if they will be building 32k versions.
But is 32k enough?
If it’s not we can change directions now and make a board with an M3 and separate BLE radio. That might be best anyway.

Mik responds:

If I could just compile the current code then I’d have an idea how much RAM it consumes.  Maybe it will fit easily.  I’m working on the assumption that we may be able to dump a bunch of functionality from the DW library because we only really need the ranging.  On the other hand, it looks like the ranging builds upon the basic packet handling, so there may be a limit to how much it can be chopped.


//Mik
On Sat, Nov 15, 2014 at 12:05 PM, David Carkeek <dcarkeek@gmail.com> wrote:

I thought the DW1000  I/O supply could be run at 1.8V, but it can’t. It’s 2.8V – 3.6V. There are separate 1.8V-optional supply pins for digital and analog circuits (to save power) but they can run at 3.3V. So for the time being, since the nRF51822 can run at 3.3V, the whole board will be 3.3V so all the I/O’s will be 3.3V. Later we will have to determine if running the nRF51822 at 1.8V for power saving is needed, then level shifting the signals connected to the DWM1000.

I assume the Segger adjusts to the proper I/O voltage by means of its Vref pin.

—————– 

I’m not sure how the SEGGER knows how to adjust, but I found this bit in the SEGGER documentation.

—————-
David:

Jtag:                                                              SWD:

Inline image 1             Inline image 2
Wire for SWD, correct?
Can you look on your board to see what pins I used on the module for SWO and RESET? Or maybe just take a picture and send it to me.
—————————-

Mik:
I think we should configure it for SWD. I have not yet used JTAG on the Dewbly, and I seem to be able to do everything I wanted to do with SWD… so far anyway.

I described all the connections we used on the Dewbly on p43-44 of this document. I just tested it out again, and it works fine. Please tell me, or better still amend the document if there is anything missing or wrong. In a few months I won’t remember all the details.