爱板网论坛

查看: 938|回复: 0

[原创] Nucleo-L432KC arm-none-eabi-gcc CoreMark跑分

[复制链接]

主题

好友

54

积分

童生

  • TA的每日心情
    开心
    2018-1-9 13:07
  • 签到天数: 6 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2017-12-28 22:09:36 |显示全部楼层
    在网上都是keil或IAR上移植CoreMark,没有用gcc进行移植的,现在就用arm-none-eabi-gcc编译CoreMark
    1.用stm32cubeMx创建makefile项目,选择Necleo-L432KC
    屏幕快照 2017-12-28 下午7.03.44.png

    设置80MHz系统时钟
    屏幕快照 2017-12-28 下午7.04.11.png

    选usart2,波特率9600
    屏幕快照 2017-12-28 下午7.04.44.png


    项目设置为makefile
    屏幕快照 2017-12-28 下午7.05.15.png

    屏幕快照 2017-12-28 下午7.05.36.png


    生成项目,修改makefile文件 注释掉DEBUG变量;改OPT=-O3 -fno-common -funroll-loops -finline-functions; 删除C_SOURCES中重复的文件名,添加Src/syscalls.c,Src/coremark/core_list_join.c Src/coremark/core_main.c Src/coremark/core_matrix.c Src/coremark/core_state.c Src/coremark/core_util.c Src/core_portme.c ;设置BINPATH为arm-none-eabi-gcc所在的路径;LDFLAGS += -u _printf_float ;添加flash目标“flash(BUILD_DIR)/$(TARGET).bin st-flash --reset write $< 0x08000000”;C_INCLUDES加-ISrc/coremark项

    2.移植CoreMark。下载CoreMark:http://www.eembc.org/coremark/download.php,将core_list_join.c,core_main.c,core_matrix.c ,core_state.c, core_util.c拷贝到项目的Src/coremark子目录,barebones目录的core_portme.c和core_portme.h分别拷贝到项目的Src和Inc子目录,删除stm32cubemx生成的main.c
    修改core_portme.c,删除main.c前,将main.c中的一些l常量、函数添加core_portme.c中,修改其中的start_time()、stop_time()、get_time()、portable_init()等函数。改后core_portme.c:
    1. /*
    2. <blockquote><span class="Apple-tab-span" style="white-space:pre">        </span>File : core_portme.c
    复制代码
    修改core_portme.h。改宏COMPILER_FLAGS为 "-O3 -fno-common -funroll-loops -finline-functions",加ITERATIONS 为12000
    改后的core_portme.h文件:
    1. /* File : core_portme.h */

    2. /*
    3.         Author : Shay Gal-On, EEMBC
    4.         Legal : TODO!
    5. */
    6. /* Topic : Description
    7.         This file contains configuration constants required to execute on different platforms
    8. */
    9. #ifndef CORE_PORTME_H
    10. #define CORE_PORTME_H
    11. /************************/
    12. /* Data types and settings */
    13. /************************/
    14. /* Configuration : HAS_FLOAT
    15.         Define to 1 if the platform supports floating point.
    16. */
    17. #ifndef HAS_FLOAT
    18. #define HAS_FLOAT 1
    19. #endif
    20. /* Configuration : HAS_TIME_H
    21.         Define to 1 if platform has the time.h header file,
    22.         and implementation of functions thereof.
    23. */
    24. #ifndef HAS_TIME_H
    25. #define HAS_TIME_H 1
    26. #endif
    27. /* Configuration : USE_CLOCK
    28.         Define to 1 if platform has the time.h header file,
    29.         and implementation of functions thereof.
    30. */
    31. #ifndef USE_CLOCK
    32. #define USE_CLOCK 1
    33. #endif
    34. /* Configuration : HAS_STDIO
    35.         Define to 1 if the platform has stdio.h.
    36. */
    37. #ifndef HAS_STDIO
    38. #define HAS_STDIO 1
    39. #endif
    40. /* Configuration : HAS_PRINTF
    41.         Define to 1 if the platform has stdio.h and implements the printf function.
    42. */
    43. #ifndef HAS_PRINTF
    44. #define HAS_PRINTF 1
    45. #endif

    46. /* Configuration : CORE_TICKS
    47.         Define type of return from the timing functions.
    48. */
    49. #include <time.h>
    50. typedef clock_t CORE_TICKS;

    51. /* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
    52.         Initialize these strings per platform
    53. */
    54. #ifndef COMPILER_VERSION
    55. #ifdef __GNUC__
    56. #define COMPILER_VERSION "GCC"__VERSION__
    57. #else
    58. #define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)"
    59. #endif
    60. #endif
    61. #ifndef COMPILER_FLAGS
    62. // #define COMPILER_FLAGS FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
    63. #define COMPILER_FLAGS "-O3 -fno-common -funroll-loops -finline-functions"
    64. #endif
    65. #ifndef MEM_LOCATION
    66. #define MEM_LOCATION "STACK"
    67. #endif

    68. /* Data Types :
    69.         To avoid compiler issues, define the data types that need ot be used for 8b, 16b and 32b in <core_portme.h>.

    70.         *Imprtant* :
    71.         ee_ptr_int needs to be the data type used to hold pointers, otherwise coremark may fail!!!
    72. */
    73. typedef signed short ee_s16;
    74. typedef unsigned short ee_u16;
    75. typedef signed int ee_s32;
    76. typedef double ee_f32;
    77. typedef unsigned char ee_u8;
    78. typedef unsigned int ee_u32;
    79. typedef ee_u32 ee_ptr_int;
    80. typedef size_t ee_size_t;
    81. /* align_mem :
    82.         This macro is used to align an offset to point to a 32b value. It is used in the Matrix algorithm to initialize the input memory blocks.
    83. */
    84. #define align_mem(x) (void *)(4 + (((ee_ptr_int)(x) - 1) & ~3))

    85. /* Configuration : SEED_METHOD
    86.         Defines method to get seed values that cannot be computed at compile time.

    87.         Valid values :
    88.         SEED_ARG - from command line.
    89.         SEED_FUNC - from a system function.
    90.         SEED_VOLATILE - from volatile variables.
    91. */
    92. #ifndef SEED_METHOD
    93. #define SEED_METHOD SEED_VOLATILE
    94. #endif

    95. /* Configuration : MEM_METHOD
    96.         Defines method to get a block of memry.

    97.         Valid values :
    98.         MEM_MALLOC - for platforms that implement malloc and have malloc.h.
    99.         MEM_STATIC - to use a static memory array.
    100.         MEM_STACK - to allocate the data block on the stack (NYI).
    101. */
    102. #ifndef MEM_METHOD
    103. #define MEM_METHOD MEM_STACK
    104. #endif

    105. /* Configuration : MULTITHREAD
    106.         Define for parallel execution

    107.         Valid values :
    108.         1 - only one context (default).
    109.         N>1 - will execute N copies in parallel.

    110.         Note :
    111.         If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined.

    112.         Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK> to enable them.

    113.         It is valid to have a different implementation of <core_start_parallel> and <core_end_parallel> in <core_portme.c>,
    114.         to fit a particular architecture.
    115. */
    116. #ifndef MULTITHREAD
    117. #define MULTITHREAD 1
    118. #define USE_PTHREAD 0
    119. #define USE_FORK 0
    120. #define USE_SOCKET 0
    121. #endif

    122. /* Configuration : MAIN_HAS_NOARGC
    123.         Needed if platform does not support getting arguments to main.

    124.         Valid values :
    125.         0 - argc/argv to main is supported
    126.         1 - argc/argv to main is not supported

    127.         Note :
    128.         This flag only matters if MULTITHREAD has been defined to a value greater then 1.
    129. */
    130. #ifndef MAIN_HAS_NOARGC
    131. #define MAIN_HAS_NOARGC 0
    132. #endif

    133. /* Configuration : MAIN_HAS_NORETURN
    134.         Needed if platform does not support returning a value from main.

    135.         Valid values :
    136.         0 - main returns an int, and return value will be 0.
    137.         1 - platform does not support returning a value from main
    138. */
    139. #ifndef MAIN_HAS_NORETURN
    140. #define MAIN_HAS_NORETURN 0
    141. #endif

    142. /* Variable : default_num_contexts
    143.         Not used for this simple port, must cintain the value 1.
    144. */
    145. extern ee_u32 default_num_contexts;

    146. typedef struct CORE_PORTABLE_S {
    147.         ee_u8        portable_id;
    148. } core_portable;

    149. /* target specific init/fini */
    150. void portable_init(core_portable *p, int *argc, char *argv[]);
    151. void portable_fini(core_portable *p);

    152. #if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) && !defined(VALIDATION_RUN)
    153. #if (TOTAL_DATA_SIZE==1200)
    154. #define PROFILE_RUN 1
    155. #elif (TOTAL_DATA_SIZE==2000)
    156. #define PERFORMANCE_RUN 1
    157. #else
    158. #define VALIDATION_RUN 1
    159. #endif
    160. #endif

    161. #define ITERATIONS      12000

    162. #endif /* CORE_PORTME_H */
    复制代码
    添加syscalls.c文件,newlibc库使用printf函数所调用的桩函数:
    1. /**
    2. *****************************************************************************
    3. **
    4. **  File        : syscalls.c
    5. **
    6. **  Abstract    : System Workbench Minimal System calls file
    7. **
    8. **                           For more information about which c-functions
    9. **                need which of these lowlevel functions
    10. **                please consult the Newlib libc-manual
    11. **
    12. **  Environment : System Workbench for MCU
    13. **
    14. **  Distribution: The file is distributed �as is,� without any warranty
    15. **                of any kind.
    16. **
    17. **  (c)Copyright System Workbench for MCU.
    18. **  You may use this file as-is or modify it according to the needs of your
    19. **  project. Distribution of this file (unmodified or modified) is not
    20. **  permitted. System Workbench for MCU permit registered System Workbench(R) users the
    21. **  rights to distribute the assembled, compiled & linked contents of this
    22. **  file as part of an application binary file, provided that it is built
    23. **  using the System Workbench for MCU toolchain.
    24. **
    25. *****************************************************************************
    26. */

    27. /* Includes */
    28. #include <sys/stat.h>
    29. #include <stdlib.h>
    30. #include <errno.h>
    31. #include <stdio.h>
    32. #include <signal.h>
    33. #include <time.h>
    34. #include <sys/time.h>
    35. #include <sys/times.h>


    36. /* Variables */
    37. //#undef errno
    38. extern int errno;
    39. #define FreeRTOS
    40. #define MAX_STACK_SIZE 0x2000

    41. extern int __io_putchar(int ch) __attribute__((weak));
    42. extern int __io_getchar(void) __attribute__((weak));

    43. #ifndef FreeRTOS
    44.   register char * stack_ptr asm("sp");
    45. #endif


    46. register char * stack_ptr asm("sp");

    47. char *__env[1] = { 0 };
    48. char **environ = __env;


    49. /* Functions */
    50. void initialise_monitor_handles()
    51. {
    52. }

    53. int _getpid(void)
    54. {
    55.         return 1;
    56. }

    57. int _kill(int pid, int sig)
    58. {
    59.         errno = EINVAL;
    60.         return -1;
    61. }

    62. void _exit (int status)
    63. {
    64.         _kill(status, -1);
    65.         while (1) {}                /* Make sure we hang here */
    66. }

    67. int _read (int file, char *ptr, int len)
    68. {
    69.         int DataIdx;

    70.         for (DataIdx = 0; DataIdx < len; DataIdx++)
    71.         {
    72.                 *ptr++ = __io_getchar();
    73.         }

    74. return len;
    75. }

    76. int _write(int file, char *ptr, int len)
    77. {
    78.         int DataIdx;

    79.         for (DataIdx = 0; DataIdx < len; DataIdx++)
    80.         {
    81.                 __io_putchar(*ptr++);
    82.         }
    83.         return len;
    84. }

    85. caddr_t _sbrk(int incr)
    86. {
    87.         extern char end asm("end");
    88.         static char *heap_end;
    89.         char *prev_heap_end;

    90.         if (heap_end == 0)
    91.                 heap_end = &end;

    92.         prev_heap_end = heap_end;
    93.         if (heap_end + incr > stack_ptr)
    94.         {
    95. //                write(1, "Heap and stack collision\n", 25);
    96. //                abort();
    97.                 errno = ENOMEM;
    98.                 return (caddr_t) -1;
    99.         }

    100.         heap_end += incr;

    101.         return (caddr_t) prev_heap_end;
    102. }

    103. int _close(int file)
    104. {
    105.         return -1;
    106. }


    107. int _fstat(int file, struct stat *st)
    108. {
    109.         st->st_mode = S_IFCHR;
    110.         return 0;
    111. }

    112. int _isatty(int file)
    113. {
    114.         return 1;
    115. }

    116. int _lseek(int file, int ptr, int dir)
    117. {
    118.         return 0;
    119. }

    120. int _open(char *path, int flags, ...)
    121. {
    122.         /* Pretend like we always fail */
    123.         return -1;
    124. }

    125. int _wait(int *status)
    126. {
    127.         errno = ECHILD;
    128.         return -1;
    129. }

    130. int _unlink(char *name)
    131. {
    132.         errno = ENOENT;
    133.         return -1;
    134. }

    135. int _times(struct tms *buf)
    136. {
    137.         return -1;
    138. }

    139. int _stat(char *file, struct stat *st)
    140. {
    141.         st->st_mode = S_IFCHR;
    142.         return 0;
    143. }

    144. int _link(char *old, char *new)
    145. {
    146.         errno = EMLINK;
    147.         return -1;
    148. }

    149. int _fork(void)
    150. {
    151.         errno = EAGAIN;
    152.         return -1;
    153. }

    154. int _execve(char *name, char **argv, char **env)
    155. {
    156.         errno = ENOMEM;
    157.         return -1;
    158. }
    复制代码
    3.编译运行CoreMark。在终端进入项目目录,make编译,make flash烧写固件至Nucleo-L432KC。在串口终端看结果
    result.png

    CoreMark跑分207.914616,与Keil的差不多。
    项目源码在github,https://github.com/shenxfs/coremark.git


    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    关闭

    站长推荐上一条 /3 下一条

    手机版|爱板网

    GMT+8, 2018-9-20 21:23 , Processed in 0.417888 second(s), 14 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-5   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001056号

    Powered by Discuz!

    返回顶部