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

Thread: What is the purpose of these NOPs in Teensy 4.0 initialization?

  1. #1
    Junior Member
    Join Date
    Aug 2019
    Posts
    13

    What is the purpose of these NOPs in Teensy 4.0 initialization?

    In Teensyduino's cores/teensy4/startup.c, the reset ISR void ResetHandler(void) has the following surprise:

    Code:
         ...
    
         configure_cache();
         configure_systick();
         usb_pll_start();
         reset_PFD(); //TODO: is this really needed?
     #ifdef F_CPU
         set_arm_clock(F_CPU);
     #endif
    
         asm volatile("nop\n nop\n nop\n nop": : :"memory"); // why oh why?
    
         // Undo PIT timer usage by ROM startup
         CCM_CCGR1 |= CCM_CCGR1_PIT(CCM_CCGR_ON);
         PIT_MCR = 0;
         PIT_TCTRL0 = 0;
         PIT_TCTRL1 = 0;
         PIT_TCTRL2 = 0;
         PIT_TCTRL3 = 0;
    
         ...
    It occurs immediately after setting the ARM PLL and core frequencies.

    I'm curious what its purpose is, what problem is it alleviating, and if other software reset handlers need to mimic this to avoid a known pitfall?

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    900
    Probably to clear the instruction pipeline while the clocks are stabilizing?

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,844
    From the comment, because it made it work...

    Probably trial and error. MarkT's answer if probably a good guess.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    174
    The operations are there to allow the processor to pause and consider the existential dread it becomes aware of each time it's powered on.

  5. #5
    Member
    Join Date
    Feb 2017
    Location
    Chicago, IL
    Posts
    27
    It's a quick snack for the processor. Or is that asm volatile("nom nom nom nom nom")? I forget.

    I (and others) use them for short delays; for instance, I'm driving a parallel ILI9488, and strobing the write pin low then high happens too fast for the ILI9488 to read the data @600Mhz T4.1. 8 nops between the low and high provides an appropriate pause.

Posting Permissions

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