Skip to content

Commit 7291450

Browse files
FRASTMfabiobaltieri
authored andcommitted
soc: st: stm32 devices: SW JTAG port pins config with hw model V2
During the migration to Hw model V2 the PR #63495 was not fully reported. This change is adding the support Serial Wire / JTAG port pins Signed-off-by: Francois Ramu <[email protected]>
1 parent fa6eca3 commit 7291450

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

soc/st/stm32/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ config STM32_ENABLE_DEBUG_SLEEP_STOP
3939
effectivly destroys the use-case of `west attach`. Also
4040
SEGGER RTT and similar technologies need this.
4141

42+
config SWJ_ANALOG_PRIORITY
43+
int "SWJ DP port to analog routine initialization priority"
44+
default 49
45+
help
46+
Initialization priority of the routine within the PRE_KERNEL1 level.
47+
This priority must be greater than GPIO_INIT_PRIORITY and lower than
48+
UART_INIT_PRIORITY.
49+
4250
choice POWER_SUPPLY_CHOICE
4351
prompt "STM32 power supply configuration"
4452
default POWER_SUPPLY_LDO

soc/st/stm32/common/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ zephyr_linker_sources_ifdef(CONFIG_STM32_CCM SECTIONS ccm.ld)
1111

1212
zephyr_sources_ifdef(CONFIG_STM32_BACKUP_SRAM stm32_backup_sram.c)
1313
zephyr_linker_sources_ifdef(CONFIG_STM32_BACKUP_SRAM SECTIONS stm32_backup_sram.ld)
14+
15+
if (NOT CONFIG_DEBUG AND CONFIG_PM)
16+
zephyr_sources_ifdef(CONFIG_DT_HAS_SWJ_CONNECTOR_ENABLED pm_debug_swj.c)
17+
endif()

soc/st/stm32/common/pm_debug_swj.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2023 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/pinctrl.h>
8+
#include <zephyr/init.h>
9+
10+
#define SWJ_NODE DT_NODELABEL(swj_port)
11+
12+
PINCTRL_DT_DEFINE(SWJ_NODE);
13+
14+
const struct pinctrl_dev_config *swj_pcfg = PINCTRL_DT_DEV_CONFIG_GET(SWJ_NODE);
15+
16+
/*
17+
* Serial Wire / JTAG port pins are enabled as part of SoC default configuration.
18+
* When debug access is not needed and in case power consumption performance is
19+
* expected, configure matching pins to analog in order to save power.
20+
*/
21+
22+
static int swj_to_analog(void)
23+
{
24+
int err;
25+
26+
/* Set Serial Wire / JTAG port pins to analog mode */
27+
err = pinctrl_apply_state(swj_pcfg, PINCTRL_STATE_SLEEP);
28+
if (err < 0) {
29+
__ASSERT(0, "SWJ pinctrl setup failed");
30+
return err;
31+
}
32+
33+
return 0;
34+
}
35+
36+
/* Run this routine as the earliest pin configuration in the target,
37+
* to avoid potential conflicts with devices accessing SWJ-DG pins for
38+
* their own needs.
39+
*/
40+
SYS_INIT(swj_to_analog, PRE_KERNEL_1, CONFIG_SWJ_ANALOG_PRIORITY);

0 commit comments

Comments
 (0)