Content originally posted in LPCWare by PhilYoung on Mon Apr 09 12:34:32 MST 2012
I've been playing around with startup code for this and found there are a few benefits of doing things slightly different to the way the examples work.
The example code builds the application as a single binary including both the M0 and M4 code, which requires re-flashing the entire code and re-building the M4 app each time the M0 project is updated.
This creates a bootable image for the M0 but is inefficient as the image must be de-compressed and copied to RAM to be executed, generally it's better simply to build an M0 bootable image to be executed from flash so that the ram footprint is much smaller, this also allows the boot loader code to remain in flash further reducing the memory overhead as only the important application code needs to be copied to SRAM for speed.
To achieve this I simply create a scatter load file which sets the load and execute address for the M0 startup code at a fixed address in flash which is known to the M4 app, the M4 then simply sets the shadow address of the M0 memory to the base address of the M0 image in flash and lets the M0 do all of the init code, this allows the compressed const data and code to be de-compressed directly from flash to the required execute address.
It also allows the M0 image to be flashed without erasing the M4 image, and allows the M4 to perform runtime updates of the M0 image.
Additionally, the method used in the examples to build a data structure generates a compressed image and requires to de-compress this since the table containing the M0 image is defined as unsigned char LR0[], i.e. it is not const so cannot reside in flash. It's better to include this file into the main M4 image if this is required by using a simple file that changes the type to const and exports the symbol. I simply have a file containing 2 lines
extern const
#include "LR0.h"
where LR0.h is the file generated by the M0 project. This changes the type of LR0 to const, i.e. +RO instead of the default +RW.
The M4 image then simply places LR0 in a section at 0x1c040000 allowing it to be overwritten independantly of the M4 code.