forked from wasp-os/wasp-reloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many PineTime payloads (currently including mcuboot) are broken if booted with the spinor in deep powerdown. Let's wake the spinor during reloading to avoid bugs when switching from a firmware with power down support to one without. The changes here are suprisingly large because we have to refactor the existing spi code to untangle it from the st7789 driver. Signed-off-by: Daniel Thompson <[email protected]>
- Loading branch information
1 parent
819713d
commit cdd5e76
Showing
10 changed files
with
167 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.*.swp | ||
build-*/ | ||
src/boards/*/bootloader.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* Copyright (C) 2020 Daniel Thompson | ||
*/ | ||
|
||
#include "spi.h" | ||
|
||
#include <nrf_gpio.h> | ||
#include <nrf_spi.h> | ||
|
||
#define SPIx NRF_SPI0 | ||
#define SPI_MODE NRF_SPI_MODE_3 | ||
#define SPI_SCK 2 | ||
#define SPI_MOSI 3 | ||
|
||
void spi_init(void) | ||
{ | ||
nrf_gpio_pin_write(SPI_SCK, SPI_MODE >= 2); | ||
nrf_gpio_cfg(SPI_SCK, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT, | ||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE); | ||
nrf_gpio_pin_clear(SPI_MOSI); | ||
nrf_gpio_cfg_output(SPI_MOSI); | ||
|
||
|
||
nrf_spi_pins_set(SPIx, SPI_SCK, SPI_MOSI, NRF_SPI_PIN_NOT_CONNECTED); | ||
nrf_spi_frequency_set(SPIx, NRF_SPI_FREQ_8M); | ||
nrf_spi_configure(SPIx, SPI_MODE, NRF_SPI_BIT_ORDER_MSB_FIRST); | ||
|
||
nrf_spi_enable(SPIx); | ||
} | ||
|
||
void spi_teardown(void) | ||
{ | ||
/* no need to tear down SCK and MOSI - output pins can be left alone */ | ||
nrf_spi_event_clear(SPIx, NRF_SPI_EVENT_READY); | ||
nrf_spi_disable(SPIx); | ||
nrf_gpio_cfg_default(SPI_MOSI); | ||
nrf_gpio_cfg_default(SPI_SCK); | ||
} | ||
|
||
void spi_write(const uint8_t *data, unsigned len) | ||
{ | ||
const uint8_t *endp = data + len; | ||
|
||
/* paranoid... but worthwhile due to the havoc this could cause */ | ||
nrf_spi_event_clear(SPIx, NRF_SPI_EVENT_READY); | ||
|
||
/* send first character */ | ||
nrf_spi_txd_set(SPIx, *data++); | ||
|
||
/* TXD is double buffers so we can xmit and then poll for the event */ | ||
while (data < endp) { | ||
nrf_spi_txd_set(SPIx, *data++); | ||
|
||
while (!nrf_spi_event_check(SPIx, NRF_SPI_EVENT_READY)) {} | ||
nrf_spi_event_clear(SPIx, NRF_SPI_EVENT_READY); | ||
(void) nrf_spi_rxd_get(SPIx); | ||
} | ||
|
||
/* wait for the final character */ | ||
while (!nrf_spi_event_check(SPIx, NRF_SPI_EVENT_READY)) {} | ||
nrf_spi_event_clear(SPIx, NRF_SPI_EVENT_READY); | ||
(void) nrf_spi_rxd_get(SPIx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* Copyright (C) 2020 Daniel Thompson | ||
*/ | ||
|
||
#ifndef RELOADER_SPI_H__ | ||
#define RELOADER_SPI_H__ | ||
|
||
#include <stdint.h> | ||
|
||
void spi_init(void); | ||
void spi_teardown(void); | ||
void spi_write(const uint8_t *data, unsigned len); | ||
|
||
#endif /* RELOADER_SPI_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* Copyright (C) 2020 Daniel Thompson | ||
*/ | ||
|
||
#include "spinor.h" | ||
|
||
#include <nrf_gpio.h> | ||
|
||
#include "board.h" | ||
#include "spi.h" | ||
|
||
#ifdef CONFIG_HAVE_SPINOR | ||
|
||
uint32_t spinor_page_size_get(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
int spinor_page_erase(uint32_t addr) | ||
{ | ||
return -1; | ||
} | ||
|
||
void spinor_word_write(uint32_t addr, uint32_t value) | ||
{ | ||
} | ||
|
||
void spinor_preinit(void) | ||
{ | ||
nrf_gpio_pin_set(CONFIG_SPINOR_CS); | ||
nrf_gpio_cfg_output(CONFIG_SPINOR_CS); | ||
} | ||
|
||
void spinor_init(void) | ||
{ | ||
/* release deep power-down (RDP) */ | ||
nrf_gpio_pin_clear(CONFIG_SPINOR_CS); | ||
spi_write((const uint8_t*) "\xab", 1); | ||
nrf_gpio_pin_set(CONFIG_SPINOR_CS); | ||
} | ||
|
||
#endif /* CONFIG_HAVE_SPINOR */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* Copyright (C) 2020 Daniel Thompson | ||
*/ | ||
|
||
#ifndef RELOADER_SPINOR_H__ | ||
#define RELOADER_SPINOR_H__ | ||
|
||
#include <stdint.h> | ||
|
||
uint32_t spinor_page_size_get(void); | ||
int spinor_page_erase(uint32_t addr); | ||
void spinor_word_write(uint32_t addr, uint32_t value); | ||
void spinor_preinit(void); | ||
void spinor_init(void); | ||
|
||
#endif /* RELOADER_SPINOR_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters