-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
boards: shields: nrf2240ek: 500mA pmic current limit on bootup #17140
boards: shields: nrf2240ek: 500mA pmic current limit on bootup #17140
Conversation
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: fee8112ff1d8d3773686f83afaa343e9cff2bf27 more detailssdk-nrf:
Github labels
List of changed files detected by CI (2)
Outputs:ToolchainVersion: 9338b70c26 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds. Note: This comment is automatically posted by the Documentation Publishing GitHub Action. |
e0394f4
to
2eb329b
Compare
2eb329b
to
d3c6bca
Compare
{ | ||
int err; | ||
struct i2c_dt_spec bus = I2C_DT_SPEC_GET(DT_NODELABEL(nrf2240ek_pmic)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rationale for direct i2c writes.
The regulator.h
API promises the function regulator_set_current_limit
https://github.com/nrfconnect/sdk-zephyr/blob/fb6ca20a06ba31a3dc1b86d6986d48ad4a5760b0/include/zephyr/drivers/regulator.h#L604
but it is not implemented
https://github.com/nrfconnect/sdk-zephyr/blob/fb6ca20a06ba31a3dc1b86d6986d48ad4a5760b0/drivers/regulator/regulator_npm1300.c#L637
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add an implementation of regulator_set_current_limit()
there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regulator_set_current_limit
for VBUS is not implemented because USB interface of PMIC is not considered a regulator. BUCK1, BUCK2, LDO1 and LDO2 are regulators, and they indeed don't support setting of a current limit.
There is charger
interface you could use, I'll post a more detailed answer below in a moment.
{ | ||
int err; | ||
struct i2c_dt_spec bus = I2C_DT_SPEC_GET(DT_NODELABEL(nrf2240ek_pmic)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add an implementation of regulator_set_current_limit()
there?
return nrf2240ek_pmic_init(); | ||
} | ||
|
||
SYS_INIT(shield_init, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not guarantee that the I2C driver will be initialized first. The priority value should be greater.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addrssed in commit ece601a
west.yml
Outdated
@@ -72,7 +72,7 @@ manifest: | |||
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html | |||
- name: zephyr | |||
repo-path: sdk-zephyr | |||
revision: fb6ca20a06ba31a3dc1b86d6986d48ad4a5760b0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to the rest of the changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To setup current limit on bootup I need to put C code within shield. It was impossible in current sdk-zephyr, but in upstream zephyr there is a commit that makes it possible. Cherry-pick from upstream zephyr and sha update is in separate commit. It could be done in a separate PR, but if I did it in a separate PR one could ask in that PR why is this cherry-pick necessary.
So this change is necessary here, but not core of the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you could implement the workaround you need using existing functions. The driver with the interface you need is "npm1300 charger":
https://github.com/nrfconnect/sdk-zephyr/blob/fb6ca20a06ba31a3dc1b86d6986d48ad4a5760b0/dts/bindings/sensor/nordic%2Cnpm1300-charger.yaml
https://github.com/nrfconnect/sdk-zephyr/blob/fb6ca20a06ba31a3dc1b86d6986d48ad4a5760b0/drivers/sensor/nordic/npm1300_charger/npm1300_charger.c
Most of its settings come from device tree and it implements sensor
interface.
I believe the device tree setting vbus-limit-microamp
is what you would want to use, see example:
https://github.com/nrfconnect/sdk-zephyr/blob/fb6ca20a06ba31a3dc1b86d6986d48ad4a5760b0/boards/shields/npm1300_ek/npm1300_ek.overlay#L52
It sets a different register than the one you have used. I believe the difference is that the one you used is intended for usage for when USB host tells the device (in the process of USB enumeration if I'm not mistaken) what is the actual maximal current it supports, and the one that is set by this dts setting is intended for default initial value that is used before host tells what is the limit. nPM1300 does not handle this conversation with a host, that's why it is implemented this way.
If you're sure that you want to use the registers you've used, you'll have to call sensor_attr_set()
:
const struct sensor_value currentLimit = { .val1 = 0, val2 = 500000 };
sensor_attr_set(charger_device, SENSOR_CHAN_CURRENT, SENSOR_ATTR_CONFIGURATION, ¤tLimit);
Please note that you must be sure that the source is indeed able to provide the current you need. I believe that in some cases just drawing 500 mA would be an issue.
b5a7803
to
ece601a
Compare
Regarding #17140 (review) #17140 (comment) #17140 (comment) and taking into account the F2F discussion, would it be okay to merge it as is. |
ece601a
to
77b0376
Compare
Bringing objects close to the PCB antenna of the nRF2240EK might cause voltage drops which could in effect reset the nRF2240 what is invisible to the remaining application. To counteract this phenomenon the current limit of the nPM1300 pmic present on the nRF2240EK is increased to 500mA. Signed-off-by: Andrzej Kuros <[email protected]>
77b0376
to
fee8112
Compare
@anangl @WalkingTalkingPotato I changed the approach. The workaround uses now the advised |
Bringing objects close to the PCB antenna of the nRF2240EK might
cause voltage drops which could in effect reset the nRF2240 what is
invisible to the remaining application.
To counteract this phenomenon the current limit of the PMIC
present on the nRF2240EK is increased to 500mA.