使用gcc编译calendar
This commit is contained in:
		
							
								
								
									
										0
									
								
								Project/.gitignore → .gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										0
									
								
								Project/.gitignore → .gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -16,31 +16,42 @@ static app_struct *g_me; | ||||
|  | ||||
|  | ||||
| //<2F><>const<73><74><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD><EFBFBD>ֵ | ||||
| __asm static void save_const(void *const_addr,u32 value) | ||||
| static void save_const(void *const_addr, u32 value) | ||||
| { | ||||
| 	str r1,[r0] | ||||
| 	bx lr | ||||
|     __asm__ volatile ( | ||||
|         "str %1, [%0]" | ||||
|         : | ||||
|         : "r" (const_addr), "r" (value) | ||||
|         : "memory" | ||||
|     ); | ||||
| } | ||||
|  | ||||
| __asm void *get_r9(void) | ||||
| void *get_r9(void) | ||||
| { | ||||
| 	mov r0,r9 | ||||
| 	bx lr | ||||
|     void *result; | ||||
|     __asm__ volatile ( | ||||
|         "mov %0, r9" | ||||
|         : "=r" (result) | ||||
|         : | ||||
|         : | ||||
|     ); | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| __asm void set_r9(void *r9) | ||||
| void set_r9(void *r9_val) | ||||
| { | ||||
| 	mov r9 ,r0 | ||||
| 	bx lr | ||||
|     __asm__ volatile ( | ||||
|         "mov r9, %0" | ||||
|         : | ||||
|         : "r" (r9_val) | ||||
|         : "r9" | ||||
|     ); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| void *global_in(void) | ||||
| { | ||||
| 	void *t=get_r9();	 | ||||
| 	void *t=get_r9(); | ||||
| 	set_r9(g_r9); | ||||
| 	return t; | ||||
| } | ||||
| @@ -54,15 +65,15 @@ void global_out(void *r9) | ||||
| void global_init(app_struct *me) | ||||
| { | ||||
| 	void *t=get_r9(); | ||||
| 		 | ||||
|  | ||||
| 	//ʹ<>ú<EFBFBD><C3BA><EFBFBD>ǿ<EFBFBD>и<EFBFBD>ֵ | ||||
| 	save_const((void *)&g_r9,(u32)t); | ||||
| 	g_me=me; | ||||
| 	 | ||||
|  | ||||
| 	//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD><E1B9A9>ϵͳ<CFB5><CDB3><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>app | ||||
| 	extern int __app_exit(void *); | ||||
| 	g_me->exit=__app_exit; | ||||
| 	 | ||||
|  | ||||
| } | ||||
|  | ||||
| //app<70><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
| @@ -75,7 +86,7 @@ void global_run_start(void) | ||||
| //app<70><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
| void global_run_exit(void) | ||||
| { | ||||
| 	if(g_me)  | ||||
| 	if(g_me) | ||||
| 	{ | ||||
| 		if(g_me->run_state) g_me->run_state--; | ||||
| 	} | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										288
									
								
								Project_App_Calendar/make.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										288
									
								
								Project_App_Calendar/make.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,288 @@ | ||||
| import os | ||||
| import sys | ||||
| import time | ||||
| import shutil | ||||
| import dataclasses | ||||
| import subprocess | ||||
| from pathlib import Path | ||||
| from multiprocessing import Process,Queue,Value,cpu_count | ||||
|  | ||||
|  | ||||
| os.environ["PATH"]+=";D:/Program Files/arm-gnu-toolchain/bin" | ||||
| os.environ["LANG"]="zh_CN.GBK" | ||||
|  | ||||
| CC="arm-none-eabi-gcc" | ||||
| AS = CC + ' -x assembler-with-cpp' | ||||
| OBJCPY="arm-none-eabi-objcopy" | ||||
| OBJDUMP="arm-none-eabi-objdump" | ||||
| SIZE="arm-none-eabi-size" | ||||
|  | ||||
| CFLAG=[ | ||||
|   '-mcpu=cortex-m4', | ||||
|   '-mthumb', | ||||
|   '-mfpu=fpv4-sp-d16', | ||||
|   '-mfloat-abi=hard', | ||||
|   '-O3', | ||||
|   '-Wall', | ||||
|   '-fdata-sections', | ||||
|   '-ffunction-sections', | ||||
|  | ||||
|   # debug | ||||
|   '-g -gdwarf-2', | ||||
|   '-fpic', | ||||
|   '-e my_main -Wl,--section-start=.app_info=0x00000000 -nostartfiles -nodefaultlibs' | ||||
| ] | ||||
|  | ||||
| DEF=[ | ||||
|   '-DUSE_STDPERIPH_DRIVER', | ||||
|   '-DSTM32F429_439xx', | ||||
|   '-DARM_MATH_CM4', | ||||
|   '-D__FPU_PRESENT=1', | ||||
|   # '-D__GNUC__', | ||||
|   '-D__packed=__attribute__((__packed__))', | ||||
|   '-D__weak=__attribute__((weak))', | ||||
|   '-D__RTTHREAD__', | ||||
|   # 使用usb时打开这个宏 系统时钟会被设置为168MHz USB时钟为48MHz | ||||
|   # 如果不打开这个宏 系统时钟会被设置为180MHz USB会通信异常 | ||||
|   '-D__USB_USB__', | ||||
| ] | ||||
|  | ||||
| INC=[ | ||||
|   '-IApp_Src/drive', | ||||
|   '-IApp_Src/main', | ||||
|   '-IApp_Src/main/inc/MyWinCore', | ||||
|   '-IApp_Src/main/inc/software', | ||||
|   '-IApp_Src/main/inc/Window', | ||||
|   '-IApp_Src/win' | ||||
| ] | ||||
|  | ||||
| SRC_DIR=[ | ||||
| ] | ||||
|  | ||||
| SRC=[ | ||||
|   'App_Src/main/main.c', | ||||
|   'App_Src/main/global.c', | ||||
|   'App_Src/main/main_asm.s', | ||||
|   'App_Src/win/mywin_user_calendar.c', | ||||
| ] | ||||
|  | ||||
|  | ||||
| TARGET="stm32" | ||||
|  | ||||
| OUTPUT="output" | ||||
|  | ||||
|  | ||||
| # 找到目录下的所有指定类型的文件 | ||||
| def find_type(path: str, fix: str): | ||||
|   root = Path(path) | ||||
|   file_list=[] | ||||
|   for file in root.rglob(f"*{fix}"): | ||||
|     if file.is_file(): | ||||
|       file_list.append(f"{file}") | ||||
|   return file_list | ||||
|  | ||||
|  | ||||
| def tran_path(path:str): | ||||
|   path=os.path.normpath(os.path.join(OUTPUT,path)) | ||||
|   base_path=os.path.dirname(path) | ||||
|   if not os.path.exists(base_path): | ||||
|     os.makedirs(base_path) | ||||
|   return path | ||||
|  | ||||
|  | ||||
| # 判断是否需要重新生成 | ||||
| def check_rebuild(dst:str,src:list): | ||||
|   if(not os.path.exists(dst)): | ||||
|     return True | ||||
|   dst_time=os.path.getmtime(dst) | ||||
|   src_time=[] | ||||
|   for i in src: | ||||
|     src_time.append(os.path.getmtime(i)) | ||||
|   src_time.sort() | ||||
|   if(src_time[-1]>dst_time): | ||||
|     return True | ||||
|   return False | ||||
|  | ||||
|  | ||||
|  | ||||
| # 读取.d文件,返回依赖文件列表 | ||||
| def read_depend_files(name:str): | ||||
|   with open(name) as f: | ||||
|     lines=f.readlines() | ||||
|     t='' | ||||
|     for line in lines: | ||||
|       line=line.strip() | ||||
|       if(line[-1]=='\\'): | ||||
|         t+=line[:-1] | ||||
|       else: | ||||
|         t+=line | ||||
|     t=t.split(':')[-1].strip() | ||||
|     t=t.split(' ') | ||||
|     return t | ||||
|  | ||||
|  | ||||
| @dataclasses.dataclass | ||||
| class cmd_item_t: | ||||
|   cmd:str | ||||
|   info:str | ||||
|  | ||||
| def run_cmd(cmd_queue:Queue,cpu_index:int,return_list:Queue,failed_num): | ||||
|   ack=True | ||||
|   while(not cmd_queue.empty()): | ||||
|     if(failed_num.value>0): | ||||
|       break | ||||
|     try: | ||||
|       cmd=cmd_queue.get_nowait() | ||||
|     except Exception: | ||||
|       break | ||||
|     print(f"[{cpu_index}] {cmd.info}") | ||||
|     # ret=os.system(cmd.cmd) | ||||
|     try: | ||||
|       ret = subprocess.run(cmd.cmd, shell=True, timeout=60).returncode | ||||
|     except subprocess.TimeoutExpired: | ||||
|       print("命令执行超时!") | ||||
|       failed_num.value += 1 | ||||
|       ret = -1 | ||||
|     if(ret!=0): | ||||
|       print(f"[{cpu_index}] ret={ret}") | ||||
|       ack=False | ||||
|       failed_num.value+=1 | ||||
|       break | ||||
|   return_list.put((cpu_index,ack)) | ||||
|  | ||||
|  | ||||
| def run_cmd_queue(cmd_queue:Queue,cpu_num:int=8): | ||||
|   if(cmd_queue.empty()): | ||||
|     return True | ||||
|   process_list = [] | ||||
|   return_list=Queue() | ||||
|   failed_num=Value('i',0) | ||||
|   for i in range(cpu_num): | ||||
|     p = Process(target=run_cmd,args=(cmd_queue,i,return_list,failed_num,)) | ||||
|     p.daemon=True | ||||
|     p.start() | ||||
|     process_list.append(p) | ||||
|   for i in process_list: | ||||
|     i.join() | ||||
|   ret=True | ||||
|   while not return_list.empty(): | ||||
|     i=return_list.get() | ||||
|     if(not i[1]): | ||||
|       ret=False | ||||
|       print(f"子进程 [{i[0]}] 运行失败") | ||||
|   return_list.cancel_join_thread() | ||||
|   # 消耗掉所有数据防止进程无法退出 | ||||
|   while not cmd_queue.empty(): | ||||
|     cmd_queue.get() | ||||
|   cmd_queue.cancel_join_thread() | ||||
|   return ret | ||||
|  | ||||
|  | ||||
| # 保证目标都存在 | ||||
| def check_exists(src:list): | ||||
|   for item in src: | ||||
|     for i in range(10): | ||||
|       if(os.path.exists(item)): | ||||
|         break | ||||
|       time.sleep(0.1) | ||||
| # 生成依赖关系 | ||||
| def build_depend(src:list): | ||||
|   CmdQueue=Queue() | ||||
|   dst_list=[] | ||||
|   flags=f"{' '.join(INC)} {' '.join(DEF)} {' '.join(CFLAG)}" | ||||
|   for i in src: | ||||
|     name_t=os.path.splitext(tran_path(i)) | ||||
|     name=name_t[0] | ||||
|     file_type=name_t[-1] | ||||
|     if(not file_type in ['.c','.C','.cpp']): | ||||
|       continue | ||||
|     dst='.'.join([name,'d']) | ||||
|     if(check_rebuild(dst,[i])): | ||||
|       cmd=f"{CC} -MM {i} -o {dst} {flags}" | ||||
|       CmdQueue.put(cmd_item_t(cmd,f"更新 {dst}")) | ||||
|       dst_list.append(dst) | ||||
|   return run_cmd_queue(CmdQueue) | ||||
|  | ||||
| # 生成中间文件 | ||||
| def build_object(src:list): | ||||
|   CmdQueue=Queue() | ||||
|   dst_list=[] | ||||
|   flags=f"{' '.join(INC)} {' '.join(DEF)} {' '.join(CFLAG)}" | ||||
|   for i in src: | ||||
|     name_t=os.path.splitext(tran_path(i)) | ||||
|     name=name_t[0] | ||||
|     file_type=name_t[-1] | ||||
|     dst='.'.join([name,'o']) | ||||
|     cd='.'.join([name,'d']) | ||||
|     cmd = '' | ||||
|     if(file_type in ['.c','.C']): | ||||
|       if(check_rebuild(dst,read_depend_files(cd))): | ||||
|         cmd=f"{CC} -c {i} -o {dst} {flags}" | ||||
|     elif(file_type in ['.s','.S','.asm','.ASM']): | ||||
|       if(check_rebuild(dst,[i])): | ||||
|         cmd=f"{AS} -c {i} -o {dst} {flags}" | ||||
|         cmd+=f"&& {OBJDUMP} -D {dst} > {dst}.lst" | ||||
|     if(len(cmd)>0): | ||||
|       CmdQueue.put(cmd_item_t(cmd,f"编译 {dst}")) | ||||
|       dst_list.append(dst) | ||||
|   return run_cmd_queue(CmdQueue) | ||||
|  | ||||
|  | ||||
| # 生成可执行文件 | ||||
| def build_target(src:list): | ||||
|   flags=f"{' '.join(INC)} {' '.join(DEF)} {' '.join(CFLAG)}" | ||||
|   obj_list=[] | ||||
|   for i in src: | ||||
|     name=os.path.splitext(tran_path(i))[0] | ||||
|     obj_list.append('.'.join([name,'o'])) | ||||
|   dst=os.path.join(OUTPUT,TARGET)+".elf" | ||||
|   if(check_rebuild(dst,obj_list)): | ||||
|     rsp=f"{' '.join(obj_list)} -o {dst} {flags} \ | ||||
|     -Wl,-Map={OUTPUT}/{TARGET}.map,--cref -Wl,--gc-sections \ | ||||
|     -Wl,-print-memory-usage" | ||||
|     print(f"链接 {dst}") | ||||
|     with open(f"{OUTPUT}/{TARGET}.rsp",'w+') as f: | ||||
|       f.write(rsp.replace('\\','/')) | ||||
|     ret=os.system(f"{CC} @{OUTPUT}/{TARGET}.rsp") | ||||
|     return ret==0 | ||||
|   return False | ||||
|  | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|   global SRC | ||||
|  | ||||
|   if not os.path.exists(OUTPUT): | ||||
|     os.mkdir(OUTPUT) | ||||
|  | ||||
|   for item in SRC_DIR: | ||||
|     SRC += find_type(item,'.c') | ||||
|  | ||||
|   if len(sys.argv) > 1: | ||||
|     l=[] | ||||
|     if sys.argv[1] == 'show_inc': | ||||
|       l=INC | ||||
|     elif sys.argv[1] == 'show_src': | ||||
|       l=SRC | ||||
|     l.sort() | ||||
|     for item in l: | ||||
|       t=item.replace('\\','/') | ||||
|       print(f"\"Project/{t}\",") | ||||
|     return | ||||
|  | ||||
|   if build_depend(SRC): | ||||
|     if build_object(SRC): | ||||
|       if build_target(SRC): | ||||
|         os.system(f"{OBJCPY} -O binary -S {OUTPUT}/{TARGET}.elf {OUTPUT}/{TARGET}.bin") | ||||
|         os.system(f"{OBJCPY} -O ihex {OUTPUT}/{TARGET}.elf {OUTPUT}/{TARGET}.hex") | ||||
|         os.system(f"{OBJDUMP} -D {OUTPUT}/{TARGET}.elf > {OUTPUT}/{TARGET}.lst") | ||||
|  | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|   tick_start=time.time() | ||||
|   main() | ||||
|   tick_end=time.time() | ||||
|   print(f"cost: {tick_end-tick_start}") | ||||
|   # for item in find_type('Src/zlib',".c"): | ||||
|   #   print(f"'{item}',".replace('\\','/')) | ||||
		Reference in New Issue
	
	Block a user
	 ranchuan
					ranchuan