This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Custom Board Pin Mapping

Hi Nordic Team!

After developing our firmware on the nRF52 HDK, we designed our custom board, and we're starting to write our custom board configuration file.

The main problem I have is that there's no official documentation on how to do this.

From what I gathered around the forum, is that I need to define my custom board file assigning each pin it's function, and then change the board flag on the make file (see here).

On the other hand, there's also the possibility of editing the nrf_drv_config.h file (see here).

Finally, certain pins have to be configured trough their register if they want to be used for GPIO or other peripheral drivers (see here and here).

So my question is, do I have to do all three? Is writing the custom_board enough?

As a reference here's the mapping needed for our board design:

  • GPIO Inputs: P0.00, P0.19, P0.20, P0.26, P0.29 and P0.30
  • GPIO Outputs: P0.13, P0.17, P0.18, P0.21, P0.31
  • Analog Inputs: AIN0, AIN1, AIN2, and AIN3
  • TWI: P0.11(SCL) and P0.12 (SDA)
  • UART: P0.28(TXD), P0.29(RXD), P.027(CTS) and P0.25(RTS)
  • SPI: P0.14(MOSI), P0.15 (MISO) and P0.16 (SCK)
  • PWM: P0.09

Our firmware is based on the nRF52832 using S132 SD and SDK ver 11.0 and we're using a GCC based environment.

Thanks in advance

Parents
  • Hi,

    You are not required to create a custom_board.h, but it is convenient to have all peripheral pin defines in a common file. This also makes it easier to switch between different boards, given that the rest of the source files is setup to use the common defines. There is a short description of how to create the file here, but I would recommend that you start with the pca10040.h board file if you have developed your firmware using the nRF52 DK.

    You can use the defined from custom_board.h in nrf_drv_config.h, for configuration of TWI, UART etc. As the NFC and reset pins have special functions, they have to be configured if you want to use these for general GPIO.

    Best regards,

    Jørgen

  • I would recommend doing something like this:

    pca10040.h/custom_board.h:

    #define TWI0_SCL_PIN             11
    #define TWI0_SDA_PIN             12
    

    nrf_drv_config.h:

    #define TWI0_ENABLED 1
    
    #if (TWI0_ENABLED == 1)
    #define TWI0_USE_EASY_DMA 1
    
    #define TWI0_CONFIG_FREQUENCY    NRF_TWI_FREQ_100K
    #define TWI0_CONFIG_SCL          TWI0_SCL_PIN             
    #define TWI0_CONFIG_SDA          TWI0_SDA_PIN             
    #define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TWI0_INSTANCE_INDEX      0
    #endif
    

    main.c:

    static const nrf_drv_twi_t m_twi0 = NRF_DRV_TWI_INSTANCE(TWI0_INSTANCE_INDEX);
    
    const nrf_drv_twi_config_t twi0_config  = NRF_DRV_TWI_DEFAULT_CONFIG(TWI0_INSTANCE_INDEX);
    
    //   You can also configure pins manually:
    //
    //   const nrf_drv_twi_config_t twi0_config = {
    //      .scl                = 11,
    //      .sda                = 12,
    //      .frequency          = NRF_TWI_FREQ_100K,
    //      .interrupt_priority = APP_IRQ_PRIORITY_HIGH
    //   };
    
    nrf_drv_twi_init(&m_twi0, &twi0_config , twi_handler, NULL);
    
Reply
  • I would recommend doing something like this:

    pca10040.h/custom_board.h:

    #define TWI0_SCL_PIN             11
    #define TWI0_SDA_PIN             12
    

    nrf_drv_config.h:

    #define TWI0_ENABLED 1
    
    #if (TWI0_ENABLED == 1)
    #define TWI0_USE_EASY_DMA 1
    
    #define TWI0_CONFIG_FREQUENCY    NRF_TWI_FREQ_100K
    #define TWI0_CONFIG_SCL          TWI0_SCL_PIN             
    #define TWI0_CONFIG_SDA          TWI0_SDA_PIN             
    #define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
    
    #define TWI0_INSTANCE_INDEX      0
    #endif
    

    main.c:

    static const nrf_drv_twi_t m_twi0 = NRF_DRV_TWI_INSTANCE(TWI0_INSTANCE_INDEX);
    
    const nrf_drv_twi_config_t twi0_config  = NRF_DRV_TWI_DEFAULT_CONFIG(TWI0_INSTANCE_INDEX);
    
    //   You can also configure pins manually:
    //
    //   const nrf_drv_twi_config_t twi0_config = {
    //      .scl                = 11,
    //      .sda                = 12,
    //      .frequency          = NRF_TWI_FREQ_100K,
    //      .interrupt_priority = APP_IRQ_PRIORITY_HIGH
    //   };
    
    nrf_drv_twi_init(&m_twi0, &twi0_config , twi_handler, NULL);
    
Children
No Data
Related