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

Status
Not open for further replies.

cebersp

Well-known member
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
 
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... :) )
 
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.
 
(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.
 
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:
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!
 
:)

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.
 
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:
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.
 
> 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.
 
> 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.
 
Status
Not open for further replies.
Back
Top