Yep - I thought I would try changing the #if 0's to 1s... To see what it all needed... As you mentioned it requires usbmem.h/c, but again have not looked any deeper!
teensy4b.menu.opt.o3std.build.flags.optimize=-O3 -fno-tree-loop-if-convert -fno-sched-interblock -fno-tree-copyrename -fno-ipa-sra -fgcse-las -fno-schedule-insns -fno-tree-loop-distribute-patterns -fno-caller-saves -fno-optimize-strlen -fno-inline-functions-called-once -fno-tree-slsr -fno-tree-scev-cprop -funroll-all-loops -fno-sched-dep-count-heuristic -fno-tree-ccp -fno-predictive-commoning -fno-ipa-pure-const -fno-merge-constants
// Stack frame
// xPSR
// ReturnAddress
// LR (R14) - typically FFFFFFF9 for IRQ or Exception
// R12
// R3
// R2
// R1
// R0
// Code from :: https://community.nxp.com/thread/389002
void HardFault_HandlerC(unsigned int *hardfault_args) [COLOR=#ff0000]__attribute__((used));[/COLOR]
__attribute__((naked))
void unused_interrupt_vector(void)
{
__asm( ".syntax unified\n"
"MOVS R0, #4 \n"
"MOV R1, LR \n"
"TST R0, R1 \n"
"BEQ _MSP \n"
"MRS R0, PSP \n"
"B HardFault_HandlerC \n"
"_MSP: \n"
"MRS R0, MSP \n"
"B HardFault_HandlerC \n"
".syntax divided\n") ;
}
__attribute__((weak))
void HardFault_HandlerC(unsigned int *hardfault_args) {
volatile unsigned int nn ;
[COLOR=#ff0000]#if defined(PRINT_DEBUG_STUFF) [/COLOR]
volatile unsigned int stacked_r0 ;
volatile unsigned int stacked_r1 ;
volatile unsigned int stacked_r2 ;
volatile unsigned int stacked_r3 ;
volatile unsigned int stacked_r12 ;
volatile unsigned int stacked_lr ;
volatile unsigned int stacked_pc ;
volatile unsigned int stacked_psr ;
volatile unsigned int _CFSR ;
volatile unsigned int _HFSR ;
volatile unsigned int _DFSR ;
volatile unsigned int _AFSR ;
volatile unsigned int _BFAR ;
volatile unsigned int _MMAR ;
volatile unsigned int addr ;
stacked_r0 = ((unsigned int)hardfault_args[0]) ;
stacked_r1 = ((unsigned int)hardfault_args[1]) ;
stacked_r2 = ((unsigned int)hardfault_args[2]) ;
stacked_r3 = ((unsigned int)hardfault_args[3]) ;
stacked_r12 = ((unsigned int)hardfault_args[4]) ;
stacked_lr = ((unsigned int)hardfault_args[5]) ;
stacked_pc = ((unsigned int)hardfault_args[6]) ;
stacked_psr = ((unsigned int)hardfault_args[7]) ;
// Configurable Fault Status Register
// Consists of MMSR, BFSR and UFSR
_CFSR = (*((volatile unsigned int *)(0xE000ED28))) ;
// Hard Fault Status Register
_HFSR = (*((volatile unsigned int *)(0xE000ED2C))) ;
// Debug Fault Status Register
_DFSR = (*((volatile unsigned int *)(0xE000ED30))) ;
// Auxiliary Fault Status Register
_AFSR = (*((volatile unsigned int *)(0xE000ED3C))) ;
// Read the Fault Address Registers. These may not contain valid values.
// Check BFARVALID/MMARVALID to see if they are valid values
// MemManage Fault Address Register
_MMAR = (*((volatile unsigned int *)(0xE000ED34))) ;
// Bus Fault Address Register
_BFAR = (*((volatile unsigned int *)(0xE000ED38))) ;
//__asm("BKPT #0\n") ; // Break into the debugger // NO Debugger here.
asm volatile("mrs %0, ipsr\n" : "=r" (addr)::);
printf_debug("\nFault irq %d\n", addr & 0x1FF);
printf_debug(" stacked_r0 :: %x\n", stacked_r0);
printf_debug(" stacked_r1 :: %x\n", stacked_r1);
printf_debug(" stacked_r2 :: %x\n", stacked_r2);
printf_debug(" stacked_r3 :: %x\n", stacked_r3);
printf_debug(" stacked_r12 :: %x\n", stacked_r12);
printf_debug(" stacked_lr :: %x\n", stacked_lr);
printf_debug(" stacked_pc :: %x\n", stacked_pc);
printf_debug(" stacked_psr :: %x\n", stacked_psr);
printf_debug(" _CFSR :: %x\n", _CFSR);
printf_debug(" _HFSR :: %x\n", _HFSR);
printf_debug(" _DFSR :: %x\n", _DFSR);
printf_debug(" _AFSR :: %x\n", _AFSR);
printf_debug(" _BFAR :: %x\n", _BFAR);
printf_debug(" _MMAR :: %x\n", _MMAR);
[COLOR=#ff0000]#endif[/COLOR]
IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_03 = 5; // pin 13
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_03 = IOMUXC_PAD_DSE(7);
GPIO2_GDIR |= (1 << 3);
GPIO2_DR_SET = (1 << 3);
GPIO2_DR_CLEAR = (1 << 3); //digitalWrite(13, LOW);
if ( F_CPU_ACTUAL >= 600000000 )
set_arm_clock(300000000);
while (1)
{
GPIO2_DR_SET = (1 << 3); //digitalWrite(13, HIGH);
// digitalWrite(13, HIGH);
for (nn = 0; nn < 2000000/2; nn++) ;
GPIO2_DR_CLEAR = (1 << 3); //digitalWrite(13, LOW);
// digitalWrite(13, LOW);
for (nn = 0; nn < 18000000/2; nn++) ;
}
}
@Defragster:
I had to do the following changes to make LTO work:
Can you review that, and (maybe) do a pullrequest for Paul? Thanks
Suppose USB coming along as best it can - haven't seen Paul note it lately …
Don't be sorry - if its like the one I had its the cold that just doesn't want to go away.Sorry. I had an outdoor event to attend last week which seemed fine at the time, but then relapsed on this damn cold! Did the "lots of rest and liquids" thing for a few days. A couple PJRC tech issues came up, like needing to fix / update our test fixtures. Feeling better these last few days, built up more beta test hardware... so we can expand the list.
Maybe I'll extent the quick-and-dirty USB serial to implement available() and read(). That should give us something to at least use for testing, until I can really work on performance optimization.
Can we make a list: which module uses which clock, please?
Yep - I thought I would try changing the #if 0's to 1s... To see what it all needed... As you mentioned it requires usbmem.h/c, but again have not looked any deeper!
...
Maybe I'll extent the quick-and-dirty USB serial to implement available() and read(). That should give us something to at least use for testing, until I can really work on performance optimization.
I'm guessing you're looking for something different than the huge list on pages 987-1000 of the RT1050 ref manual, rev2 ?
#define SER_IN Serial1
void setup() {
// put your setup code here, to run once:
SER_IN.begin(1843200);
while (!SER_IN && millis() < 4000 );
SER_IN.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}
float val;
void loop() {
SER_IN.print("Enter a number - float if you please = ");
while (SER_IN.available() == 0) { delay(100);}
delay(100);
val = SER_IN.parseFloat();
SER_IN.print("You Entered=");
SER_IN.println(val);
if ( 10 == SER_IN.peek() ) { SER_IN.read(); SER_IN.println("Ate the NewLine!"); }
}
virtual int available(void);
virtual int peek(void);
Yes HardwareSerial:eek() is implemented, which is very similar to the read function:Is Serial#.peek() not implemented? This code works on "Serial" with T_3.6 { without the two delay(100)'s }
Also this code as FASTER w/LTO hangs T4 but works FAST w/LTO:
I'm doing this to test w/LTO compile and FrankB's (used) - it seemed simple sketch - when I fault at the end of setup() { …; GPT1_CNT = 5; // FAULT } it gives the DUMP and blinks but acts really ODD confusing TyComm to a Windows Hourglass, not responding - even with debug_tt. I've done a lot of faulting - mostly this one on T4 - and not seen this before?
int HardwareSerial::peek(void)
{
uint32_t head, tail;
head = rx_buffer_head_;
tail = rx_buffer_tail_;
if (head == tail) return -1;
if (++tail >= rx_buffer_total_size_) tail = 0;
if (tail < rx_buffer_size_) {
return rx_buffer_[tail];
} else {
return rx_buffer_storage_[tail-rx_buffer_size_];
}
}
int HardwareSerial::read(void)
{
uint32_t head, tail;
int c;
head = rx_buffer_head_;
tail = rx_buffer_tail_;
if (head == tail) return -1;
if (++tail >= rx_buffer_total_size_) tail = 0;
if (tail < rx_buffer_size_) {
c = rx_buffer_[tail];
} else {
c = rx_buffer_storage_[tail-rx_buffer_size_];
}
rx_buffer_tail_ = tail;
if (rts_pin_baseReg_) {
uint32_t avail;
if (head >= tail) avail = head - tail;
else avail = rx_buffer_total_size_ + head - tail;
if (avail <= rts_low_watermark_) rts_assert();
}
return c;
}
#define SER_IN Serial1
void setup() {
// put your setup code here, to run once:
SER_IN.begin(115200);
while (!SER_IN && millis() < 4000 );
SER_IN.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}
float val;
void loop() {
SER_IN.print("Enter a number - float if you please = ");
while (SER_IN.available() == 0) { delay(100);}
delay(100);
val = SER_IN.parseFloat();
SER_IN.print("You Entered=");
SER_IN.println(val);
int ch;
while ((ch = SER_IN.read()) != -1) SER_IN.printf("%02x ", ch);
SER_IN.println();
if ( 10 == SER_IN.peek() ) { SER_IN.read(); SER_IN.println("Ate the NewLine!"); }
}
C:\Users\kurte\Documents\Arduino\zzz\zzz.ino Feb 15 2019 05:52:06
Enter a number - float if you please = You Entered=1.23
0d 0a
Enter a number - float if you please =
Yes, a list which shows which library or module uses which clock (and at which speed, if it changes it) actually. Perhaps it could show which other resources are used, too.
Such a list would it make way easier to write compatible libraries, without guessing "does any lib change the settings of 'my' clock"?" Or, can I change it, without breaking other things?
For example the audio-lib *will* change the freq. of PLL4 and does not use the defaults. Anything else should be aware of that.
And if we want to use higher speeds for SPI, we need to adjust some things, too..
A lot of info to absorb if you want to get into it.
Thanks Paul - I normally had to hunt for it...This is the link for a copy of just the USB 2.0 spec (hosted on PJRC's server) without all that other stuff.
https://www.pjrc.com/teensy/beta/usb20.pdf
I've never understood why the USB-If website doesn't support the concept of permalinks to these important documents.