Skip to content

Commit

Permalink
Merge pull request #1046 from spark/feature/photon_system_backup
Browse files Browse the repository at this point in the history
photon backup memory
  • Loading branch information
technobly authored Jul 20, 2016
2 parents 28fea92 + ddf9063 commit de15a24
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ SECTIONS
link_stack_end = .;
}> SRAM AT> SRAM

INCLUDE backup_ram_system.ld
INCLUDE backup_ram_user.ld
INCLUDE backup_ram_system.ld

/DISCARD/ :
{
Expand Down
2 changes: 2 additions & 0 deletions modules/photon/system-part2/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ MEMORY
The value given here is the sum of system_static_ram_size and stack_size
*/
SRAM (rwx) : ORIGIN = 0x20020000 - 42K, LENGTH = 42K

INCLUDE backup_ram_memory.ld
}


Expand Down
26 changes: 16 additions & 10 deletions user/tests/app/backup_ram/backup_ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@
*/
#include "application.h"

retained int variable = 10;
retained int app_backup = 10;
int app_ram = 10;

STARTUP(System.disableFeature(FEATURE_RETAINED_MEMORY));

void setup()
{
System.enableFeature(FEATURE_RETAINED_MEMORY);
Serial.begin(9600);
while (!Serial.available()) Particle.process();
Serial.begin(9600);
while (!Serial.available()) Particle.process();

if (int(&app_backup) < 0x40024000) {
Serial.printlnf("ERROR: expected app_backup in backup memory, but was at %x", &app_backup);
}

if (int(&variable) < 0x30000000) {
Serial.printlnf("ERROR: expected variable in backup memory, but was at %x", &variable);
return;
}
if (int(&app_ram) >= 0x40024000) {
Serial.printlnf("ERROR: expected app_ram in sram memory, but was at %x", &app_ram);
}

Serial.println(variable);
variable++;
Serial.printlnf("app_backup(%x):%d, app_ram(%x):%d", &app_backup, app_backup, &app_ram, app_ram);
app_backup++;
app_ram++;
}
22 changes: 22 additions & 0 deletions user/tests/wiring/api/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,25 @@ test(system_flags)
API_COMPILE(System.disable(SYSTEM_FLAG_MAX));
API_COMPILE(System.enabled(SYSTEM_FLAG_MAX));
}

// todo - use platform feature flags
#if defined(STM32F2XX)
// subtract 4 bytes for signature (3068 bytes)
#define USER_BACKUP_RAM ((1024*3)-4)
#endif // defined(STM32F2XX)

#if defined(USER_BACKUP_RAM)
static retained uint8_t app_backup[USER_BACKUP_RAM];

test(backup_ram)
{
// Not designed to be run!
// only here to prevent compiler from optimizing out the app_backup array.
int total = 0;
for (unsigned i=0; i<sizeof(app_backup); i++) {
total += app_backup[i]; // 8 bytes for the
}
Serial.println(total);
}

#endif // defined(USER_BACKUP_RAM)
45 changes: 43 additions & 2 deletions user/tests/wiring/no_fixture/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


#if PLATFORM_ID >= 3
test(System_FreeMemory)
test(SYSTEM_01_freeMemory)
{
// this test didn't work on the core attempting to allocate the current value of
// freeMemory(), presumably because of fragmented heap from
Expand All @@ -22,7 +22,7 @@ test(System_FreeMemory)
}
#endif

test(system_version)
test(SYSTEM_02_version)
{
uint32_t versionNumber = System.versionNumber();
// Serial.println(System.versionNumber()); // 328193 -> 0x00050201
Expand All @@ -35,3 +35,44 @@ test(system_version)

assertTrue(strcmp(expected,System.version().c_str())==0);
}

// todo - use platform feature flags
#if defined(STM32F2XX)
// subtract 4 bytes for signature (3068 bytes)
#define USER_BACKUP_RAM ((1024*3)-4)
#endif // defined(STM32F2XX)

#if defined(USER_BACKUP_RAM)

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

static retained uint8_t app_backup[USER_BACKUP_RAM];
static uint8_t app_ram[USER_BACKUP_RAM];

test(SYSTEM_03_user_backup_ram)
{
int total_backup = 0;
int total_ram = 0;
for (unsigned i=0; i<(sizeof(app_backup)/sizeof(app_backup[0])); i++) {
app_backup[i] = 1;
app_ram[i] = 1;
total_backup += app_backup[i];
total_ram += app_ram[i];
}
// Serial.printlnf("app_backup(0x%x), app_ram(0x%x)", &app_backup, &app_ram);
// Serial.printlnf("total_backup: %d, total_ram: %d", total_backup, total_ram);
assertTrue(total_backup==(USER_BACKUP_RAM));
assertTrue(total_ram==(USER_BACKUP_RAM));

if (int(&app_backup) < 0x40024000) {
Serial.printlnf("ERROR: expected app_backup in user backup memory, but was at %x", &app_backup);
}
assertTrue(int(&app_backup)>=0x40024000);

if (int(&app_ram) >= 0x40024000) {
Serial.printlnf("ERROR: expected app_ram in user sram memory, but was at %x", &app_ram);
}
assertTrue(int(&app_ram)<0x40024000);
}

#endif // defined(USER_BACKUP_RAM)

0 comments on commit de15a24

Please sign in to comment.