Skip to content

Fix timing issues found in "Flash - clock and cache test" #4666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions TESTS/mbed_hal/flash/functional_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,57 @@ static void erase_range(flash_t *flash, uint32_t addr, uint32_t size)
size = size > sector_size ? size - sector_size : 0;
}
}
#ifdef __CC_ARM
MBED_NOINLINE
__asm static void delay_loop(uint32_t count)
{
1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a question regarding this 1, is it required? I came across this code today, and wondering if this is line is needed?

SUBS a1, a1, #1
BCS %BT1
BX lr
}
#elif defined (__ICCARM__)
MBED_NOINLINE
static void delay_loop(uint32_t count)
{
__asm volatile(
"loop: \n"
" SUBS %0, %0, #1 \n"
" BCS.n loop\n"
: "+r" (count)
:
: "cc"
);
}
#else // GCC
MBED_NOINLINE
static void delay_loop(uint32_t count)
{
__asm__ volatile (
"%=:\n\t"
#if defined(__thumb__) && !defined(__thumb2__)
"SUB %0, #1\n\t"
#else
"SUBS %0, %0, #1\n\t"
#endif
"BCS %=b\n\t"
: "+l" (count)
:
: "cc"
);
}
#endif

MBED_NOINLINE
static int time_cpu_cycles(uint32_t cycles)
{
Timer timer;
timer.start();

int timer_start = timer.read_us();

volatile uint32_t delay = (volatile uint32_t)cycles;
while (delay--);

uint32_t delay = cycles;
delay_loop(delay);
int timer_end = timer.read_us();

timer.stop();
Expand Down
21 changes: 21 additions & 0 deletions platform/mbed_toolchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@
#endif
#endif

/** MBED_NOINLINE
* Declare a function that must not be inlined.
*
* @code
* #include "mbed_toolchain.h"
*
* MBED_NOINLINE void foo() {
*
* }
* @endcode
*/
#ifndef MBED_NOINLINE
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
#define MBED_NOINLINE __attribute__((noinline))
#elif defined(__ICCARM__)
#define MBED_NOINLINE _Pragma("inline=never")
#else
#define MBED_NOINLINE
#endif
#endif

/** MBED_FORCEINLINE
* Declare a function that must always be inlined. Failure to inline
* such a function will result in an error.
Expand Down