Search This Blog

Thursday, April 25, 2024

CH32V003 tidbits

A minimalistic prototyping PCB can be made with a 0.1uF soldered onto pin 7 and 9 of a TSSOP-20 breakout board. The back side of the PCB contains SOIC pads that can be used for the 8 and 16 pins versions of the chip.  The chip can operate between 2.7V to 5V with the reset threshold programmable from 2.7V to 4.4V.

Minimalistic CH32V003 prototyping board

Core


QingKe V2 series microprocessor is a 32-bit general-purpose MCU microprocessor based on the standard 
RISC-V instruction subset RV32E(Base Integer Instruction Set) C(16-bit compression instruction) with only 16 general-purpose registers.

V2 series supports addition to custom XW extensions, Hardware Prologue/Epilogue (HPE), Vector Table Free (VTF), single-wire serial debug interface (SDI), and support for "WFE" instructions.

The following topics are covered in their QingKeV2_Processor_Manual 
Chapter 2 Exception 
Chapter 3 PFIC and Interrupt Control 
Chapter 4 System Timer (SysTick)
Chapter 5 Processor Low-power Settings 
Chapter 7 CSR Register List 

See reference manual for peripheral programming and application code example. The debug protocol and debug registers are documented in the RISC-V QingKeV2 Microprocessor Debug Manual.

GPIO

While CH32V003F4 pins are backward compatible with STM8F3 (TSSOP-20), 2 additional GPIO pins are available - VCAP pin replaced as PD0 and RST pin can be reused as PD7.

There are some GPIO input threshold differences between the STM8 and CH32V003.

I/O characteristics: STM8 has CMOS input threshold while CH32v003 has LVTTL threshold.

Note: Pull down resistors I normally use for push buttons on shared I/O needs to be below 8.9K.
3.3V * 8.9K /(8.9K + 30K) = 0.755V and 5V * 8.9K/(8.9K + 30K) = 1.144V

There are four 5V tolerant pins: PC1, PC2, PC5, PC6 (vs 2 in STM8) and up to 8 ADC pins. The alternate functions are more flexible as some can be mapped to additional GPIO pins. For the 20 pins package, Port C and D are rearranged as two contiguous 8-bit ports which make life easier for interfacing to byte-wise devices.

CH32V003F4P6 (TSSOP-20) GPIO pinout and their alternate functions

Bootloader

The chip doesn't have a Boot pin to select Bootloader externally. Instead there is a Mode bit that can be set to either jump to user code or bootload upon Reset.  SystemReset_StartMode(uint32_t Mode) under   
/EXAM/SRC/Peripheral/src/ch32v00x_flash.c in the application code example.


PlatformIO forum talks about how to modify the bootloader: here

Debricking


WCH-Link Utility menu - Full Chip Erase

Resources:

There is a bit-bang USB implementation available in beta - RV003USB  This implementation looks much cleaner than the STM8 VUSB project that I have been using.  The USB pins are configurable in usb_config.h 

There is a CH32V003 F4P6 V-USB Development Board with the USB pins on PA1 and PA2.

Alternate IDE:

Visual Studio Code using Platform IO plugin and Community-PIO-CH32V platform

Upgrade path

The next cheapest upgrade is the CH32X035 or CH32X033 which aren't pin compatible, but they can operate at 5V.  They are USB Connectivity parts.  This bumps up the RISC-V core, FLASH, SRAM, ADC, UART, USB.

The design document is currently untranslated while the reference manual is available in English.

CH32X033/035 features

RV32I – Base Integer Instruction Set, 32-bit. Currently version 2.1
M – Standard Extension for Integer Multiplication and Division
A – Standard Extension for Atomic Instructions
C – Standard Extension for Compressed Instructions

The most accessible parts are the TSSOP-20 with cheaply available breakout boards.  I have originally ordered the TSSOP and find myself maxing out the GPIO very quickly for a couple of projects I have in mind.  I have ordered some QSOP28 but cannot find a cheap source for breakout boards. QSOP has a pin pitch of 0.635mm (0.025") which is slightly tighter than the 0.65mm pitch for TSSOP20 which I can manage with my home made PCB.

Their 0.4mm pitched QFN parts on the other hand would require commercial quality PCB.


Sunday, April 7, 2024

The most uneventful WRT310N V2 8MB FLASH upgrade

 I bought this router at a thrift shop a long time ago for $5 mostly for its Gigabit Ethernet. It has been gathering dust as I have other ones with better specs.

Linksys WRT310N V2

Recently I need its 4MB FLASH for something else and my orders haven't came it.  I made a backup of the chip with my programmer.  3 months later, one of the orders finally showed up. I burnt a copy of the old 4MB image into a 8MB SPI FLASH: MX25L640EM2I.  It is important to keep the binary image of the chip as it contains some specific factory NVRAM settings e.g. MAC addresses that are not in the .trx file.

It boots up and showed 8MB in the status and managed to save a new setting. i.e. the FLASH chip is recognized.  I took a risk and upgrade to an image intended for 8MB device.  The worst that could happen is that I have to burn in a 4MB image and compile my own 8MB to support it.

It turns out that generic builds files with 32K NVRAM, MIPSR2 and without USB under the K26 directory works fine so far.  I picked the Max configuration with the full features set: 
freshtomato-K26-NVRAM32K_RT-MIPSR2-2023.1-Max.zip


It took about 90 seconds for the upgrade.  The most annoying part is to figure out the user name and password.  It took me quite a few tries as the username was changed to root from my previous firmware. Rest of it is uneventful.

It is good that the generic build recognizes the model as well as the correct FLASH size.

Status Overview showing router name and specs

Firmware version

Wednesday, March 13, 2024

The dreaded KB5034441 - what actually worked for me

Normally I don't talk much about fixing Windows problems as the tech blogs are a dime a dozen.  However, I have yet to find one that fixes the "0x80070643 - ERROR_INSTALL_FAILURE" with KB5034441. They seem all point to the WinRE partition wasn't sized sufficiently and each of them parroting the same stuff.  

I have resize the partition, but it still fails the update.  I have tried the PatchWinREScript_2004plus.ps1 from Microsoft, but it returned with a bunch of errors.  Obviously isn't fool proof enough for the end users.  I even ask Microsoft Copilot AI for a detail step by step instructions and it still isn't enough as there were errors in some of the steps.

I tried a whole bunch of things unsuccessfully and my WinRe was disabled.  I went through the usual long list of instructions trying to restore it manually e.g. extracting install.wim etc, but given up before I would do more damages. It is like a never ending quest like 50+ hours RPG with each quest requiring completing additional subtasks and no one have any up to date info.

What actually worked for me was to simply reinstall Windows. Obviously this is with the increased WinRe partition to 800MB and the install option of preserving the data and apps. This is the one with the least user interaction required, but no one else suggested this.

I let it install all the updates again and finally the dreaded KB installed properly. Whatever prerequisites that was broken along the way is now back to what they expect.  Don't forget to do a disk clean up for the old windows install and change back all your preferences that Windows like to muck with.

When in doubt, reinstall Windows.  :P



Sunday, January 21, 2024

CH341A Pro Serial PROM Programmer mods

The CH341A Pro Serial PROM Programmer is low cost programmer based on the CH341 USB Serial chip with special protocol modes for I2C and SPI.  A good source for the hardware info for the programmer is here

Some of the modifications are well documented on the eevblog. I cleaned up the mods and added a few.

Programmer modified for 3.3V

The programmer is modified for 3.3V I/O voltages as the ZIF socket is wired for 3.3V (see J3).

  • Vcc at pin 28 - connected to 3.3V (Required).  The CH431 chip I/O rail is set to the 3.3V supply from U1.

    Modification to PCB

    Side view of the modification

  • V3 at pin 9 - connected to 3.3V (Recommended by datasheet).  The internal 3.3V regulator for USB should be connected to the external source if Vcc is running from 3.3V.  I have measured the voltage at V3 and it is pretty closed to 3.3V, but modified it anyways as it is easy.
    V3 connected to metal tab of U1 - 3.3V regulator output


  • RN1C - connected to 3.3V (Optional).  The power LED (D1) is too bright because it is connected to 5V instead of 3.3V like D2.  The power LED now has similar brightness as D2.

Top trace: Resistor pack pull up that was connected to 5V
Bottom trace: 3.3V from U1 regulator

I have made a small plug for the programming cable using a protoboard.


I have replaced the spring for the clip-on programming cable as it is too strong and bent the pins on some of my chips.

Original spring (Bottom) is replaced with a weaker spring (top) from my junk box.


Wednesday, January 17, 2024

Counterfeit STM8S003

 I went into ordering some counterfeit STM8S003 recently as the parts dried up and the prices were getting higher.  I didn't think much at the time as the seller had been around for a few years and had good reviews.

Aliexpress dispute initially rejected my claim and I had to dig much deeper for additional proof.  

I also did some extra digging and found out that STM8 is also a trademark, so leaving it in the description is sufficient enough to associate the part from ST Micro.  Aliexpress into real trouble if "STM8" result from their search engine shows a counterfeit part and they refused a refund sheltering guilty parties.

They have finally gave and started the refund process.


The seller photo edit out the company logo as it is a trademark and even left their company name in the picture.
I found another (counterfeit???) part that has the company logo intact.  The part look innocent enough except for markings on the third line..

Same part with similar pin1 dimple and "e4" logo.


Order page vs actual shipped parts

The actually shipped parts are actual a different batch of counterfeit that don't even look like the picture!  The ST logo is replace with a thinner version that looks more like 5T and the "E4" uses a different font as the top part of '4' is now closed.  The pin 1 dimple is now gone meaning that they now use a different part as the the base for the counterfeit.

Here is another look under the microscope.  The real ST part marking are engraved with a Laser while the counterfeit part is printed on.  Laser are cheap enough, that isn't the sure fire way of telling these days.

Left side is the real part that I have
Right Side is the counterfeit parts from the order

Part marking from STM8S003 datasheet

STM8S003 marking: PHL = Philippines, Year = 4, Week = 06 and Revision = Y
The counterfeit part uses a slightly different format.  CHN = China. The date code could be 03, 6 or 0, 36.

I have wired the part onto a protoboard.  My preliminary test probing the parasitic ESD protection diodes indicate that the counterfeit base part has same Power/Ground pin locations and likely it is also a microcontroller of some kind.  However unlike other simpler counterfeit parts, one can't exactly program it without knowing what it actually is.

The VCAP pin has no voltage output.  There are no active I/O pins, so likely there is no bootstrap loader.

There are a few other microcontrollers that shares a similar pinout and package.  e.g. Nuvoton N76E003AT20 (8051), HK32F003M (ARM M0) and possibly more.


I don't have a Nu-Link to try out, so there isn't much I can do.