From 53371d6a4924e72c0a8a843824e1bb78e42e81eb Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Fri, 26 Jan 2024 16:23:25 -0800 Subject: [PATCH] disable NFC pins --- errors.txt | 32 -------------------------------- libs/core/codal.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 32 deletions(-) delete mode 100644 errors.txt diff --git a/errors.txt b/errors.txt deleted file mode 100644 index 4377269f1d2..00000000000 --- a/errors.txt +++ /dev/null @@ -1,32 +0,0 @@ - 85%] Building CXX object CMakeFiles/MICROBIT.dir/pxtapp/st7735/screen.cpp.obj -/src/pxtapp/st7735/screen.cpp: In constructor 'pxt::WDisplay::WDisplay()': -/src/pxtapp/st7735/screen.cpp:65:38: error: no matching function for call to 'codal::SPIScreenIO::SPIScreenIO(codal::SPI&)' - io = new SPIScreenIO(*spi); - ^ -In file included from /src/pxtapp/st7735/screen.cpp:9:0: -/src/libraries/codal-core/./inc/drivers/SPIScreenIO.h:39:5: -note: candidate: codal::SPIScreenIO::SPIScreenIO(codal::NRF52SPI&) - SPIScreenIO(SPI &spi); - ^~~~~~~~~~~ -/src/libraries/codal-core/./inc/drivers/SPIScreenIO.h:39:5: note: no known conversion for argument 1 from 'codal::SPI' to 'codal::NRF52SPI&' -/src/libraries/codal-core/./inc/drivers/SPIScreenIO.h:35:7: note: candidate: constexpr codal::SPIScreenIO::SPIScreenIO(const codal::SPIScreenIO&) - class SPIScreenIO : public ScreenIO - ^~~~~~~~~~~ -/src/libraries/codal-core/./inc/drivers/SPIScreenIO.h:35:7: note: no known conversion for argument 1 from 'codal::SPI' to 'const codal::SPIScreenIO&' -/src/libraries/codal-core/./inc/drivers/SPIScreenIO.h:35:7: note: -candidate: constexpr codal::SPIScreenIO::SPIScreenIO(codal::SPIScreenIO&&) -/src/libraries/codal-core/./inc/drivers/SPIScreenIO.h:35:7: note: -no known conversion for argument 1 from 'codal::SPI' to 'codal::SPIScreenIO&&' -/src/pxtapp/st7735/screen.cpp:84:86: error: invalid conversion from 'codal::SPI*' to 'codal::NRF52SPI*' [-fpermissive] - - smart = new JDDisplay(spi, LOOKUP_PIN(DISPLAY_CS), LOOKUP_PIN(DISPLAY_DC)); - ^ -In file included from /src/pxtapp/st7735/screen.cpp:11:0: -/src/pxtapp/st7735/jddisplay.h:52:5: note: initializing argument 1 of 'pxt::JDDisplay::JDDisplay(codal::NRF52SPI*, codal::Pin*, codal::Pin*)' - JDDisplay(SPI *spi, Pin *cs, Pin *flow); - ^~~~~~~~~ -make[2]: *** [CMakeFiles/MICROBIT.dir/pxtapp/st7735/screen.cpp.obj] Error 1 -make[1]: *** [CMakeFiles/MICROBIT.dir/all] Error 2 -make: *** [all] Error 2 - - diff --git a/libs/core/codal.cpp b/libs/core/codal.cpp index 70275c4b5ec..d75f434cdc8 100644 --- a/libs/core/codal.cpp +++ b/libs/core/codal.cpp @@ -49,11 +49,49 @@ MicroBit uBit; MicroBitEvent lastEvent; bool serialLoggingDisabled; +#if defined(NRF52840) || defined(NRF52833) +#define IS_3_3_V() ((NRF_UICR->REGOUT0 & 7) == 5) +#else +#define IS_3_3_V() 1 +#endif + +static void disableNFConPins() { + // Ensure NFC pins are configured as GPIO. If not, update the non-volatile UICR. + if (NRF_UICR->NFCPINS || !IS_3_3_V()) { + DMESG("RESET UICR\n"); + // Enable Flash Writes + NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos); + while (NRF_NVMC->READY == NVMC_READY_READY_Busy) + ; + + // Configure PINS for GPIO use. + if (NRF_UICR->NFCPINS) + NRF_UICR->NFCPINS = 0; + +#if defined(NRF52840) || defined(NRF52833) + // Set VDD to 3.3V + if ((NRF_UICR->REGOUT0 & 7) != 5) + NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~7) | 5; +#endif + + // Disable Flash Writes + NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos); + while (NRF_NVMC->READY == NVMC_READY_READY_Busy) + ; + + // Reset, so the changes can take effect. + NVIC_SystemReset(); + } +} + void platform_init() { microbit_seed_random(); int seed = microbit_random(0x7fffffff); DMESG("random seed: %d", seed); seedRandom(seed); + + // not working here, try in CODAL + // disableNFConPins(); } void initMicrobitGC() {