Teensy 3.2 OTA update Slows down MCU -Flash_erase_upper()

schmo

Member
hy
i am using the ota update to flash my teensy during the running.
I use this source:
https://github.com/Photosynq/PhotosynQ-Firmware/blob/master/multispeq1/flasher.cpp


This means, i send the hex file over the CAN-Bus to the teensy 3.2 and after the transfer (4bytes all 50ms ~90min) i will send a command over CAN-Bus to flash the firmware.

If i start sending the firmware the source code is deleting the upper flash of the teensy. but this makes the teensy realy slowly. (my Idle Loop Counter per Sec goes down from 45kHz to nearly 13kHz) and will never increase back to 45kHz


what is happening in these lines of code, that the MCU is slowing down so extreme?



Code:
RAMFUNC static int flash_erase_sector(uint32_t address, int unsafe)
{
	if (address > FLASH_SIZE || (address & (FLASH_SECTOR_SIZE - 1)) != 0) // basic checks
		return 1;

	if (address == (0x40C & ~(FLASH_SECTOR_SIZE - 1)) && unsafe != 54321)    // 0x40C is dangerous, don't erase it without override
		return 2;

	__disable_irq();

	// wait for flash to be ready!
	while ((FTFL_FSTAT & FTFL_FSTAT_CCIF) != FTFL_FSTAT_CCIF)
	{
	};

	// clear error flags
	FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL | FTFL_FSTAT_MGSTAT0;

	// erase sector
	FTFL_FCCOB0 = 0x09;
	FTFL_FCCOB1 = address >> 16;
	FTFL_FCCOB2 = address >> 8;
	FTFL_FCCOB3 = address;

	FTFL_FSTAT = FTFL_FSTAT_CCIF;  // execute!

	while ((FTFL_FSTAT & FTFL_FSTAT_CCIF) != FTFL_FSTAT_CCIF)  // wait for ready
	{
	};

	FMC_PFB0CR = 0xF << 20;  // flush cache

	if (!leave_interrupts_disabled)
		__enable_irq();

	return FTFL_FSTAT & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL | FTFL_FSTAT_MGSTAT0);

}  // flash_erase_sector()



With best regards
 
Since this is not officially supported - did you ask PhotosynQ ?

Edit: You're not really erasing the flash with some khz... do you ??
 
Last edited:
no what i meaned is that i have a timer in the loop methode, which is counting the idle loops.

my plan is to start the flash prozess during the normal process.
Erase the upper half of the flash and then send over CAN-Bus 2 Firmware Bytes every 50ms.

But erasing leads to the effect that the cpu power is decreasing...


does anybody has a other solution for OTA Updates?
 
Showing loop() / 'idle loop' code and the code that calls flash_erase_sector() might point to the problem if it is code based
 
The routine does flush the cache, which will temporarily slow down the execution of other code. But I can't see any reason that it would cause a permanent slow down.

Try commenting out the "flush cache" line and see what happens.

Do be careful that you aren't continually erasing or writing flash - it's life is limited. Erase and flash should be rare events, only occurring when firmware needs to be updated.
 
...
Do be careful that you aren't continually erasing or writing flash - it's life is limited. Erase and flash should be rare events, only occurring when firmware needs to be updated.

That's why I asked for loop() code - it seems what ever driving it may be being neurotic and doing too much too often
 
Back
Top