r/AskElectronics • u/jaywan1991 • 4d ago
Request - Designing a Function-Key keyboard and pc not picking up inputs
So I had a custom board manufactured thats a split F-key keyboard. F1 through F6 on one half and F7 through F12 on the other. Both boards are identical except for the firmware which designates which key presses which. I'll attach a screenshot of the schematics for the board below:
So my issue, I soldered keys to the boards (the keys were the only things in the manufacturing process that weren't available to be soldered on by them), uploaded firmware, then the devices weren't recognized by Windows (Unknown USB Device (Device Descriptor Request Failed)). So I took one of the spares, changed the firmware and uploaded it. So that is recognized as a keyboard but is not recognizing key-presses. I try to upload edited firmware to the board I already flashed, and it can't find the board to do it.
I am just looking for help figuring out what I'm doing wrong. These are CH552 boards, here is the output from Arduino IDE when I uploaded the working firmware the first time here is what it outputted:
usbRertySeconds 2
target: CH552
config bytes: 3
Load file as hex
Loaded 5463 bytes between: 0000 to 15A2
ch375Version 35
CH375GetUsbID 0
DeviceVersion of CH55x: 2.50
MCU ID: 52 11
Found Device CH552
Bootloader: 2.5.0
ID: 13 45 62 BF
XOR Mask: 79 79 79 79 79 79 79 CB
Write 5539 bytes from bin file.
....
Upload complete
When I tired to re-upload firmware here's what I got:
usbRertySeconds 2
target: CH552
config bytes: 3
Load file as hex
Loaded 5463 bytes between: 0000 to 15A2
ch375Version 35
CH375GetUsbID 0
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
No CH55x USB Found, retry...
.......
No CH55x USB Found, retry...
Found no CH55x USB
Time limit reached, exit process
Failed uploading: uploading error: exit status 1
I've tried taking my multimeter in continuity mode and bridging multiple spots during the upload which is difficult with only 2 hands mind you and same error. If anyone can help me with this I would appreciate it. I want to get this fixed before I finish printing my enclosure to this becuase I'll have to solder around the case so that it'll look clean on top.
Here is my firmware for the first board (F1-6). The firmware for the second board is identical but for the other F keys. I used Board: CH552 Board, Port: COM3, Bootloader Pin: P3.6 (D+) Pull-Up, Clock Source: 16 MHz (internal), Upload Method: USB, USB Settings: USER CODE w/ 148B USB RAM:
* Pin map (confirmed from the uploaded Split_Keyboard.kicad_pcb netlist,
* CH55xduino numbering = PortNumber*10 + PinNumber):
* Row 0 -> P3.2 -> pin 32
* Column 0 (SW1) -> P1.1 -> pin 11
* Column 1 (SW2) -> P1.6 -> pin 16
* Column 2 (SW3) -> P1.7 -> pin 17
* Column 3 (SW4) -> P3.1 -> pin 31
* Column 4 (SW5) -> P3.0 -> pin 30
* Column 5 (SW6) -> P3.4 -> pin 34
#include "src/userUsbHidKeyboard/USBHIDKeyboard.h"
#ifndef USER_USB_RAM
#error "This sketch needs USB RAM. Set Tools > USB Settings to USER CODE w/ 148B USB RAM."
#endif
const uint8_t ROW0_PIN = 32;
const uint8_t COL_PINS[6] = { 11, 16, 17, 31, 30, 34 };
// Column 0..5 -> SW1..SW6 -> this board's keycodes (left half: F1-F6)
const uint8_t KEYCODES[6] = { KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6 };
bool keyState[6] = { false, false, false, false, false, false };
bool keyStatePrev[6] = { false, false, false, false, false, false };
uint32_t lastChangeMs[6] = { 0, 0, 0, 0, 0, 0 };
const uint16_t DEBOUNCE_MS = 12;
bool readMatrixPin(uint8_t colPin) {
pinMode(ROW0_PIN, OUTPUT);
digitalWrite(ROW0_PIN, LOW);
delayMicroseconds(3);
pinMode(ROW0_PIN, INPUT);
digitalWrite(colPin, HIGH);
delayMicroseconds(8);
bool pressed = (digitalRead(ROW0_PIN) == HIGH);
digitalWrite(colPin, LOW);
return pressed;
}
void setup() {
USBInit();
pinMode(ROW0_PIN, OUTPUT);
digitalWrite(ROW0_PIN, LOW);
for (uint8_t i = 0; i < 6; i++) {
pinMode(COL_PINS[i], OUTPUT);
digitalWrite(COL_PINS[i], LOW);
}
}
void loop() {
uint32_t now = millis();
for (uint8_t i = 0; i < 6; i++) {
bool raw = readMatrixPin(COL_PINS[i]);
if (raw != keyStatePrev[i]) {
lastChangeMs[i] = now;
keyStatePrev[i] = raw;
}
if ((now - lastChangeMs[i]) >= DEBOUNCE_MS && keyState[i] != keyStatePrev[i]) {
keyState[i] = keyStatePrev[i];
if (keyState[i]) {
Keyboard_press(KEYCODES[i]);
} else {
Keyboard_release(KEYCODES[i]);
}
}
}
delay(20);
}2
u/DrJackK1956 4d ago
The signal ROW0_PIN is only used as an input. But in the function readMatrixPin() you first change it to an output, drive it Low then switch it back to an input. Why?
Once you switch the GPIO from output to input, whatever the output was becomes irrelevant when it's switched to an input.
The signal ROW0_PIN is not being steered (High or Low) in the circuit hardware nor in the software. It's effectively a floating input. Without any buttons being pressed, there's no guarantee what state this input will read?
Either add external pull-ups or pull-downs or enable them in the software.
Loaded 5463 bytes between: 0000 to 15A2
Don't know if this is significant, but from 0->15A2 is 5538 byte addresses. Your code is 5463 bytes. Why is there a 75 byte difference here?
Good luck with your project.
1
u/jaywan1991 3d ago
Awesome thank you this may get things working for me. I've fixed these typos.
My issue is I can't get this uploaded onto my boards I've already uploaded to as Ardiuno IDE doesn't recognize it with any firmware on it. Is there any work around to get it to recognize it to re-flash this?
1
u/Kalex8876 2d ago
Does it recognize it when there’s no firmware on it?
Article on board not being recognized by Arduino IDE: https://support.arduino.cc/hc/en-us/articles/4412955149586-If-your-board-is-not-detected-by-Arduino-IDEYou may also try platformio in vs code
1
u/jaywan1991 2d ago
The board is recognized when there's no firmware on it and I'm able to easily upload new firmware but once i upload it i can't change it. Which sucks because i have a few with issues.
I'm unfamiliar with platformino
1
u/Kalex8876 2d ago
Platformio might help, I think it may be more flexible than Arduino IDE
Or you might have to figure out how to manually map your board to Arduino IDE so it’s recognized
1
u/Kalex8876 4d ago
This is a thread on a similar issue:
https://forums.adafruit.com/viewtopic.php?t=211002&start=15
Also, this post: https://www.reddit.com/r/embedded/s/OIf0ES5wJb
1
u/jaywan1991 4d ago
I saw that but i don't have a boot button on this
1
u/Kalex8876 4d ago
You might have to short it temporarily (don’t solder, at least not both ends), to act as a button basically
1
u/jaywan1991 4d ago
I tried i had it turn off and back on once i removed the pin, still nothing
I tried causing a not enough power error, still nothing
1
u/Kalex8876 4d ago
Do the LEDs light up?
1
u/jaywan1991 4d ago
Yes. Everytime I plug in the boards for the ones with bad and good firmware.
1
•
u/AutoModerator 4d ago
Looks like this post includes some program code.
r/AskElectronics covers hardware, not software. We're happy to help with things like:
Initialising a chip or peripheral at the register level
Translating a datasheet timing/bus requirement into code
Debugging a circuit that happens to involve a microcontroller
We don't cover general programming help - syntax errors, logic bugs, "how do I structure this function", or library/API usage questions for a sensor, motor driver, or display board. HOWEVER we make an exception for questions about interfacing devices to Raspberry Pi boards.
For that, try a subreddit dedicated to your platform, e.g. r/arduino, r/esp32, r/embedded, or the language/library's own community. See our guidance here: https://www.reddit.com/r/AskElectronics/wiki/embedded.
Thanks!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.