Sorry I don't speak german, but the topic is interesting even it is old
this is the only one I found that talks about short delay on cortex.
I wanted u delay based on the systick.
I am coding with ST HAL for the STM32F3xx
I did not understand the asm code above, so I wrote my own solution that
I share here :
1 | typedef struct __libclk_systickInfo
|
2 | {
|
3 | unsigned long ulRes_ns ; //!< cpt resolution
|
4 | unsigned long ulMax_ns ; //!< delay max appliable NS
|
5 | } LIBCLK_SYSTICKINFO;
|
6 |
|
7 | static LIBCLK_SYSTICKINFO g_systickInfo = {0};
|
8 |
|
9 | void libclk_dlyInit( void )
|
10 | {
|
11 | // Compute the max appliable
|
12 |
|
13 | /*
|
14 | * Compute troncate to int but this does not matter, we'll
|
15 | compensate later "SystemCoreClock "
|
16 | */
|
17 | g_systickInfo.ulRes_ns = (1000000000/SystemCoreClock);
|
18 |
|
19 | /*
|
20 | * Delay on a full counwtown result in impossible thresold detection : we give 100 us margin to CPU (@72MHz)
|
21 | */
|
22 | g_systickInfo.ulMax_ns = ((SysTick->LOAD ) *
|
23 | g_systickInfo.ulRes_ns) - 100000 ;
|
24 |
|
25 | }
|
26 |
|
27 | void libclk_delayNs( unsigned long dlyNs )
|
28 | {
|
29 | // add 1 count to compensate division truncation
|
30 | unsigned long dly_cnt = dlyNs / g_systickInfo.ulRes_ns + 1;
|
31 | // systick execute a countdown
|
32 | unsigned long dly_val = 0;
|
33 | unsigned long systick_val = SysTick->VAL;
|
34 |
|
35 | // deactivate assert when benchmarking
|
36 | assert( g_systickInfo.ulRes_ns && g_systickInfo.ulMax_ns);
|
37 | assert( dly_cnt <= g_systickInfo.ulMax_ns);
|
38 |
|
39 | if( systick_val >= dly_cnt )
|
40 | {
|
41 | dly_val = systick_val - dly_cnt;
|
42 | // wait underflow with 1 countdown detection
|
43 | while( (SysTick->VAL > dly_val) && (SysTick->VAL < systick_val) ){};
|
44 | }
|
45 | else
|
46 | {
|
47 | dly_val = SysTick->LOAD - ( dly_cnt - systick_val ) ;
|
48 | // wait underflow
|
49 | while(SysTick->VAL < systick_val);
|
50 | // wait target underflowed
|
51 | while( SysTick->VAL > dly_val ) {};
|
52 | }
|
53 | }
|
I just did test in debug mode with a gcc toolchain, the minimum I could
do was 1,35 us. I bet the result is better when optimising but my target
was to have us delays.
It would be better if this code was written in disassembly as the
compilation option would not influence the result, but I am not used to
assembly code.
Regards.