Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 3.2 OTA update Slows down MCU -Flash_erase_upper()

  1. #1
    Junior Member
    Join Date
    Oct 2015
    Posts
    9

    Teensy 3.2 OTA update Slows down MCU -Flash_erase_upper()

    hy
    i am using the ota update to flash my teensy during the running.
    I use this source:
    https://github.com/Photosynq/Photosy...q1/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

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,438
    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 by Frank B; 09-01-2017 at 03:30 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2015
    Posts
    9
    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?

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    6,437
    Showing loop() / 'idle loop' code and the code that calls flash_erase_sector() might point to the problem if it is code based

  5. #5
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    252
    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.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    6,437
    Quote Originally Posted by jonr View Post
    ...
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •