STM8L050J3: SWIM and USART TX on same pin?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-02 10:27 PM - last edited on ‎2025-04-03 1:32 AM by Andrew Neil
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-03 12:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-03 1:30 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-03 2:23 AM - edited ‎2025-04-08 10:17 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-08 12:54 AM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-08 10:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-09 3:25 AM
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.
