| 
LPC55S69 PWM踩坑寄录 在使用 lpc55s69_nxp_evk 开发板对接 rtduino 的过程,对接 PWM 部分的时候,遇到了不少坑,在此记录。 BSP 中 driver 的问题由于调用的 SDK 版本问题,kCLOCK_CTimer 需要更改为 kCLOCK_Timer,这个问题在与定时器相关的 drv_hwtimer 文件中同样存在。 同样因为 SDK 的版本问题,CTIMER_SetupPwmPeriod 函数增加了一个参数 /*! 
 * brief Configures the PWM signal parameters. 
 * 
 * Enables PWM mode on the match channel passed in and will then setup the match value 
 * and other match parameters to generate a PWM signal. 
 * This function can manually assign the specified channel to set the PWM cycle. 
 * 
 * note When setting PWM output from multiple output pins, all should use the same PWM 
 * period 
 * 
 * param base             Ctimer peripheral base address 
 * param pwmPeriodChannel Specify the channel to control the PWM period 
 * param matchChannel     Match pin to be used to output the PWM signal 
 * param pwmPeriod        PWM period match value 
 * param pulsePeriod      Pulse width match value 
 * param enableInt        Enable interrupt when the timer value reaches the match value of the PWM pulse, 
 *                         if it is 0 then no interrupt will be generated. 
 * 
 * return kStatus_Success on success 
 *         kStatus_Fail If matchChannel is equal to pwmPeriodChannel; this channel is reserved to set the PWM period 
 */ 
status_t CTIMER_SetupPwmPeriod(CTIMER_Type *base, 
                               const ctimer_match_t pwmPeriodChannel, 
                               ctimer_match_t matchChannel, 
                               uint32_t pwmPeriod, 
                               uint32_t pulsePeriod, 
                               bool enableInt)新增的 param pwmPeriodChannel 指定一个定时器的通道控制 PWM 的 Period ,需要注意的是,其中提示:当使用一个定时器的多个通道输出 PWM 时,其 Period 均是一致的。通过对比之前版本的 SDK ,了解到之前是使用 kCTIMER_Match_3 通道作为 pwmPeriodChannel 。因此,在对应的参数位置填入 kCTIMER_Match_3 。  
 引脚配置问题解决上述的那些问题之后,就已经可以正常使用 PWM 了。但是在对接 RTduino 的过程中又出现了新的问题。 在 RTduino 框架下一直不能正常使用 PWM 功能,最后发现,是需要将引脚配置为对应的功能,具体对应到的是 RT-Thread\rtthread\bsp\lpc55sxx\lpc55s69_nxp_evk\board\MCUX_Config\board\pin_mux 相关文件,可以通过 NXP 官方工具进行配置 MCUXpresso Config Tools 修改引脚功能后,rtduino 框架下的 PWM 还是对接不上,debug 发现在 drv_pwm 中定时器2对应的是 pwm1 ,而 RT-Thread 的设备框架下应该对应的是 pwm2 ,导致识别不到。于是将 drv_pwm 中定时器2改为 pwm2 ,呼吸灯正常。  
之后优化的方向使用 bsp 时注意到,drv_pwm 中只考虑了定时器2一种情况,并且只有一个通道。接下来需要对 PWM 设备进一步的抽象,更好的对接到 RT-Thread 的设备框架下。  
        
        
        
         |