Skip to content

cpu/qn908x/periph_i2c: allow internal pull-up on SCL #19729

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

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

maribu
Copy link
Member

@maribu maribu commented Jun 12, 2023

Contribution description

Allow the board config to specify use of external or external pull-up resistor on the SCL up. Default to the internal pull-up, two weak pull ups in parallel are preferable over no pull-up.

Testing procedure

make BOARD=qn9080dk -C examples/default flash term

On master: No output at all, board hangs.

This PR:

2023-06-12 21:08:02,168 # main(): This is RIOT! (Version: 2023.07-devel-610-g0e09b)
2023-06-12 21:08:02,170 # Welcome to RIOT!
> saul
2023-06-12 21:08:05,285 # saul
2023-06-12 21:08:05,287 # ID	Class		Name
2023-06-12 21:08:05,289 # #0	ACT_SWITCH	LED red
2023-06-12 21:08:05,291 # #1	ACT_SWITCH	LED green
2023-06-12 21:08:05,293 # #2	ACT_SWITCH	LED blue
2023-06-12 21:08:05,295 # #3	SENSE_BTN	Button(SW1)
2023-06-12 21:08:05,297 # #4	SENSE_BTN	Button(SW2)
2023-06-12 21:08:05,299 # #5	SENSE_ACCEL	mma8x5x
> saul read 5
2023-06-12 21:08:09,560 # saul read 5
2023-06-12 21:08:09,563 # Reading from #5 (mma8x5x|SENSE_ACCEL)
2023-06-12 21:08:09,566 # Data:	[0]          67 mgₙ
2023-06-12 21:08:09,568 # 	[1]          -5 mgₙ
2023-06-12 21:08:09,570 # 	[2]        1063 mgₙ

(Note: The mma8x5x is connected via I2C and the driver hangs in master during the first I2C access due to bogus clock stretching due to the missing pull-up.)

Issues/PRs references

This fixes #19021

@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: cpu Area: CPU/MCU ports labels Jun 12, 2023
@github-actions github-actions bot added the Platform: ARM Platform: This PR/issue effects ARM-based platforms label Jun 12, 2023
@riot-ci
Copy link

riot-ci commented Jun 12, 2023

Murdock results

✔️ PASSED

98b3839 cpu/qn908x/periph_i2c: enable internal pull-up on SCL

Success Failures Total Runtime
6934 0 6934 11m:21s

Artifacts

@@ -366,6 +366,7 @@ typedef struct {
gpio_t pin_scl; /**< SCL pin */
gpio_t pin_sda; /**< SDA pin */
uint32_t speed; /**< bus speed in bit/s */
bool external_pull_up; /**< Do not enable internal pull-up on SCL? */
Copy link
Contributor

Choose a reason for hiding this comment

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

Does anything speak against always enabling this?
That's now it's done on e.g. nRF5x

Copy link
Member Author

@maribu maribu Jun 13, 2023

Choose a reason for hiding this comment

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

At least in theory this could reduce power consumption while the SCL is driven low by the controller / clock-stretched by the peripheral.

E.g. if a 3.3 V SCL line is driven low and there is a $1\text{ }\mathrm{k\Omega}$ resistor the current flowing throw it will be

$$ I = \frac{R}{U} = \frac{1\text{ }\mathrm{k\Omega}}{3.3\text{ }\mathrm{V}} = 3.3\text{ }\mathrm{mA} $$

but e.g. with $50\text{ }\mathrm{k\Omega}$ resistor it would only be $66\text{ }\mathrm{\mu A}$.

But then again, a weaker pull up results in a lower data rate and therefore would consume the current over a longer period of time.

Maybe its best to just enable it always until someone has a real world example where it is beneficial to only have the external pull up.

Always enable the internal pull-up on the SCL line to always have a
functional I2C bus. This may increase power consumption where an
external pull up is present as well. But let's wait for a real world
use case where this would help to extend battery life before making
this configurable.

This fixes RIOT-OS#19021
@maribu maribu force-pushed the cpu/qn908x/periph_i2c branch from 76d148b to 98b3839 Compare June 13, 2023 12:47
@maribu
Copy link
Member Author

maribu commented Jun 13, 2023

bors merge

@maribu maribu closed this Jun 13, 2023
@bors
Copy link
Contributor

bors bot commented Jun 13, 2023

Already running a review

@maribu maribu reopened this Jun 13, 2023
@maribu
Copy link
Member Author

maribu commented Jun 13, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented Jun 13, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@maribu
Copy link
Member Author

maribu commented Jun 13, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented Jun 13, 2023

Already running a review

bors bot added a commit that referenced this pull request Jun 13, 2023
19724: dist/tools/openocd: add OPENOCD_SERVER_ADDRESS variable r=maribu a=fabian18



19729: cpu/qn908x/periph_i2c: allow internal pull-up on SCL r=maribu a=maribu

### Contribution description

Allow the board config to specify use of external or external pull-up resistor on the SCL up. Default to the internal pull-up, two weak pull ups in parallel are preferable over no pull-up.


Co-authored-by: Fabian Hüßler <fabian.huessler@ml-pa.com>
Co-authored-by: Marian Buschsieweke <marian.buschsieweke@posteo.net>
@bors
Copy link
Contributor

bors bot commented Jun 13, 2023

This PR was included in a batch that was canceled, it will be automatically retried

@bors
Copy link
Contributor

bors bot commented Jun 14, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 650bef6 into RIOT-OS:master Jun 14, 2023
@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
@maribu maribu deleted the cpu/qn908x/periph_i2c branch December 5, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

qn9080 I2C driver spins in endless loop
3 participants