STC 8051: Some research notes

I picked up a bunch of those uCs + a dev board quite some time ago. I even did some initial digging, but due to the lack of free time postponed any work on them. These uCs may not seem that tasty as stm32, but are still quite powerful and dirt cheap. (If you want to flood the market with something).



The good about them is:

  • Dirt cheap
  • Programmed via plain serial
  • A nice selection of on-board stuff

The bad things are:

  • sdcc instead of gcc as a compiler (not actually a bad thing, just missing some gcc .section magic)
  • Weird 8051 architecture (Looks like a 30 year old mammoth still in action)
  • win-only isp software written in (sic!) Visual Basic 6.

So, anyway, I wanted to start developing for them using the tools I use, and that doesn’t include that crappy Keil thingie for brain-damaged people.
First things first, we have an official header, that can only be used in Keil. To use it in sdcc we have to either rewrite it from scratch, or process it via a perl script. Say thanks to the sdcc guys, they have a cool but outdated perl voodoo in support/scripts/keil2sdcc.pl in the sdcc distribution.The only thing I had to do, is update it to reflect the reality and send the patch up the mail list.

If you feel lazy on converting it yourself, you can grab my ready to use header at my github.

Next I added support for sdcc/8051 targets to my homebrew buildsystem called ‘Antares’ (That’s my own ‘arduino for kernel hackers’)

Things to pay attention to:

  • Stock developer board misses resistors on the UART RX/TX lines, therefore gets powered by these lines, effectively preventing you from getting into bootloader mode. Adding a few 1k5 resistors saves the day.
  • Stock isp software fails to properly read .ihx sdcc output as well as packihx .hex output. For that to work you’ll need to give it a .bin obtained by running a hex2bin on the ihx file.
  • ISP software DOES NOT work in wine. It starts, it sends data to the serial port(e.g. I see it coming with a sniffer), but it never detects the uC. My guess is: either the wrong port settings due to a bug in wine serial port implementation, or some timings get screwed due to being run in wine.

Things WIP:

  • Linux isp downloader.

I have figured out a few things about the protocol, and have to put a few things together, but in no way it already works.

Meanwhile, you can grab a sample 8051 project for antares if building the firmware under linux and flashing via windows suits you.

I’ll put together a better Getting Started once I’m through with reversing the ISP protocol.

Print Friendly

Leave a Reply