Skip to content

Commit

Permalink
boards: shields: nrf2240ek: 500mA pmic current limit on bootup
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ankuns committed Sep 3, 2024
1 parent a8f8590 commit e0394f4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
12 changes: 12 additions & 0 deletions boards/shields/nrf2240ek/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

if(CONFIG_SHIELD_NRF2240EK)

zephyr_library()
zephyr_library_sources(src/shield.c)

endif()
8 changes: 7 additions & 1 deletion boards/shields/nrf2240ek/nrf2240ek.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
};
};

fem_twi: &arduino_i2c {
&arduino_i2c {
status = "okay";
compatible = "nordic,nrf-twim";

Expand All @@ -27,4 +27,10 @@ fem_twi: &arduino_i2c {
status = "okay";
reg = <0x30>;
};

nrf2240ek_pmic: pmic@6b {
compatible = "nordic,npm1300";
status = "okay";
reg = <0x6b>;
};
};
76 changes: 76 additions & 0 deletions boards/shields/nrf2240ek/src/shield.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/i2c.h>

#define NPM1300_REGADDR_VBUSIN_TASKUPDATEILIMSW 0x0200U

#define NPM1300_REGVAL_VBUSIN_TASKUPDATEILIMSW_NOEFFECT 0x00U
#define NPM1300_REGVAL_VBUSIN_TASKUPDATEILIMSW_SELVBUSILIM0 0x01U

#define NPM1300_REGADDR_VBUSIN_VBUSINILIM0 0x0201U

#define NPM1300_REGVAL_VBUSIN_VBUSINILIM0_500MA0 0U

/**
* @brief Writes a register of a nPM1300 device through I2C.
*
* @param spec I2C specification from the devicetree.
* @param reg_addr Address of the register within nPM1300 device.
* @param value The value to write into the register.
*
* @return As underlying @ref i2c_write_dt function. @c 0 if successful.
*/
static inline int npm1300_reg_write_dt(
const struct i2c_dt_spec *spec,
uint16_t reg_addr,
uint8_t value)
{
/* Note: There is only 8-bit reg_addr version in drivers/i2c.h provided by Zephyr.
* The nPM1300 uses the 16-bit register address.
*/

uint8_t tx_buf[3] = {
(uint8_t)(reg_addr >> 8),
(uint8_t)reg_addr,
value
};

return i2c_write_dt(spec, tx_buf, 3);
}

static int nrf2240ek_pmic_init(void)
{
int err;
struct i2c_dt_spec bus = I2C_DT_SPEC_GET(DT_NODELABEL(nrf2240ek_pmic));

err = npm1300_reg_write_dt(&bus,
NPM1300_REGADDR_VBUSIN_TASKUPDATEILIMSW,
NPM1300_REGVAL_VBUSIN_TASKUPDATEILIMSW_SELVBUSILIM0);

if (err != 0) {
return err;
}

err = npm1300_reg_write_dt(&bus,
NPM1300_REGADDR_VBUSIN_VBUSINILIM0,
NPM1300_REGVAL_VBUSIN_VBUSINILIM0_500MA0);

if (err != 0) {
return err;
}

return 0;
}

static int shield_init(void)
{
return nrf2240ek_pmic_init();
}

SYS_INIT(shield_init, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY);

0 comments on commit e0394f4

Please sign in to comment.