I am using STM32F205RBT6, Keil 4.73 & Ulink2 & SWD communication
I was trying some test codes for low power mode. One of app note says to configure all inputs pins as analog mode, by first enabling the clock & then after configuring in analog mode disable the clock to all pins. I have written my code at last.
Now problem is since all pins gets configured including debug pins: SWCLK & SWDIO as analog. So first time I was able to debug the chip by loading code into it. But after that since pins gets configured so I am not able to debug/load code anymore. Error message comes "SWD communication failure."
1. I have switched off power supply & then again switched on to check , but cannot do that. 2. I had forcefully put reset line low & then connect the debugger. Error message comes: "Could stop Cortex M3 device, so check JTAG cable"
How to remove that problem. Application note : AN3430 by ST , Page 19
void main() { /* enable all peripherals clock */ GPIOC_CLK_ENABLE(); GPIOH_CLK_ENABLE(); GPIOA_CLK_ENABLE(); GPIOB_CLK_ENABLE(); GPIOD_CLK_ENABLE(); /* delay after enabling peripheral */ DELAY_AFTER_RCC_ENABLE(); /* Configure GPIO pins : PC13 PC14 PC15 PC0 PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10 PC11 PC12 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15|GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure GPIO pins : PH0 PH1 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure); /* Configure GPIO pins : PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 PA8 PA9 PA10 PA11 PA12 PA13 PA14 PA15 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15|GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure GPIO pins : PB0 PB1 PB2 PB10 PB11 PB12 PB13 PB14 PB15 PB3 PB4 PB5 PB6 PB7 PB8 PB9 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15|GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure GPIO pins : PD2 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); ///* disable all peripherals clock */ GPIOC_CLK_DISABLE(); GPIOH_CLK_DISABLE(); GPIOA_CLK_DISABLE(); GPIOB_CLK_DISABLE(); GPIOD_CLK_DISABLE(); }
Then DON'T do that when you have a debugger attached, and DON'T expect the debug interface to work if you kill the regulator for the CPU and GPIO either.
Review what you can do with DBGMCU, and think clearly about what you can and cannot expect to debug through these events. Configure the system DIFFERENTLY when on the debugger. Consider other methods for providing diagnostic information, either outputting via a serial device, or logging to a storage device.
I normally use an UART, CAN, SPI or similar and create a monitor interface.
So I might send a command 'sleep' or maybe if there are many supported power modes "pm0", "pm1", "pm2", ...
Then I can experiment with code, see the current consumption and verify that the subject can wake up again. The code that implements this "pm0" will of course have to check if the debug output buffer is empty before stopping all clocks - no use to have a monitor port if any important printout lines gets locked up in the buffer with the UART/SPI/... disabled.
Doing too interesting experiments from main() means that broken code can lock up the processor before I get access to the device which can be a bit irritating. Turning off the clocking of the JTAG interface is a good way to fail the debug session :)
Having a monitor port available can be worth a lot since it allows the factory to run factory tests or report error messages. And it's possible to visit a live installation and pick up statistics or see if any strange events has happened.