POFCON configuration causing hard fault in SDK 17.1.0 with nrf52832

Hi! 

I'm migrating some code from an 14.2.0 SDK to the 17.1.0 SDK and cleaning up a big mess. 

Whenever I call nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V27) with either true or false, I get a hard fault. 
I read the docs, and I see HFCLK needs to be on. I enable it like this at wake up 

    nrf_drv_clock_init();
    nrf_drv_clock_hfclk_request(NULL);
    while (!nrf_drv_clock_hfclk_is_running())
    {
    } 

I confirm HFHCLK is running with SRC RC and STATE = 1 (running)
However when I try to call nrf_power_pofcon_set I am getting a hard fault. 

I also printed these to RTT for a sanity check

<info> app: NRFX_CLOCK_ENABLED: 1
<info> app: NRFX_POWER_CLOCK_ENABLED: 1
<info> app: NRF_POWER_HAS_POFCON: 1
<info> app: NRF_POWER_HAS_VDDH: 0
<info> app: POWER_POFCON_THRESHOLD_Msk: 30

I have burned quite a few hours on this so any tips are appreciated. Thanks!

  • Thanks Hung.

    Based on your advice I saw nrf_drv_power.c has support for using pof with softdevice. 
    I added that, and configured. 

        nrf_drv_power_pofwarn_config_t config = { 
            .handler  = pof_handler, 
            .thr = NRF_POWER_POFTHR_V27 
        };
        nrf_drv_power_pof_init(&config);

    I was able to get the pof_handler to fire today, how ever I see in only supports 2.7v, 2.5v, 2.3v, 2.1v via nrf_drv_power.c, and I want to use 2.8v , so I think I'm going to pull all of this into my own application and stop using nrf_drv_power.c

  • Here is the working code for others trying to figure this out.
    Its confusing b/c of mixed APIs

        nrf_drv_power_pofwarn_config_t config = { 
            .handler  = pof_handler, 
        };
        
        nrfx_power_pof_init(&config);
        sd_power_pof_threshold_set(NRF_POWER_THRESHOLD_V28);
        sd_power_pof_enable(true);

Related