I got side-tracked discovering how to get Nordic's Open Bootloader working on the Nano 33 BLE, although I do know that Arduino's version of bossac is an option as well.
The best solution I've found is to use Nordic's drivers as per the following Nordic "pin_change_int" example:
/**
* Copyright (c) 2014 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
* @defgroup pin_change_int_example_main main.c
* @{
* @ingroup pin_change_int_example
* @brief Pin Change Interrupt Example Application main file.
*
* This file contains the source code for a sample application using interrupts triggered by GPIO pins.
*
*/
#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#ifdef BSP_BUTTON_0
#define PIN_IN 43 // BSP_BUTTON_0
#endif
#ifndef PIN_IN
#error "Please indicate input pin"
#endif
#ifdef BSP_LED_0
#define PIN_OUT 41 // BSP_LED_0
#endif
#ifndef PIN_OUT
#error "Please indicate output pin"
#endif
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_drv_gpiote_out_toggle(PIN_OUT);
}
/**
* @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
* and configures GPIOTE to give an interrupt on pin change.
*/
static void gpio_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
/**
* @brief Function for application main entry.
*/
int main(void)
{
gpio_init();
while (true)
{
// Do nothing.
}
}
/** @} */
I've tested this example exactly as it is, apart from that I've changed the input pin and LED to be as I require for my receiving Nano 33 BLE. I'm using Segger Embedded Studio to program (via my nRF52840-DK) my Nano boards via their debug interface.
I did try continuing with setting the registers directly as much as possible, but I've found that certain things don't work (at least not when starting via the SES pre-built example projects/settings that I've tried).
For example, the following doesn't configure and set the input pin to logic high...
// Configure PIN_GPIO as input
// ---------------------------
NRF_GPIO->PIN_CNF[PIN_GPIO] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
But the following (which I copied from nrf_gpio_cfg(...) within nrf_gpio.h, substituted the relevant values directly into the nrf_gpio_cgf(...) function, and then added it to main()) does set the pin...
NRF_GPIO_Type *reg = nrf_gpio_pin_port_decode(&BUTTON_GPIO);
reg->PIN_CNF[BUTTON_GPIO] =
((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) |
((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) |
((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) |
((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
But then the following doesn't work (i.e., always returns 0 or 1, but I can't remember which) nrf_gpio_pin_read(BUTTON_GPIO).
So, by using: nrf_gpio_cfg_input(BUTTON_GPIO, NRF_GPIO_PIN_PULLUP) instead, it does then indeed work (Segger Embedded Studio is absolutely awesome for hoping through function calls across different files by mouse-right-click options).
Incidentally, from searching via SES, I noticed that the previously mentioned: nrf_gpio_cfg(...) is called from: nrf_gpio_cfg_input(...)'s definition.
Incidentally, from the above "pin_change_int" example...
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler)
"nrf_drv_gpiote_in_init(...)" leads to: "nrfx_gpiote_in_init(...)" which uses: nrf_gpio_cfg_input(...)
However, although I was now able to send PPM from one board to another in demo/slow mode, making the receiving board LED blink exactly synchronised: GPIOTE_IRQHandler() wasn't getting called (but at least the receiving board doesn't crash). Incidentally, ultimately I might not need to use the GPIOTE handler, although it'll probably be best to, and in any case it's useful to know about for the future.
Then I was led to discovering the following as quoted below...
"Why don't you use the driver. You cannot implement GPIOTE_IRQHandler if you include nrf_drv_gpiote, and I do not recommend to modify the GPIOTE_IRQHandler in nrf_drv_gpiote.".
And: #include "nrf_gpio.h", has: #include <nrfx.h>, which has: nrf_drv_gpiote.h, which is within: ...integration/nrfx/legacy
Anyway, I'm tempted to ask questions about all this on DevZone, but maybe not. Probably just using their SDK's functions is best, and they have indeed worked perfectly for me so far.
Cheers!