Skip to content

Commit

Permalink
Bangle.js2: In flash bootloader, don't store flash write code in RAM …
Browse files Browse the repository at this point in the history
…(no need) (fix #2458)
  • Loading branch information
gfwilliams committed Jan 29, 2024
1 parent bb241ae commit 1a0b38e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Automatic decoding and pretokenisation of 'atob(".....")' strings
Pull out pretokenisation on SAVE_ON_FLASH boards (pretokenised code can be executed, it's just not tokenised in Espruino - saves 1kb)
Bangle.js: Fix out of bounds coordinates in LCD code that caused screen corruption on newer GCC builds (#2455)
Bangle.js2: In flash bootloader, don't store flash write code in RAM (no need) (fix #2458)

2v20 : Ensure String.charCodeAt returns NaN for out of bounds chars
Bangle.js2: When rendering overlays, *do not* use the current FG/BG color for 1 bit overlays
Expand Down
28 changes: 15 additions & 13 deletions targets/nrf5x_dfu/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct {
#endif

/// Read data while sending 0
__attribute__( ( long_call, section(".data") ) ) static void spiFlashRead(unsigned char *rx, unsigned int len) {
static void spiFlashRead(unsigned char *rx, unsigned int len) {
NRF_GPIO_PIN_CLEAR_FAST((uint32_t)pinInfo[SPIFLASH_PIN_MOSI].pin);
for (unsigned int i=0;i<len;i++) {
int result = 0;
Expand All @@ -58,7 +58,7 @@ __attribute__( ( long_call, section(".data") ) ) static void spiFlashRead(unsign
}
}

__attribute__( ( long_call, section(".data") ) ) static void spiFlashWrite(unsigned char *tx, unsigned int len) {
static void spiFlashWrite(unsigned char *tx, unsigned int len) {
for (unsigned int i=0;i<len;i++) {
int data = tx[i];
for (int bit=7;bit>=0;bit--) {
Expand All @@ -69,13 +69,13 @@ __attribute__( ( long_call, section(".data") ) ) static void spiFlashWrite(unsig
}
}

__attribute__( ( long_call, section(".data") ) ) static void spiFlashWriteCS(unsigned char *tx, unsigned int len) {
static void spiFlashWriteCS(unsigned char *tx, unsigned int len) {
NRF_GPIO_PIN_CLEAR_FAST((uint32_t)pinInfo[SPIFLASH_PIN_CS].pin);
spiFlashWrite(tx,len);
NRF_GPIO_PIN_SET_FAST((uint32_t)pinInfo[SPIFLASH_PIN_CS].pin);
}

__attribute__( ( long_call, section(".data") ) ) static unsigned char spiFlashStatus() {
static unsigned char spiFlashStatus() {
unsigned char buf = 5;
NRF_GPIO_PIN_CLEAR_FAST((uint32_t)pinInfo[SPIFLASH_PIN_CS].pin);
spiFlashWrite(&buf, 1);
Expand Down Expand Up @@ -121,7 +121,7 @@ void spiFlashInit() {
flashWakeUp();
flashWakeUp();
flashWakeUp();
#endif
#endif
// disable block protect 0/1/2
unsigned char buf[2];
int tries = 3;
Expand All @@ -145,7 +145,7 @@ void spiFlashInit() {
jshDelayMicroseconds(100000);
}

__attribute__( ( long_call, section(".data") ) ) void spiFlashReadAddr(unsigned char *buf, uint32_t addr, uint32_t len) {
void spiFlashReadAddr(unsigned char *buf, uint32_t addr, uint32_t len) {
unsigned char b[4];
// Read
b[0] = 0x03;
Expand All @@ -158,7 +158,7 @@ __attribute__( ( long_call, section(".data") ) ) void spiFlashReadAddr(unsigned
NRF_GPIO_PIN_SET_FAST((uint32_t)pinInfo[SPIFLASH_PIN_CS].pin);
}

__attribute__( ( long_call, section(".data") ) ) void intFlashErase(uint32_t addr) {
void intFlashErase(uint32_t addr) {
NRF_NVMC->CONFIG = 2;
while(!NRF_NVMC->READY);
NRF_NVMC->ERASEPAGE = addr;
Expand All @@ -167,7 +167,7 @@ __attribute__( ( long_call, section(".data") ) ) void intFlashErase(uint32_t add
while(!NRF_NVMC->READY);
}

__attribute__( ( long_call, section(".data") ) ) void intFlashWrite(uint32_t addr, unsigned char *data, uint32_t len) {
void intFlashWrite(uint32_t addr, unsigned char *data, uint32_t len) {
while (len) {
NRF_NVMC->CONFIG = 1;
while(!NRF_NVMC->READY);
Expand Down Expand Up @@ -212,7 +212,7 @@ bool flashEqual(FlashHeader header, uint32_t addr) {

#if defined(LCD_CONTROLLER_GC9A01)
// LCD output for generic SPI LCDs
__attribute__( ( long_call, section(".data") ) ) void xlcd_wr(int data) {
void xlcd_wr(int data) {
for (int bit=7;bit>=0;bit--) {
NRF_GPIO_PIN_WRITE_FAST(LCD_SPI_SCK, 0 );
NRF_GPIO_PIN_WRITE_FAST(LCD_SPI_MOSI, ((data>>bit)&1) );
Expand All @@ -221,7 +221,7 @@ __attribute__( ( long_call, section(".data") ) ) void xlcd_wr(int data) {
}
#endif

__attribute__( ( long_call, section(".data") ) ) void xlcd_rect(int x1,int y1, int x2, int y2, bool white) {
void xlcd_rect(int x1,int y1, int x2, int y2, bool white) {
#if defined(LCD_CONTROLLER_GC9A01)
NRF_GPIO_PIN_WRITE_FAST(LCD_SPI_DC, 0); // command
NRF_GPIO_PIN_WRITE_FAST(LCD_SPI_CS, 0);
Expand Down Expand Up @@ -258,7 +258,7 @@ __attribute__( ( long_call, section(".data") ) ) void xlcd_rect(int x1,int y1, i
#endif
}

__attribute__( ( long_call, section(".data") ) ) void flashDoUpdate(FlashHeader header, uint32_t headerAddr) {
void flashDoUpdate(FlashHeader header, uint32_t headerAddr) {
unsigned char buf[256];
int size, addr;

Expand Down Expand Up @@ -368,7 +368,9 @@ void flashCheckFile(uint32_t fileAddr) {
lcd_print_hex(header.size); lcd_println(" SIZE");
lcd_print_hex(header.CRC); lcd_println(" CRC");
lcd_print_hex(header.version); lcd_println(" VERSION");
if (header.address==0xf7000) return; // NO BOOTLOADER - FOR TESTING
/* NO BOOTLOADER UPDATES ALLOWED as we'd be overwriting ourself.
It would brick the device */
if (header.address>=0xf7000 || ((header.address+header.size)>0xf7000)) return;
// Calculate CRC
lcd_println("CRC TEST...");
unsigned char buf[256];
Expand Down Expand Up @@ -468,7 +470,7 @@ void flashCheckAndRun() {

// Put the SPI Flash into deep power-down mode
void flashPowerDown() {
spiFlashInit(); //
spiFlashInit(); //
unsigned char buf = 0xB9; // SPI Flash deep power-down
spiFlashWriteCS(&buf,1);
nrf_delay_us(2); // Wait at least 1us for Flash IC to enter deep power-down
Expand Down

0 comments on commit 1a0b38e

Please sign in to comment.