modifying nrf_spim p10056 to a p10056e build


I am having quite a frustrating time trying to make SPI drivers compile into a 52811 project I already started, so I thought I'd back off, and try to just get an SPI example project running (simulated) on the 52840-DK 

Of course there are exactly zero example projects for SPI that are even supplied in the SDK to target 52811 in emulated mode on a 52840-DK (Not a great look...) so I've jumped in to modify nrf_spim for p10056 into p10056e.

now first up, this example uses SPI instance 3 while the 52811 only has instances 0 and 1... so I modified this in the 52840 project, and got that at least compiling... (mod sdk_config.h to target instance 1 and turn off extended features.., them modified main.c to call for instance 0 instead of 3, and not use the dcx version of the transfer function and comment out references to extended features in the peripheral setup... ) all good - that compiles. I also modified the example to use port pins that actually exist on the 52811 (and are the actual pins I want to use on the custom board some day when I'm no longer stuck on such a basic fundamental simple thing as compiling an example project form the SDK for such a simple commonly usef peripheral as SPI)

Then to do the compile target transfer... I tried to follow the project migration instructions from nordic, and think I did OK (discovered a whole pile of things for Segger Embedded Studio project migration that are completely missed in the official migration instructions... like the whole soft FPU, linker heap size, stack size, etc -  but hey at least the differences were in existing projects that had 10056 and 10056e targets available so that was something!) 

But now I'm stuck with some complaint about "BSP_BUTTON_ACTION_LONG_PUSH" not being defined in bsp.c, this is caused because of something called BSP_DEFINES_ONLY being set to 1 somewhere (segger embedded studio "go to definition" function  can't find it, but hey... the compiler and the live code highlighter sure can!), which causes the button action define I'm missing to never be made... BUT different rules in a section of bsp.c cause code that relies on that define to be enabled... hence the fail to compile....  I can go in and modify the preprocessor commands so that the problematic code lines also get killed when the define they are referencing gets killed, but then I get more flow-on errors in bsp.c

And with this, quite frankly, I'm not convinced now that it's even possible to target an SPI example project port to either a real 52811 or an emulated one on the SDK.. at least without some surgery inside the SDK. Which makes me wonder if nordic themselves, letalone anyone else, has even used the SPI peripherals in a 52811 yet... 

So anyway - if you take this attached stuff and drop it into SDK15.3/examples/peripheral/nfx_spim then load up the project with segger embedded studio, you can also have all the fun I'm having... I'd be very happy to see an example of an SPI peripheral master being configured to run on an 82511 (or at least emulated!) if anyone can see something I might have missed? 



main.c
/**
 * Copyright (c) 2017 - 2019, 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.
 *
 */
#include "nrfx_spim.h"
#include "app_util_platform.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "boards.h"
#include "app_error.h"
#include <string.h>
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#define NRFX_SPIM_SCK_PIN  18
#define NRFX_SPIM_MOSI_PIN 14
#define NRFX_SPIM_MISO_PIN 17
#define NRFX_SPIM_SS_PIN   12
//#define NRFX_SPIM_DCX_PIN  30

#define SPI_INSTANCE  0                                           /**< SPI instance index. */
static const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */

static volatile bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */

#define TEST_STRING "Nordic123456789012345678901234567890"
static uint8_t       m_tx_buf[] = TEST_STRING;           /**< TX buffer. */
static uint8_t       m_rx_buf[sizeof(TEST_STRING) + 1];  /**< RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf);        /**< Transfer length. */

void spim_event_handler(nrfx_spim_evt_t const * p_event,
                       void *                  p_context)
{
    spi_xfer_done = true;
    NRF_LOG_INFO("Transfer completed.");
    if (m_rx_buf[0] != 0)
    {
        NRF_LOG_INFO(" Received:");
        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
    }
}

int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, m_length, m_rx_buf, m_length);

    nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
    spi_config.frequency      = NRF_SPIM_FREQ_1M;
    spi_config.ss_pin         = NRFX_SPIM_SS_PIN;
    spi_config.miso_pin       = NRFX_SPIM_MISO_PIN;
    spi_config.mosi_pin       = NRFX_SPIM_MOSI_PIN;
    spi_config.sck_pin        = NRFX_SPIM_SCK_PIN;
    //spi_config.dcx_pin        = NRFX_SPIM_DCX_PIN;
    //spi_config.use_hw_ss      = true;
    spi_config.ss_active_high = false;
    APP_ERROR_CHECK(nrfx_spim_init(&spi, &spi_config, spim_event_handler, NULL));

    NRF_LOG_INFO("NRFX SPIM example started.");

    while (1)
    {
        // Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, m_length);
        spi_xfer_done = false;

        //APP_ERROR_CHECK(nrfx_spim_xfer_dcx(&spi, &xfer_desc, 0, 15));
        APP_ERROR_CHECK(nrfx_spim_xfer(&spi, &xfer_desc, 0));

        while (!spi_xfer_done)
        {
            __WFE();
        }

        NRF_LOG_FLUSH();

        bsp_board_led_invert(BSP_BOARD_LED_0);
        nrf_delay_ms(200);
    }
}
pca10056e.zip


  • FYI... just modified a TWI example project from scratch to work for emulated 52811 on 52840-DK, and had exactly the same problem.  (project needs TWI too, and I wanted a sanity check that i hadn't made a mistake in translating the Segger Embedded Studio project file)

    Also, note that if I continue to hack bsp.c so it at least compiles (putting in the same rules to block out code that depends on that define, as the define has!) the next problem I get is that the linker doesn't link, because I get a multiple definitions of UARTE0_UART0_IRQHandler

    Here's the hacked bsp.c file from the SDK that gets me to the definition collision for the linker, in both the TWI example port I'm trying to do, and the SPI example port I was trying to do yesterday.


    bsp.c
    /**
     * Copyright (c) 2014 - 2019, 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.
     *
     */
    #include "bsp.h"
    #include <stddef.h>
    #include <stdio.h>
    #include "nordic_common.h"
    #include "nrf.h"
    #include "nrf_gpio.h"
    #include "nrf_error.h"
    #include "bsp_config.h"
    #include "boards.h"
    
    #ifndef BSP_SIMPLE
    #include "app_timer.h"
    #include "app_button.h"
    #endif // BSP_SIMPLE
    
    #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
    static bsp_indication_t m_stable_state        = BSP_INDICATE_IDLE;
    static bool             m_leds_clear          = false;
    static uint32_t         m_indication_type     = 0;
    static bool             m_alert_on            = false;
    APP_TIMER_DEF(m_bsp_leds_tmr);
    APP_TIMER_DEF(m_bsp_alert_tmr);
    #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
    
    #if BUTTONS_NUMBER > 0 && !defined(BSP_DEFINES_ONLY) //KH ADDED LAT TOEST TO MATCH HEADER FILE 
    #ifndef BSP_SIMPLE 
    static bsp_event_callback_t   m_registered_callback         = NULL;
    static bsp_button_event_cfg_t m_events_list[BUTTONS_NUMBER] = {{BSP_EVENT_NOTHING, BSP_EVENT_NOTHING}};
    APP_TIMER_DEF(m_bsp_button_tmr);
    static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action);
    #endif // BSP_SIMPLE
    
    #ifndef BSP_SIMPLE
    static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
    {
        #ifdef BSP_BUTTON_0
        {BSP_BUTTON_0, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_0
    
        #ifdef BSP_BUTTON_1
        {BSP_BUTTON_1, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_1
    
        #ifdef BSP_BUTTON_2
        {BSP_BUTTON_2, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_2
    
        #ifdef BSP_BUTTON_3
        {BSP_BUTTON_3, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_3
    
        #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_4
    
        #ifdef BSP_BUTTON_5
        {BSP_BUTTON_5, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_5
    
        #ifdef BSP_BUTTON_6
        {BSP_BUTTON_6, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_6
    
        #ifdef BSP_BUTTON_7
        {BSP_BUTTON_7, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_7
    
    };
    #endif // BSP_SIMPLE
    #endif // BUTTONS_NUMBER > 0
    
    #if (BUTTONS_NUMBER > 0)
    bool bsp_button_is_pressed(uint32_t button)
    {
        if (button < BUTTONS_NUMBER)
        {
            return bsp_board_button_state_get(button);
        }
        else
        {
            //If button is not present always return false
            return false;
        }
    }
    #endif
    
    #if (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) && !defined(BSP_DEFINES_ONLY) //KH ADDED LAT TOEST TO MATCH HEADER FILE 
    /**@brief Function for handling button events.
     *
     * @param[in]   pin_no          The pin number of the button pressed.
     * @param[in]   button_action   Action button.
     */
    static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        bsp_event_t        event  = BSP_EVENT_NOTHING;
        uint32_t           button = 0;
        uint32_t           err_code;
        static uint8_t     current_long_push_pin_no;              /**< Pin number of a currently pushed button, that could become a long push if held long enough. */
        static bsp_event_t release_event_at_push[BUTTONS_NUMBER]; /**< Array of what the release event of each button was last time it was pushed, so that no release event is sent if the event was bound after the push of the button. */
    
        button = bsp_board_pin_to_button_idx(pin_no);
    
        if (button < BUTTONS_NUMBER)
        {
            switch (button_action)
            {
                case APP_BUTTON_PUSH:
                    event = m_events_list[button].push_event;
                    if (m_events_list[button].long_push_event != BSP_EVENT_NOTHING)
                    {
                        err_code = app_timer_start(m_bsp_button_tmr, APP_TIMER_TICKS(BSP_LONG_PUSH_TIMEOUT_MS), (void*)&current_long_push_pin_no);
                        if (err_code == NRF_SUCCESS)
                        {
                            current_long_push_pin_no = pin_no;
                        }
                    }
                    release_event_at_push[button] = m_events_list[button].release_event;
                    break;
                case APP_BUTTON_RELEASE:
                    (void)app_timer_stop(m_bsp_button_tmr);
                    if (release_event_at_push[button] == m_events_list[button].release_event)
                    {
                        event = m_events_list[button].release_event;
                    }
                    break;
                case BSP_BUTTON_ACTION_LONG_PUSH:
                    event = m_events_list[button].long_push_event;
            }
        }
    
        if ((event != BSP_EVENT_NOTHING) && (m_registered_callback != NULL))
        {
            m_registered_callback(event);
        }
    }
    
    /**@brief Handle events from button timer.
     *
     * @param[in]   p_context   parameter registered in timer start function.
     */
    static void button_timer_handler(void * p_context)
    {
        bsp_button_event_handler(*(uint8_t *)p_context, BSP_BUTTON_ACTION_LONG_PUSH);
    }
    
    
    #endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE)
    
    
    #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) 
    static void leds_off(void)
    {
        if (m_alert_on)
        {
            uint32_t i;
            for (i = 0; i < LEDS_NUMBER; i++)
            {
                if (i != BSP_LED_ALERT)
                {
                    bsp_board_led_off(i);
                }
            }
        }
        else
        {
            bsp_board_leds_off();
        }
    }
    
    
    /**@brief       Configure leds to indicate required state.
     * @param[in]   indicate   State to be indicated.
     */
    static uint32_t bsp_led_indication(bsp_indication_t indicate)
    {
        uint32_t err_code   = NRF_SUCCESS;
        uint32_t next_delay = 0;
    
        if (m_leds_clear)
        {
            m_leds_clear = false;
            leds_off();
        }
    
        switch (indicate)
        {
            case BSP_INDICATE_IDLE:
                leds_off();
                err_code       = app_timer_stop(m_bsp_leds_tmr);
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_SCANNING:
            case BSP_INDICATE_ADVERTISING:
                // in advertising blink LED_0
                if (bsp_board_led_state_get(BSP_LED_INDICATE_INDICATE_ADVERTISING))
                {
                    bsp_board_led_off(BSP_LED_INDICATE_INDICATE_ADVERTISING);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING ? ADVERTISING_LED_OFF_INTERVAL :
                                 ADVERTISING_SLOW_LED_OFF_INTERVAL;
                }
                else
                {
                    bsp_board_led_on(BSP_LED_INDICATE_INDICATE_ADVERTISING);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING ? ADVERTISING_LED_ON_INTERVAL :
                                 ADVERTISING_SLOW_LED_ON_INTERVAL;
                }
    
                m_stable_state = indicate;
                err_code       = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL);
                break;
    
            case BSP_INDICATE_ADVERTISING_WHITELIST:
                // in advertising quickly blink LED_0
                if (bsp_board_led_state_get(BSP_LED_INDICATE_ADVERTISING_WHITELIST))
                {
                    bsp_board_led_off(BSP_LED_INDICATE_ADVERTISING_WHITELIST);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING_WHITELIST ?
                                 ADVERTISING_WHITELIST_LED_OFF_INTERVAL :
                                 ADVERTISING_SLOW_LED_OFF_INTERVAL;
                }
                else
                {
                    bsp_board_led_on(BSP_LED_INDICATE_ADVERTISING_WHITELIST);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING_WHITELIST ?
                                 ADVERTISING_WHITELIST_LED_ON_INTERVAL :
                                 ADVERTISING_SLOW_LED_ON_INTERVAL;
                }
                m_stable_state = indicate;
                err_code       = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL);
                break;
    
            case BSP_INDICATE_ADVERTISING_SLOW:
                // in advertising slowly blink LED_0
                if (bsp_board_led_state_get(BSP_LED_INDICATE_ADVERTISING_SLOW))
                {
                    bsp_board_led_off(BSP_LED_INDICATE_ADVERTISING_SLOW);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING_SLOW ? ADVERTISING_SLOW_LED_OFF_INTERVAL :
                                 ADVERTISING_SLOW_LED_OFF_INTERVAL;
                }
                else
                {
                    bsp_board_led_on(BSP_LED_INDICATE_ADVERTISING_SLOW);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING_SLOW ? ADVERTISING_SLOW_LED_ON_INTERVAL :
                                 ADVERTISING_SLOW_LED_ON_INTERVAL;
                }
                m_stable_state = indicate;
                err_code       = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL);
                break;
    
            case BSP_INDICATE_ADVERTISING_DIRECTED:
                // in advertising very quickly blink LED_0
                if (bsp_board_led_state_get(BSP_LED_INDICATE_ADVERTISING_DIRECTED))
                {
                    bsp_board_led_off(BSP_LED_INDICATE_ADVERTISING_DIRECTED);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING_DIRECTED ?
                                 ADVERTISING_DIRECTED_LED_OFF_INTERVAL :
                                 ADVERTISING_SLOW_LED_OFF_INTERVAL;
                }
                else
                {
                    bsp_board_led_on(BSP_LED_INDICATE_ADVERTISING_DIRECTED);
                    next_delay = indicate ==
                                 BSP_INDICATE_ADVERTISING_DIRECTED ?
                                 ADVERTISING_DIRECTED_LED_ON_INTERVAL :
                                 ADVERTISING_SLOW_LED_ON_INTERVAL;
                }
                m_stable_state = indicate;
                err_code       = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(next_delay), NULL);
                break;
    
            case BSP_INDICATE_BONDING:
                // in bonding fast blink LED_0
                bsp_board_led_invert(BSP_LED_INDICATE_BONDING);
    
                m_stable_state = indicate;
                err_code       =
                    app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(BONDING_INTERVAL), NULL);
                break;
    
            case BSP_INDICATE_CONNECTED:
                bsp_board_led_on(BSP_LED_INDICATE_CONNECTED);
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_SENT_OK:
                // when sending shortly invert LED_1
                m_leds_clear = true;
                bsp_board_led_invert(BSP_LED_INDICATE_SENT_OK);
                err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(SENT_OK_INTERVAL), NULL);
                break;
    
            case BSP_INDICATE_SEND_ERROR:
                // on receving error invert LED_1 for long time
                m_leds_clear = true;
                bsp_board_led_invert(BSP_LED_INDICATE_SEND_ERROR);
                err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(SEND_ERROR_INTERVAL), NULL);
                break;
    
            case BSP_INDICATE_RCV_OK:
                // when receving shortly invert LED_1
                m_leds_clear = true;
                bsp_board_led_invert(BSP_LED_INDICATE_RCV_OK);
                err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(RCV_OK_INTERVAL), NULL);
                break;
    
            case BSP_INDICATE_RCV_ERROR:
                // on receving error invert LED_1 for long time
                m_leds_clear = true;
                bsp_board_led_invert(BSP_LED_INDICATE_RCV_ERROR);
                err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(RCV_ERROR_INTERVAL), NULL);
                break;
    
            case BSP_INDICATE_FATAL_ERROR:
                // on fatal error turn on all leds
                bsp_board_leds_on();
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_ALERT_0:
            case BSP_INDICATE_ALERT_1:
            case BSP_INDICATE_ALERT_2:
            case BSP_INDICATE_ALERT_3:
            case BSP_INDICATE_ALERT_OFF:
                err_code   = app_timer_stop(m_bsp_alert_tmr);
                next_delay = (uint32_t)BSP_INDICATE_ALERT_OFF - (uint32_t)indicate;
    
                // a little trick to find out that if it did not fall through ALERT_OFF
                if (next_delay && (err_code == NRF_SUCCESS))
                {
                    if (next_delay > 1)
                    {
                        err_code = app_timer_start(m_bsp_alert_tmr,
                                                   APP_TIMER_TICKS(((uint16_t)next_delay * ALERT_INTERVAL)),
                                                   NULL);
                    }
                    bsp_board_led_on(BSP_LED_ALERT);
                    m_alert_on = true;
                }
                else
                {
                    bsp_board_led_off(BSP_LED_ALERT);
                    m_alert_on = false;
    
                }
                break;
    
            case BSP_INDICATE_USER_STATE_OFF:
                leds_off();
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_USER_STATE_0:
                leds_off();
                bsp_board_led_on(BSP_LED_INDICATE_USER_LED1);
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_USER_STATE_1:
                leds_off();
                bsp_board_led_on(BSP_LED_INDICATE_USER_LED2);
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_USER_STATE_2:
                leds_off();
                bsp_board_led_on(BSP_LED_INDICATE_USER_LED1);
                bsp_board_led_on(BSP_LED_INDICATE_USER_LED2);
                m_stable_state = indicate;
                break;
    
            case BSP_INDICATE_USER_STATE_3:
    
            case BSP_INDICATE_USER_STATE_ON:
                bsp_board_leds_on();
                m_stable_state = indicate;
                break;
    
            default:
                break;
        }
    
        return err_code;
    }
    
    
    /**@brief Handle events from leds timer.
     *
     * @note Timer handler does not support returning an error code.
     * Errors from bsp_led_indication() are not propagated.
     *
     * @param[in]   p_context   parameter registered in timer start function.
     */
    static void leds_timer_handler(void * p_context)
    {
        UNUSED_PARAMETER(p_context);
    
        if (m_indication_type & BSP_INIT_LEDS)
        {
            UNUSED_VARIABLE(bsp_led_indication(m_stable_state));
        }
    }
    
    
    /**@brief Handle events from alert timer.
     *
     * @param[in]   p_context   parameter registered in timer start function.
     */
    static void alert_timer_handler(void * p_context)
    {
        UNUSED_PARAMETER(p_context);
        bsp_board_led_invert(BSP_LED_ALERT);
    }
    #endif // #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
    
    
    /**@brief Configure indicators to required state.
     */
    uint32_t bsp_indication_set(bsp_indication_t indicate)
    {
        uint32_t err_code = NRF_SUCCESS;
    
    #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) 
    
        if (m_indication_type & BSP_INIT_LEDS)
        {
            err_code = bsp_led_indication(indicate);
        }
    
    #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
        return err_code;
    }
    
    
    uint32_t bsp_init(uint32_t type, bsp_event_callback_t callback)
    {
        uint32_t err_code = NRF_SUCCESS;
    
    #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
        m_indication_type     = type;
    #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
    
    #if (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) && !defined(BSP_DEFINES_ONLY) //JH ADDED LAT TOEST TO MATCH HEADER FILE 
        m_registered_callback = callback;
    
        // BSP will support buttons and generate events
        if (type & BSP_INIT_BUTTONS)
        {
            uint32_t num;
    
            for (num = 0; ((num < BUTTONS_NUMBER) && (err_code == NRF_SUCCESS)); num++)
            {
                err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_DEFAULT);
            }
    
            if (err_code == NRF_SUCCESS)
            {
                err_code = app_button_init((app_button_cfg_t *)app_buttons,
                                           BUTTONS_NUMBER,
                                           APP_TIMER_TICKS(50));
            }
    
            if (err_code == NRF_SUCCESS)
            {
                err_code = app_button_enable();
            }
    
            if (err_code == NRF_SUCCESS)
            {
                err_code = app_timer_create(&m_bsp_button_tmr,
                                            APP_TIMER_MODE_SINGLE_SHOT,
                                            button_timer_handler);
            }
        }
    #elif (BUTTONS_NUMBER > 0) && (defined BSP_SIMPLE)
        bsp_board_init(type);
    #endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE)
    
    #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
        if (type & BSP_INIT_LEDS)
        {
          //handle LEDs only. Buttons are already handled.
          bsp_board_init(BSP_INIT_LEDS);
    
          // timers module must be already initialized!
          if (err_code == NRF_SUCCESS)
          {
              err_code =
                  app_timer_create(&m_bsp_leds_tmr, APP_TIMER_MODE_SINGLE_SHOT, leds_timer_handler);
          }
    
          if (err_code == NRF_SUCCESS)
          {
              err_code =
                  app_timer_create(&m_bsp_alert_tmr, APP_TIMER_MODE_REPEATED, alert_timer_handler);
          }
        }
    #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
    
        return err_code;
    }
    
    
    #ifndef BSP_SIMPLE
    /**@brief Assign specific event to button.
     */
    uint32_t bsp_event_to_button_action_assign(uint32_t button, bsp_button_action_t action, bsp_event_t event)
    {
        uint32_t err_code = NRF_SUCCESS;
    
    #if BUTTONS_NUMBER > 0 && !defined(BSP_DEFINES_ONLY) //KH ADDED LAT TOEST TO MATCH HEADER FILE 
        if (button < BUTTONS_NUMBER)
        {
            if (event == BSP_EVENT_DEFAULT)
            {
                // Setting default action: BSP_EVENT_KEY_x for PUSH actions, BSP_EVENT_NOTHING for RELEASE and LONG_PUSH actions.
                event = (action == BSP_BUTTON_ACTION_PUSH) ? (bsp_event_t)(BSP_EVENT_KEY_0 + button) : BSP_EVENT_NOTHING;
            }
            switch (action)
            {
                case BSP_BUTTON_ACTION_PUSH:
                    m_events_list[button].push_event = event;
                    break;
                case BSP_BUTTON_ACTION_LONG_PUSH:
                    m_events_list[button].long_push_event = event;
                    break;
                case BSP_BUTTON_ACTION_RELEASE:
                    m_events_list[button].release_event = event;
                    break;
                default:
                    err_code = NRF_ERROR_INVALID_PARAM;
                    break;
            }
        }
        else
        {
            err_code = NRF_ERROR_INVALID_PARAM;
        }
    #else
        err_code = NRF_ERROR_INVALID_PARAM;
    #endif // BUTTONS_NUMBER > 0
    
        return err_code;
    }
    
    #endif // BSP_SIMPLE
    
    
    uint32_t bsp_buttons_enable()
    {
    #if (BUTTONS_NUMBER > 0) && !defined(BSP_SIMPLE)
        return app_button_enable();
    #else
        return NRF_ERROR_NOT_SUPPORTED;
    #endif
    }
    
    uint32_t bsp_buttons_disable()
    {
    #if (BUTTONS_NUMBER > 0) && !defined(BSP_SIMPLE)
        return app_button_disable();
    #else
        return NRF_ERROR_NOT_SUPPORTED;
    #endif
    }
    static uint32_t wakeup_button_cfg(uint32_t button_idx, bool enable)
    {
    #if !defined(BSP_SIMPLE)
        if (button_idx <  BUTTONS_NUMBER)
        {
            nrf_gpio_pin_sense_t sense = enable ?
                             (BUTTONS_ACTIVE_STATE ? NRF_GPIO_PIN_SENSE_HIGH : NRF_GPIO_PIN_SENSE_LOW) :
                             NRF_GPIO_PIN_NOSENSE;
            nrf_gpio_cfg_sense_set(bsp_board_button_idx_to_pin(button_idx), sense);
            return NRF_SUCCESS;
        }
    #else
        UNUSED_PARAMETER(button_idx);
        UNUSED_PARAMETER(enable);
    #endif
        return NRF_ERROR_NOT_SUPPORTED;
    
    }
    uint32_t bsp_wakeup_button_enable(uint32_t button_idx)
    {
        return wakeup_button_cfg(button_idx, true);
    }
    
    uint32_t bsp_wakeup_button_disable(uint32_t button_idx)
    {
        return wakeup_button_cfg(button_idx, false);
    }
    

  • Failing an actual resolution to this exact issue... is there any recommended approach for just throwing out the SDK completely (or partially?) and writing my own drivers for the peripherals I need, while still being able to configure and use a softdevice, and not stepping on any shared resource requirement's toes?

  • Hi,

    I tested porting the nrfx_spim example to pca10056e and I did not face any BSP related errors, however, I used a different approach than you did. I copied the pca10056e projects from uart example into nrfx_spim example, copied sdk_config from pca10056 directory into pca10056e directory, and added the missing source files required by the nrfx_spim example. I also face the multiple UART handler error, but this can easily be fixed by setting NRFX_PRS_BOX_2_ENABLED to 1 in your sdk_config.h file (fewer peripheral instances on nRF52811 cause less required resource sharing boxes, in nRF52811 box 2 is used for UART/UARTE, while box 4 is used in nRF52840).

    Attached project: nrfx_spim_pca10056e.zip

    Best regards,
    Jørgen

  • thanks for the answer..

    When I get some time, I'd like to dig into what the difference is between the config for a uart project and the blinky project for the same target, I'm sure it'll be instructive to see what difference makes some defines for the bsp button handling code fall over in a screaming heap.

    I had a quick search, but haven't been able to find much info on what these PRS_BOX values even mean? letalone why I need to set one of these for a particular chip but can't for another. the SDK help files for the whole PRS are particularly frustrating in describing each setting as...  itself..... 

    Anyway - since asking this question, I decided that the 52811 isn't for this project.

    Having no room to compile a debug version of the firmware, before I had even started any dev beyond configuring some on chip peripherals and the BLE radio from a sample skeleton project that does nothing....... well, that seems to be asking for trouble. 

    I've got an nRF52-DK and some eval boards for the parts the custom board was using, and now I'm progressing on the 52832...