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 swj_to_analog(void)22static 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); 41