From fdf808ee24fe8cdfbad7d3f6db905489549564bb Mon Sep 17 00:00:00 2001 From: flabbergast Date: Thu, 11 Feb 2016 21:12:19 +0000 Subject: [PATCH 1/3] Chibios: Fix a HardFault bug (wait after start). --- tmk_core/protocol/chibios/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index b62cfa9c..d588e4de 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -101,6 +101,13 @@ int main(void) { while(USB_DRIVER.state != USB_ACTIVE) chThdSleepMilliseconds(50); + /* Do need to wait here! + * Otherwise the next print might start a transfer on console EP + * before the USB is completely ready, which sometimes causes + * HardFaults. + */ + chThdSleepMilliseconds(50); + print("USB configured.\n"); /* init TMK modules */ From fa52d8ba7468a8bbb5754a5be1df249af7ecfece Mon Sep 17 00:00:00 2001 From: flabbergast Date: Thu, 11 Feb 2016 21:14:28 +0000 Subject: [PATCH 2/3] Chibios: cleanup usb_main code. --- tmk_core/protocol/chibios/usb_main.c | 8 ++++---- tmk_core/protocol/chibios/usb_main.h | 6 +----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index d248b447..e2c9d9bf 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -33,9 +33,9 @@ * --------------------------------------------------------- */ -uint8_t keyboard_idle = 0; -uint8_t keyboard_protocol = 1; -uint16_t keyboard_led_stats = 0; +uint8_t keyboard_idle __attribute__((aligned(2))) = 0; +uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; +uint16_t keyboard_led_stats __attribute__((aligned(2))) = 0; volatile uint16_t keyboard_idle_count = 0; static virtual_timer_t keyboard_idle_timer; static void keyboard_idle_timer_cb(void *arg); @@ -1350,7 +1350,7 @@ int8_t sendchar(uint8_t c) { return 0; } osalSysUnlock(); - /* Timeout after 5us if the queue is full. + /* Timeout after 100us if the queue is full. * Increase this timeout if too much stuff is getting * dropped (i.e. the buffer is getting full too fast * for USB/HIDRAW to dequeue). Another possibility diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h index d8f30e95..30d8fcae 100644 --- a/tmk_core/protocol/chibios/usb_main.h +++ b/tmk_core/protocol/chibios/usb_main.h @@ -58,9 +58,6 @@ void send_remote_wakeup(USBDriver *usbp); #define NKRO_REPORT_KEYS (NKRO_EPSIZE - 1) #endif -/* this defines report_keyboard_t and computes REPORT_SIZE defines */ -// #include "report.h" - /* extern report_keyboard_t keyboard_report_sent; */ /* keyboard IN request callback handler */ @@ -122,8 +119,7 @@ typedef struct { #define CONSOLE_EPSIZE 16 /* Number of IN reports that can be stored inside the output queue */ -#define CONSOLE_QUEUE_CAPACITY 2 -#define CONSOLE_QUEUE_BUFFER_SIZE (CONSOLE_QUEUE_CAPACITY * CONSOLE_EPSIZE) +#define CONSOLE_QUEUE_CAPACITY 4 /* Console flush time */ #define CONSOLE_FLUSH_MS 50 From 803b65ea43b6b27d5c43af1705a7cbc87c87946b Mon Sep 17 00:00:00 2001 From: flabbergast Date: Sat, 13 Feb 2016 10:01:16 +0000 Subject: [PATCH 3/3] Chibios: Revert common.mk change (fix AVR linking problem). --- tmk_core/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/common.mk b/tmk_core/common.mk index ebaafd1d..4c943f04 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -1,4 +1,4 @@ -COMMON_DIR = $(TMK_DIR)/common +COMMON_DIR = common SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/keyboard.c \ $(COMMON_DIR)/action.c \