Skip to content
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

stm32: pm: Enable to driver JTAG port pns to analog when not required #63495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boards/arm/nucleo_wba52cg/board.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")

set(OPENOCD "/local/mcu/tools/openocd/src/openocd" CACHE FILEPATH "" FORCE)
set(OPENOCD_DEFAULT_PATH /local/mcu/tools/openocd/tcl)

include(${ZEPHYR_BASE}/boards/common/stm32cubeprogrammer.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
2 changes: 0 additions & 2 deletions boards/arm/nucleo_wba52cg/support/openocd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ set CLOCK_FREQ 8000
reset_config srst_only srst_nogate

source [find target/stm32wbax.cfg]

gdb_memory_map disable
11 changes: 6 additions & 5 deletions doc/hardware/pinctrl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ In most situations, the states defined in Devicetree will be the ones used in
the compiled firmware. However, there are some cases where certain states will
be conditionally used depending on a compilation flag. A typical case is the
``sleep`` state. This state is only used in practice if
:kconfig:option:`CONFIG_PM_DEVICE` is enabled. If a firmware variant without device
power management is needed, one should in theory remove the ``sleep`` state from
Devicetree to not waste ROM space storing such unused state.
:kconfig:option:`CONFIG_PM` or :kconfig:option:`CONFIG_PM_DEVICE` is enabled.
If a firmware variant without these power management configurations is needed,
one should in theory remove the ``sleep`` state from Devicetree to not waste ROM
space storing such unused state.

States can be skipped by the ``pinctrl`` Devicetree macros if a definition named
``PINCTRL_SKIP_{STATE_NAME}`` expanding to ``1`` is present when pin control
Expand All @@ -157,8 +158,8 @@ management:

.. code-block:: c

#ifndef CONFIG_PM_DEVICE
/** If device power management is not enabled, "sleep" state will be ignored. */
#if !defined(CONFIG_PM) && !defined(CONFIG_PM_DEVICE)
/** Out of power management configurations, ignore "sleep" state. */
#define PINCTRL_SKIP_SLEEP 1
#endif

Expand Down
11 changes: 11 additions & 0 deletions dts/arm/st/u5/stm32u5.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,17 @@
status = "disabled";
};
};

};

swj_port: swj_port {
compatible = "swj-connector";
pinctrl-0 = <&debug_jtms_swdio_pa13 &debug_jtck_swclk_pa14
&debug_jtdi_pa15 &debug_jtdo_swo_pb3
&debug_jtrst_pb4>;
pinctrl-1 = <&analog_pa13 &analog_pa14 &analog_pa15
&analog_pb3 &analog_pb4>;
pinctrl-names = "default", "sleep";
};

die_temp: dietemp {
Expand Down
10 changes: 10 additions & 0 deletions dts/arm/st/wba/stm32wba.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,16 @@
};
};

swj_port: swj_port {
compatible = "swj-connector";
pinctrl-0 = <&debug_jtms_swdio_pa13 &debug_jtck_swclk_pa14
&debug_jtdi_pa15 &debug_jtdo_swo_pb3
&debug_jtrst_pb4>;
pinctrl-1 = <&analog_pa13 &analog_pa14 &analog_pa15
&analog_pb3 &analog_pb4>;
Comment on lines +468 to +471
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the dtsi is the best place to put that since the pins can be used for something else than debug.
For example, in the nucleo_wba55cg.dts, PA15, PB3 and PB4 are used for SPI1. Depending on the order of initialization, I think it could result in drivers not functioning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, so we should make sure this is done before configuring any other device and change priority

pinctrl-names = "default", "sleep";
};

smbus1: smbus1 {
compatible = "st,stm32-smbus";
#address-cells = <1>;
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: 2 additions & 2 deletions include/zephyr/drivers/pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ struct pinctrl_dev_config {

/** @cond INTERNAL_HIDDEN */

#ifndef CONFIG_PM_DEVICE
/** If device power management is not enabled, "sleep" state will be ignored. */
#if !defined(CONFIG_PM) && !defined(CONFIG_PM_DEVICE)
/** Out of power management configurations, ignore "sleep" state. */
#define PINCTRL_SKIP_SLEEP 1
#endif

Expand Down
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()
8 changes: 8 additions & 0 deletions soc/arm/st_stm32/common/Kconfig.soc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ config USE_STM32_ASSERT
help
Enable asserts in STM32Cube HAL and LL drivers.

config SWJ_ANALOG_PRIORITY
int "SWJ DP port to analog routine initialization priority"
default 49
help
Initialization priority of the routine within the PRE_KERNEL1 level.
This priority must be greater than GPIO_INIT_PRIORITY and lower than
UART_INIT_PRIORITY.

choice POWER_SUPPLY_CHOICE
prompt "STM32 power supply configuration"
default POWER_SUPPLY_LDO
Expand Down
40 changes: 40 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,40 @@
/*
* 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);
erwango marked this conversation as resolved.
Show resolved Hide resolved
if (err < 0) {
__ASSERT(0, "SWJ pinctrl setup failed");
return err;
}

return 0;
}

/* Run this routine as the earliest pin configuration in the target,
* to avoid potential conflicts with devices accessing SWJ-DG pins for
* their own needs.
*/
SYS_INIT(swj_to_analog, PRE_KERNEL_1, CONFIG_SWJ_ANALOG_PRIORITY);
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ manifest:
groups:
- hal
- name: hal_stm32
revision: 22925907a6faeb601fc9a0d8cbb65c4b26d38043
revision: 60c9634f61c697e1c310ec648d33529712806069
path: modules/hal/stm32
groups:
- hal
Expand Down
Loading