7 years, 3 months ago.

Bootloader_K64F

I am trying to integrate the Bootloader_K64F library by Erik Olieman with the mbed-rtos to re flash a FRDMK64F device.

I am experiencing a hang when it tries to execute _disable_irq() in run_command():

/* Clear possible flags which are set, run command, wait until done */
void run_command(void) {
    //Clear possible old errors, start command, wait until done
    __disable_irq();            //Disable IRQs, preventing IRQ routines from trying to access flash (thanks to https://mbed.org/users/mjr/)

Import programBootloader_K64F

Example of a Serial bootloader for the K64F platform

Has anyone else had this issue?

Many thanks

Ryan

1 Answer

7 years, 3 months ago.

I uploaded slightly modified version, which can prevent problems when you are using RTOS. However I haven't been able to reproduce disable_irq causing issues. You can try adding:

SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;

Which disables the systick interrupt (from https://www.lpcware.com/content/forum/systick-interrupt-disable-generates-hardfault), but disable_irq should do the same.

If you keep having issues, can you publish the complete program you are using?

Hi Erik

Thank you for your reply, after a little bit of printf'ing i noticed that it gets into the: <<code>> while (!(FTFA->FSTAT & FTFA_FSTAT_CCIF_MASK)); <</code>>

but it loops around 5 times before it crashes and the red LED on the FRDM board lights up with about 50% duty.

posted by Ryan Stephen 08 Dec 2016

Having issues publishing, its asking me to commit changes in FreescaleIAP when i have no changes and so it wont publish the project.

posted by Ryan Stephen 08 Dec 2016

FreescaleIAP should be a folder, and not a library. If you have it as library, well there is your problem ;).

posted by Erik - 08 Dec 2016

Ahh i see, thanks, there is another library (EthernetInterface) which was already included in the project, I have made no changes to it yet it is asking me to publish the library. If i publish it wont it create a new version where anyone here can update their EthernetInterface library to? Still quite new to mbed.

As it happens i think there is a fundamental issue with either my board or the revision of the board because i have tried just your code and it crashed without modifying anything and i have tried to create a watchdog timer and when ever trying to write to registers the device crashes (even with the unlock bit set for that register) Is there something i am missing?

Many thanks

posted by Ryan Stephen 13 Dec 2016

My code certainly shouldn't crash your board. At which state does it crash? Although while it can be a broken board, it really is not that likely.

Regarding watchdog timer, I haven't used that one on the K64F myself, however the easiest way to make a Freescale MCU crash is by trying to access a register that is not clocked. EG if you write to the UART registers before you enable to peripheral clock to the UART, it will lock up.

posted by Erik - 13 Dec 2016

I thought it was the _disable_irq() but in fact it is when it reads from the register:

<<code>> while (!(FTFA->FSTAT & FTFA_FSTAT_CCIF_MASK));<</code>>

the IAPDEBUG printf's stop and the reset led on the board also illuminates with about 50% duty.

How do you enable peripheral clock?

posted by Ryan Stephen 14 Dec 2016

A while ago I checked that, but from old code I think it was this line for an ADC:

SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK;

Regarding the bootloader, if you can publish a program which shows the issue I can have a look at it, but since my own one works fine I can't do much.

posted by Erik - 14 Dec 2016

Many thanks, i have published this copy of your code, i have only changed the location for each freescaleIAP function: https://developer.mbed.org/users/STEPHER2/code/frdmk64_bootloader/ and have tested the code on my board and it indeed crashes it. Thank you for having a look at it.

posted by Ryan Stephen 15 Dec 2016

I just wanted to have a look at it, but sadly my K64F is completely unresponsive. I managed to track it down to a power switch being kept disabled by the interface MCU, but I have no idea why it is doing it. Since also no USB drive, no serial, no nothing enabled, I have the feeling it is broken. Maybe I manage to fix it, but for now I sadly simply don't have a board anymore to test it on.

posted by Erik - 26 Dec 2016

I managed to get it functional again (the bootloader of the interface chip appears broken to me, but it did manage to update itself with the mbed firmware. It still appears broken, but it does accept bin files again).

Your problem: Disable IAPDEBUG :P. You changed more than the address. IAPDEBUG uses printf, you disabled that at one spot, but not on others. So it tries to call printf, which is located in the area that was just erased, and it crashes.

Edit: Took me few takes, but while I didn't verify it, I assume line 238 is the issue why it fails after erasing: After erasing it calls check error, and that one will report (hopefully) there were no errors. And that printf wasn't commented out. But it is better to just disable IAPDEBUG since printfs dont work anyway when running a bootloader :).

posted by Erik - 26 Dec 2016

Hi Erik, I hope you had a great Christmas!? Thanks for your help, i disabled IAPDEBUG and tried again with no avail. I then added:

<<code>SIM->SCGC6 |= SIM_SCGC6_FTF_MASK;<</code>

at the beginning of the code and it didn't crash! It printed '#' to the terminal but for some reason didnt complete flashing and returned with 'Error!'. Not sure why i needed to enable the clock for the flash peripheral?

Could this be a board revision issue? On the sticker on the backside of the FRDMK64f board i am seeing:

700-28163 REV D SCH-28163 REV E3

Thanks

Ryan

posted by Ryan Stephen 05 Jan 2017

Can you publish your program again with current version you are using? Just to be sure that now works on mine (btw if you just import mine without any changes, does it function?).

I checked why I didn't enable that clock: Reason is simply that by default it is enabled, granted it might be considered nice to make sure it is enabled in the library, but in general it should not be required.

Numbers on my K64F are the same, only rev B and rev D1. But I don't know if that means a different MCU revision, or just a different board.

posted by Erik - 05 Jan 2017

Ok just published to the same location with the clock enable. It seems to write to flash as i get the "#" 's but still i get an "Error!" before the terminal window has completed sending. When i then try and reset the board nothing happens.

posted by Ryan Stephen 06 Jan 2017

No if i import your code without the flash clock set my board just freezes.

posted by Ryan Stephen 06 Jan 2017

Can you print the value of SIM->SCGC6 before you change it? And which program are you trying to send? Could it be larger than the space you erased? I just normally test with simple blinky program.

Besides this I don't think I can really help you much further: I tried your program on mine, and there it simply works.

posted by Erik - 07 Jan 2017