拓十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

程控版cubemx生成工程后的修改项

程控版cubemx生成工程后的修改项

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_HEAP

2.复制以下内容到 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 */#include<rthw.h>#include<rtthread.h>#include"main.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_heap+RT_HEAP_SIZE;}#endifvoidSysTick_Handler(void){rt_interrupt_enter();rt_tick_increase();rt_interrupt_leave();}#ifdefRT_USING_FINSH#include<finsh.h>staticvoidreboot(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.Instance=USART3;UartHandle.Init.BaudRate=1000000;UartHandle.Init.WordLength=UART_WORDLENGTH_8B;UartHandle.Init.StopBits=UART_STOPBITS_1;UartHandle.Init.Parity=UART_PARITY_NONE;UartHandle.Init.Mode=UART_MODE_TX_RX;UartHandle.Init.HwFlowCtl=UART_HWCONTROL_NONE;UartHandle.Init.OverSampling=UART_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_ti=0,size=0;chara='\r';__HAL_UNLOCK(&UartHandle);size=rt_strlen(str);for(i=0;i<size;i++){if(*(str+i)=='\n'){HAL_UART_Transmit(&UartHandle,(uint8_t*)&a,1,1);}HAL_UART_Transmit(&UartHandle,(uint8_t*)(str+i),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){ch=UartHandle.Instance->DR&0xff;}else{rt_thread_mdelay(10);}returnch;}#endif

3.复制以下内容到"rtconfig.h"

//* RT-Thread config file */#ifndef__RTTHREAD_CFG_H__#define__RTTHREAD_CFG_H__// <<< Use Configuration Wizard in Context Menu >>>// <h>Basic Configuration// <o>Maximal level of thread priority <8-256>// <i>Default: 32#defineRT_THREAD_PRIORITY_MAX32// <o>OS tick per second// <i>Default: 1000 (1ms)#defineRT_TICK_PER_SECOND1000// <o>Alignment size for CPU architecture data access// <i>Default: 4#defineRT_ALIGN_SIZE4// <o>the max length of object name<2-16>// <i>Default: 8#defineRT_NAME_MAX8// <c1>Using RT-Thread components initialization// <i>Using RT-Thread components initialization#defineRT_USING_COMPONENTS_INIT// </c>// <c1>Using user main// <i>Using user main#defineRT_USING_USER_MAIN// </c>// <o>the size of main thread<1-4086>// <i>Default: 512#defineRT_MAIN_THREAD_STACK_SIZE1024// </h>// <h>Debug Configuration// <c1>enable kernel debug configuration// <i>Default: enable kernel debug configuration//#define RT_DEBUG// </c>// <o>enable components initialization debug configuration<0-1>// <i>Default: 0#defineRT_DEBUG_INIT0// <c1>thread stack over flow detect// <i> Diable Thread stack over flow detect//#define RT_USING_OVERFLOW_CHECK// </c>// </h>// <h>Hook Configuration// <c1>using hook// <i>using hook//#define RT_USING_HOOK// </c>// <c1>using idle hook// <i>using idle hook//#define RT_HOOK_USING_FUNC_PTR// </c>// </h>// <h>Software timers Configuration// <c1> Enables user timers// <i> Enables user timers//#define RT_USING_TIMER_SOFT// </c>// <o>The priority level of timer thread <0-31>// <i>Default: 4#defineRT_TIMER_THREAD_PRIO4// <o>The stack size of timer thread <0-8192>// <i>Default: 512#defineRT_TIMER_THREAD_STACK_SIZE512// </h>// <h>IPC(Inter-process communication) Configuration// <c1>Using Semaphore// <i>Using Semaphore#defineRT_USING_SEMAPHORE// </c>// <c1>Using Mutex// <i>Using Mutex//#define RT_USING_MUTEX// </c>// <c1>Using Signal// <i>Using Signal//#define RT_USING_SIGNALS// </c>// <c1>Using Event// <i>Using Event//#define RT_USING_EVENT// </c>// <c1>Using MailBox// <i>Using MailBox#defineRT_USING_MAILBOX// </c>// <c1>Using Message Queue// <i>Using Message Queue//#define RT_USING_MESSAGEQUEUE// </c>// </h>// <h>Memory Management Configuration// <c1>Using Mempool Management// <i>Using Mempool Management//#define RT_USING_MEMPOOL// </c>// <c1>Dynamic Heap Management// <i>Dynamic Heap Management//#define RT_USING_HEAP// </c>// <c1>using small memory// <i>using small memory//#define RT_USING_SMALL_MEM// </c>// <c1>Small Memory Algorithm// <i>Small Memory Algorithm#defineRT_USING_SMALL_MEM_AS_HEAP// </c>// </h>// <h>Console Configuration// <c1>Using console// <i>Using console#defineRT_USING_CONSOLE// </c>// <o>the buffer size of console <1-1024>// <i>the buffer size of console// <i>Default: 128 (128Byte)#defineRT_CONSOLEBUF_SIZE128// </h>// <h>Enable FinSH Configuration// <c1>include shell config// <i> Select this choice if you using FinSH#defineRT_USING_FINSH// </c>// </h>#ifdefined(RT_USING_FINSH)#include"finsh_config.h"#endif// <h>Device Configuration// <c1>using device framework// <i>using device framework#defineRT_USING_DEVICE// </c>// </h>// <<< end of configuration section >>>#endif
返回列表