恒美微站
首页
关于我们
建站服务
主题模板
案例展示
资讯中心
联系我们
程控版cubemx生成工程后的修改项
首页
资讯中心
/
程控版cubemx生成工程后的修改项
程控版cubemx生成工程后的修改项
发布时间:2026/9/30 6:50:48
1.“rtdef.h” 在此文件第58行中包含以下文件typedefstructrt_driver*rt_driver_t;typedefstructrt_device*rt_device_t;#defineRT_USING_DEVICE#defineRT_USING_MUTEX#defineRT_USING_EVENT#defineRT_USING_SMALL_MEM#defineRT_USING_HEAP2.复制以下内容到 board.c 文件中/* * Copyright (c) 2006-2019, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2021-05-24 the first version */#includerthw.h#includertthread.h#includemain.h#ifdefined(RT_USING_USER_MAIN)defined(RT_USING_HEAP)/* * Please modify RT_HEAP_SIZE if you enable RT_USING_HEAP * the RT_HEAP_SIZE max value (sram size - ZI size), 1024 means 1024 bytes */#defineRT_HEAP_SIZE(15*1024)staticrt_uint8_trt_heap[RT_HEAP_SIZE];RT_WEAKvoid*rt_heap_begin_get(void){returnrt_heap;}RT_WEAKvoid*rt_heap_end_get(void){returnrt_heapRT_HEAP_SIZE;}#endifvoidSysTick_Handler(void){rt_interrupt_enter();rt_tick_increase();rt_interrupt_leave();}#ifdefRT_USING_FINSH#includefinsh.hstaticvoidreboot(uint8_targc,char**argv){rt_hw_cpu_reset();}MSH_CMD_EXPORT(reboot,Reboot System);#endif/* RT_USING_FINSH *//** * This function will initial your board. */voidrt_hw_board_init(void){externvoidSystemClock_Config(void);HAL_Init();SystemClock_Config();SystemCoreClockUpdate();/* * 1: OS Tick Configuration * Enable the hardware timer and call the rt_os_tick_callback function * periodically with the frequency RT_TICK_PER_SECOND. */HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/RT_TICK_PER_SECOND);/* Call components board initial (use INIT_BOARD_EXPORT()) */#ifdefRT_USING_COMPONENTS_INITrt_components_board_init();#endif#ifdefined(RT_USING_USER_MAIN)defined(RT_USING_HEAP)rt_system_heap_init(rt_heap_begin_get(),rt_heap_end_get());#endif}#ifdefRT_USING_CONSOLEstaticUART_HandleTypeDef UartHandle;staticintuart_init(void){/* TODO: Please modify the UART port number according to your needs */UartHandle.InstanceUSART3;UartHandle.Init.BaudRate1000000;UartHandle.Init.WordLengthUART_WORDLENGTH_8B;UartHandle.Init.StopBitsUART_STOPBITS_1;UartHandle.Init.ParityUART_PARITY_NONE;UartHandle.Init.ModeUART_MODE_TX_RX;UartHandle.Init.HwFlowCtlUART_HWCONTROL_NONE;UartHandle.Init.OverSamplingUART_OVERSAMPLING_16;if(HAL_UART_Init(UartHandle)!HAL_OK){while(1);}return0;}INIT_BOARD_EXPORT(uart_init);voidrt_hw_console_output(constchar*str){rt_size_ti0,size0;chara\r;__HAL_UNLOCK(UartHandle);sizert_strlen(str);for(i0;isize;i){if(*(stri)\n){HAL_UART_Transmit(UartHandle,(uint8_t*)a,1,1);}HAL_UART_Transmit(UartHandle,(uint8_t*)(stri),1,1);}}#endif#ifdefRT_USING_FINSHcharrt_hw_console_getchar(void){/* Note: the initial value of ch must 0 */intch-1;if(__HAL_UART_GET_FLAG(UartHandle,UART_FLAG_RXNE)!RESET){chUartHandle.Instance-DR0xff;}else{rt_thread_mdelay(10);}returnch;}#endif3.复制以下内容到rtconfig.h//* RT-Thread config file */#ifndef__RTTHREAD_CFG_H__#define__RTTHREAD_CFG_H__// Use Configuration Wizard in Context Menu // hBasic Configuration// oMaximal level of thread priority 8-256// iDefault: 32#defineRT_THREAD_PRIORITY_MAX32// oOS tick per second// iDefault: 1000 (1ms)#defineRT_TICK_PER_SECOND1000// oAlignment size for CPU architecture data access// iDefault: 4#defineRT_ALIGN_SIZE4// othe max length of object name2-16// iDefault: 8#defineRT_NAME_MAX8// c1Using RT-Thread components initialization// iUsing RT-Thread components initialization#defineRT_USING_COMPONENTS_INIT// /c// c1Using user main// iUsing user main#defineRT_USING_USER_MAIN// /c// othe size of main thread1-4086// iDefault: 512#defineRT_MAIN_THREAD_STACK_SIZE1024// /h// hDebug Configuration// c1enable kernel debug configuration// iDefault: enable kernel debug configuration//#define RT_DEBUG// /c// oenable components initialization debug configuration0-1// iDefault: 0#defineRT_DEBUG_INIT0// c1thread stack over flow detect// i Diable Thread stack over flow detect//#define RT_USING_OVERFLOW_CHECK// /c// /h// hHook Configuration// c1using hook// iusing hook//#define RT_USING_HOOK// /c// c1using idle hook// iusing idle hook//#define RT_HOOK_USING_FUNC_PTR// /c// /h// hSoftware timers Configuration// c1 Enables user timers// i Enables user timers//#define RT_USING_TIMER_SOFT// /c// oThe priority level of timer thread 0-31// iDefault: 4#defineRT_TIMER_THREAD_PRIO4// oThe stack size of timer thread 0-8192// iDefault: 512#defineRT_TIMER_THREAD_STACK_SIZE512// /h// hIPC(Inter-process communication) Configuration// c1Using Semaphore// iUsing Semaphore#defineRT_USING_SEMAPHORE// /c// c1Using Mutex// iUsing Mutex//#define RT_USING_MUTEX// /c// c1Using Signal// iUsing Signal//#define RT_USING_SIGNALS// /c// c1Using Event// iUsing Event//#define RT_USING_EVENT// /c// c1Using MailBox// iUsing MailBox#defineRT_USING_MAILBOX// /c// c1Using Message Queue// iUsing Message Queue//#define RT_USING_MESSAGEQUEUE// /c// /h// hMemory Management Configuration// c1Using Mempool Management// iUsing Mempool Management//#define RT_USING_MEMPOOL// /c// c1Dynamic Heap Management// iDynamic Heap Management//#define RT_USING_HEAP// /c// c1using small memory// iusing small memory//#define RT_USING_SMALL_MEM// /c// c1Small Memory Algorithm// iSmall Memory Algorithm#defineRT_USING_SMALL_MEM_AS_HEAP// /c// /h// hConsole Configuration// c1Using console// iUsing console#defineRT_USING_CONSOLE// /c// othe buffer size of console 1-1024// ithe buffer size of console// iDefault: 128 (128Byte)#defineRT_CONSOLEBUF_SIZE128// /h// hEnable FinSH Configuration// c1include shell config// i Select this choice if you using FinSH#defineRT_USING_FINSH// /c// /h#ifdefined(RT_USING_FINSH)#includefinsh_config.h#endif// hDevice Configuration// c1using device framework// iusing device framework#defineRT_USING_DEVICE// /c// /h// end of configuration section #endif