Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 3 1 2 3 LastLast
Results 1 to 25 of 53

Thread: T4 software restart procedure and freeram function

  1. #1
    Senior Member
    Join Date
    Aug 2017
    Posts
    306

    T4 software restart procedure and freeram function

    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

  2. #2
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,558
    This might help: https://forum.pjrc.com/threads/54711...l=1#post207343

    UPDATE:
    THink this is all you need to do:
    Code:
    SCB_AIRCR = 0x05FA0004;
    And for reference:
    https://mcuoneclipse.com/2015/07/01/...with-software/

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,541
    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.

  4. #4
    Senior Member
    Join Date
    Aug 2017
    Posts
    306
    @jms513 and @Paul - Thanks guys.
    Instant answers. This forum is the best

  5. #5
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,558
    @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 by mjs513; 09-09-2019 at 12:22 AM.

  6. #6
    Senior Member
    Join Date
    Aug 2017
    Posts
    306
    Quote Originally Posted by mjs513 View Post
    @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

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,238
    Quote Originally Posted by wwatson View Post
    @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:
    Quote Originally Posted by PaulStoffregen View Post
    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/...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.

  8. #8
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,558
    @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 by mjs513; 09-09-2019 at 11:41 AM.

  9. #9
    Senior Member
    Join Date
    Aug 2017
    Posts
    306
    Quote Originally Posted by mjs513 View Post
    @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.

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,238
    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?

  11. #11
    Junior Member
    Join Date
    Apr 2013
    Posts
    19
    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.

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    This lib has a reset:
    https://github.com/FrankBoesing/T4_PowerButton

    AIRCR does not work - it may reset the processor, but seems to confuse the power distribution of all the rest.

  13. #13
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,238
    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.

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Quote Originally Posted by defragster View Post
    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.

  15. #15
    Junior Member
    Join Date
    Apr 2013
    Posts
    19
    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...

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    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)

  17. #17
    Junior Member
    Join Date
    Apr 2013
    Posts
    19
    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?

  18. #18
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    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.

  19. #19
    Junior Member
    Join Date
    Apr 2013
    Posts
    19
    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!

  20. #20
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,238
    Quote Originally Posted by Frank B View Post
    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.

    Quote Originally Posted by Frank B View Post
    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.

  21. #21
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Quote Originally Posted by defragster View Post
    or the Power button acts wrong.
    Does it? I did not notice that so far.

  22. #22
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,238
    Quote Originally Posted by Frank B View Post
    Does it? I did not notice that so far.
    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.

  23. #23
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Would you mind to give it a short test with my lib?
    I can't try it right now.

  24. #24
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,541
    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.

  25. #25
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Quote Originally Posted by defragster View Post
    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 by Frank B; 01-23-2020 at 04:20 PM.

Posting Permissions

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