RT-Thread Studio使用笔记(八):PWM的使用

it2023-06-08  68

 按board.h说明进行配置

    根据前几次实验,发现使用RTT组件非常简单,只要根据board.h中对应的步骤进行修改即可,比如要使用pwm组件,需要进行如下4步操作。

/** if you want to use pwm you can use the following instructions. * * STEP 1, open pwm driver framework support in the RT-Thread Settings file * * STEP 2, define macro related to the pwm * such as #define BSP_USING_PWM1 * * STEP 3, copy your pwm timer init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file * such as void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) and * void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) * * STEP 4, modify your stm32xxxx_hal_config.h file to support pwm peripherals. define macro related to the peripherals * such as #define HAL_TIM_MODULE_ENABLED * */

概况来说,仅仅需要如下4步即可完成配置:

1. 使能框架层2. 打开板级支持宏定义3. 拷贝初始化函数(cubemx)4. 打开hal库外设模块使能

但是,PWM的使用,还需要单独进行通道的使能配置(系统没有自动使能),,如下所示:

#define BSP_USING_PWM3 // 必须进行PWM通道的使能操作 #define BSP_USING_PWM3_CH1 #define BSP_USING_PWM3_CH2

 

 

最新回复(0)