Unverified Commit e4c14482 authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Remove exception handling code, save RAM and FLASH (#245)

Use a libstdc++ compiled with -fno-exceptions to avoid including the
code needed to unwind C++ exceptions.

Saves ~4K RAM and ~5K flash.
parent 05356da2
...@@ -122,32 +122,41 @@ int __USBGetMouseReportID() { ...@@ -122,32 +122,41 @@ int __USBGetMouseReportID() {
} }
static uint8_t *GetDescHIDReport(int *len) { static uint8_t *GetDescHIDReport(int *len) {
static uint8_t *report = nullptr;
int report_len = 0;
if (report) {
free(report);
}
if (__USBInstallKeyboard && __USBInstallMouse) { if (__USBInstallKeyboard && __USBInstallMouse) {
static uint8_t desc_hid_report[] = { uint8_t desc_hid_report[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1)), TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1)),
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(2)) TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(2))
}; };
if (len) { report_len = sizeof(desc_hid_report);
*len = sizeof(desc_hid_report); report = (uint8_t *)malloc(report_len);
} memcpy(report, desc_hid_report, report_len);
return desc_hid_report;
} else if (__USBInstallKeyboard && ! __USBInstallMouse) { } else if (__USBInstallKeyboard && ! __USBInstallMouse) {
static uint8_t desc_hid_report[] = { uint8_t desc_hid_report[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1)) TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1))
}; };
if (len) { report_len = sizeof(desc_hid_report);
*len = sizeof(desc_hid_report); report = (uint8_t *)malloc(report_len);
} memcpy(report, desc_hid_report, report_len);
return desc_hid_report;
} else { // if (!__USBInstallKeyboard && __USBInstallMouse) { } else { // if (!__USBInstallKeyboard && __USBInstallMouse) {
static uint8_t desc_hid_report[] = { uint8_t desc_hid_report[] = {
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(1)) TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(1))
}; };
if (len) { report_len = sizeof(desc_hid_report);
*len = sizeof(desc_hid_report); report = (uint8_t *)malloc(report_len);
} memcpy(report, desc_hid_report, report_len);
return desc_hid_report; }
if (len) {
*len = report_len;
} }
return report;
} }
// Invoked when received GET HID REPORT DESCRIPTOR // Invoked when received GET HID REPORT DESCRIPTOR
...@@ -161,14 +170,14 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance) { ...@@ -161,14 +170,14 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance) {
const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
(void)index; (void)index;
static uint8_t *usbd_desc_cfg = NULL; static uint8_t *usbd_desc_cfg = nullptr;
if (!usbd_desc_cfg) { if (!usbd_desc_cfg) {
bool hasHID = __USBInstallKeyboard || __USBInstallMouse; bool hasHID = __USBInstallKeyboard || __USBInstallMouse;
uint8_t interface_count = (__USBInstallSerial ? 2 : 0) + (hasHID ? 1 : 0) + (__USBInstallMIDI ? 2 : 0); uint8_t interface_count = (__USBInstallSerial ? 2 : 0) + (hasHID ? 1 : 0) + (__USBInstallMIDI ? 2 : 0);
static uint8_t cdc_desc[TUD_CDC_DESC_LEN] = { uint8_t cdc_desc[TUD_CDC_DESC_LEN] = {
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE) TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE)
}; };
...@@ -176,20 +185,20 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { ...@@ -176,20 +185,20 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
int hid_report_len; int hid_report_len;
GetDescHIDReport(&hid_report_len); GetDescHIDReport(&hid_report_len);
uint8_t hid_itf = __USBInstallSerial ? 2 : 0; uint8_t hid_itf = __USBInstallSerial ? 2 : 0;
static uint8_t hid_desc[TUD_HID_DESC_LEN] = { uint8_t hid_desc[TUD_HID_DESC_LEN] = {
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
TUD_HID_DESCRIPTOR(hid_itf, 0, HID_ITF_PROTOCOL_NONE, hid_report_len, EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) TUD_HID_DESCRIPTOR(hid_itf, 0, HID_ITF_PROTOCOL_NONE, hid_report_len, EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
}; };
uint8_t midi_itf = hid_itf + (hasHID ? 1 : 0); uint8_t midi_itf = hid_itf + (hasHID ? 1 : 0);
static uint8_t midi_desc[TUD_MIDI_DESC_LEN] = { uint8_t midi_desc[TUD_MIDI_DESC_LEN] = {
// Interface number, string index, EP Out & EP In address, EP size // Interface number, string index, EP Out & EP In address, EP size
TUD_MIDI_DESCRIPTOR(midi_itf, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64) TUD_MIDI_DESCRIPTOR(midi_itf, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64)
}; };
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (hasHID ? sizeof(hid_desc) : 0) + (__USBInstallMIDI ? sizeof(midi_desc) : 0); int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (hasHID ? sizeof(hid_desc) : 0) + (__USBInstallMIDI ? sizeof(midi_desc) : 0);
static uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = { uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
// Config number, interface count, string index, total length, attribute, power in mA // Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, interface_count, USBD_STR_0, usbd_desc_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA) TUD_CONFIG_DESCRIPTOR(1, interface_count, USBD_STR_0, usbd_desc_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA)
}; };
...@@ -277,6 +286,7 @@ void __USBStart() { ...@@ -277,6 +286,7 @@ void __USBStart() {
} }
mutex_init(&__usb_mutex); mutex_init(&__usb_mutex);
tusb_init(); tusb_init();
irq_set_exclusive_handler(USB_TASK_IRQ, usb_irq); irq_set_exclusive_handler(USB_TASK_IRQ, usb_irq);
......
...@@ -76,7 +76,7 @@ extern "C" int main() { ...@@ -76,7 +76,7 @@ extern "C" int main() {
#endif #endif
#if defined DEBUG_RP2040_PORT #if defined DEBUG_RP2040_PORT
DEBUG_RP2040_PORT.begin(); DEBUG_RP2040_PORT.begin(115200);
#endif #endif
#ifndef NO_USB #ifndef NO_USB
......
File added
...@@ -43,6 +43,7 @@ compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/l ...@@ -43,6 +43,7 @@ compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/l
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt" compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
compiler.libpico="{runtime.platform.path}/lib/libpico.a" compiler.libpico="{runtime.platform.path}/lib/libpico.a"
compiler.libstdcpp="{runtime.platform.path}/lib/libstdc++.a"
compiler.c.cmd=arm-none-eabi-gcc compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-c {compiler.warning_flags} {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g compiler.c.flags=-c {compiler.warning_flags} {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g
...@@ -113,7 +114,7 @@ recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3 ...@@ -113,7 +114,7 @@ recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3
recipe.hooks.linking.prelink.2.pattern="{compiler.path}{compiler.S.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -c "{runtime.platform.path}/boot2/{build.boot2}.S" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" -o "{build.path}/boot2.o" recipe.hooks.linking.prelink.2.pattern="{compiler.path}{compiler.S.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -c "{runtime.platform.path}/boot2/{build.boot2}.S" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" -o "{build.path}/boot2.o"
## Combine gc-sections, archives, and objects ## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.ldflags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" "{build.path}/boot2.o" {compiler.libpico} -lm -lc -lstdc++ -lc -Wl,--end-group recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.ldflags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" "{build.path}/boot2.o" {compiler.libpico} -lm -lc {compiler.libstdcpp} -lc -Wl,--end-group
## Create output (UF2 file) ## Create output (UF2 file)
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2" recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment