|
| 1 | +# Generic STM8S105 breakout board |
| 2 | + |
| 3 | +These simple breakout boards are are available on aliexpress and the other |
| 4 | +usual china web sites as "stm8s105k4t6 development board" for $1.60 |
| 5 | +including shipping. |
| 6 | + |
| 7 | +STM8S105K4T6 microcontroller, 16 KB Flash, 2 KB RAM, 1 KB EEPROM |
| 8 | + |
| 9 | + - LED on PE5, active low. |
| 10 | + - external crystal 8MHz on PA1/PA2 or internal oszillator with 16 MHz |
| 11 | + - build-in serial bootloader |
| 12 | + - all I/O-pins accessible on header pins |
| 13 | + - mounting position for 4 pin SWIM connector (for ST-Link flash tool) |
| 14 | + - micro-USB connector for power supply only (data lines not connected) |
| 15 | + - 3.3V I/O voltage, regulator on board |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +These boards are the bigger brother of the [STM8S103 breakout |
| 21 | +boards](stm8blue.md) with more I/O lines, more flash and more EEPROM. They |
| 22 | +are build around a CPU STM8S105K4T6 with 16MHz internal oscillator, 16kB |
| 23 | +flash, 2kB RAM, and 1kB EEPROM. The CPU includes a UART, SPI, I2C, PWM, 10 |
| 24 | +bit ADC, 3 timer, and up to 25 I/O pins - almost like an Arduino Nano, but |
| 25 | +only half the flash space. |
| 26 | + |
| 27 | +One (red) LED is connected to GPIO PE5. The push button is for reset. The |
| 28 | +CPU runs on 3.3V, a linear regulator is integrated on the board. The micro |
| 29 | +USB connector is only for (5V) power supply, the data lines are not |
| 30 | +connected. |
| 31 | + |
| 32 | +All CPU pins are easily accessible on (optional) pin headers (pitch 2.54mm, |
| 33 | +perfect for breadboards). |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +## I2C not easy accessible |
| 40 | + |
| 41 | +Unfortunatly, I2C is only available as an alternate pin function on this |
| 42 | +CPU. So far, there is no support in Sduino for handling the alternate |
| 43 | +function remapping bits in the option byte. |
| 44 | + |
| 45 | +It is possible to modify these configuration registers via SWIM using a |
| 46 | +flash tool and stm8flash, but you are on your own there. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +## Connection to the flash tool |
| 51 | + |
| 52 | +I am using the ST-Link V2 compatible flash tool in the green plastic |
| 53 | +housing. The one in the metal housing uses a different pinout. |
| 54 | + |
| 55 | +Connection to the flashtool: |
| 56 | + |
| 57 | +Signal name |P3 on CPU board |Green flash tool|Metal flash tool |
| 58 | +------ |:-----: |:-----: |:-----: |
| 59 | +3V3 |1 |2 | 7 |
| 60 | +SWIM |2 |5 | 5 |
| 61 | +GND |3 |7 | 3 |
| 62 | +NRST |4 |9 | 1 |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +## Pin number mappings |
| 67 | + |
| 68 | +The Arduino environment uses its own pin numbering scheme independent from |
| 69 | +the physical CPU pin numbers. Many Arduino sketches and libraries contain |
| 70 | +hard-coded assumptions about the number of pins with special functions. |
| 71 | +Ideally, all these numbers would be the same and all programs could be |
| 72 | +compiled without changes. |
| 73 | + |
| 74 | +Unfortunatly, it turns out that a perfect mapping is not possible. |
| 75 | + |
| 76 | +In the end I chose a simple geometric numbering for the module. The |
| 77 | +numbering is similar to a classic DIP package with the USB connector as the |
| 78 | +pin 1 marking. It starts with port pin PC3 and counting up from 0. This |
| 79 | +results in this mapping: |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +sduino pin | STM8S105 CPU port pin |
| 86 | +---------- | --------------------- |
| 87 | + 0-4 | PC3-PC7 |
| 88 | + 5-12 | PD0-PD7 |
| 89 | +13,14 | PA1-PA2, connected to the 8 MHz crystal, weak output drivers |
| 90 | +16-21 | PB5-PB0 (reverse order, weak output drivers) |
| 91 | + 22 | PE5, weak output driver |
| 92 | + 23,24 | PC1-PC2, weak output drivers |
| 93 | + |
| 94 | +- serial: 10,11 |
| 95 | +- SPI: 2,3,4,22 |
| 96 | +- I2C: 16,17 (has to be activated as an alternative function first) |
| 97 | +- Analog: 16-21 |
| 98 | +- PWM: 0,1,5,7-9,23,24 |
| 99 | +- LED: 22 |
| 100 | + |
| 101 | +pros of this approach: |
| 102 | + |
| 103 | +- Easy and logical for use on a breadboard |
| 104 | +- Very clear and logical port pin ordering |
| 105 | + |
| 106 | +cons of this approach: |
| 107 | + |
| 108 | +- All functions use totally different pin numbers than Arduino |
| 109 | + |
| 110 | +I am still not really happy with this mapping. Instead of simplifing things |
| 111 | +it only adds another layer of abstraction and confusion. To avoid this I |
| 112 | +added definitions for the regular CPU pin names like `PA1` and `PD2`. In the |
| 113 | +end, this notation seems to be a lot easier to me. I am open for suggestions |
| 114 | +for a better pin number mapping. |
| 115 | + |
| 116 | + |
| 117 | +The chosen pin mapping for the STM8S105K (possible alternate function in |
| 118 | +paratheses): |
| 119 | + |
| 120 | +|Phys. STM8 pin|Name |Functions |Geometrical mapping|special funcion |
| 121 | +|---: |--- |--- | --- |--- |
| 122 | +|2 |PA1 |(OscIn, no HS) |13 | |
| 123 | +|3 |PA2 |(OscOut, no HS) |14 | |
| 124 | +|8 |PF4 |Ain12 (not supported, no HS)|15 | |
| 125 | +|11 |PB5 |Ain5, [SDA], no HS |16 |Analog A0 |
| 126 | +|12 |PB4 |Ain4, [SCL], no HS |17 |Analog A1 |
| 127 | +|13 |PB3 |Ain3, no HS |18 |Analog A2 |
| 128 | +|14 |PB2 |Ain2, no HS |19 |Analog A3 |
| 129 | +|15 |PB1 |Ain1, no HS |20 |Analog A4 |
| 130 | +|16 |PB0 |Ain0, no HS |21 |Analog A5 |
| 131 | +|17 |PE5 |SPI_NSS, no HS |22 |LED |
| 132 | +|18 |PC1 |T1-1 |23 |PWM |
| 133 | +|19 |PC2 |T1-2 |24 |PWM |
| 134 | +|20 |PC3 |T1-3 |0 |PWM |
| 135 | +|21 |PC4 |T1-4 |1 |PWM |
| 136 | +|22 |PC5 |SCK |2 | |
| 137 | +|23 |PC6 |MOSI |3 | |
| 138 | +|24 |PC7 |MISO |4 | |
| 139 | +|25 |PD0 |T3-2 |5 |PWM |
| 140 | +|26 |PD1 |SWIM |6 | |
| 141 | +|27 |PD2 |T3-1 |7 |PWM |
| 142 | +|28 |PD3 |T2-2 |8 |PWM |
| 143 | +|29 |PD4 |T2-1/Beep |9 |PWM |
| 144 | +|30 |PD5 |TX |10 | |
| 145 | +|31 |PD6 |RX |11 | |
| 146 | +|32 |PD7 |TLI |12 | |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +## Special pins |
| 151 | + |
| 152 | +Most pins on the right side are weaker than the other pins. Try avoiding |
| 153 | +these pins for LEDs and other higher current applications: D13-D22 (PA1/PA2, |
| 154 | +PF4, PB5-PB0, PE5) |
0 commit comments