Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bsp][wch]增加适配CH32V208 CAN驱动 #7366

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

zylugl
Copy link
Contributor

@zylugl zylugl commented Apr 25, 2023

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

[

为什么提交这份PR (why to submit this PR)

我在调试CH32V208时,发现原先的CH32_drivers没有配置对ch32v208的匹配。经我修改drv_can.c,完成了对can的驱动匹配。

你的解决方案是什么 (what is your solution)

增加宏编译条件,增加匹配CH32V208的can_baud_rate_tab定义,同时因为ch32v208有CAN1 在CAN的相关操作上增加了CH32V307的编译条件,有效的过滤掉CH32V208的CAN2的相关定义,避免编译时报错。

在什么测试环境下测试通过 (what is the test environment)

在scons下对CH32V208、CH32V307均编译通过,在相关开发板上也测试通过。
]

当前拉取/合并请求的状态 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

@@ -91,14 +91,15 @@ static struct ch32v307x_can_obj drv_can1 =
};
#endif

#ifdef BSP_USING_CAN2
#if (defined BSP_USING_CAN2) && (defined CH32V30x_D8C)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这么改的原因是什么?CH32V30x_D8C 这个不支持 CAN2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果CH32V30x_D8C这个不支持CAN2,BSP里不开启不就好了?

@zylugl
Copy link
Contributor Author

zylugl commented Apr 27, 2023 via email

@zylugl
Copy link
Contributor Author

zylugl commented Apr 27, 2023 via email

@Guozhanxin
Copy link
Member

是这样的,CH32V208,他只有1个can1。既使不开启,他也会报错,用这个条件后,他就不去编译CAN2了,你可以测试一下。其实可以象国民技术的N32L403那样,重写一bCAN但是那样,代码太多了。综合来讲,这样时间成本最低,也可以反馈给沁恒,让他们自己修改。   华仔 @.***  

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年4月27日(星期四) 中午11:24 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [RT-Thread/rt-thread] 增加适配CH32V208 CAN驱动 (PR #7366) @Guozhanxin commented on this pull request. In bsp/wch/risc-v/Libraries/ch32_drivers/drv_can.c: > @@ -91,14 +91,15 @@ static struct ch32v307x_can_obj drv_can1 = }; #endif -#ifdef BSP_USING_CAN2 +#if (defined BSP_USING_CAN2) && (defined CH32V30x_D8C) 如果CH32V30x_D8C这个不支持CAN2,BSP里不开启不就好了? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

这里不是本身就有一个宏控制吗? BSP_USING_CAN2 不开启这个宏不就好了吗。不开启的话,下面的代码不参与编译,也不会报错吧。

@zylugl
Copy link
Contributor Author

zylugl commented Apr 27, 2023 via email

@zylugl
Copy link
Contributor Author

zylugl commented Apr 27, 2023 via email

Copy link
Member

@mysterywolf mysterywolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无需更改,只是作为后续重新梳理的参考

@@ -91,14 +91,15 @@ static struct ch32v307x_can_obj drv_can1 =
};
#endif

#ifdef BSP_USING_CAN2
#ifdef CAN2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef CAN2
#if defined(BSP_USING_CAN2) && defined(CAN2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我建议这里就用 #ifdef BSP_USING_CAN2, 然后在前面加上一个总的
#if (defined BSP_USING_CAN2) && !(defined CAN2)
#error "CAN2 is not available for this board. Please change kconfig."
#endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果只使用 #if defined(BSP_USING_CAN2) && defined(CAN2) 的话 则有可能用户选择了BSP_USING_CAN2但是其实没有CAN2 编译虽然不会报错但是会给用户造成困惑

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实际上应该由BSP的开发者保证kconfig里面没有BSP_USING_CAN2,但是开发者可能犯错误,使用#error提供一种纠错机制

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外群里有关于到底应该用#ifdef BSP_USING_CAN2还是#ifdef CAN2的讨论,原则上在ops里应该是不关心BSP的事的所以应该用#ifdef CAN2,但是如果用#ifdef CAN2 则可能出现用户没有选择BSP_USING_CAN2的时候CAN2相关的资源仍然被占用了,其原因在于CAN2的初始化代码跟CAN1写在一起了。这其实不符合rtt的规范,如果后面有人跟进的话,可以考虑一个独立于CAN1和CAN2(复用)的ops,这样在ops里面就不存在该用BSP_USING_CAN2还是CAN2的问题了,只在外面定义对向的时候用#ifdef BSP_USING_CAN2来判断是否生成针对CAN2的对象。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以上评论主要是为了后续讨论,不需要执行。

@@ -132,7 +133,7 @@ rt_weak void ch32v307x_can_gpio_init(CAN_TypeDef *can_base)
*/
}
#endif
#ifdef BSP_USING_CAN2
#ifdef CAN2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef CAN2
#if defined(BSP_USING_CAN2) && defined(CAN2)

@@ -955,7 +974,7 @@ void CAN1_SCE_IRQHandler(void)
}
#endif /* BSP_USING_CAN1 */

#ifdef BSP_USING_CAN2
#ifdef CAN2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef CAN2
#if defined(BSP_USING_CAN2) && defined(CAN2)

@@ -1132,7 +1151,7 @@ int rt_hw_can_init(void)
rt_hw_can_register(&drv_can1.device, drv_can1.name, &_can_ops, &drv_can1);
#endif /* BSP_USING_CAN1 */

#ifdef BSP_USING_CAN2
#ifdef CAN2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef CAN2
#if defined(BSP_USING_CAN2) && defined(CAN2)

@supperthomas supperthomas changed the title 增加适配CH32V208 CAN驱动 [bsp][wch]增加适配CH32V208 CAN驱动 May 4, 2023
修改serial.h的引用错误
@mysterywolf mysterywolf marked this pull request as draft June 10, 2023 04:42
@mysterywolf mysterywolf added the discussion This PR/issue needs to be discussed later label Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BSP discussion This PR/issue needs to be discussed later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants