Skip to content

Conversation

@100ask-alen
Copy link
Contributor

@100ask-alen 100ask-alen commented Oct 14, 2022

拉取/合并请求描述:(PR description)

[
在使用stm32的pwm驱动时,发现其初始化channel的时候是根据device->channel这个值去初始化的,device->channel这个值是在pwm_configh.h里面定义设置的,又根据rtt的pwm例程,和常规习惯,应该大多数人会更喜欢设置channel=1/2/3/4,而不是在pwm_configh.h中将channel设置为TIM_CHANNEL_1/2/3/4,因此建议drv_pwm.c做出PR中的修改。

在实际开发中,因pwm_configh.h的示例均是.channel=0,又没有做出解释说明要让.channel=TIM_CHANNEL_1/2/3/4的值,容易误操作导致没有成功输出PWM,这是我在实际开发中遇到的现实问题,因而提出此建议。
]

以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 本拉取/合并请求代码是高质量的 Code in this PR is of high quality
  • 本拉取/合并使用formatting等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@Guozhanxin
Copy link
Member

感觉是可以的,只要hal库里的定义不改的话。
image
还有是不是需要在代码里加个判断,安全一点

#if (TIM_CHANNEL_4 != 0x0000000CU ) 
#error “xxx”
#endif

@Guozhanxin Guozhanxin added the +1 Agree +1 label Oct 24, 2022
@100ask-alen
Copy link
Contributor Author

channel = 0x04 * (device->channel - 1)
这个算式我是抄的原drv_pwm.c里面一个函数里面的,原来的drv_pwm.c支持这样的算式的话,应该影响不大?
我不是很清楚原来的stm32的drv_pwm.c是谁写的。

@100ask-alen
Copy link
Contributor Author

源文件的
static rt_err_t drv_pwm_enable(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable)
static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration)
static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration)
static rt_err_t drv_pwm_set_pulse(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration)
这些函数都是这样换算的通道值。

@Guozhanxin
Copy link
Member

源文件的 static rt_err_t drv_pwm_enable(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable) static rt_err_t drv_pwm_get(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration) static rt_err_t drv_pwm_set(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration) static rt_err_t drv_pwm_set_pulse(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration) 这些函数都是这样换算的通道值。

嗯,感觉应该没啥问题

@100ask-alen
Copy link
Contributor Author

建议在pwm_config.h里面加点注释,说明下那个结构体的几个成员该如何设置值,合法范围是多少。

给stm32f4的pwm_config.h添加几句注释说明参数取值范围。
@mysterywolf
Copy link
Member

嗯嗯 可以增加注释 说实话 我都不知道那个channel成员变量是干啥的 看都设置为0 我也没管它 ,但是需要注意下 rt-thread的注释是用/**/ 而不是//

更改注释方式,从//改为/**/
@100ask-alen
Copy link
Contributor Author

其它系列的pwm通道数,不是全都了解各有多少个,现在不确定是否都是每个定时器只有4个通道, 其它系列的pwm_config.h也需要改一改才行,我找个时间改改看,先不忙合并吧。

@mysterywolf mysterywolf added the in progress PR/issue in progress. label Oct 24, 2022
@mysterywolf
Copy link
Member

https://github.com/mysterywolf/formatting 可以用这个脚本扫描一下

@mysterywolf
Copy link
Member

如果PR 已经准备好 请告知

@mysterywolf mysterywolf added the BSP: STM32 BSP related with ST/STM32 label Oct 26, 2022
细节调整
@mysterywolf mysterywolf added +2 Agree +2 and removed in progress PR/issue in progress. labels Oct 26, 2022
linshire added a commit to linshire/rt-thread that referenced this pull request Oct 29, 2022
mysterywolf pushed a commit that referenced this pull request Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BSP: STM32 BSP related with ST/STM32 +1 Agree +1 +2 Agree +2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants