T4 software restart procedure and freeram function

Status
Not open for further replies.
@Frank - I was on my way to Zzzzz I realized I should have added after send, glad you tested. - Glad/Sad my recollection was correct :)/:(. That thread where I chimed in started with that or similar issue - puzzling over something about that that went from there to get to the 2 second idea.

@Paul - Bummer you are not finding better path with less grief. I manage/try to avoid the manual ... last I looked was those 128 NVRAM bits - I got the address - but it took Frank to 'find' the undocumented bit to enable their use … :mad:

Re: SCB_AIRCR - "worked for the BETAs?" - IIRC a post it worked using the 1052 - not sure it worked after that when 1062 arrived?
 
I've fixed the "pwr-button failure after reset" (-without callback) issue.

Class constructors are called before setup(). I've used this feature to save and reset SNVS_LPSR.
(did not want to mess the startup hooks)

@Tim, can you test?
see latest version on github
 
I've fixed the "pwr-button failure after reset" (-without callback) issue.

Class constructors are called before setup(). I've used this feature to save and reset SNVS_LPSR.
(did not want to mess the startup hooks)

@Tim, can you test?
see latest version on github

Yes, Seems to work right. Good Fix and very 'classy' : __class_reset_snvs_psr

>> Only way it causes trouble is: after shutdown with 'arm_reset()', the Program is held/touched on Power On and new 'non POWER' sketch is uploaded - not Normal. The restart is not cleared and then funny things happen - had to hold power 5 seconds then press again and next upload took a Button press. Something like that is what started that other thread with WMXZ : issue-to-reporogram-T4-0 - which is what led to this :)

> TESTING :: With new github lib
- ran power.ino sketch
- it said : Restart after power down { expected }
- pressed button and it shutdown fast : Callback called - Switching off now.
- Pressed button and it woke : Restart after power down
- Loaded another sketch and Power Off normal 5 seconds
- Power On - back to same sketch
- Uploaded power.ino : Restart after power down
- TyComm Reset power.ino shows : First power on

> Added this to power.ino loop() : if ( Serial.available() ) arm_reset();
- upload other sketch
- Power Off : It stayed OFF
- Power On : sketch came up running
- Uploaded power.ino : Restart after power down

All seems good and right and usable. Cool using FLASHRAM to keep code on FLASH.

Can you make this all go away with #ifdef so if included and same sketch runs on on a T_3.x::
Compile give: 'T:\tCode\libraries\T4_PowerButton\T4_PowerButton.cpp:29:19: fatal error: imxrt.h: No such file or directory' and then all the functions will be MAD if note defined to 'go away' with macros or a fake class for unsupported parts.

>> I see : set_arm_power_button_callback(0); // Disable fast Power Off
- does disable the FAST SHUTDOWN - maybe add that as a comment in the sample?

Nice with the add of: arm_enable_nvram
- having easy to use state storage for reset seems relevant
> Can you add a sample showing use addressing into those 128 bits?
- like my sample indexing 4 DWORDS?
 
Paul:
Is there more to it than this? Does it take a bootloader change?:
Code:
void ResetHandler(void)
{
	unsigned int i;

#if defined(__IMXRT1062__)
	IOMUXC_GPR_GPR17 = (uint32_t)&_flexram_bank_config;
	// IOMUXC_GPR_GPR16 = 0x00000007; // https://forum.pjrc.com/threads/57553-T4-software-restart-procedure-and-freeram-function?p=227448&viewfull=1#post227448
	IOMUXC_GPR_GPR16 = 0x00200007;

I did a 15s Restore on a T4. Run the code below and SEND USB Serial. The device restarts, but does NOT connect on USB. The sketch resumes the fast blink, after about a 2 second delay, but does not establish USB connect until the next Device Power cycle?
> I did this on two T4's One with vBat cell above doing the 15s Restore in case the FrankB power code was causing the 2 second delay, and then on another T4 with no vBat that had NOT run the FrankB Power - and both act the same.
<edit: make that more like 4 second delay before sketch starts Fast Blink without USB connect>

This sketch wait for incoming Serial - then resets:
Code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial && millis() < 4000 );
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  pinMode(13, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  if ( Serial.available() )SCB_AIRCR = 0x05FA0004;
    digitalWriteFast( 13, !digitalReadFast(13));
    delay(50);
}
 
That's it, just change that 0 to 2 in startup.c.

What that undocumented bit in GPR16 really does, I have no idea. Well, other than preventing soft reboot from working... it definitely does that.

That's the 2nd undocument bit we found :)
Great.
Or... not great. I wonder how many undocumented "features" the "reference manual" (<-???) really hides.

Wonder if it makes sense to look at the docs for the prior chips..
How did you find that bit ?
I did blind guessing and try and error.. was more luck than everything else.

@Defragster: Thank you for testing.. hm.. now i can delete that stuff.. lol :)
Documenting: hm, yes, if I feel like it...
 
That's it, just change that 0 to 2 in startup.c.

What that undocumented bit in GPR16 really does, I have no idea. Well, other than preventing soft reboot from working... it definitely does that.

Okay - then why does sketch above restart and not USB connect? Is that the behavior you see? More work to do?

Also the 2 second Sleep restart is faster than this 4 second reset?
 
Okay - then why does sketch above restart and not USB connect? Is that the behavior you see? More work to do?

Also the 2 second Sleep restart is faster than this 4 second reset?


Hm, for me it works.. ?!? I tried your sketch (post #32), Tim. Reset is fast, and USB reconnects.
 
Okay - then why does sketch above restart and not USB connect?

I ran it here (msg #32 code).

Every time I type anything and click Send in the serial monitor, it reboots and USB always reconnects. I tested with Arduino 1.8.9 and Teensyduino 1.49 on Linux 64 bit. Did you use Arduino or other software? I'm guessing you used Windows.
 
I ran it here (msg #32 code).

Every time I type anything and click Send in the serial monitor, it reboots and USB always reconnects. I tested with Arduino 1.8.9 and Teensyduino 1.49 on Linux 64 bit. Did you use Arduino or other software? I'm guessing you used Windows.

Nothing but Windows … Win 10

I was using TyComm SerMon - built with IDE 1.8.9 - opened and used Teensy Ports SerMon - Same thing.

Built with IDE and uploaded with TeensyLoader - IDE SerMon Send and restart - 4 seconds - LED FLASH - No Teensy on USB.
 
UPDATE:
I had it plugged through the POWERED HUB I've been using for year +

Plugged USB to TOP ports on DELL and TWO T4's work perfectly FAST

Back to that HUB and - Slow and NO USB behavior repeats ?????
 
Tried another Powered HUB - USB3 HUB with embedded HDD I used for USB testing. Plug that into PC - plug T4 into HUB/DRIVE and it works fine there too.

The USB2 HUB that troubles is a NewEgg/Rosewill RHB-330 that seems no longer stocked. With Two end ports always powered USB and 5 top side USB on a single power switch.


During T4 Beta I noted that USB was kept alive oddly from VamPower or something - I use a dongle switch that cuts 5V power - but leaves data lines.

That has not been an issues and whatever it was made sense or didn't matter at the time.

NOW - that dongle switch is not relevant : Wondering if there is some portion of USB alive that this hub is interacting with?
 
UPDATE:
I had it plugged through the POWERED HUB I've been using for year +

Plugged USB to TOP ports on DELL and TWO T4's work perfectly FAST

Back to that HUB and - Slow and NO USB behavior repeats ?????

Reminds me of my T3.x USB-problems with HUBs I had ...
Since T4 they are gone :)

Edit: I'm glad that the watchdog works now. It would have been real pain for serious software without...
 
Reminds me of my T3.x USB-problems with HUBs I had ...
Since T4 they are gone :)

Those 7 hub ports have been central to all I did the last year with T4 since Beta. The unit is powered and long and slender and fits on my monitor stand, and 2 on and 5 switched was handy at times ....
 
I ran it here (msg #32 code).

Every time I type anything and click Send in the serial monitor, it reboots and USB always reconnects. I tested with Arduino 1.8.9 and Teensyduino 1.49 on Linux 64 bit. Did you use Arduino or other software? I'm guessing you used Windows.

Paul - assuming you might be trying a hub or two? Windows?

Not sure what else I can do. The reboot takes a long time on the hub and no sign or effort to rejoin USB.

If I plug the USB HUB HDD unit into the HUB that fails and Plug the T4 into that - it works Properly.

Of course SLOW reboot is 4 seconds … with :: while (!Serial && millis() < 4000 );

This code does fast blink on start 4 secs while not seeing USB - then goes slower blink - but not connecting when on the Rosewill hub direct.
Code:
void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
  while (!Serial && millis() < 4000 ) {
    digitalWriteFast( 13, !digitalReadFast(13));
    delay(50);
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}

void loop() {
  if ( Serial.available() )SCB_AIRCR = 0x05FA0004;
  digitalWriteFast( 13, !digitalReadFast(13));
  delay(500);
}
 
I tested with Linux (Ubuntu 18.04, 64 bit) and a no-name 7 port hub which is actually two "Genesys Logic, Inc. 4-port hub" chips inside, VID=05e3, PID=0610.

Would you be willing to send me that problematic hub?

Certainly would, already going to post office tomorrow. Just got a box I can use to send it in, will be there early next week.

btw - as far as TD 1.49 and i2c - I got a group of i2c hardware today and Wire scanner tested well to find them all as advertised with T_3.2 and T_4 and a T_3.6. Didn't get back to computer to test on other than Wire yet.
 
Using the 'Rosewill RHB-330 Hub' With a fresh T4 wired to alternate PC USB port it works FIRST TIME (maybe two) after plugging it in and returns to USB, hitting SEND again Resets and then never appears again on USB – though T4 is running. Until the T4 is repowered a Button to bootloader and reset from PC doesn’t work again to get on USB {edit: After a RESET 'Send'}. I put that T4 direct to PC USB and it worked over and over. I moved that HUB to my Surface PC and saw the same behavior. *This also used a different PC to HUB mini USB cable.

Updated sketch with altered blink when !Serial in loop:
Code:
void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
  while (!Serial && millis() < 4000 ) {
    digitalWriteFast( 13, !digitalReadFast(13));
    delay(50);
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}

void loop() {
  if ( Serial.available() )SCB_AIRCR = 0x05FA0004;
  digitalWriteFast( 13, !digitalReadFast(13));
  if ( !Serial ) {
    delay(50);
    digitalWriteFast( 13, !digitalReadFast(13));
  }
  delay(300);
}
 
Last edited:
@Frank B - Thank you for pointing me to this link. I have the weekend to myself (I think), so hope to integrate this into my system. Also want to play with the soft reset that @everybody and you has put so much work into.
This forum is so good.
 
Last edited:
Just edited startrup.c to change :
Code:
IOMUXC_GPR_GPR16 = 0x00200007;

Running a graphics program in STBASIC and pressing <ctrl><alt><del> does a complete soft reset to my boot screen. Next step is to integrate the memory monitor and see if the values return to the same values as during power up.
 
Status
Not open for further replies.
Back
Top