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

Thread: printf error at 24 MHz with teensy4.0

  1. #1
    Senior Member
    Join Date
    Feb 2019
    Posts
    123

    printf error at 24 MHz with teensy4.0

    If I run the following program:
    Code:
    extern "C" uint32_t set_arm_clock(uint32_t frequency);
       
    float x1,x2 ;
    float b11,b12,b21,b22 ;
    float xshb1,xshb2 ;
    
    void setup() {
      Serial.begin(115200);  
      while(!Serial) ;
      Serial.println("teensy40timingMat22Mul1printError1...") ;
      set_arm_clock(24000000) ;
     
      b11=cos(1) ;
      b12=sin(1) ;
      b21=-sin(1) ;
      b22=cos(1) ; 
      
      x1=1.0 ; x2=0.0 ;
      xshb1=b11*x1+b12*x2 ;
      xshb2=b21*x1+b22*x2 ;
      
      Serial.print("x1   =") ;  printFloat(x1) ;
      Serial.print("     x2=") ;  printFloat(x2) ; Serial.println(" ") ;
      Serial.print("xshb1=") ;  printFloat(xshb1) ;
      Serial.print("  xshb2=") ;  printFloat(xshb2) ; Serial.println(" ") ;
      }
    
    void printFloat(float x){
      Serial.printf(" ::%15.10f",x) ;
      //Serial.print(x) ;
      }
          
    void loop() {
       }
    I would expect the following output:
    Code:
    teensy40timingMat22Mul1printError1...
    x1   = ::   1.0000000000     x2= ::   0.0000000000 
    xshb1= ::   0.5403022766  xshb2= ::  -0.8414709568
    Instead I get something like this:
    Code:
    teensy40timingMat22Mul1printError1...
    x1   = ::   1.0000000000     x2= ::   0.0000000000 
    xshb1=\GmGH3}/Aޟ�k<�Hik/({̰^'đ  xshb2= ::  -0.8414709568
    The output depends on the program I did execute before this program. The output you see is for the case that the program is the first after powering up the teensy 4.0.
    It seems that printf uses some wrong memory. The error has been observed only at 24MHz CPU frequency. With other frequencies I don't see the error. Any idea what goes wrong here?

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,208
    I've seen that as well - seems it was more intermittent so continue code and printing and see what happens - but generally worked. Not sure if T4 is spec'd to have USB at 24 MHz - Paul will likely comment when he sees your post.

    For now try 25 or 26 MHz request and check F_CPU_ACTUAL - bumping up the next notch may be work-around- but won't result in the same power profile as it Voltage drops again at 24 MHz.

    Though one clock until TD 1.48 was at 30 MHz in 24 MHz mode - general tests here may predate that - though sure I tested as I discovered coding error behind the 30 MHz issue.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,498
    We should probably configure the USB PHY to only work at 12 Mbit speed when 24 MHz is configured.

    Really, it's pretty amazing it works at all. I believe NXP has a minimum speed spec for USB to get enough memory bandwidth. I don't recall the number, but I remember it had 3 digits! 24 MHz is so far below what is supposed to be able to work at all.

  4. #4
    Senior Member
    Join Date
    Feb 2019
    Posts
    123
    Quote Originally Posted by PaulStoffregen View Post
    We should probably configure the USB PHY to only work at 12 Mbit speed when 24 MHz is configured.
    Can I configure the USB PHY to work at 12 Mbit?

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,498
    I haven't tried it in device mode, but in host mode the PORTSC register PFSC bit forces 12 Mbit speed.

    https://github.com/PaulStoffregen/US.../ehci.cpp#L262

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Is it possible, that the Teensy is not the only problem?. A similar problem occurs with the Serial monitor?
    Last edited by Frank B; 01-27-2020 at 10:15 PM.

  7. #7
    Senior Member
    Join Date
    Feb 2019
    Posts
    123
    I now observe printf errors also on the teensy 4.0 running at 100MHz

Posting Permissions

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