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: cvitek: fix cvitek uart driver can not repeat configure #9257

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

Z8MAN8
Copy link
Contributor

@Z8MAN8 Z8MAN8 commented Jul 27, 2024

After first called from uart open, the dw8250_uart_configure API cannot be called again. Otherwise, this will mess up the device, and uart will not act properly to interrupt again.

Analysis: Configure uart device will close recive interrupte, causing uart device to malfunction.

Solution: After configure uart device, enable the device's recive interrupte.

Reviewed-by: Chen Wang [email protected]

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

[

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

Fixed #9150

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

After configure uart device, enable the device's recive interrupte.

请提供验证的bsp和config (provide the config and bsp)

  • BSP: bsp/cvitek
  • .config:
  • action:

]

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

@Z8MAN8
Copy link
Contributor Author

Z8MAN8 commented Jul 27, 2024

@unicornx

@Rbb666 Rbb666 added the BSP: Cvitek BSP related with cvitek label Jul 27, 2024
@@ -132,6 +132,8 @@ static rt_err_t dw8250_uart_configure(struct rt_serial_device *serial, struct se
clock_divisor = DIV_ROUND_CLOSEST(UART_INPUT_CLK, 16 * serial->config.baud_rate);
dw8250_uart_setbrg(base, clock_divisor);

dw8250_write32(base, UART_IER, UART_IER_RDI);
Copy link
Member

Choose a reason for hiding this comment

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

这里应该不是这么来操作。如果涉及到中断,可以先行判断之前的状态是什么样的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

@Z8MAN8 Z8MAN8 force-pushed the cvitek_uart_driver_cfg_bug branch from 9ca3d50 to 9e4dcf5 Compare July 28, 2024 15:30
@unicornx unicornx self-assigned this Jul 29, 2024
@unicornx
Copy link
Contributor

@Z8MAN8 请在 #9150 里 AT 我一下,这样我就可以 assign 那个 issue 给你了。

@@ -132,6 +134,9 @@ static rt_err_t dw8250_uart_configure(struct rt_serial_device *serial, struct se
clock_divisor = DIV_ROUND_CLOSEST(UART_INPUT_CLK, 16 * serial->config.baud_rate);
dw8250_uart_setbrg(base, clock_divisor);

if(last_ier_state == UART_IER_RDI)
Copy link
Contributor

@unicornx unicornx Jul 29, 2024

Choose a reason for hiding this comment

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

if( 之间应该有空格,这个 formating 检查不出来吗?

另外,直接判断 last_ier_state == UART_IER_RDI 不妥,而是要判断 IER[0] 这一位以前是否是 1,IER 其他位也可能会是 1。

Copy link
Contributor

Choose a reason for hiding this comment

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

if( 之间应该有空格,这个 formating 检查不出来吗?

另外,直接判断 last_ier_state == UART_IER_RDI 不妥,而是要判断 IER[0] 这一位以前是否是 1,IER 其他位也可能会是 1。

其他的 bit 位是不是也应该恢复?所以这个 issue 的完整 fix 应该就是一个完整的 backup -> restore 的操作。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

formating没检查出来,已手动更改,位判断也已解决

Copy link
Contributor

@unicornx unicornx Jul 29, 2024

Choose a reason for hiding this comment

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

formating没检查出来,已手动更改,位判断也已解决

只恢复 UART_IER_RDI 这个位是不够的,其他 bit 的值也需要恢复。

BTW:我不知道 github 是否有机制重新发起下一次 review,你可以研究一下。
最土的方法,你下次每一次改好重新 push 后,可以在 PR 里明确 AT 所有的 reviewer 然后请求第 N 次 review。有时候 review 的 PR 多了我也不知道你是否改过了,以及是否重新 push 过。

Copy link
Contributor

@unicornx unicornx Jul 29, 2024

Choose a reason for hiding this comment

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

formating没检查出来,已手动更改,位判断也已解决

只恢复 UART_IER_RDI 这个位是不够的,其他 bit 的值也需要恢复。

BTW:我不知道 github 是否有机制重新发起下一次 review,你可以研究一下。 最土的方法,你下次每一次改好重新 push 后,可以在 PR 里明确 AT 所有的 reviewer 然后请求第 N 次 review。有时候 review 的 PR 多了我也不知道你是否改过了,以及是否重新 push 过。

追加一个问题:

为啥当初代码里是直接将 UART_IER 置 0,传统的做法一般是对需要的位设置,其他位保持不变。
另外,这个 dw8250_uart_configure 为什么用不到 cfg 这个参数?请研究一下。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

没有保持其他位确实是有问题的,根据 cfg 传参进行配置这部分确实缺少了,需要补上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已重新修改,请重新review

Copy link
Contributor

@unicornx unicornx left a comment

Choose a reason for hiding this comment

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

comments 见上。

@Z8MAN8 Z8MAN8 force-pushed the cvitek_uart_driver_cfg_bug branch from 9e4dcf5 to 953db55 Compare July 29, 2024 06:41
@unicornx unicornx assigned Z8MAN8 and unassigned unicornx Jul 29, 2024
@unicornx
Copy link
Contributor

这个 PR 先解决 #9150 的问题吧,cfg 传参进行配置这部分缺少的问题后面再单独修改吧。

@Z8MAN8
Copy link
Contributor Author

Z8MAN8 commented Aug 16, 2024

这个 PR 先解决 #9150 的问题吧,cfg 传参进行配置这部分缺少的问题后面再单独修改吧。

好的 明白

After first called from uart open, the dw8250_uart_configure
API cannot be called again. Otherwise, this will mess up the
device, and uart will not act properly to interrupt again.

Analysis: Configure uart device will close recive interrupte,
causing uart device to malfunction.

Solution: After configure uart device, enable the device's
recive interrupte.

Signed-off-by: Shicheng Chu <[email protected]>
Reviewed-by: Chen Wang <[email protected]>
@@ -132,6 +134,9 @@ static rt_err_t dw8250_uart_configure(struct rt_serial_device *serial, struct se
clock_divisor = DIV_ROUND_CLOSEST(UART_INPUT_CLK, 16 * serial->config.baud_rate);
dw8250_uart_setbrg(base, clock_divisor);

if (last_ier_state & UART_IER_RDI)
dw8250_write32(base, UART_IER, UART_IER_RDI);
Copy link
Contributor

Choose a reason for hiding this comment

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

image

再说一遍:这里只恢复了 UART_IER_RDI 对应的 bit 位,那么原先其他的 bit 位状态还是被覆盖为 0 了。

@mysterywolf
Copy link
Member

@unicornx 请确认这个PR是否可以合并?

@unicornx
Copy link
Contributor

@unicornx 请确认这个PR是否可以合并?

我这里没有问题了,也 approve 了。但我看熊大还没有 approve。

@unicornx
Copy link
Contributor

@BernardXiong hi, 请 review & commnet,谢谢。

@BernardXiong BernardXiong added the +1 Agree +1 label Sep 4, 2024
@mysterywolf mysterywolf merged commit cea7670 into RT-Thread:master Sep 4, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BSP: Cvitek BSP related with cvitek +1 Agree +1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] [bsp/cvitek] uart configure cannot be called again
5 participants