nop delay issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

nop delay issue

386 Views
曾经怀念
Contributor II
It may be due to my incorrect MPU configuration, so I added a function to disable the MPU before the RamInit startup file.
 
```
DisableMPU:
    DSB
    ISB
    LDR  R0, =0xE000ED94
    LDR  R1, =0xFFFFFFF8
    STR  R1, [R0]
    DSB
    ISB


RamInit:
    /* Initialize SRAM ECC */
    LDR  R0, =__RAM_INIT
...
```
 
Then after I solved the MPU problem, I deleted that function.
something wrong happend, the same delay function, the delay time changed from 2ms to 16ms
 
BCC_WAIT_FOR_MUL4_CYCLES(624510)
 
#define BCC_WAIT_FOR_MUL4_CYCLES(cycles) \
          __asm( \
            "movs r0, %[cycles] \n" \
            "0: \n"              \
              "subs r0, #4 \n"   \
              "nop \n"           \
            "bne 0b \n"          \
             :                       \
             : [cycles] "r" (cycles) \
             : "r0", "r1", "cc"      \
          )
 
 
I have already compared the MPU/CGM/PLL/SYSTEM CONTROL ... , and they are all consistent.
0 Kudos
Reply
1 Reply

350 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @曾经怀念 

 

MPU is a module which affects the cache attributes. If you want to make some memory area cache inhibited or cacheable, this must be done by configuration of MPU.

If the execution time is changed in that way, it’s obviously caused by different cache attributes – default MPU attributes when MPU is disabled vs. attributes configured by your application.

So, you need to take this into consideration.

 

From my experience, it’s better to keep such hard loops in cacheable memory. Here’s the reason why (simplified):

If some loop is placed to non-cacheable memory, it depends on exact address. If the loop fits within one flash line, it will be read from physical flash (which is slow) only first time then then the code will be fetched from flash read buffer. So, the execution time will be fast. If you shift the code, so the loop will be split to two flash lines, the physical flash needs to be read many times due to buffer miss. This will make the execution significantly slower.

So, anytime you add some code to your project, everything may be shifted and it can affect the hard loops.

If you keep this code in cacheable memory, the instruction cache will eliminate most of such effects.

 

Another option is to keep such loop at defined address which is non-cacheable. The disadvantage is that you need to have such area defined in linker file.

 

Regards,

Lukas

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2341822%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Enop%20delay%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2341822%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CDIV%3E%3CSPAN%3E%3CSPAN%3E%3CFONT%20color%3D%22%230000FF%22%3EIt%20may%20be%20due%20to%20my%20incorrect%20MPU%20configuration%2C%20so%20I%20added%20a%20function%20to%20disable%20the%20MPU%20before%20the%20RamInit%20startup%20file.%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CSPAN%3E%60%60%60%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23FF9900%22%3E%3CSPAN%3EDisableMPU%3A%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23FF9900%22%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EDSB%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23FF9900%22%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EISB%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23FF9900%22%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3ELDR%3C%2FSPAN%3E%3CSPAN%3E%20%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ER0%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3D%3C%2FSPAN%3E%3CSPAN%3E0xE000ED94%3C%2FSPAN%3E%3C%2F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sp%3B%20%3C%2FSPAN%3E%3CSPAN%3ELDR%3C%2FSPAN%3E%3CSPAN%3E%20%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ER0%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3D%3C%2FSPAN%3E%3CSPAN%3E__RAM_INIT%3CBR%20%2F%3E%3C%2FSPAN%3E...%3C%2FDIV%3E%3CDIV%3E%60%60%60%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3EThen%20after%20I%20solved%20the%20MPU%20problem%2C%20I%20deleted%20that%20function.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CSPAN%3E%3CFONT%20color%3D%22%230000FF%22%3Esomething%20wrong%20happend%2C%20the%20same%20delay%20function%2C%20the%20delay%20time%20changed%20from%202ms%20to%2016ms%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CSPAN%3EBCC_WAIT_FOR_MUL4_CYCLES(624510)%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23define%3C%2FSPAN%3E%20%3CSPAN%3EBCC_WAIT_FOR_MUL4_CYCLES%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3Ecycles%3C%2FSPAN%3E%3CSPAN%3E)%20%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E__asm%3C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p%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%22nop%20%3C%2FSPAN%3E%3CSPAN%3E%5Cn%3C%2FSPAN%3E%3CSPAN%3E%22%3C%2FSPAN%3E%3CSPAN%3E%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%22bne%200b%20%3C%2FSPAN%3E%3CSPAN%3E%5Cn%3C%2FSPAN%3E%3CSPAN%3E%22%3C%2FSPAN%3E%3CSPAN%3E%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3A%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3A%20%5Bcycles%5D%20%3C%2FSPAN%3E%3CSPAN%3E%22r%22%3C%2FSPAN%3E%3CSPAN%3E%20(cycles)%20%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3A%20%3C%2FSPAN%3E%3CSPAN%3E%22r0%22%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3E%22r1%22%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3E%22cc%22%3C%2FSPAN%3E%3CSPAN%3E%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSPAN%3EI%20have%20already%20compared%20the%20MPU%2FCGM%2FPLL%2FSYSTEM%20CONTROL%20...%20%2C%20and%20they%20are%20all%20consistent.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2342055%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20nop%20delay%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2342055%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F134657%22%20target%3D%22_blank%22%3E%40%E6%9B%BE%E7%BB%8F%E6%80%80%E5%BF%B5%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EMPU%20is%20a%20module%20which%20affects%20the%20cache%20attributes.%20If%20you%20want%20to%20make%20some%20memory%20area%20cache%20inhibited%20or%20cacheable%2C%20this%20must%20be%20done%20by%20configuration%20of%20MPU.%3C%2FP%3E%0A%3CP%3EIf%20the%20execution%20time%20is%20changed%20in%20that%20way%2C%20it%E2%80%99s%20obviously%20caused%20by%20different%20cache%20attributes%20%E2%80%93%20default%20MPU%20attributes%20when%20MPU%20is%20disabled%20vs.%20attributes%20configured%20by%20your%20application.%3C%2FP%3E%0A%3CP%3ESo%2C%20you%20need%20to%20take%20this%20into%20consideration.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EFrom%20my%20experience%2C%20it%E2%80%99s%20better%20to%20keep%20such%20hard%20loops%20in%20cacheable%20memory.%20Here%E2%80%99s%20the%20reason%20why%20(simplified)%3A%3C%2FP%3E%0A%3CP%3EIf%20some%20loop%20is%20placed%20to%20non-cacheable%20memory%2C%20it%20depends%20on%20exact%20address.%20If%20the%20loop%20fits%20within%20one%20flash%20line%2C%20it%20will%20be%20read%20from%20physical%20flash%20(which%20is%20slow)%20only%20first%20time%20then%20then%20the%20code%20will%20be%20fetched%20from%20flash%20read%20buffer.%20So%2C%20the%20execution%20time%20will%20be%20fast.%20If%20you%20shift%20the%20code%2C%20so%20the%20loop%20will%20be%20split%20to%20two%20flash%20lines%2C%20the%20physical%20flash%20needs%20to%20be%20read%20many%20times%20due%20to%20buffer%20miss.%20This%20will%20make%20the%20execution%20significantly%20slower.%3C%2FP%3E%0A%3CP%3ESo%2C%20anytime%20you%20add%20some%20code%20to%20your%20project%2C%20everything%20may%20be%20shifted%20and%20it%20can%20affect%20the%20hard%20loops.%3C%2FP%3E%0A%3CP%3EIf%20you%20keep%20this%20code%20in%20cacheable%20memory%2C%20the%20instruction%20cache%20will%20eliminate%20most%20of%20such%20effects.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EAnother%20option%20is%20to%20keep%20such%20loop%20at%20defined%20address%20which%20is%20non-cacheable.%20The%20disadvantage%20is%20that%20you%20need%20to%20have%20such%20area%20defined%20in%20linker%20file.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ERegards%2C%3C%2FP%3E%0A%3CP%3ELukas%3C%2FP%3E%3C%2FLINGO-BODY%3E