T4 software restart procedure and freeram function

Status
Not open for further replies.

wwatson

Well-known member
On the T4 is there a procedure for performing a software restart? Could it be as simple as calling ResetHandler() in startup.c?
It seems to me that there was talk of how to get the memory usage for T4 ram in the T4 First Beta Test thread but I can't seem to find it.
Can anybody point me to this information?

Thanks
 
Yup, just write to AIRCR. That's a register from the ARM core, so it's usually not documented in the chip's reference manual.
 
@Paul - @wwatson

Warning - the command I listed shuts down the 1062. To restart the sketch I had to remove power and reapply power. It seems to behave the same way as the power off button. Just tried it with the blink sketch.

UPDATE:
I just put it on the PRJC breakout board and issued the reset command - the chip shut down but the green power light stayed on. Pressing the on off button brought it back to life.
 
Last edited:
@Paul - @wwatson

Warning - the command I listed shuts down the 1062. To restart the sketch I had to remove power and reapply power. It seems to behave the same way as the power off button. Just tried it with the blink sketch.

UPDATE:
I just put it on the PRJC breakout board and issued the reset command - the chip shut down but the green power light stayed on. Pressing the on off button brought it back to life.

@mjs513 - I just set it up to use ctrl-alt-del (USB keyboard) and it just locks up so I will dig deeper and see what I come up with. Going back to work tomorrow after a weeks vacation playing with the T4.

Thanks for the info:)
 
@mjs513 - I just set it up to use ctrl-alt-del (USB keyboard) and it just locks up so I will dig deeper and see what I come up with. Going back to work tomorrow after a weeks vacation playing with the T4.

Thanks for the info:)

I asked this on the T4_Beta thread but never tried it - @mjs513 followed up with this info post #3105:
Sure. Use AIRCR, just like on all other 32 bit ARM.

@defragster, @Paul - I found this on AIRCR for ARM processors, https://mcuoneclipse.com/2015/07/01/how-to-reset-an-arm-cortex-m-with-software/, will this do the trick?
Code:
void KIN1_SoftwareReset(void)
{
  /* Generic way to request a reset from software for ARM Cortex */
  /* See https://community.freescale.com/thread/99740
     To write to this register, you must write 0x5FA to the VECTKEY field, otherwise the processor ignores the write.
     SYSRESETREQ will cause a system reset asynchronously, so need to wait afterwards.
   */
#if KIN1_IS_USING_KINETIS_SDK
  SCB_AIRCR = (0x5FA<<SCB_AIRCR_VECTKEY_Pos)|SCB_AIRCR_SYSRESETREQ_Msk;
#else
  SCB_AIRCR = SCB_AIRCR_VECTKEY(0x5FA) | SCB_AIRCR_SYSRESETREQ_MASK;
#endif
  for(;;) {
    /* wait until reset */
  }
}
just not sure what needs to be changed :) leave that to you defragster.
 
@wwatson - @defragster

Yeah that function pretty boils down to that one single line to set the SCB_AICR.

from the core cm7.h file:
Code:
#define SCB_AIRCR_VECTKEY_Pos              16U                                            /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk              (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos)            /*!< SCB AIRCR: VECTKEY Mask */

#define SCB_AIRCR_SYSRESETREQ_Pos           2U                                            /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk          (1UL << SCB_AIRCR_SYSRESETREQ_Pos)             /*!< SCB AIRCR: SYSRESETREQ Mask */
when you do the math comes out the same way.
 
Last edited:
@Paul - @wwatson

Warning - the command I listed shuts down the 1062. To restart the sketch I had to remove power and reapply power. It seems to behave the same way as the power off button. Just tried it with the blink sketch.

UPDATE:
I just put it on the PRJC breakout board and issued the reset command - the chip shut down but the green power light stayed on. Pressing the on off button brought it back to life.

@mjs513 - Sorry for the late response. I had the same result. Played with the the information you provided and came up with nothing.
 
Just tested the " SCB_AIRCR = 0x05FA0004; " - indeed it shuts the T4 OFF/OFF. Did it in conjunction with the RTC WAKE code on other thread - setting the wake time doesn't wake the CPU suggesting OFF/OFF not just powered down with low power unit running to wake it seemed?
 
Has anybody gotten anywhere with this? Being able to trigger a full reset from code is such a fundamentally useful feature, it would be a shame if it didn't work on T4.
I spent the evening searching the web (using increasingly generic search terms), but I couldn't find anything suggesting the SCB_AIRCR method shouldn't work with the T4's processor.
 
Paul seemed to expect the SCB_AIRCR to work as well. There maybe be something fixable in the bootloader catching it that Paul may address in future if possible.
 
Paul seemed to expect the SCB_AIRCR to work as well. There maybe be something fixable in the bootloader catching it that Paul may address in future if possible.

Yes, it might be that we just have to set or reset some bits to make AIRCR work. But without knowing what happens exactly we can only do blind guesses. It worked on the betas.
 
So, what would be the right way to catch Paul's attention? I suppose submitting an issue on GitHub, but I have close to zero experience with GitHub. Besides, I could only write "SCB_AIRCR doesn't work. Please try to fix." I have a feeling that wouldn't be the right way to do this...
 
I'm sure it's on his list already. The priority might not be very high - as there IS a way to reset (although I don't like it, too)
 
as there IS a way to reset (although I don't like it, too)
Can you tell me why you don't like it? I am assuming you're refering to the T4_PowerButton library you referenced above. I just tried it and it works a treat. Calling arm_reset() from anywhere within the code appears to do exactly what I need. Are you expecting any problems under certain conditions?
 
It can take up to 2 seconds until the rtc alarm fires and switches the Teensy on.
Then, minor reason, it kills any existing rtc alarm and so it must be rewritten after restart - but that's solvable.
 
Ah, I see. Well, that doesn't matter in my case, so it's absolutely perfect for what I need to do.
Thank you so much for this solution, you just saved me a lot of trouble with the my current project!
 
I'm sure it's on his list already. The priority might not be very high - as there IS a way to reset (although I don't like it, too)

Seems I saw it noted that it was on his list - if a bootloader change can address it and be found I suppose as time allows.

It can take up to 2 seconds until the rtc alarm fires and switches the Teensy on.
Then, minor reason, it kills any existing rtc alarm and so it must be rewritten after restart - but that's solvable.

I pulled the lib down Frank - but haven't gotten to it yet. I see you note the issues with it I found, 2 seconds slow but better than nothing but, and takes effort on next start to clear it or the Power button acts wrong.
 
I've been working on this problem today, and it remains quite a mystery.

Weeks ago I had thought it may be a bootloader bug. I imagined the bootloader might be mis-configuring vector catchbits, but it is not. Just now I tried programming the IMXRT chip with a program that writes to SCB_AIRCR after 4 seconds, then I programmed its MKL02 with a do-nothing program (expect powerup sequencing to get the IMXRT to turn on). After a cold power up, it still locks up when SCB_AIRCR is written, even when there's been absolutely no activity from the bootloader. So it's not looking like the bootloader is causing this problem.

I'm re-reading chapter 20 of the reference manual, which is some of the very worst chip documentation I've ever seen. Right now, I'm not feeling very hopeful to find a solution. :(
 
If the restart timer is not cancelled on the next start - do Power Off button - the timer will bring it back again if I'm remembering the right thing from the thread where I first tried it.

@Defragster:
yup - i can confirm this.
If you just add the callback in the library, it works ;) An empty function is enough.
I think I can fix it for the case without the callback, but we're going out for dinner now.

@Paul AIRCR: there are so many configuration options regarding power - I tried to find something, but I'm lost ..
What did change? I remember, it worked for the BETAs? Is that correct?
 
Last edited:
Status
Not open for further replies.
Back
Top