Skip to content

Commit

Permalink
Guess SRAM size from program initial SP
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Dec 18, 2024
1 parent 211b750 commit 3a9fad7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pinetime.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pinetime.h"

#include "byte_util.h"
#include "components/i2c/bma425.h"
#include "components/i2c/cst816s.h"
#include "components/i2c/hrs3300.h"
Expand All @@ -22,12 +23,14 @@ pinetime_t *pinetime_new(const program_t *program)
uint32_t initial_sp;
program_write_to(program, (uint8_t *)&initial_sp, sizeof(initial_sp));

size_t sram_size;
if (initial_sp > 0x20010000)
sram_size = 512 * 1024;
else
printf("Initial SP: 0x%08x\n", initial_sp);

size_t sram_size = initial_sp - x(2000, 0000);
if (sram_size < NRF52832_SRAM_SIZE)
sram_size = NRF52832_SRAM_SIZE;

printf("SRAM size: %ld bytes\n", sram_size);

pinetime_t *pt = malloc(sizeof(pinetime_t));
pt->state_store = state_store_new();
pt->nrf = nrf52832_new(program, sram_size, pt->state_store);
Expand Down

0 comments on commit 3a9fad7

Please sign in to comment.