Kenji Arai
/
FPU_performance_on_F446_and_F411
Check FPU function using Cos & Sin calculation
Revision 1:a8ba417b1717, committed 2021-01-25
- Comitter:
- kenjiArai
- Date:
- Mon Jan 25 05:09:37 2021 +0000
- Parent:
- 0:c46022441981
- Child:
- 2:742afd5cf29f
- Commit message:
- Run on mbed-os6.6.0
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_revision.cpp Mon Jan 25 05:09:37 2021 +0000 @@ -0,0 +1,27 @@ +/* + * Check Mbed revision + * + * Copyright (c) 2019,'20,'21 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Created: July 17th, 2019 + * Revised: January 11th, 2021 + */ + +#include "mbed.h" + +// RUN ONLY ON mbed-os-6.6.0 +// https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-6.6.0 +#if (MBED_MAJOR_VERSION == 6) &&\ + (MBED_MINOR_VERSION == 6) &&\ + (MBED_PATCH_VERSION == 0) +#else +# error "Please use mbed-os-6.6.0" +#endif + +void print_revision(void) +{ + printf("MBED_MAJOR_VERSION = %d, ", MBED_MAJOR_VERSION); + printf("MINOR = %d, ", MBED_MINOR_VERSION); + printf("PATCH = %d\r\n", MBED_PATCH_VERSION); +}
--- a/main.cpp Thu Aug 31 11:40:11 2017 +0000 +++ b/main.cpp Mon Jan 25 05:09:37 2021 +0000 @@ -1,36 +1,36 @@ /* - * Check FPU function using Cos & Sin calculation + * Check FPU function using Cos & Sin calculation * - * Copyright (c) 2017 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ + * Copyright (c) 2017,'21 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ * Modify: August 31st, 2017 - * Revised: August 31st, 2017 + * Revised: January 25th, 2021 */ /*============================================================================== - ------------------------ My boards result ------------------------------- - STM32F446RE STM32F411RE - Sys Clock 180 MHz 100 MHz - double 24074 nS 39751 nS - ratio(double/float) 20.02 21.85 - float 1102 nS 1986 nS - ratio(F411/F446 double) 1.65 - ratio(F411/F446 float) 1.80 + -------------------- My boards result ------------------------------- + STM32F446RE STM32F411RE STM32H743ZI2 + Sys Clock 180 MHz 100 MHz 480 MHz + double 23844 nS 39710 nS 1149 ns + float 1085 nS 1954 nS 375 ns + ratio(double/float) 21.98 20.32 3.06 + + ratio(F446/H743 double) 20.75 + ratio(F446/H743 float) 2.89 + ratio(F411/F446 double) 1.67 + ratio(F411/F446 float) 1.80 ============================================================================*/ // Include -------------------------------------------------------------------- #include "mbed.h" +#include "uart_as_stdio.h" // Definition ----------------------------------------------------------------- -#if defined(TARGET_STM32F446RE) || defined(TARGET_STM32F411xE) +#define PI 3.14159265 #define BUF_SIZE 7000 -#else -#error "You need modify your program for your specific target CPU" -#endif // Constractor ---------------------------------------------------------------- -Serial pc(USBTX, USBRX); DigitalIn sw(USER_BUTTON); Timer t; @@ -39,53 +39,59 @@ double buf1[BUF_SIZE]; // ROM / Constant data -------------------------------------------------------- - + // Function prototypes -------------------------------------------------------- void test_FPU_0(float *buf0); void test_FPU_1(double *buf1); +extern void print_revision(void); //------------------------------------------------------------------------------ // Control Program //------------------------------------------------------------------------------ int main() { - pc.printf("\r\nSystem Clock = %d Hz\r\n", HAL_RCC_GetSysClockFreq()); + print_revision(); + printf("\r\nSystem Clock = %d Hz\r\n", HAL_RCC_GetSysClockFreq()); // Check FPU settings #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + // Set bits 20-23 to enable CP10 and CP11 coprocessors + // SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); // Mbed compiler set CP10 and CP11 Full Access - // SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); - pc.printf("Use FPU function (compiler enables FPU)\r\n"); - pc.printf("SCB->CPACR(0x%08x) = 0x%08x\r\n", &SCB->CPACR, SCB->CPACR); + printf("Use FPU function (compiler enables FPU)\r\n"); + printf("SCB->CPACR(0x%08x) = 0x%08x\r\n", + (uint32_t)&SCB->CPACR, SCB->CPACR); #else - #warning "NOT use FPU in your setting" +#warning "NOT use FPU in your setting" #endif - pc.printf("Buf size in RAM = %d + %d = %d bytes\r\n", - sizeof(buf0), sizeof(buf1), sizeof(buf0) + sizeof(buf1)); - pc.printf("Repeat number = %d\r\n", BUF_SIZE); - pc.printf("\r\nHit any key or push USER SW then show buffer content\r\n"); - pc.printf("Following time is average calculate time Sin()+Cos()\r\n"); - pc.printf(" (float) (double)\r\n"); + printf("Buf size in RAM = %d + %d = %d bytes\r\n", + sizeof(buf0), sizeof(buf1), sizeof(buf0) + sizeof(buf1)); + printf("Repeat number = %d\r\n", BUF_SIZE); + printf("\r\nHit any key then show buffer content\r\n"); + printf("Following time is average calculate time Sin()+Cos()\r\n"); + printf(" (float) (double)\r\n"); while (true) { uint32_t t0, t1; t.reset(); t.start(); test_FPU_0(buf0); - t0 = t.read_us(); + t0 = t.elapsed_time().count(); t.reset(); t.start(); test_FPU_1(buf1); - t1 = t.read_us(); - pc.printf("t0 =%.3f uS, t1 =%.3f uS\r\n", - (float)t0 / (float)BUF_SIZE, (float)t1 / (float)BUF_SIZE); - if ((sw == 0) || (pc.readable())){ - for (uint16_t n = 0; n < BUF_SIZE; n++){ - pc.printf("%+8.6f,%+8.6lf,%+8.6lf\r\n", - buf0[n], buf1[n], (double)buf0[n] - buf1[n]); + t1 = t.elapsed_time().count(); + printf("t0 =%.3f uS, t1 =%.3f uS\r\n", + (double)t0 / (double)BUF_SIZE, (double)t1 / (double)BUF_SIZE); + if (readable()) { + for (uint16_t n = 0; n < BUF_SIZE; n++) { + printf("%+8.6f,%+8.6lf,%+8.6lf\r\n", + buf0[n], buf1[n], (double)buf0[n] - buf1[n]); } - while (pc.readable()){ pc.getc();} + while (readable()) { + getc(); + } } - wait(1.0f); + ThisThread::sleep_for(1s); } } @@ -97,7 +103,7 @@ step = ((2.0f * PI) + 0.1f) / (float)BUF_SIZE; d = 0.0f; - for(i = 0; i < BUF_SIZE; i++){ + for(i = 0; i < BUF_SIZE; i++) { d0 = sin(d); d1 = cos(d); d += step; @@ -111,9 +117,9 @@ volatile double d, d0, d1; double step; - step = ((2.0f * PI) + 0.1f) / (double)BUF_SIZE; - d = 0.0f; - for(i = 0; i < BUF_SIZE; i++){ + step = ((2.0 * PI) + 0.1) / (double)BUF_SIZE; + d = 0.0; + for(i = 0; i < BUF_SIZE; i++) { d0 = sin(d); d1 = cos(d); d += step;
--- a/mbed-os.lib Thu Aug 31 11:40:11 2017 +0000 +++ b/mbed-os.lib Mon Jan 25 05:09:37 2021 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#db4be94693c3a873cfa0c025a5ad2e62b86a8474 +https://github.com/ARMmbed/mbed-os/#84d991342a41011fc417aab62c0f5a8832f1d18f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Mon Jan 25 05:09:37 2021 +0000 @@ -0,0 +1,9 @@ +{ + "target_overrides": { + "*": { + "target.printf_lib": "std", + "target.components_add": ["SD"], + "target.features_add":["STORAGE"] + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uart_as_stdio/uart_as_stdio.cpp Mon Jan 25 05:09:37 2021 +0000 @@ -0,0 +1,46 @@ +/* + * mbed Application program + * Redirect Standard Input/Output + * + * Copyright (c) 2021 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Created: January 13th, 2021 + * Revised: January 14th, 2021 + */ + +// Include -------------------------------------------------------------------- +#include "mbed.h" + +// Definition ----------------------------------------------------------------- + +// Constructor ---------------------------------------------------------------- +static BufferedSerial pc(USBTX, USBRX, 115200); + +// RAM ------------------------------------------------------------------------ + +// ROM / Constant data -------------------------------------------------------- + +// Function prototypes -------------------------------------------------------- + +//------------------------------------------------------------------------------ +// Control Program +//------------------------------------------------------------------------------ +uint8_t readable() +{ + return pc.readable(); +} + +void putc(uint8_t c) +{ + char dt[4]; + dt[0] = (char)c; + pc.write(dt, 1); +} + +uint8_t getc() +{ + char dt[4]; + pc.read(dt, 1); + return (uint8_t)dt[0]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uart_as_stdio/uart_as_stdio.h Mon Jan 25 05:09:37 2021 +0000 @@ -0,0 +1,17 @@ +/* + * mbed Application program + * Redirect Standard Input/Output + * + * Copyright (c) 2021 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Created: January 13th, 2021 + * Revised: January 14th, 2021 + */ + +#include "mbed.h" + +// Function prototypes -------------------------------------------------------- +uint8_t readable(void); +void putc(uint8_t c); +uint8_t getc(void);