TA的每日心情 | 开心 2020-1-23 13:37 |
---|
签到天数: 8 天 连续签到: 1 天 [LV.3]偶尔看看II
|
在网上都是keil或IAR上移植CoreMark,没有用gcc进行移植的,现在就用arm-none-eabi-gcc编译CoreMark
1.用stm32cubeMx创建makefile项目,选择Necleo-L432KC
设置80MHz系统时钟
选usart2,波特率9600
项目设置为makefile
生成项目,修改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:- /*
- <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文件:- /* File : core_portme.h */
- /*
- Author : Shay Gal-On, EEMBC
- Legal : TODO!
- */
- /* Topic : Description
- This file contains configuration constants required to execute on different platforms
- */
- #ifndef CORE_PORTME_H
- #define CORE_PORTME_H
- /************************/
- /* Data types and settings */
- /************************/
- /* Configuration : HAS_FLOAT
- Define to 1 if the platform supports floating point.
- */
- #ifndef HAS_FLOAT
- #define HAS_FLOAT 1
- #endif
- /* Configuration : HAS_TIME_H
- Define to 1 if platform has the time.h header file,
- and implementation of functions thereof.
- */
- #ifndef HAS_TIME_H
- #define HAS_TIME_H 1
- #endif
- /* Configuration : USE_CLOCK
- Define to 1 if platform has the time.h header file,
- and implementation of functions thereof.
- */
- #ifndef USE_CLOCK
- #define USE_CLOCK 1
- #endif
- /* Configuration : HAS_STDIO
- Define to 1 if the platform has stdio.h.
- */
- #ifndef HAS_STDIO
- #define HAS_STDIO 1
- #endif
- /* Configuration : HAS_PRINTF
- Define to 1 if the platform has stdio.h and implements the printf function.
- */
- #ifndef HAS_PRINTF
- #define HAS_PRINTF 1
- #endif
- /* Configuration : CORE_TICKS
- Define type of return from the timing functions.
- */
- #include <time.h>
- typedef clock_t CORE_TICKS;
- /* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
- Initialize these strings per platform
- */
- #ifndef COMPILER_VERSION
- #ifdef __GNUC__
- #define COMPILER_VERSION "GCC"__VERSION__
- #else
- #define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)"
- #endif
- #endif
- #ifndef COMPILER_FLAGS
- // #define COMPILER_FLAGS FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
- #define COMPILER_FLAGS "-O3 -fno-common -funroll-loops -finline-functions"
- #endif
- #ifndef MEM_LOCATION
- #define MEM_LOCATION "STACK"
- #endif
- /* Data Types :
- To avoid compiler issues, define the data types that need ot be used for 8b, 16b and 32b in <core_portme.h>.
- *Imprtant* :
- ee_ptr_int needs to be the data type used to hold pointers, otherwise coremark may fail!!!
- */
- typedef signed short ee_s16;
- typedef unsigned short ee_u16;
- typedef signed int ee_s32;
- typedef double ee_f32;
- typedef unsigned char ee_u8;
- typedef unsigned int ee_u32;
- typedef ee_u32 ee_ptr_int;
- typedef size_t ee_size_t;
- /* align_mem :
- 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.
- */
- #define align_mem(x) (void *)(4 + (((ee_ptr_int)(x) - 1) & ~3))
- /* Configuration : SEED_METHOD
- Defines method to get seed values that cannot be computed at compile time.
- Valid values :
- SEED_ARG - from command line.
- SEED_FUNC - from a system function.
- SEED_VOLATILE - from volatile variables.
- */
- #ifndef SEED_METHOD
- #define SEED_METHOD SEED_VOLATILE
- #endif
- /* Configuration : MEM_METHOD
- Defines method to get a block of memry.
- Valid values :
- MEM_MALLOC - for platforms that implement malloc and have malloc.h.
- MEM_STATIC - to use a static memory array.
- MEM_STACK - to allocate the data block on the stack (NYI).
- */
- #ifndef MEM_METHOD
- #define MEM_METHOD MEM_STACK
- #endif
- /* Configuration : MULTITHREAD
- Define for parallel execution
- Valid values :
- 1 - only one context (default).
- N>1 - will execute N copies in parallel.
- Note :
- If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined.
- Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK> to enable them.
- It is valid to have a different implementation of <core_start_parallel> and <core_end_parallel> in <core_portme.c>,
- to fit a particular architecture.
- */
- #ifndef MULTITHREAD
- #define MULTITHREAD 1
- #define USE_PTHREAD 0
- #define USE_FORK 0
- #define USE_SOCKET 0
- #endif
- /* Configuration : MAIN_HAS_NOARGC
- Needed if platform does not support getting arguments to main.
- Valid values :
- 0 - argc/argv to main is supported
- 1 - argc/argv to main is not supported
- Note :
- This flag only matters if MULTITHREAD has been defined to a value greater then 1.
- */
- #ifndef MAIN_HAS_NOARGC
- #define MAIN_HAS_NOARGC 0
- #endif
- /* Configuration : MAIN_HAS_NORETURN
- Needed if platform does not support returning a value from main.
- Valid values :
- 0 - main returns an int, and return value will be 0.
- 1 - platform does not support returning a value from main
- */
- #ifndef MAIN_HAS_NORETURN
- #define MAIN_HAS_NORETURN 0
- #endif
- /* Variable : default_num_contexts
- Not used for this simple port, must cintain the value 1.
- */
- extern ee_u32 default_num_contexts;
- typedef struct CORE_PORTABLE_S {
- ee_u8 portable_id;
- } core_portable;
- /* target specific init/fini */
- void portable_init(core_portable *p, int *argc, char *argv[]);
- void portable_fini(core_portable *p);
- #if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) && !defined(VALIDATION_RUN)
- #if (TOTAL_DATA_SIZE==1200)
- #define PROFILE_RUN 1
- #elif (TOTAL_DATA_SIZE==2000)
- #define PERFORMANCE_RUN 1
- #else
- #define VALIDATION_RUN 1
- #endif
- #endif
- #define ITERATIONS 12000
- #endif /* CORE_PORTME_H */
复制代码 添加syscalls.c文件,newlibc库使用printf函数所调用的桩函数:- /**
- *****************************************************************************
- **
- ** File : syscalls.c
- **
- ** Abstract : System Workbench Minimal System calls file
- **
- ** For more information about which c-functions
- ** need which of these lowlevel functions
- ** please consult the Newlib libc-manual
- **
- ** Environment : System Workbench for MCU
- **
- ** Distribution: The file is distributed �as is,� without any warranty
- ** of any kind.
- **
- ** (c)Copyright System Workbench for MCU.
- ** You may use this file as-is or modify it according to the needs of your
- ** project. Distribution of this file (unmodified or modified) is not
- ** permitted. System Workbench for MCU permit registered System Workbench(R) users the
- ** rights to distribute the assembled, compiled & linked contents of this
- ** file as part of an application binary file, provided that it is built
- ** using the System Workbench for MCU toolchain.
- **
- *****************************************************************************
- */
- /* Includes */
- #include <sys/stat.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <stdio.h>
- #include <signal.h>
- #include <time.h>
- #include <sys/time.h>
- #include <sys/times.h>
- /* Variables */
- //#undef errno
- extern int errno;
- #define FreeRTOS
- #define MAX_STACK_SIZE 0x2000
- extern int __io_putchar(int ch) __attribute__((weak));
- extern int __io_getchar(void) __attribute__((weak));
- #ifndef FreeRTOS
- register char * stack_ptr asm("sp");
- #endif
- register char * stack_ptr asm("sp");
- char *__env[1] = { 0 };
- char **environ = __env;
- /* Functions */
- void initialise_monitor_handles()
- {
- }
- int _getpid(void)
- {
- return 1;
- }
- int _kill(int pid, int sig)
- {
- errno = EINVAL;
- return -1;
- }
- void _exit (int status)
- {
- _kill(status, -1);
- while (1) {} /* Make sure we hang here */
- }
- int _read (int file, char *ptr, int len)
- {
- int DataIdx;
- for (DataIdx = 0; DataIdx < len; DataIdx++)
- {
- *ptr++ = __io_getchar();
- }
- return len;
- }
- int _write(int file, char *ptr, int len)
- {
- int DataIdx;
- for (DataIdx = 0; DataIdx < len; DataIdx++)
- {
- __io_putchar(*ptr++);
- }
- return len;
- }
- caddr_t _sbrk(int incr)
- {
- extern char end asm("end");
- static char *heap_end;
- char *prev_heap_end;
- if (heap_end == 0)
- heap_end = &end;
- prev_heap_end = heap_end;
- if (heap_end + incr > stack_ptr)
- {
- // write(1, "Heap and stack collision\n", 25);
- // abort();
- errno = ENOMEM;
- return (caddr_t) -1;
- }
- heap_end += incr;
- return (caddr_t) prev_heap_end;
- }
- int _close(int file)
- {
- return -1;
- }
- int _fstat(int file, struct stat *st)
- {
- st->st_mode = S_IFCHR;
- return 0;
- }
- int _isatty(int file)
- {
- return 1;
- }
- int _lseek(int file, int ptr, int dir)
- {
- return 0;
- }
- int _open(char *path, int flags, ...)
- {
- /* Pretend like we always fail */
- return -1;
- }
- int _wait(int *status)
- {
- errno = ECHILD;
- return -1;
- }
- int _unlink(char *name)
- {
- errno = ENOENT;
- return -1;
- }
- int _times(struct tms *buf)
- {
- return -1;
- }
- int _stat(char *file, struct stat *st)
- {
- st->st_mode = S_IFCHR;
- return 0;
- }
- int _link(char *old, char *new)
- {
- errno = EMLINK;
- return -1;
- }
- int _fork(void)
- {
- errno = EAGAIN;
- return -1;
- }
- int _execve(char *name, char **argv, char **env)
- {
- errno = ENOMEM;
- return -1;
- }
复制代码 3.编译运行CoreMark。在终端进入项目目录,make编译,make flash烧写固件至Nucleo-L432KC。在串口终端看结果
CoreMark跑分207.914616,与Keil的差不多。
项目源码在github,https://github.com/shenxfs/coremark.git
|
|