blog.soch.cc

How to brick (and prevent bricking) an STM8

3rd November, 2026

There’s an option bit on the STM8S001J3 that, when enabled without precaution, bricks the chip.

The Device

The STM8S001J3 is one of the cheapest 8-bit microcontroller currently on the market. I bought a reel of 10 for 0.60€ a piece. It’s a serious ATTINY85 alternative, but you’ll need a SOP-8 adapter.

The STM8S has a few disadvantages. It has 5 usable pins instead of the usual 6 for 8-pinned chips. It doesn’t have GCC support. It has no external reset pin. It uses the SWIM protocol.

It’s also easy to brick an STM8S if you’re careless.

stm8s001j3 pinout diagram

The Brick - Enabling the TIM2_CH1 on STM8S

For one reason or another, you may need a timer. Let’s say you picked TIM2_CH1. TIM2_CH1 is the alternate function of pin PC5. To enable TIM2_CH1, the AFR0 bit must be set.

Here’s the problem. Setting the option bit AFR0 also remaps pin PC6 to its alternate function. The pin PC6 is physically the same as SWIM, the pin used to program the chip. With the SWIM pin now overriden, the chip is no longer programmable. Since the STM8S does not have an external reset pin, this change is permanent.

In this state, flashing the STM8S returns SWIM error 0x04. This means the chip is bricked.

The Method

The official recommendation to prevent this from happening is surprisingly straightforward. The application note suggests adding a 5 second delay at the beginning of the firmware before assigning other functions to the SWIM pin.1

Footnotes

  1. Application note AN5047

Comments

Click to leave a comment on Mastodon. It'll show up here!