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

nrf52832 custom board: uart code giving hardfault

Hi,

I am able to program my custom board using nrf52dk (only 32 Mhz osc populated on custom board), and I can also see the output of SEGGER_RTT_WriteString() though JLinkRTTClient command. But I am getting hardfaults when I have uart in use.

I have set the source for LFCLK to be internal RC oscillator. I know internal rc osc is not the best option when uart needs to be used, but would it cause a hardfault ? What could be the possible reasons for hardfault ? Backtrace is not giving much information:

#0  0x0001e054 in ?? ()
#1  <signal handler called>
#2  0x00000000 in ?? ()
#3  0x00020256 in uart_event_handler (p_event=0x8e5, p_context=0x20000400) at ../components/libraries/uart/app_uart.c:49 Backtrace stopped: previous frame inner to this frame (corrupt stack?)

The above happens after four loops which try to run app_uart_put() (see code below).

Code:

void bsp_configuration()
{
    uint32_t err_code = NRF_SUCCESS;

    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;

    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
        // Do nothing.
    }

    APP_TIMER_INIT(APP_TIMER_PRESCALER, /*APP_TIMER_MAX_TIMERS,*/ APP_TIMER_OP_QUEUE_SIZE, NULL);

    err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
}



void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) {
        SEGGER_RTT_printf(0,"Error (id,pc,info): %x,%x,%x\n");
}

void gpiote_init() {
    if (!nrf_drv_gpiote_is_init())
        nrf_drv_gpiote_init();

    uint32_t err;
    
    nrf_drv_gpiote_out_config_t led_config = GPIOTE_CONFIG_OUT_SIMPLE(true);

    err = nrf_drv_gpiote_out_init(18, &led_config);
    APP_ERROR_CHECK(err);
}

/**@brief Function for application main entry. Does not return. */
int main(void)
{
    // Setup bsp module.
    bsp_configuration();
    uart_init();
    gpiote_init();

    uint32_t err;
    uint8_t byte;
    err = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err);
    SEGGER_RTT_Init();
    nrf_delay_ms(DELAY_MS);

    for (;;) {
        SEGGER_RTT_WriteString(0,"Toggling led 18\n");
        nrf_drv_gpiote_out_toggle(18); 
        nrf_delay_ms(500);
        app_uart_put('*');
    }
}

Output I get from JLinkRTTClient:

Error (id,pc,info): 2000FF2C,2000FF2C,1440000
Error (id,pc,info): 2000FF2C,2000FF2C,1440000
Toggling led 18
Toggling led 18

I do not get hardfaults if I comment out app_uart_put().

Related