cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-DOSCO, FLASH

AD�?b
Senior

Hello

I want to write to FLASH variable uint32_t time at power off. Which signal to use for this?

greetings

Andrzej

1 ACCEPTED SOLUTION

Accepted Solutions

Yes, EXTI 16 would generate an interrupt. Not sure it gives you time to write to flash, or if that's a desirable course of action.

You'll need to weigh the risks there.

The flash sectors are quite large, and slow to erase, you'd want to journal your 32-bit write across a sector so the time to write is short.

View solution in original post

5 REPLIES 5

What signal? There isn't one telling you the power source is collapsing. You could perhaps use an EXTI to an external trigger circuit, but you'd need to be able to keep the system running long enough to do whatever you need. Perhaps it could switch to the reserve supply, and then go directly into STANDBY until the primary supply is restored.

The flash is relatively slow, and uses a charge pump, it is generally inadvisable to try and write with a failing supply. You might consider writing to BKPRAM, and powering the VBAT from a battery or super-cap. You could perhaps update this in the 1 KHz task.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi

I have to save only one uint32_t variable after power off.

Can't use PWD signal and EXTI 16 interrupt?

What do you think?

greetings

Andrzej

Yes, EXTI 16 would generate an interrupt. Not sure it gives you time to write to flash, or if that's a desirable course of action.

You'll need to weigh the risks there.

The flash sectors are quite large, and slow to erase, you'd want to journal your 32-bit write across a sector so the time to write is short.

I will read the variable after loading the program.

Then I'll erase the sector. When an interrupt appears,

I will save a new variable.

Hi

It doesn't work as I would like.

I configure:

1. NVIC / PVD interrupt through EXTI line 16

2. Code generation / PVD interrupt through EXTI line 16

3. In main.c I have:

static void MX_NVIC_Init (void);

4. And:

static void MX_NVIC_Init (void)

{ / * PVD_IRQn interrupt configuration * /

HAL_NVIC_SetPriority (PVD_IRQn, 5, 0);

HAL_NVIC_EnableIRQ (PVD_IRQn);

}

5. Elimination:

void HAL_PWR_PVDCallback ()

{ HAL_FLASH_Program (FLASH_TYPEPROGRAM_WORD, FLASH_SECTOR_3, total_time); // saving to FALSH

HAL_FLASH_Lock ();

}

/ * USER CODE END 4 * /

6. I add:

total_time = * (__ IO uint32_t *) FLASH_SECTOR_3; // reading from FLASH

HAL_FLASH_Unlock (); // FLASH unlock for writing

HAL_PWR_EnablePVD ();

Did not work. Why?

Andrzej