cancel
Showing results for 
Search instead for 
Did you mean: 

write internal flash with PVD interrupt

fab04
Associate II

Hi everybody,

I use a STM32L476RG. I'm trying to write 4 bytes in the flash memory on a PVD IT.

I can write/read in the flash, it works.

I've programmed my PVD on level 6 (2.9V) and BOR level is at 1.7V. I've used AN4718 to design a vbat system with a supercapacitor (3V/1F). So after I've cut the powersupply, I've around 10s to do the writing operation (normally it's enough).

So I cut my supply, the IT is detected, I write 4 bytes in the flash memory (In debug mode, I've put a break point in my function, and I know that the IT is well detected, and I see my data writes in the flash memory).

When I put my supply, sometimes it works and the right value is displayed (I displayed it on a terminal), and sometimes is like the flash memory is blank (address in flash is filled with FF).

After the writing in flash, I'm waiting 5ms to be sure that data are well written.

/**
  * @brief This function handles PVD/PVM1/PVM2/PVM3/PVM4 interrupts through EXTI lines 16/35/36/37/38.
  */
void PVD_PVM_IRQHandler(void)
{
  /* USER CODE BEGIN PVD_PVM_IRQn 0 */
 
  /* USER CODE END PVD_PVM_IRQn 0 */
  HAL_PWREx_PVD_PVM_IRQHandler();
  /* USER CODE BEGIN PVD_PVM_IRQn 1 */
  write_flash_pvd();
 
  /* USER CODE END PVD_PVM_IRQn 1 */
}
/***********************************************************************
   \fn      void write_flash_pvd(void)
   \brief   Ecriture dans la flash lors d'une perte d'alimentation
 
   \param   aucun
   \return  aucun
************************************************************************/
void
write_flash_pvd(void) {
	/*memset(buffer_rx_flash, 0, sizeof(buffer_rx_flash));
	read_internal_flash((uint8_t*)buffer_rx_flash,ADDR_FLASH_PAGE_510);
	if (strcmp((char *)buffer_rx_flash,"TEST 1\r\n") == 0) {
	  strcpy((char *)buffer_rx_flash,"TEST 2\r\n");
	} else {
	  strcpy((char *)buffer_rx_flash,"TEST 1\r\n");
	}*/
	uint16_t wait;
 
	write_internal_flash(buf_pvd, ADDR_FLASH_PAGE_510);
	for (wait = 0; wait < 40000; wait++) {
	  asm("NOP");
	}
	for (wait = 0; wait < 40000; wait++) {
	  asm("NOP");
	}
	HAL_GPIO_WritePin(GPIOA, UC_DO_RELAIS_ALARME_Pin, SET);
}

If you have any ideas, I'll be very happy.

0 REPLIES 0