Unable to enable gain control on nRF21540 FEM with nRF5340

Hello,

I’m trying to get an nRF21540 FEM working with a chip-down nRF5340 design under NCS v2.4.2. I’m able to enable the FEM at its default gain setting, but I hit a wall trying to get gain control either via the mode-gpios property and associated KConfig settings, or dynamic control via SPI0 on the network core.

I have a pin forwarder defined in the application core's DTS:

gpio_fwd: nrf-gpio-forwarder {
        compatible = "nordic,nrf-gpio-forwarder";
		status = "okay";
		nrf21540-gpio-if {
			gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>, /* rx-en-gpios */
					<&gpio1 6 GPIO_ACTIVE_HIGH>, /* tx-en-gpios */
					<&gpio0 29 GPIO_ACTIVE_HIGH>, /* pdn-gpios */
					<&gpio1 8 GPIO_ACTIVE_HIGH>;
		};
		nrf21540-spi-if {
			gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>, /* clk */
					<&gpio0 27 GPIO_ACTIVE_HIGH>, /* mosi */
					<&gpio0 24 GPIO_ACTIVE_HIGH>, /* csn */
					<&gpio0 26 GPIO_ACTIVE_HIGH>; /* miso */
		};	
    };
 

Here's my hci_rpmsg.overlay:

/ {
   nrf_radio_fem: nrf21540_fem {
		compatible  = "nordic,nrf21540-fem";
		tx-en-gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
		rx-en-gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
		pdn-gpios   = <&gpio0 29 GPIO_ACTIVE_HIGH>;
		// mode-gpios  = <&gpio1 8 GPIO_ACTIVE_HIGH>;
		spi-if = <&nrf_radio_fem_spi>;
		supply-voltage-mv = <1800>;
  	};
};

&radio {
	fem = <&nrf_radio_fem>;
};

&uart0 {
   status = "disabled";
};

fem_spi: &spi0 {
	status = "okay";
	pinctrl-0 = <&spi0_default_alt>;
	pinctrl-1 = <&spi0_sleep_alt>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>;

	nrf_radio_fem_spi: nrf21540_fem_spi@0 {
		compatible = "nordic,nrf21540-fem-spi";
		status = "okay";
		reg = <0>;
		spi-max-frequency = <8000000>;
	};
};

&pinctrl {

	spi0_default_alt: spi0_default_alt {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK,  0, 28)>,
					<NRF_PSEL(SPIM_MISO, 0, 26)>,
					<NRF_PSEL(SPIM_MOSI, 0, 27)>;
		};
	};
	spi0_sleep_alt: spi0_sleep_alt {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK,  0, 28)>,
					<NRF_PSEL(SPIM_MISO, 0, 26)>,
					<NRF_PSEL(SPIM_MOSI, 0, 27)>;
			low-power-enable;
		};
	};
};

And here's the relevant settings from my hci_rpmsg.conf:

CONFIG_FEM=y
CONFIG_FEM_AL_LIB=y
CONFIG_MPSL_FEM=y
CONFIG_MPSL_FEM_ONLY=y

CONFIG_GPIO=y
CONFIG_MPSL_FEM_NRF21540_GPIO=y

# CONFIG_SPI=y
# CONFIG_SPI_NRFX=y
# CONFIG_NRFX_SPIM0=y
# CONFIG_MPSL_FEM_NRF21540_GPIO_SPI=y
# CONFIG_MPSL_FEM_NRF21540_RUNTIME_PA_GAIN_CONTROL=y

CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB_POUTA=20
CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB_POUTB=10
CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB=20

It builds successfully and has a much higher RSSI than with the FEM configs disabled, as expected.

When I uncomment the nrf_radio_fem's mode-gpios definition to allow switching between 10dB and 20dB, I get an undeclared device error originating from:

/opt/nordic/ncs/v2.4.2/nrf/subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c:174:25: note: in expansion of macro 'DEVICE_DT_GET'
174 | DEVICE_DT_GET(MPSL_FEM_GPIO_PORT(mode_gpios)),

And when I uncomment the SPI-related configs, I get another undeclared device error originating from:

/opt/nordic/ncs/v2.4.2/zephyr/drivers/spi/spi_nrfx_spim.c:625:1: note: in expansion of macro 'SPI_NRFX_SPIM_DEFINE'
625 | SPI_NRFX_SPIM_DEFINE(0);

In my experience, these types of error are usually due to some missing KConfig flag, but I'm all out of guesses as to which I may be missing that's not covered in the official docs. Or am I missing something else?

Thanks

  • Hi

    1. Make sure you've set CONFIG_MPSL_FEM_NRF21540_GPIO on your end and that the following GPIOs are set, which are must-haves on the nRF21540: tx-en-gpios, rx-en-gpios, pdn-gpios

    2. You need to set the Bluetooth LE controller with the CONFIG_BT_LL_SOFTDEVICE in your config and child image config files to use the SoftDevice controller for your nRF5340 project.

    Best regards,

    Simon

  • Hi

    So, it seems we found a bug on our side here, and this will be updated in future revisions, please see the diff here:

    diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h
    index 842b4189184..4961c58bd1d 100644
    --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h
    +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h
    @@ -57,6 +57,7 @@
    #include <hal/nrf_rtc.h>
    #include <hal/nrf_aar.h>
    #include <hal/nrf_ccm.h>
    +#include <hal/nrf_gpiote.h>
    #include <hal/nrf_dppi.h>
    #include "radio_nrf5_dppi_resources.h"
    #include "radio_nrf5_dppi.h"

    Best regards,

    Simon

  • Thanks, this fixes the build error with the Zephyr Controller version, but setting the TX power level through bt_hci_cmd_send_sync() returns a maximum of 3dB gain for gain settings over 3dB, and the RSSI as shown in the NRF Connect iOS app is not affected by settings above 3dB, so mode pin control through the network core is still not working.

    Turns out I'm able to work around this by controlling the mode GPIO directly from the application core, so I'm going to run with that for the time being. 

    I'd really appreciate an answer to my other question as well: if SoftDevice supports direction finding, any idea why the direction_finding_connectionless_tx produces an i/o error when starting periodic advertisements? 

  • Hi

    What function exactly in the Direction Finding connectionless TX sample is it that returns this I/O error on your end? I would chuck it up to the FEM being used in your design, but I don't have much more info on that. What are you using as the receiver for the Direction Finding here exactly?

    Best regards,

    Simon

Related