There is a slight inconsistency here with UART which has the pins defined in syscfg.yml, whereas other peripherals are defined directly in hal_bsp.c:

    UART_0:
        description: 'TBD'
        value:  1
    UART_0_PIN_TX:
        description: 'TBD'
        value:  6
    UART_0_PIN_RX:
        description: 'TBD'
        value:  8
    UART_0_PIN_RTS:
        description: 'TBD'
        value:  0
    UART_0_PIN_CTS:
        description: 'TBD'
        value: 0

There may well be reason(s) for this, but it might be easier to maintain to have everything in the .c file unless I'm missing something (entirely possible).


On 06/12/16 22:35, will sanfilippo wrote:
I think the issue here is when folks are using the nordic SDK as well as our 
HAL. The idea was that pin configurations would be in hal_bsp.c; nowhere else. 
When we moved out the nordic SDK, pin definitions from nrf_drv_config.h were 
moved into pkg.yml. This made for some conflicts.

I have an idea but not sure it is a good one. I will use the twi interface as 
an example; I think the rest of the nordic SDK is similar. Sorry to be 
“pedantic” here; but you know me :-)

Users can setup their own config structures and pass that config into the 
nordic SDK initialization. For example:

Here is the initialization function for twi. Note the *p_config structure:

ret_code_t nrf_drv_twi_init(nrf_drv_twi_t const *p_instance,
                                            nrf_drv_twi_config_t const 
*p_config,
                                            nrf_drv_twi_evt_handler_t    
event_handler,
                                            void *p_context)


Here is the structure:
/**
  * @brief Structure for the TWI master driver instance configuration.
  */
typedef struct
{
     uint32_t            scl;   ///< SCL pin number.
     uint32_t            sda;   ///< SDA pin number.
     nrf_twi_frequency_t frequency; ///< TWI frequency.
     uint8_t             interrupt_priority;  ///< Interrupt priority.

} nrf_drv_twi_config_t;

In hal_bsp.c, someone would create this structure with pin defintions just like 
we do for our HAL and thus all pin defintions would be in hal_bsp.c. They then 
pass this structure in the init call. No more pin definitions in pkg.yml.

Another option which has been mentioned by others is to have a header file that 
contains all the pin definitions and this can be in the bsp. These definitions 
can be the same as the ones in nrf_drv_config.h or they can be user defined. My 
preference is to have them user-defined.

Hopefully this makes sense...

Will


On Dec 6, 2016, at 12:33 PM, Kevin Townsend <ke...@adafruit.com> wrote:

Hi,

I was trying to test out an I2C chip with a previously working driver to verify 
the HW, but it isn't clear anymore where to set pins (post Nordic SDK removal). 
I couldn't get I2C to work after tweaking the pkg.yml file which has a lot of 
pin defines, for example:

    - '-DTWI0_CONFIG_SCL=26'
    - '-DTWI0_CONFIG_SDA=25'

After triple checking plus resolving some conflicts where master and slave of 
the same bus types were set (in pkg.yml), etc., I looked at the hal_bsp.c file 
and see they are also hard coded there:

#if MYNEWT_VAL(I2C_0)
static const struct nrf52_hal_i2c_cfg hal_i2c_cfg = {
    .scl_pin = 27,
    .sda_pin = 26,
    .i2c_frequency = 100    /* 100 kHz */
};
#endif

It might be easier to make the hal_bsp.c here use the values from pkg.yml, or 
any solution really not to have two defines?

* 
https://github.com/apache/incubator-mynewt-core/blob/master/hw/bsp/nrf52dk/src/hal_bsp.c#L79
* 
https://github.com/apache/incubator-mynewt-core/blob/master/hw/bsp/nrf52dk/pkg.yml#L72

There are some conflicts as well like I'm guessing this isn't possible together?

* 
https://github.com/apache/incubator-mynewt-core/blob/master/hw/bsp/nrf52dk/pkg.yml#L74
* 
https://github.com/apache/incubator-mynewt-core/blob/master/hw/bsp/nrf52dk/pkg.yml#L76

Not trying to be a PITA ... but it was a bit confusing changing pins but not 
seeing the results. :)

I can send in a pull request as well if that's easier, but maybe other people 
here have a better idea of where you want all the pins defines to be between 
the .c file, syscfg.yml and pkg.yml?

I just couldn't get I2C to work, for example with this scanner I put together 
which worked fine previously:

static int
shell_i2cscan_cmd(int argc, char **argv)
{
    uint8_t addr;
    int32_t timeout = OS_TICKS_PER_SEC / 10;
    uint8_t dev_count = 0;

    console_printf("Scanning I2C bus 0\n"
                   "     0  1  2  3  4  5  6  7  8  9  a  b  c  d e  f\n"
                   "00:          ");

    /* Scan all valid I2C addresses (0x03..0x77) */
    for (addr = 0x03; addr < 0x78; addr++) {
        int rc = hal_i2c_master_probe(0, addr, timeout);
        /* Print addr header every 16 bytes */
        if (!(addr % 16)) {
          console_printf("\n%02x: ", addr);
        }
        /* Display the addr if a response was received */
        if (!rc) {
            console_printf("%02x ", addr);
            dev_count++;
        } else {
            console_printf("-- ");
        }
    }
    console_printf("\nFound %u devices on I2C bus 0\n", dev_count);

    return 0;
}

Kevin


Reply via email to