diff --git a/model/MicroBit.cpp b/model/MicroBit.cpp index b2c61405..49610b69 100644 --- a/model/MicroBit.cpp +++ b/model/MicroBit.cpp @@ -47,6 +47,60 @@ static const uint32_t reflash_status = 0xffffffff; static volatile MicroBitNoInitMemoryRegion __attribute__ ((section (".noinit"))) microbit_no_init_memory_region; +#define IS_3_3_V() ((NRF_UICR->REGOUT0 & 7) == 5) + +NFConPins::NFConPins() { + DMESG("disableNFConPins\n"); + // 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; + + // Set VDD to 3.3V + if ((NRF_UICR->REGOUT0 & 7) != 5) + NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~7) | 5; + + // 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(); + } +} + + /* + // Ensure NFC pins are configured as GPIO. If not, update the non-volatile UICR. + + + + if (NRF_UICR->NFCPINS) + { + 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. + NRF_UICR->NFCPINS = 0; + + // 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(); + } +*/ + /** * Constructor. * @@ -59,7 +113,7 @@ MicroBit::MicroBit() : bleManager(), ble( &bleManager), #endif - + nfc(), systemTimer(NRF_TIMER1, TIMER1_IRQn), adcTimer(NRF_TIMER2, TIMER2_IRQn), @@ -71,7 +125,8 @@ MicroBit::MicroBit() : io(adc, touchSensor), serial(io.usbTx, io.usbRx, NRF_UARTE0), _i2c(io.sda, io.scl), - i2c(io.P20, io.P19), + i2c(io.sda, io.scl), + // i2c(io.P20, io.P19), power(_i2c, io, systemTimer), flash(_i2c, io, power), internalFlash(MICROBIT_STORAGE_PAGE, 1, MICROBIT_CODEPAGESIZE), @@ -95,27 +150,6 @@ MicroBit::MicroBit() : // Clear our status status = 0; - /* - // Ensure NFC pins are configured as GPIO. If not, update the non-volatile UICR. - if (NRF_UICR->NFCPINS) - { - 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. - NRF_UICR->NFCPINS = 0; - - // 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(); - } - */ - // Configure serial port for debugging //SERIAL_TODO: diff --git a/model/MicroBit.h b/model/MicroBit.h index d5f57883..dc8ec058 100644 --- a/model/MicroBit.h +++ b/model/MicroBit.h @@ -104,6 +104,10 @@ DEALINGS IN THE SOFTWARE. */ namespace codal { + class NFConPins { + public: NFConPins(); + }; + class MicroBit : public MicroBitDevice, public CodalComponent { private: @@ -132,7 +136,7 @@ namespace codal MicroBitBLEManager bleManager; BLEDevice *ble; #endif - + NFConPins nfc; NRFLowLevelTimer systemTimer; NRFLowLevelTimer adcTimer; NRFLowLevelTimer capTouchTimer; diff --git a/target-locked.json b/target-locked.json index b9097603..c4132896 100644 --- a/target-locked.json +++ b/target-locked.json @@ -13,7 +13,7 @@ "CODAL_TIMESTAMP": "uint64_t", "CONFIG_GPIO_AS_PINRESET": 1, "CONFIG_NFCT_PINS_AS_GPIOS": 1, - "DEVICE_BLE": 1, + "DEVICE_BLE": 0, "DEVICE_COMPONENT_COUNT": 60, "DEVICE_DEFAULT_PULLMODE": "PullMode::Down", "DEVICE_DEFAULT_SERIAL_MODE": "SYNC_SLEEP", @@ -26,7 +26,7 @@ "DEVICE_STACK_SIZE": 2048, "DEVICE_TAG": 0, "DEVICE_USB": 0, - "DMESG_SERIAL_DEBUG": 0, + "DMESG_SERIAL_DEBUG": 1, "EVENT_LISTENER_DEFAULT_FLAGS": "MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY", "HARDWARE_NEOPIXEL": 1, "LED_MATRIX_MAXIMUM_BRIGHTNESS": 245, diff --git a/target.json b/target.json index 32981b8b..d078e513 100644 --- a/target.json +++ b/target.json @@ -25,7 +25,7 @@ "DEVICE_COMPONENT_COUNT":60, "DEVICE_DEFAULT_PULLMODE":"PullMode::Down", "DEVICE_PANIC_HEAP_FULL":1, - "DMESG_SERIAL_DEBUG":0, + "DMESG_SERIAL_DEBUG":1, "CODAL_DEBUG":"CODAL_DEBUG_DISABLED", "DEVICE_USB":0, "CODAL_TIMESTAMP":"uint64_t", @@ -42,7 +42,7 @@ "CAPTOUCH_DEFAULT_CALIBRATION" : 3500, "HARDWARE_NEOPIXEL": 1, "CODAL_TIMER_32BIT": 1, - "DEVICE_BLE": 1 + "DEVICE_BLE": 0 }, "definitions":"-DAPP_TIMER_V2 -DAPP_TIMER_V2_RTC1_ENABLED -DNRF_DFU_TRANSPORT_BLE=1 -DNRF52833_XXAA -DNRF52833 -DTARGET_MCU_NRF52833 -DNRF5 -DNRF52833 -D__CORTEX_M4 -DS113 -DTOOLCHAIN_GCC -D__START=target_start",