在使用 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-Threadrtthreadbsplpc55sxxlpc55s69_nxp_evkboardMCUX_Configboardpin_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 的設備框架下。
-
LPC
+關注
關注
8文章
136瀏覽量
77714 -
定時器
+關注
關注
23文章
3255瀏覽量
115387 -
RT-Thread
+關注
關注
31文章
1305瀏覽量
40390 -
PWM輸出
+關注
關注
1文章
66瀏覽量
5221
發布評論請先 登錄
相關推薦
評論