cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L050J3: SWIM and USART TX on same pin?

Cpg2
Associate II

Hi. I am designing Schematic for STM8L050J3 chip. In that, pin1( first pin) , in datasheet they mentioned as SWIM in port A0 of pin1 and USART TX in port A2 of pin1. I want to use this pin as SWIM for programming as well as USART for data transmission. How can i use that? Is there a way?  

6 REPLIES 6
Peter BENSCH
ST Employee

Welcome @Cpg2, to the community!

You can use pin 1 for SWIM as well as for a UART. This question is also answered in the data sheet of the STM8L050J3, section 3.16:

Recommendations for SWIM pin (pin#1) sharing
If the SWIM pin should be used with the I/O pin functionality, it is recommended to add a ~5 seconds delay in the firmware before changing the functionality on the pin with SWIM functions. This action allows the user to set the device into SWIM mode after the device power on and to be able to reprogram the device. If the pin with SWIM functionality is set to I/O mode immediately after the device reset, the device is unable to connect through the SWIM interface and it is locked forever (if the NRST pin is not available on the package). This initial delay can be removed in the final (locked) code.

Does it answer your question?

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thank you sir. I also have another question. Can that pin be used for SWIM and USART at a time in a parallel manner? I will also program and the data also will be transmitted using USART . Will that affect the pin?. or one pin used at a time?

The pin can only execute one function at a time, i.e. either SWIM or USART. Both at the same time, e.g. for debugging, is not possible.

However, you can switch the function at any time, i.e. from SWIM to USART or vice versa, but this is not practical for debugging.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Cpg2
Associate II

I appreciate your answer. Could you please suggest how I can use same pin for SWIM and then I will use it for UART_Tx to see data. I will not be using both pin at a time but separately. As you mentioned I will use delay of 5s also. just need small example code that I can use in the requested configuration.

 

Thanks in advance!!

I answered too quickly and have to correct my previous statement (already done above): as soon as you set pin 1 to PA2, you block the SWIM function. For this reason, the time delay of 5s is recommended during the development phase of the programme, so that you have time to connect the debugger via SWIM. Once the programme has been completed, the time can then be set to zero, which means that the device can no longer be addressed via SWIM.

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Cpg2
Associate II

Noted.  considering STM8L050J3 is just an 8-pin IC and we have to use a few pins for multiple functions, could you please suggest which pin to use for i2C, UART, interrupt to wake up from sleep, and digital input pin? We are a young team and learning things.