Skip to content

Commit

Permalink
soc: stm32: PM: Disable jtag port pins if no debug
Browse files Browse the repository at this point in the history
At chip startup, jtag pins are configured by default to enable
debug.
This configuration adds consumption and when using PM profile,
we can save ~40uA by resetting this configuration and setting pins
to analog mode.

Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
  • Loading branch information
erwango committed Oct 6, 2023
1 parent bb07484 commit 502a219
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dts/arm/st/wba/stm32wba.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
};
};

jtag_port: jtag_port {
compatible = "gpio-jtag";
jtag-gpios = <&gpioa 13 0>, <&gpioa 14 0>, <&gpioa 15 0>,
<&gpiob 3 0> ,<&gpiob 4 0>;
};

soc {
flash: flash-controller@40022000 {
compatible = "st,stm32-flash-controller", "st,stm32wba-flash-controller";
Expand Down
5 changes: 5 additions & 0 deletions dts/bindings/gpio/swj-connector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Serial Wire - JTAG Connector

compatible: "swj-connector"

include: pinctrl-device.yaml
4 changes: 4 additions & 0 deletions soc/arm/st_stm32/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ zephyr_sources_ifdef(CONFIG_STM32_BACKUP_SRAM stm32_backup_sram.c)
zephyr_linker_sources_ifdef(CONFIG_STM32_BACKUP_SRAM SECTIONS stm32_backup_sram.ld)

zephyr_sources(soc_config.c)

if (NOT CONFIG_DEBUG AND CONFIG_PM)
zephyr_sources_ifdef(CONFIG_DT_HAS_SWJ_CONNECTOR_ENABLED pm_debug_swj.c)
endif()
36 changes: 36 additions & 0 deletions soc/arm/st_stm32/common/pm_debug_swj.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/drivers/pinctrl.h>
#include <zephyr/init.h>

#define SWJ_NODE DT_NODELABEL(swj_port)

PINCTRL_DT_DEFINE(SWJ_NODE);

const struct pinctrl_dev_config *swj_pcfg = PINCTRL_DT_DEV_CONFIG_GET(SWJ_NODE);

/*
* Serial Wire / JTAG port pins are enabled as part of SoC default configuration.
* When debug access is not needed and in case power consumption performance is
* expected, configure matching pins to analog in order to save power.
*/

static int swj_to_analog(void)
{
int err;

/* Set Serial Wire / JTAG port pins to analog mode */
err = pinctrl_apply_state(swj_pcfg, PINCTRL_STATE_SLEEP);
if (err < 0) {
__ASSERT(0, "SWJ pinctrl setup failed");
return err;
}

return 0;
}

SYS_INIT(swj_to_analog, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

0 comments on commit 502a219

Please sign in to comment.