cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-DISCO, STM32CubeIDE, FLASH, supply voltage drop

ADębs.1
Senior

Hi

How to generate an interrupt when the supply voltage drops?

Andrzej

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
TDK
Guru

There are some predefined possibilities available with the PVD functionality.

For an arbitrary level, hook up an ADC to the supply (with resistor divider), or use the VBAT tap if VBAT=VDD, and use the ADC analog watchdog functionality.

If you feel a post has answered your question, please click "Accept as Solution".
ADębs.1
Senior

I have the following:

/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
	if (GPIO_Pin == WE_Pin) {
		on = 1;
		HAL_FLASH_Unlock();
//		FLASH_Erase_Sector(FLASH_SECTOR_7, FLASH_VOLTAGE_RANGE_3);
		HAL_FLASHEx_Erase(FLASH_SECTOR_7, FLASH_VOLTAGE_RANGE_3);
		HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, FLASH_SECTOR_7, 400);
		HAL_FLASH_Lock();
		set_time = *(__uint32_t*) FLASH_SECTOR_7;
	}
}
/* USER CODE END 4 */

Why is it crashing on deleting FLASH?

greetings

Andrzej

TDK
Guru
Piranha
Chief II

And apparently compiler warnings are also for kids, not "the real guys"...

1. I interrupted lowering the PVD below 3.0. Works.

2. I have set FLASH_EraseInitTypeDef EraseInitStruct;

void FLASH_Erase(void) {
	EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
	EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
	EraseInitStruct.Sector = FLASH_SECTOR_7;
	EraseInitStruct.NbSectors = 1;
 
	HAL_FLASH_Unlock();
	if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK)
	;
}

3. I have inserted a FLASH record into the interrupt

void HAL_PWR_PVDCallback(void) {
        HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, FLASH_SECTOR_7, total_time);
	HAL_FLASH_Lock();
}

4. Builds without error

5. I have concerns about entering the program into DISCOVERY because I blocked the contact between DISCOVERY and Laptop when I entered it earlier.

6. is this program correct?

Other problem:

1. FLASH_SECTOR_7 has the address 0x08C0 0000

2. The IDE reads FFFF FFFF at this address

3. There should be a variable uint32_t total_time at this address

4. In Live Expression I read 4101158945 and not FFFF FFFF

5. These are different values. Why?

greetings

Andrzej