TCKB: My journey in the world of STM32 driven keyboards (60%)

User avatar
Ced67

04 Nov 2016, 01:26

Hello everyone,
As an introduction, I'll talk a bit about me and say I'm an embedded software engineer since about ten years. The firm I work for make a huge use of multiple STM32 arm micro controllers and I play with them every day :ugeek:

1) The genesis

For my personal entertainment I wanted to take a look at the new development tools STMicroelectronics provides for their line of mcus. My main concern was about STM32CubeMX which is a device configuration gui and code generator.

While the possibilities provided by that tool were interesting, I was a bit frustrated by the lack of concrete application I had to give it.
Being a late MK guy, (I'm typing right now on my brown Ducky Shine4), I decided in the first part to explore the software side of moderns MK. By modern I mean USB. The usb hid class that is generated by cubeMX is a mouse device and was my first headache... but I managed to adapt it to a 6kro keyboard.
With a 1ms polling and debouncing, my first prototype looked like that:
Image
The black box is a logic analyzer I used to monitor matrix polling and usb frames.

I created my first two layers/ten keys usb keyboard, driven by an STM32L053R8T6 nucleo eval kit (32MHz, 8kB ram, 64kB flash, 2kB user eeprom)! :mrgreen:

2) Code that seriously
You may imagine that playing with ten switches on a breadboard can be quickly boring. It was!
As a consequence for the second iteration of my creature, i came to the conclusion that i needed to structure all that test code I put together to make it easier to upgrade.
To ease my software skills, and focus on the application side, I choose to run my microcontroller through a real time operating system.
Good news, CubeMX can generate a FreeRTOS project skeleton. I rewrote my application from scratch in the form of several tasks and came to the same ten keys USB board... with an embedded OS! :lol:

3) Give it some pimp
My previous step with FreeRTOS being quite promising, I felt the urge to throw some glitter on the monster and make it a princess... And as I had another nucleo kit in the drawer, I fired my best soldering iron and quickly soldered a 5*14 led matrix... (you see what I did there ;) )
One of the caveat of driving a led matrix is that the mcu outputs are not strong enough to provide the necessary current. To solve that matter, I used a bunch of N and P channel MOSFETS hooked to that second kit:
Image
Image
This is only a small part of the actual matrix.

Both controllers are connected through an 8MHz SPI link with an homemade protocol.
Right now, each key press is sent to the computer and the led controller:

4) Serious business
Ok, the thing runs quite well but if I want to make it usable, I'll have to design a bit of hardware.
For a first timer in the custom keyboard land, I found a lot of help from the community and specifically through the GH60 project from which I kept the board outline, switch/stabilizer and fixing holes coordinates as I had no reference hardware to reverse.
To ease the process I choose to make a strict ANSI/ISO compatible board. Sorry to all the exotic layouts lovers :oops:
After a few days of trial and errors with Kicad, the beast was drawn, the all mighty dual processor TCKB (Tiny Custom Key Board).
Image
Image

The hidden part is a silly movie quote I keep for myself until someone get a hand on one of the few pcbs that will be produced.

5) Holy mailman!
Today, November 03rd, after three weeks, I had the pleasure to find in my mailbox five of those marvelous red gems:
Image
Image
Image
Image
Image

Needless to say that I'm eager to solder all the component I collected through the bay the past weeks and check for routing mistakes. Too bad I'll have some busy days to come and will not be able to solder my new toy until at least a week.

6) Download !
Your hawk eye must have noticed the little Open Hardware logo on the pcb.

The kicad files are saved int the following GitHub repo: https://github.com/Ced67/TCKB_Kicad

While the software sources are in that one : https://github.com/Ced67/TCKB_Software


7) More to come...
I'll add some tutorials on how to flash the STM32s using different tools: USB to Serial, Segger J-Link, ST-Link...

Thanks for reading!
Last edited by Ced67 on 26 Oct 2020, 18:28, edited 3 times in total.

User avatar
duynguyenle

10 Nov 2016, 01:02

This is intriguing, I am not really familiar with these MCUs, in the keyboard community it seems Atmel controllers are pretty much the ubiquitous. What are the advantages/disadvantages of using this controller compared to the Atmel Mega and what firmware does this run? Did you write your own firmware for scanning the matrix or use TMK or something else?

User avatar
ohaimark
Kingpin

10 Nov 2016, 01:37

I've seen few new controller chip alternatives. Watching this to see how it develops.

User avatar
Ced67

10 Nov 2016, 10:02

Atmel in the keyboard community is like chicken and egg:
Were firmwares like TMK written because Atmel were preponderant (as were teensies) or were Atmel widely adopted because TMK is a good and easy piece of software? :D

As i said in the presentation, I choose to use an stm32 platform as a guinea pig to evaluate the STMicroelectronics tools I may use professionally.

Software wise, TMK is not compatible as is. Maybe someone tried to migrate it but it needs a lot of work... I didn't even looked for that eventuality.
At the moment, I wrote my own firmwares - this is a dual mcu board - which of course is not (and probably will never be) as featured as TMK.

Hardware perfs may be on the stm32 side with pros and cons depending of the MCU family. The ones I work with are on the low cost/low power end: stm32L053 (Cortex M0+) and stm32L151 (Cortex M3).

To compare from Farnell website :
http://fr.farnell.com/stmicroelectronic ... dp/2503296
http://fr.farnell.com/atmel/atmega32u4- ... dp/2443182
ATMEGA32U4-AURSTM32L053C8T6
ProsPower is 5v tolerent
KB community, firmware and documentation
Crystal less design
Cheaper
Faster 32MHz
32bits
More power and resources
Embedded uart bootloader*
Cons Slower 16MHz
8 bits
Less resources and memory
Power supply is limited, needs a voltage regulator (max 4V)
Poor community in the keyboard world
*Middle range devices can even have embedded dfu bootloader. Of course, flashing a custom dfu bootloader is possible.
The minimum required equipment to flash a pristine stm32 is the cheapest usb to uart converter you can find :
http://www.ebay.fr/itm/1Stuck-USB-to-RS ... Swa39UrkX-
Last edited by Ced67 on 16 Nov 2016, 11:44, edited 1 time in total.

User avatar
duynguyenle

10 Nov 2016, 21:36

Ced67 wrote: Atmel in the keyboard community is like chicken and egg:
Were firmwares like TMK written because Atmel were preponderant (as were teensies) or were Atmel widely adopted because TMK is a good and easy piece of software? :D

As i said in the presentation, I choose to use an stm32 platform as a guinea pig to evaluate the STMicroelectronics tools I may use professionally.

Software wise, TMK is not compatible as is. Maybe someone tried to migrate it but it needs a lot of work... I didn't even looked for that eventuality.
At the moment, I wrote my own firmwares - this is a dual mcu board - which of course is not (and probably will never be) as featured as TMK.

Hardware perfs may be on the stm32 side with pros and cons depending of the MCU family. The ones I work with are on the low cost/low power end: stm32L053 (Cortex M0+) and stm32L151 (Cortex M3).

To compare from Farnell website :
http://fr.farnell.com/stmicroelectronic ... dp/2444630
http://fr.farnell.com/atmel/atmega32u4- ... dp/2443182
ATMEGA32U4-AURSTM32L053C8T6
ProsPower is 5v tolerent
KB community, firmware and documentation
Crystal less design
Cheaper
Faster 32MHz
32bits
More power and resources
Embedded uart bootloader*
Cons Slower 16MHz
8 bits
Less resources and memory
Power supply is limited, needs a voltage regulator (max 4V)
Poor community in the keyboard world
*Middle range devices can even have embedded dfu bootloader. Of course, flashing a custom dfu bootloader is possible.
The minimum required equipment to flash a pristine stm32 is the cheapest usb to uart converter you can find :
http://www.ebay.fr/itm/1Stuck-USB-to-RS ... Swa39UrkX-
Thanks for the insight, this is very cool! You are right that TMK is the de facto standard for a lot of boards because it's powerful and customisable, but it's very interesting to see alternate options available. I would love to have a play around with one of these if you decide to sell your excess PCBs!

User avatar
Ced67

14 Nov 2016, 10:34

duynguyenle wrote: Thanks for the insight, this is very cool! You are right that TMK is the de facto standard for a lot of boards because it's powerful and customisable, but it's very interesting to see alternate options available. I would love to have a play around with one of these if you decide to sell your excess PCBs!
Why not :)
But before that, I'll need some time to debug the whole thing.
I was out in the family last week-end and could not work on it. I'm still in the soldering phase and I'm struggling a bit with the lqfp package which has a finer space between legs than the Atmel tqfp:
avr-arm.jpg
avr-arm.jpg (89.53 KiB) Viewed 55015 times
http://amichalec.net/2015/04/avr-to-arm/ (not from me but interesting in the same way).

User avatar
vvp

14 Nov 2016, 11:38

I used small diameter (Ø 1.3 mm) bevel (hoof) tip for the LQFP STM32 package. It goes fine with enough flux. You can both add and remove a tiny bit of solder with it. Though a soldering wick is quicker if you need to remove a lot of solder.
I had a better feel doing LQFP with an iron than with hot air. But hot air is much better for small SMD resistors and capacitors (or any small parts which do not have as many leads as LQFP).

User avatar
Ced67

14 Nov 2016, 11:47

Thanks for the help :)
I used flux (maybe not enough) and leaded solder. The soldering station I use at work only has a conic tip... I'll check if I can find a bevel one.
For all the other smd component, I use hot air which is easier as you said.

User avatar
Ced67

17 Nov 2016, 23:05

Debug time :geek:
The switch matrix is functional!
Image


All the SMDs are soldered but I made a misake...
Initially, I opted for a dual STM32L151 setup but realized later that as crystal-less it can be, the only subsystem that rely on external clock is the usb controller /facepalm :roll:

My only way to fix that was to replace one of the microcontroller with an STM32L053 which is 100% crystal-less, usb included.

Now the setup is:
  • STM32L053 (Cortex-M0+) : switch matrix and usb
    STM32L151 (Cortex-M3) : leds matrix
I kept the Cortex-M3 for the leds as it is more efficient in case I would achieve complicated matrix effects (not likely but who knows).

PS: Note for later revision: Add a crystal footprint, just in case!

PPS: I used that Chipquik unsolder stuff... It's marvelous :o :

User avatar
Ced67

21 Nov 2016, 09:03

Good morning everyone!
The hardware is fine and I'm live testing it today at work :)
Image


Leds could have been a bit brighter but I choose resistors to avoid frying a led column in case multiplexing stops and get stuck for too long (can happen during step by step firmware debug).
I'll see later if I can decrease the resistor a little bit.

Here you can see it with a cheap acrylic case from ebay and doubleshot ABS Ducky caps (ISO-FR layout is a pain to find online).

User avatar
Ced67

30 Dec 2016, 20:45

Hello everyone!
It's been a while since the last update about my project.

I think I tested it quite thoroughly and I'm now able to provide the sources files (Soft and PCB). I updated the first post as well.

Kicad: https://github.com/Ced67/TCKB_Kicad
C: https://github.com/Ced67/TCKB_Software

For your entertainment, here is a quick family photo (The top one seems blue but it's white in reality...):
Image
Last edited by Ced67 on 26 Oct 2020, 18:29, edited 1 time in total.

Matt_

01 Jan 2017, 19:12

A lot of this is beyond my grasp, but I command you for trying something new. I think Flabbergast has been toying with STM32s for a while too but they're surprisingly rare in keyboards despite their price point and potential.

And that family photo is great!

User avatar
Ced67

01 Jan 2017, 20:59

Matt_ wrote: A lot of this is beyond my grasp, but I command you for trying something new. I think Flabbergast has been toying with STM32s for a while too but they're surprisingly rare in keyboards despite their price point and potential.

And that family photo is great!
Thanks :D
I would be glad to share about my project with other STM32 users!
Too bad they are so rare because, as you said, they have a strong perf/price ratio.

xyverz

06 Jan 2017, 17:45

Thanks for sharing this. You've done *fabulous* work with these boards!

Kiri

08 Jan 2017, 06:52

Hey, I'm new to this and wonder where would someone get their PCB manufactured.

User avatar
Ced67

08 Jan 2017, 16:03

Hi, I did mine on YOUPCB.
Their instant quote tells spot on the cost of your board.

My order was dual layer, 280*94.6mm, 1.6mm pcb, 1oz copper, direct gold finish and dhl direct package and I paid less than 50€ for five boards, shipping included.

User avatar
Daniel

08 Jan 2017, 17:56

Nice work :) I once bookmarked this here: https://sourceforge.net/projects/keyboard-stm32/ as I have a STM32 dev board laying around. Maybe this is interesting for you.

User avatar
Ced67

08 Jan 2017, 18:29

Yes I know this one! It even had a thread here on DT and was one of my first inspirations.

But as I wanted my application to run with an embedded operating system (FreeRTOS), that vvb stm32 code was not suitable.

Thanks for the highlight :)

iobuggy

20 Apr 2017, 21:30

hi Guys and hello to evry one.
this project made me crazy.
I"m verry interested in making this kind of project with a stm32L100R8Tx and make a new cad dessign for the board to support the micro controller,but the problem for me cant get to port the TCKB_Software for the stm32L100R8tx.
If someone can port it will be great and I can start my project.
Pls help guys.
Thank you from bottom of my heart.

User avatar
Ced67

20 Apr 2017, 22:23

Hi,
I'm on my phone right now and dont have access to my desktop.
To answer quickly, the major porting must be done through the stm32cubemx project.
I don't have the datasheet for the stm32l100 but I believe it is pin compatible with the stm32l053 I used.
Be careful though as some stm32 limes rely on an external crystal for usb.
If not, you can reuse my 60% cad.

I may have à look at the l100 when i'll be back home.

iobuggy

21 Apr 2017, 00:15

Thank you for the quick reply.
I tested to port the tckb softwere to a new stm32l100r8tx with the cubemx than with keil to configure files with yours,but no result,out of my hands.
If you can port it it will be great and I can start my project with the new ported tckb software.
thank you BEST REGARDS.

User avatar
Ced67

21 Apr 2017, 09:26

Do you have an already defined layout/schematic?
That would help for the cubemx definitions.

In a first time, I would like you to try to compile it as is with the same coocox version i used (I wrote it in the github description), just to make sûre we start on the same basis.

iobuggy

21 Apr 2017, 12:20

Hi,
Yes I did define the leyout schematics.
I did install your version of coocox but that version does not support the stm32l100 series,But I have seen a new beta version of coocoxv2.0 that supports the stm32l100.

will be testing this ide beta and see if it will change something.
Thank you for your help.
Your keyboard is un inspiration for making a great keyboard like this.
thank you.

User avatar
DarKou

21 Apr 2017, 13:14

Hello,

Really interesting project !

Je vais suivre les évolutions de près parce que je pense que tu vas m'inspirer pour un nouveau custom :D

User avatar
Ced67

22 Apr 2017, 11:48

iobuggy wrote: Hi,
Yes I did define the leyout schematics.
I did install your version of coocox but that version does not support the stm32l100 series,But I have seen a new beta version of coocoxv2.0 that supports the stm32l100.

will be testing this ide beta and see if it will change something.
Thank you for your help.
Your keyboard is un inspiration for making a great keyboard like this.
thank you.
Are you sure?
My coocox 1.7.8 has stm32l100r8 definitions :
Image

I had a look at the datasheet and as I thought, the stm32L1xx line rely on an external crystal (HSE) to clock the usb controller.
I would recommend you to switch to the L0 line which is 100% crystalless and cheaper (even if it's only a Cortex M0, it is powerful enough for a keyboard controller ;) )

User avatar
vvp

22 Apr 2017, 20:26

Can you somehow quantify what
Device shows lower ESD performance than the other products from STM32F0 family.
means in the errata of STM32F072?

They should have written the voltage for human body model and charge device model so that we can get some idea how serious it is.

User avatar
Ced67

22 Apr 2017, 20:32

I can't quantify that but I believe it means it is more noisy than their stm32F cousins at equal operating conditions.
My electromagnetism knowledge is quite null :)

User avatar
vvp

23 Apr 2017, 00:29

ESD means Electro-Static Discharge.
It meas it is more sensitive to get broken when you touch it e.g. after you pulled off your sweater.
Check chapter 6.3.12 of this document.
The errata for the chip says that it is doing worse than specified. I would like to have an idea how much worse.

User avatar
Ced67

23 Apr 2017, 09:31

You are right, I mixed ESD and EMI... but sorry, I can't quantify how much worse is the sensibility to static discharges :(

User avatar
Ced67

29 Apr 2017, 22:51

Hello there!

I updated my github with an stm32L100 port in a dedicated "STM32L100_Variant" branch:
https://github.com/Ced67/TCKB_Software/ ... 00_Variant

The STM32CubeMX I used seems to have a little bug that generate code for stm32l100RB even if R8 is selected... but if the code is still under 64k it should work..

The I/Os are the same as my original tckb instead of the ones used fot the external crystal (configured to 8MHz).
Ports and crystal freq can be reconfigured in stm32cubemx.

Have fun ;)

Post Reply

Return to “Workshop”