Some pins not usable when using ST-Link ?
rolo644u Thu May 26, 2016 4:59 pm
I’m experiencing a strange effect when using ST-LINK as upload tool. Some I/O pins are not usable (PB3, PB4, PA15, PA12, PA11). I test this with a simple blink sketch, using the standard digitalWrite command. All other pins work fine. Same on all my STM boards (2x Maple Mini and 2x Blue Pill).
Using the bootloader as upload tool the missing pins work, except PA12 and PA11, these are now in use for the USB so left alone.
I can’t get my head arround it, why is this ? I was thinking that the same code is flashed in both methods, only using a different transport method.
Are these pins reserved for something else or am I missing something basic info here ?
Replies
martinayotte Thu May 26, 2016 6:12 pm
This is because those pins are JTAG pins.
When using ST-Link, it doesn’t do any call to disable SWD and JTAG.
The relevant code is located in STM32F1/system/libmaple/stm32f1/include/series/gpio.h, triggered by define in board.cpp of the variant.
/**
* @brief Debug port configuration
*
* Used to configure the behavior of JTAG and Serial Wire (SW) debug
* ports and their associated GPIO pins.
*
* @see afio_cfg_debug_ports()
*/
typedef enum afio_debug_cfg {
/** Full Serial Wire and JTAG debug */
AFIO_DEBUG_FULL_SWJ = AFIO_MAPR_SWJ_CFG_FULL_SWJ,
/** Full Serial Wire and JTAG, but no NJTRST. */
AFIO_DEBUG_FULL_SWJ_NO_NJRST = AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_NJRST,
/** Serial Wire debug only (JTAG-DP disabled, SW-DP enabled) */
AFIO_DEBUG_SW_ONLY = AFIO_MAPR_SWJ_CFG_NO_JTAG_SW,
/** No debug; all JTAG and SW pins are free for use as GPIOs. */
AFIO_DEBUG_NONE = AFIO_MAPR_SWJ_CFG_NO_JTAG_NO_SW,
} afio_debug_cfg;
/**
* @brief Enable or disable the JTAG and SW debug ports.
* @param config Desired debug port configuration
* @see afio_debug_cfg
*/
static inline void afio_cfg_debug_ports(afio_debug_cfg config) {
__io uint32 *mapr = &AFIO_BASE->MAPR;
*mapr = (*mapr & ~AFIO_MAPR_SWJ_CFG) | config;
}
rolo644u Thu May 26, 2016 6:30 pm
Thanks ! That explains a lot. Now I used this piece of code in the setup section and the led on PA15 blinks
void setup() {
afio_cfg_debug_ports(AFIO_DEBUG_NONE);
martinayotte Thu May 26, 2016 7:27 pm
Beware that with AFIO_DEBUG_NONE you won’t be able to debug using ST-Link, but with AFIO_DEBUG_SW_ONLY it is allowed.
rolo644u Thu May 26, 2016 7:47 pm
Yes, thanks, have to dive into this debug functions later, on my “to learn” list !
stevestrong Sun Jan 15, 2017 2:22 pm
Well, I also got infected by this “PB4 not toggling” virus…
I cannot find the place in the repo where the afio will configure the ports to debug/non-debug.
I am using the blue pill with “Stm32duino bootloader” upload method, and I cannot toggle PB4 unless I call
afio_cfg_debug_ports(AFIO_DEBUG_NONE);
stevestrong Sun Jan 15, 2017 2:45 pm
Hm, strange, I have found in
line 48 of board.cpp where the debug port should be disabled, but it will be not disabled, although the compiler will be called with the appropriate directive:
Compiling sketch...
"C:\Users\me\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8002000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10612 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DMCU_STM32F103CB -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103CB -mthumb -march=armv7-m -D__STM32F1__ "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple" "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/include" "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include" "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/usb/stm32f1" "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/usb/usb_lib" "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple" "-IC:\Users\me\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c" "C:\Users\me\AppData\Local\Temp\arduino_build_226650\sketch\Blink.ino.cpp" -o "C:\Users\me\AppData\Local\Temp\arduino_build_226650\sketch\Blink.ino.cpp.o"
stevestrong Sun Jan 15, 2017 3:04 pm
It’s getting weird…
Compiling this code being part of board.cpp:
void boardInit(void) {
#warning "Initializing board..."
#ifndef CONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
#warning "Disabling debug port..."
disableDebugPorts();
#endif
}
martinayotte Sun Jan 15, 2017 5:00 pm
It is ” #ifndef “, not ” #ifdef “.
stevestrong Sun Jan 15, 2017 5:13 pm
Yepp, that was it.
And also that in boards.txt I should’t have had that define (don’t know where is this coming from).
I removed that define and everything is ok now.
martinayotte Sun Jan 15, 2017 6:38 pm
That is pretty normal to have this flag in the stlink upload method, since otherwise, you can only upload one time and then the SWD becomes disabled.
stevestrong Sun Jan 15, 2017 7:50 pm
Yes for Stlink, but i had it for stm32duino bootloader upload method, which i think is not wanted.
martinayotte Sun Jan 15, 2017 8:44 pm
You’re right ! Roger did that change on December 26th, I don’t know why other than allowing SWD debugging whatever upload method is used.
https://github.com/rogerclarkmelbourne/ … a4b3925ffb
stevestrong Sun Jan 15, 2017 9:56 pm
Well, i think we need to find another solution for the original idea to enable debugging, because i lost 2 days to find this issue, and maybe there will be more users who will complain about this.
RogerClark Sun Jan 15, 2017 10:52 pm
I’m confused now
People wanted the SWD pins enabled all the time, so I changed it.
Is this not what was wanted by the majority of users?
danieleff Mon Jan 16, 2017 5:26 am
Idea: enable SWD always, and disable it from pinMode if somebody wants one of its pins.
stevestrong Mon Jan 16, 2017 5:57 am
I’m just wondering how many of us are debugging when uploading with DFU, having no debugger connected.
I admit, this may be not the right place to post my issue, because this happens without using Stlink. And obviously i missed that majority vote.
This issue i see citical since the affected pin cannot be corrected with pinMode alone, one really have to use the afio cfg function, too.
But i don’t want to push my opinion, i obey the majority, i just hope that others will find this post and will know that they should use an Arduino non-compatible function “afio_cfg_debug_ports(AFIO_DEBUG_NONE);” in order to get their pin toggle in any simple sketch.
Me, I will just remove the respective define from “boards.txt” for my local and github version.
martinayotte Mon Jan 16, 2017 2:52 pm
I think that daniel’s idea is a good one :
maybe the disableDebug() should within the pinMode when those specific pins are specified.
stevestrong Mon Jan 16, 2017 3:29 pm
I don’t know whether my opinion counts, but I would suggest an IDE menu entry, this way is left to the user to enable/disable debugging according to his needs. Yes, you could say that we already have a lot of menu entries. Indeed. But still, this would be essential in my opinion. And this could be done across multiple platforms/boards.
The more because the parallel TFT libraries do set pin modes without calling pinMode() for each pin, but rather use direct register writes for multiple pin mode setting in one shot (btw, this was the way I meet this issue).
This should be linked (but can be done also independently) with information (on wiki?) pointing out the involved GPIO pins.
We anyway need some nice wiki pages regarding debugging.
Rick Kimball Mon Jan 16, 2017 4:08 pm
stevestrong wrote:…But i don’t want to push my opinion, i obey the majority, i just hope that others will find this post and will know that they should use an Arduino non-compatible function “afio_cfg_debug_ports(AFIO_DEBUG_NONE);” in order to get their pin toggle in any simple sketch.
stevestrong Mon Jan 16, 2017 5:42 pm
Rick, I did not overlooked that post, I just wanted to repeat the solution for people who browse this thread, looking for the solution.
Rick Kimball wrote:There is no majority way to use these boards. There are many different people using many different boards all in different ways.
Sign in to reply