Page 1 of 1

TMK Chibios STM32 with PS/2 mouse/trackpoint

Posted: 18 Jan 2016, 23:24
by keru
Hi, following the thread regarding the Chibios build of the TMK firmware (http://deskthority.net/workshop-f7/tmk- ... 99-60.html) I have issues with connecting a trackpoint.

Here is where I am now, if someone has suggestions or can help that would be greatly appreciated :
- STM32s use 3v but some pins are 5v tolerant, by pulling those pins up to 5v I should be able to get the right voltage to the trackpoint, when I start the MCU the data pin reads 5v and the clock pin 0v
- The threading part works because I tested it with an analog joystick read using ADCs in the same thread and it worked
- I use a pin for the RST connection to the trackpoint as I don't have the right condenser to setup the 2.2uF capacitor suggested in https://geekhack.org/index.php?topic=55 ... msg1291412 . I adapted the code to use a pin for that, it is also pulled up to 5v, but right now it reads 3.3v and I can't find a reason why.

Code: Select all

5v            TP DAT             PB3
 |                |               |
 +-/\/\/\---------+---------------+
 |
 |            TP CLK             PB4
 |                |               |
 +-/\/\/\---------+---------------+
 |
 |            TP RST             PB6
 |                |               |
 +-/\/\/\---------+---------------+
Could it be that one of the pin is pulling another low ? or should that setup be OK ?

The code used is here
here are the parts : https://github.com/abondis/tmk_keyboard ... _chibios.c and https://github.com/abondis/tmk_keyboard ... busywait.c

Posted: 18 Jan 2016, 23:52
by flabbergast
Reading the GH trackpoint post you linked above, and also this one, from this post on, I understood the following:
1) You should not be tying the RST line up. High on this means that the trackpoint is kept in the reset state (I think), it should be actually tied low during the normal functioning.
2) During power-up, it is good to reset the trackpoint module. In the referenced posts, it is achieved in one of two ways:
a) routing the RST line directly to a MCU pin, without any pull-up/downs, and this line is then manually brought up for a short time during startup (aka "Suka's firmware way"). This won't work on ARMs without a buffer or mosfet, because the MCU can't bring a line above 3.3V without external hardware.
b) making a "RC circuit" (ie 100k resistor between RST and GND, 2.2uF cap between RST and 5V), like in the post you linked. This has exactly the effect we want: right when the power is switched on, the trackpoint sees 5V on the RST line, which is then brought "slowly" down to 0 as the cap charges. The "slowly" depends on the "R" and the "C" (google). For testing you can use other values for the res and the cap, whatever you have at hand. This has the advantage that you don't have to do anything in the firmware - the trackpoint simply resets whenever the whole thing is powered up.

EDIT: Hm. a) is slightly wrong: you can achieve something this by pulling the line up to 5V like you do now, and asserting the pin low on the MCU side (during the startup), and keeping it there. When you need to reset the trackpoint, just make that pin an input (and the pull-up will then pull the RST line to 5V) for a while, and then pull it back down on the MCU side. This of course has the disadvantage that you'll be sinking current across that pull-up *all the time*. But maybe you can go with a weak pull-up (like 100k or something), then the current will be very small.

Posted: 19 Jan 2016, 04:09
by keru
Thanks for all the help. Is "sinking current all the time" a bad thing ? or it's ok until I finish debugging ?

I tried 2.a. but I misread my values, it's the CLOCK pin (PB4 in my config) that reads 3.3V, data is on at 5V and reset is at 0v. I just measure with a voltmeter so I don't see variations, but at least I know the voltages are right except for PB4 ...

I looked but I can't see anything putting it in pull-something mode, and I can't see anything different compared to PB3 which works.

With this setup, do I still keep my pins working the same way ?
- to send HIGH from the MCU to the PS/2 line, I set my pin as floating output opendrain and set it HIGH
- to send LOW from the MCU to the PS/2 line, I set my pin as floating output opendrain and set it LOW
- when I need to read the PS/2 line, I set my pin as floating input and reading HIGH means HIGH, and LOW means LOW

Thanks.

Posted: 19 Jan 2016, 10:12
by flabbergast
"Sinking current all the time" is not electrically bad (I think), it just add to the power consumption. (And also if the current is high enough so that the resistor will heat up, it shortens the lifespan of that resistor. But that shouldn't be a problem here.)

About setting the pins: correct.

Don't know why the clock pin reads 3.3V. However if the firmware is driving the clock (i.e. it's switching LOW and HIGH periodically) and you measure with a voltmeter (which is rather slow), the voltmeter will see more-less the "average" voltage. (The precise "average" will depend on how much time the pin's HIGH and how much it's LOW.)

EDIT: I've ordered a USB to PS/2 converter from ebay, so when it comes I'll try connecting with a mouse with your firmware.

Posted: 20 Jan 2016, 04:11
by keru
Just in case, I tested the trackpoint with an Arduino Pro Micro and https://github.com/rampadc/arduino-trackpoint-extended and it works correctly. Next I'm going to try with STM32duino and my STM32F103 with the same code and see if I can get something.

I also ordered bi-directional logic converter, now I'm waiting for things to arrive :)

EDIT: meanwhile I think I'll just put the arduino and mouse in an altoid box and have two USBs :) I could just use the arduino but that's no fun :) and I think I don't have enough inputs on it anyway.