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:
https://imgur.com/a/aIbLTeN
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);
}