Search This Blog

Tuesday, August 7, 2018

Portable STM32F103

Most of the projects I have in mind involve a microcontroller, LCD, some buttons, a power source, some I/O and optional mass storage or USB. These $2 MP3 player comes with most of these features, I'll need to replace the PCB with my own design.

While shopping for parts for my next project, I came across these $2 MP3 players from China. They are about 2AA batteries in size. It has all the I/O I'll ever need in a project.  It even comes in an inconspicuous injection molded case making easy to hide your gadget/key/bitcoin keeper in plain sight.

There is already a project: China cheap MP3 player hack which uses my favorite STM32F030. It is missing some of the features that I am looking for.  I initially started off with the board outline and I/O placements from that project, but quickly realized that they are not aligned correctly with my high resolution scan of the MP3 player PCB.  This is why I have decided to start my project from scratch and try to document my design process so that others may improve upon.

I am using a far more capable STM32F103 with native USB interface, dual ADC, dual SPI and a lot more memory.  It is used in Blue Pill breakout board and can be found for around $2 from China with some minor differences.  It is a popular platform and there are a lot of open source projects for the F103. In case you are wondering, the F103 sadly does not have enough processing power to decode MP3.

Features

  • STM32F103 64kB FLASH, 20kB RAM, up to 72MHz.
  • Mini-USB: USB 1.1 Full Speed (12Mbps) device, charging, SWD debug using special cable.
  • 128x64 LCD
  • Micro SD slot for SD/SDHC.
  • 3.5mm Stereo - multiple I/O functions are available 
  • e.g. 3.3V TTL serial, ADC, PWM, I2C and serial bootstrap.
  • 5 push buttons, On/Off switch
  • ~100mA Hr LiPO battery,  LTC4054 charger.

Design

Power design
The device is powered from internal Li-ion battery.  LTC4054 is used for charging the battery from USB. LDO is used to power the main circuits.


The RTC and backup RAM location are backup from the battery. A pair of silicon diodes is used to drop the battery voltage down as a single diode drops might not be enough at uA range.

From Elm-Chan web site (English): How to Use MMC/SDC


MicroSD can draw a lot of current and introduce a droop during hot-insertion.  This can reset the microcontroller or affect results of ADC.  Previously I have used a switch mode supply with a fast transient response and have seen much less droop.

The XC6206P332MR and other ultra low quiescent current LDO make compromises for low bandwidth/transient response. It has a slow recovery time for a sudden load.  While you can pile lot of passives to undo the manufacturer's design decision on $0.04 parts, it is cheaper and takes much less space to simply use 2 separate supplies for the microcontroller and the MicroSD.

I wired 2 GPIO in parallel (saving one MOSFET) to control the power to the LCD backlight (probably around 20mA).

I/O
A few of the I/O peripherals are wired together in parallel to provide different functions.  


Here are the mappings to the peripherals:


The I/O can be programmed in the following modes.


When they are programmed as Analog, the input buffers are turned off and output disconnected.  This allows the other 2 digital GPIOs to be disconnected while ADC is being used.


I/O Protection


With the 330R series resistors, the input can handle 5V CMOS level signal just fine without additional protections.  Injection current: (5V - (3.3V + 0.3V))/330R = 4.2mA

The short circuit current is limited by the resistors: 3.3V/330R = 10mA (or less - driver internal resistance)


Diode clamps are used for additional input protection.  Two series resistors are used as current limit and the signals are clamped a diode drop above the zener voltage.  The zener is pre-biased by R4 to reduce the load on the inputs below the threshold.  C2 reduce the AC impedance.

The protection circuit can be altered for clamping to 3.3V rail by depopulating (or replacing with 3.9V) D3 and relacing R4 with 0R.  There are some trade-offs in each of these option

Clamping to Zener diode:

  • Tolerance and zener voltages are harder to control.  The ideal voltage is a 3.6V zener diode pre-biased to 3.0V nominal.  3.0V + 0.3V from Schottky starts clipping around 3.2V or so and clamp at 3.9V (depending on overload voltages.)  Dropping Zener voltage helps with protection, but will clip sooner and require higher bias current.  The clamping might affect ADC accuracy above 3V.
  • I have tried an active clamp with a transistor circuit  previously in a project when I didn't have the right Zeners.  I don't have the space for it here.
  • Zener pre-biasing  raises power consumption.  One sample I tested with R4 = 330R  for Zener voltage at 2.93V and consumes about 1mA. 
  • Power is dissipated at Zener and only a small amount flows back to circuits.  It works even when circuits are off.

Clamping to power rail:

  • No tolerances, clamping or power consumption issues.  Works fine with ADC.
  • It requires the excessive current to be dissipated by circuits and may be affected by power management.
  • The LDO has a parasitic diode that could allow current to flow back to unprotected LiPO if overvoltage is sufficiently high.  A 3.9V Zener could be used to dissipate some of the current.
Bootstrap mode
The Play/Pause button is wired differently as it is also connected to the Boot0 pin.


When the button is held down during power on, the F103 jumps to the System Memory which is preprogrammed at the factory for a serial bootloader.  The serial port is wired to the stereo jack.


It is a poor man's way of loading precompiled code.  Clone STLinks are ~$2 US from China which is not much more than a serial dongle and offers much more.


Project logs

PCB v6 - made some mistakes, wait for rel 1.1
PCB rel 1 - hardware testing in progress
LCD - reverse engineered init commands.
Misc items - 32kHz oscillator startup issue/fix, battery capacity estimate.
ADC - Calibrating ADC, scaling and formatting using integer math. 
Power source detection - Detecting power source, USB connection for optimizing battery life.

Libraries that can be ported
Hardware random number generator for key generation (Poorman's Quite Random Number Generator (PQRNG) by Hardware)
Nemuisan - STM32 GPS tracker which contains STM32F103 low level driver and FatFS (Elm ChaN's FatFs Module) for reading/writing to Micro SD card
LCD driver, keypad driver, USB driver (libopencm3 or STM32CubeF1 library)
CHIP-8 emulator: Chip8 STM32F103

Reference bookmarks
HaD project: China cheap MP3 player hack  - PCB problems, components are off, wrong footprint. Not worth using.
Github: libopencm3 - open source library/driver
Website: https://github.com/avislab/STM32F103 code examples

Open source password/bitcoin keeper
Github: mooltipass

Oscilloscope based on the STM32F103 

Random number generator

I was going to use Avalanche noise generator using the charge pump on the LCD as a high voltage source, but ran out of board space.

Misc

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.