Thank you all for you answers.
Hello Massimo, nice to meet you, thank you very much for your support. Of course let continue in english if someone else would be interested to use LPC43xx in such "strange" configuration.
I try to explain better how I placed the whole code and data for both CPUs.
On both CPUs is running FreeRTOS and I have 3 different memory spaces: 1) very fast internal 264KB SRAM 2) fast external 32MB SDRAM 3) slow external 4 MB SPIFI.
I tried to map code and data so that the most used functions and used data are inside SRAM, not intensive used code or big buffers in external SDRAM and constant data or initialization data/code in external SPIFI. Of course at the reset the whole M4+M0 code is stored in external SPIFI and then copied by startup code to other memory spaces.
The device acts as the head of an antintrusion alarm system and has 2 868Mhz RTX , 2 RS485 buses, analog I/O, actuators, USB,UMTS module and ethernet port.
I decided to subdivide the whole work into 2 cores based on functions.
M0 core:
I put here all the code required to implement the low level drivers (radio communication, RS485 bus communication, hardware I/O and analog readings) plus the main device logic. It acts as a complete, standalone central alarm system main unit, where it checks for connected sensor's alarms and generates notifications to M4 and to other output devices (i.e. siren).
The bahavior of M0 logic is based on a memory buffer shared between M0 and M4 cores: here is where all system configuration is stored.
I decided for M0 this memory map:
Internal 72Kb SRAM: code and data (Except big buffers)
External SDRAM: big buffers
Internal AHB16 16KB: for stack and HEAP
M4 core:
I put here all the code required for ethernet/internet communication (with apps or HTML pages) where the settings of M0 logic behavior is created and modified. Here is placed also all the code to send emails, SMS, make voice calls,text 2 speech synthesys and other higher level tasks.
I decided for M4 this memory map:
Internal 128KB SRAM: most used code and data
External SDRAM: less used and big code/data, slow heap
External SPIFI for intitialization code and to store/read SETTINGS
Internal AHB32 32KB for stack and fast heap
SHARED
Communication between two cores are based on MESSAGE QUEUES (to send notification from M0 to M4 or command from M4 to M0) and shared memory buffers.
Shared buffers are:
SDRAM: SETTINGS and STATUS structures
AHB_IPC to store IPC QUEUE structures and other hardwired absolute memory locations used by both cores to take control of memory space.
I implemented a semaphore method to gain access to this shared memory area using a simple code:
| #define SHARED_SETTINGS_ACC_FLG0 0x2000C8f0 | | // |
| #define SHARED_SETTINGS_ACC_FLG1 0x2000C8f1 | | // |
| #define SHARED_SETTINGS_ACC_TURN 0x2000C8f2 | // |
#define SETTINGS_LOCK_FLAG0 (*((volatile uint8_t*)SHARED_SETTINGS_ACC_FLG0))
#define SETTINGS_LOCK_FLAG1 (*((volatile uint8_t*)SHARED_SETTINGS_ACC_FLG1))
#define SETTINGS_LOCK_TURN (*((volatile uint8_t*)SHARED_SETTINGS_ACC_TURN))
static inline void SETTINGS_LOCK_ENTER()
{
#ifdef CORE_M4
ASSERT(SETTINGS_LOCK_FLAG0==false);
SETTINGS_LOCK_FLAG0 = true;
SETTINGS_LOCK_TURN = 1;
while (SETTINGS_LOCK_FLAG1 && SETTINGS_LOCK_TURN == 1)
vTaskDelay(1);
#else
ASSERT(SETTINGS_LOCK_FLAG1==false);
SETTINGS_LOCK_FLAG1 = true;
SETTINGS_LOCK_TURN = 0;
while (SETTINGS_LOCK_FLAG0 && SETTINGS_LOCK_TURN == 0)
vTaskDelay(1);
#endif
}
static inline void SETTINGS_LOCK_EXIT()
{
#ifdef CORE_M4
SETTINGS_LOCK_FLAG0 = false;
#else
SETTINGS_LOCK_FLAG1 = false;
#endif
}
Also, inside each core there's a FreeRTOS semaphore implementation to serialize tasks accesses.
I hope I have made more clear how I split the job on LPC4350 and why I reached SRAM out of memory on M0 code.
I could exchange 128KB M4 memory with 72KB M0 memory so I can have some more space on M0, since under M4 I didn't have any single problem to move data/code to any memory place.
Has I told before, I was surprised that this didn't work the same on M0: I was able to split functions/data as I wanted but there' s some bug there and wrong initialization of DATA happens doing so.
Massimo, if you need other detailed descriptions of code or memory configuration please tell me.
Thank you in advance