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

soc: st: stm32 devices: SW JTAG port pins config with hw model V2 #70823

Merged
merged 1 commit into from
Apr 1, 2024
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
8 changes: 8 additions & 0 deletions soc/st/stm32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ config STM32_ENABLE_DEBUG_SLEEP_STOP
effectivly destroys the use-case of `west attach`. Also
SEGGER RTT and similar technologies need this.

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
4 changes: 4 additions & 0 deletions soc/st/stm32/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ zephyr_linker_sources_ifdef(CONFIG_STM32_CCM SECTIONS ccm.ld)

zephyr_sources_ifdef(CONFIG_STM32_BACKUP_SRAM stm32_backup_sram.c)
zephyr_linker_sources_ifdef(CONFIG_STM32_BACKUP_SRAM SECTIONS stm32_backup_sram.ld)

if (NOT CONFIG_DEBUG AND CONFIG_PM)
zephyr_sources_ifdef(CONFIG_DT_HAS_SWJ_CONNECTOR_ENABLED pm_debug_swj.c)
endif()
40 changes: 40 additions & 0 deletions soc/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);
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);
Loading