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

NRF51 Flash write during brown-out

The v3 reference manual of the nrf51 mentions:

"[The powerfail comparator] also provides hardware protection of data stored in program memory by preventing write instructions from being executed." (page 45)

The meaning of this is not entirely clear to me. Is this protection only active below 1.7V, or earlier? I'm trying to use the low-power comparator to generate an interrupt at 2.7V, then write something to flash and shut down. If I make sure that the power drop is slow enough so that there is enough time for my operations between the 2.7V and 1.7V, can I be sure that my data arrives in flash uncompromised?

Parents
  • This threshold is user set and you have to enable Power Fail comparator function explicitly . Please look into Power_Register ->POFCON

    Regarding you write operation, all writes are blocked immediately after EVENTS_POFWARN is triggered. I verified this on 100028 board

    #include <stdbool.h>
    #include <stdint.h>
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    
    #define POF_PIN      (21)
    
    void soc_hal_flash_word_unprotected_write(uint32_t * p_address, uint32_t value)
    {
      NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
      {
        // Do nothing.
      }
      *p_address = value;
    
      // Wait flash write to finish
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
      {
          // Do nothing.
      }
    
      // Turn off flash write enable and wait until the NVMC is ready.
      NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
      {
        // Do nothing.
      }
    }
    
    uint32_t *ptr = (uint32_t *)0X3C000;
    void POWER_CLOCK_IRQHandler()
    {
        if(NRF_POWER->EVENTS_POFWARN == 1)
        {
            soc_hal_flash_word_unprotected_write(ptr, 0XDEADBEEF);
            NRF_POWER->EVENTS_POFWARN = 0;
            nrf_gpio_pin_toggle(POF_PIN);
            
        }
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        // Configure LED-pins as outputs.
        LEDS_CONFIGURE(1<<POF_PIN);
        LEDS_CONFIGURE(1<<22);
        nrf_gpio_pin_clear(POF_PIN);
        nrf_gpio_pin_clear(22);
        NRF_POWER->INTENSET = POWER_INTENSET_POFWARN_Msk;
        NRF_POWER->POFCON = ((POWER_POFCON_THRESHOLD_V23 << POWER_POFCON_THRESHOLD_Pos) | (POWER_POFCON_POF_Enabled << POWER_POFCON_POF_Pos));
        NVIC_EnableIRQ(POWER_CLOCK_IRQn);
        while(1)
        {
        if(*ptr == 0XDEADBEEF)
        {
            nrf_gpio_pin_set(22);
        }
        };
        
    }
    
  • Another thread says 2.3V is adequate for flash write to work. Can I assume that EVENTS_POFWARN is wired to the internal circuitry that disables the NVMC? If so, then if, in the ISR you clear EVENTS_POFWARN (set at 2.7V) after determining it is set but before attempting write to flash, the write might succeed? My goal is, in a browning out system, to write the PC to UICR (not to program flash.) I don't need the memory protection, I need to know where in the code it is browning out, while debugging a system that intends to manage power from a weak solar powered supply. (sans SD.) I might post this as a separate question.

Reply
  • Another thread says 2.3V is adequate for flash write to work. Can I assume that EVENTS_POFWARN is wired to the internal circuitry that disables the NVMC? If so, then if, in the ISR you clear EVENTS_POFWARN (set at 2.7V) after determining it is set but before attempting write to flash, the write might succeed? My goal is, in a browning out system, to write the PC to UICR (not to program flash.) I don't need the memory protection, I need to know where in the code it is browning out, while debugging a system that intends to manage power from a weak solar powered supply. (sans SD.) I might post this as a separate question.

Children
No Data
Related