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

Thread: Where to find info on Software Restart for T3.5/3.6/4.1?

  1. #1

    Where to find info on Software Restart for T3.5/3.6/4.1?

    Hi,
    there are some threads about software restart, but I could not see, which will lead to an easy way to just do it with T3.5/3.6/4.1 using Arduino IDE.
    I just need a function which will restart the device.

    Many thanks!
    Christof

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    Quote Originally Posted by cebersp View Post
    using Arduino IDE.
    The Arduino IDE does not provide such a function.

    In your program you can use

    SCB_AIRCR = 0x05FA0004;

  3. #3
    Thank you very much, Frank, this works.
    (Although I don't feel very comfortable, when I write to a register and don't have any idea, what I am doing there... :-) )

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,455
    Forum search on "SCB_AIRCR" will find it liberally noted back to T_3.0 days IIRC - one might have comforting details - again IIRC from reading it is the common ARM way to do it.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    Quote Originally Posted by defragster View Post
    Forum search on "SCB_AIRCR" will find it liberally noted back to T_3.0 days IIRC - one might have comforting details - again IIRC from reading it is the common ARM way to do it.
    I added this page to the wiki yesterday. It contains a few additional things, too.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,740
    Quote Originally Posted by cebersp View Post
    (Although I don't feel very comfortable, when I write to a register and don't have any idea, what I am doing there... :-) )
    Google search for "DDI0403E". If Google doesn't find the PDF, click the link to ARM's website, then click "Download" to get the PDF.

    Once you're viewing the PDF, turn to page B3-602 for the AIRCR documentation.

  7. #7
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    498
    Quote Originally Posted by Frank B View Post
    I added this page to the wiki yesterday. It contains a few additional things, too.
    Hi Frank, from the Wiki:
    Code:
    SCB_AIRCR = 0x05FA0004;
    asm volatile ("dsb");
    Do I need the 2nd line as well? If so, what does it mean/do?

    Thanks,
    Paul

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    Not really.
    It just makes sure that the CPU resets as soon as possible. Otherwise it can happen some cycles later. If you want to be on the save side, add the "dsb".
    It has to do with very technical details, pipelines and more.. it is a "barrier".

    ARM says:
    Data Synchronization Barrier acts as a special kind of memory barrier. No instruction in program order after this instruction executes until this instruction completes. This instruction completes when:

    • All explicit memory accesses before this instruction complete.
    • All Cache, Branch predictor and TLB maintenance operations before this instruction complete.
    Esp. on Teensy4, (ARM Cortex-M7) a DSB is mandatory at the end of interrupt-code. Without, it can happen, that a interrupt gets called twice, because the corresponding flags have not been written early enough.
    The Reset is more or less the same.. without "DSB" it will happen, but you can not predict when exactly.

    ARM suggests the following code for a reset:
    Code:
    SCB_AIRCR = 0x05FA0004;
    asm volatile ("dsb");
    while (1) {;}
    For these reasons:
    1) It helps to compiler to detect that this code never returns and can optimize the calling code better. It does not know that SCB_AIRCR = 0x05FA0004 means "reset".
    2) It makes sure that no "digitalWriteFast(Flamethrower_enable_PIN, HIGH)" happens...
    3) ... ?
    Last edited by Frank B; 01-16-2021 at 12:44 PM.

  9. #9
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    498
    Thanks very much, it's pretty clear!
    Paul

  10. #10
    I wanted to play with this a bit so I temporarily added this line of code into the main loop():

    if(digitalReadFast(29) == LOW) SCB_AIRCR = 0x05FA0004;

    Now, even with removing that line of code I can no longer download anything from vscode/platformio to the teensy 4.1.

    Help!

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    :-)

    1) Press the button 15 seconds - until a short blink
    2) Release it.
    It should blink now and be the state where it was brand new.

    or connect 3.v3 volt to Pin 29.

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    Ooops sorry, that was for T4.

    There is nothing on T3 that would blink after 15 sec.
    So,
    1) Disconnect USB
    2) Press and hold the button
    3) WITH BUTTON PRESSED, connect USB.

    A new sketch schould upload now. Try "Blink" from the examples.
    Last edited by Frank B; 01-16-2021 at 06:23 PM.

  13. #13
    Frank-My uP is a T4.1 and the Memory wipe procedure shown on the teensy 4.1 page solved the problem.

    Memory Wipe & LED Blink Restore
    Teensy 4.1 will fully erase its non-volatile memory and return the flash memory to a simple LED blink program if the program button is held between 13 to 17 seconds. The red LED flashes briefly at the beginning of this time window. During flash erase, the red LED is on bright. When completed, Teensy 4.1 will automatically reboot and run the LED blink program, causing the orange LED to blink slowly.

    Thanks for your help. I didn't know that a factory reset was available.

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    Yes, that's the procedure I described in Post#11 (with less words)

  15. #15
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    840
    > a DSB is mandatory at the end of interrupt-code

    I believe it should also be used when disabling interrupts from non-interrupt code.

    > SCB_AIRCR = 0x05FA0004;

    Of course such things should be inside of a standardized C wrapper. Speaking of which, I think there is a need for a noInterrupts() than can be followed with restoreInterruptsToStateBeforeNoInterrupts(). Some library routines turn interrupts off then on, which is really bad if you wanted interrupts left off.

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,937
    Quote Originally Posted by jonr View Post
    > a DSB is mandatory at the end of interrupt-code

    I believe it should also be used when disabling interrupts from non-interrupt code.

    > SCB_AIRCR = 0x05FA0004;

    Of course such things should be inside of a standardized C wrapper. Speaking of which, I think there is a need for a noInterrupts() than can be followed with restoreInterruptsToStateBeforeNoInterrupts(). Some library routines turn interrupts off then on, which is really bad if you wanted interrupts left off.
    Yes and there are more examples.
    I think it can be useful for bit-banging, too, sometimes.
    Just in cases where you need to control the exact timing.

    However, that's not often the case.

Posting Permissions

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