Debian Codegraph @

ports/nrf/boards/ARDUINO_NANO_33_BLE_SENSE/board.c

raw
1 /*
2 * This file is part of the MicroPython project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2022 Arduino SA
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27 #include "nrf.h"
28 #include "nrf_gpio.h"
29 #include "nrf_rtc.h"
30
31 #define PIN_ENABLE_SENSORS_3V3 (22u)
32 #define PIN_ENABLE_I2C_PULLUP (32u)
33 #define DFU_MAGIC_SERIAL_ONLY_RESET (0xb0)
34
35 void NANO33_board_early_init(void) {
36 // Errata Nano33BLE - I2C pullup is on SWO line, need to disable TRACE
37 // was being enabled by nrfx_clock_anomaly_132
38 CoreDebug->DEMCR = 0;
39 NRF_CLOCK->TRACECONFIG = 0;
40
41 // Bootloader enables interrupt on COMPARE[0], which we don't handle
42 // Disable it here to avoid getting stuck when OVERFLOW irq is triggered
43 nrf_rtc_event_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK);
44 nrf_rtc_int_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK);
45
46 // Always enable I2C pullup and power on startup
47 // Change for maximum powersave
48 nrf_gpio_cfg_output(PIN_ENABLE_SENSORS_3V3);
49 nrf_gpio_cfg_output(PIN_ENABLE_I2C_PULLUP);
50
51 nrf_gpio_pin_set(PIN_ENABLE_SENSORS_3V3);
52 nrf_gpio_pin_set(PIN_ENABLE_I2C_PULLUP);
53 }
54
55 void NANO33_board_deinit(void) {
56 nrf_gpio_cfg_output(PIN_ENABLE_SENSORS_3V3);
57 nrf_gpio_cfg_output(PIN_ENABLE_I2C_PULLUP);
58
59 nrf_gpio_pin_clear(PIN_ENABLE_SENSORS_3V3);
60 nrf_gpio_pin_clear(PIN_ENABLE_I2C_PULLUP);
61 }
62
63 void NANO33_board_enter_bootloader(void) {
64 __disable_irq();
65 NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL_ONLY_RESET;
66 NVIC_SystemReset();
67 }