nRF52840 pin addressing

As part of efforts for providing MicroPython support, we are specifying the pin definitions for the Arduino Nano 33 BLE Sense. This Arduino board, is based upon the nRF52840 chip with the open source schematics available here.

We have a preliminary PR here, for updating the pin bindings.

Based on third party (Zephyr) documentation, it is stated that

Translate the ‘Pin’ into number for devicetree by using the following formula:

pin_no = b*32 + a

where a and b are from the Pin value in the table (Pb.a). For example, for P0.1, pin_no = 1 and for P1.0, pin_no = 32.

Figure 43 in section 6.9 of the nRF52840 Product Specification document shows PIN0 as an example. Yet, I do not find any official mention of how the GPIO pins, convert into `PIN#`.

...

To ensure that the MicroPython support of our nRF52840-based product is reliable, could you kindly provide a reference for this inside the official documentation for the nRF52840 or at least a confirmation that the statement above is accurate? 

  • Hi,

    From a chip perspective, the firmware should always refer to the Px.xx GPIO numbers (for digital pins). The physical pin naming can differ between package type and board.

    In nRF52840, there are two GPIO ports (P0 and P1, each with its own base address).

    All digital peripherals where you can assign pins use 6 bits for port and pin, where the port is the 6th bit (1<<5), see for instance SPIM, UARTE and PWM.

    How you interface with the GPIOs determine how you should reference this from the firmware. Our GPIO HAL functions provides a macro function to define pins, NRF_GPIO_PIN_MAP(port, pin) that handles conversion to correct port (adding 32 to the pin number for port1, similar to the description in your linked Zephyr documentation). When the GPIO HAL APIs are used to control GPIOs, the port number is decoded to interface the correct port base address. If you are interfacing everything through nrfx APIs, it should be safe to use this for GPIO definitions.

    I have no experience with MicroPython, so can't give any specific recommendations for best practice in this environment.

    Best regards,
    Jørgen

Related