cancel
Showing results for 
Search instead for 
Did you mean: 

How to recover SWIM pin from being used as GPIO?

gerald23
Associate II

I'm using the TSM8S001J3 for a small application that requires Pin-8 (PD1/ SWIM, PD5/ AIN5/ UART1_TX) to be used for the RS232-TX.

Currently in the code I have a way to halt the GPIO assignment prior to reassigning the SWIM pin if needed by holding the RS232-RX low during the boot process.

What I would like to find is a way I could turn off the UART1_TX function on Pin-8 and return it to the SWIM fucntion from within the program. My thought was to send a RS232 command that would reassign the pin.

Unfortunately I can't find any documentation on how to re-assign the SWIM pin to being active after it has been used for other functions.

Help please?

2 REPLIES 2
Philipp Krause
Senior II

It should be possible, as the datasheet states: "[…] there is the option that the firmware reenables the SWIM pin functionality under specific conditions such as during firmware startup or during application run. Once that this procedure is done, the SWIM interface can be used for device debug/programming."

Have you tried disabling UART1 using using the UARTD bit in UART_CR1 or just disabling the transmitter using the TEN bit in UART_CR2?

gerald23
Associate II

Hi Philipp,

I finally got it to work, and it is as the datasheet states. In the end I was making a simple mistake by trying to return the function (PD1/PD5) as a input.

The final solution was to use the " GPIO_DeInit()" function in the STM8 library .

void CrashSWIM(void)

{

   //Stop interrupts

   disableInterrupts();

   //Disable and clear UART1 configuration

   UART1_DeInit();

   // Disable/DeInit PORT D, returns PD1 as SWIM pin

   GPIO_DeInit(SWIM_GPIO_PORT);

   // Status LED full ON

   Status_LED_ON();

   //Stay here

   while (1);

}