From b6c906e55e7730ecaaf7be9a801c0631a09da7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 10:38:21 +0100 Subject: [PATCH 01/28] tusb_config: refactor code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- tusb_config.h | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/tusb_config.h b/tusb_config.h index ade54c3..7e0ec54 100644 --- a/tusb_config.h +++ b/tusb_config.h @@ -1,36 +1,19 @@ +// SPDX-License-Identifier: MIT /* - * The MIT License (MIT) - * + * Copyright (c) 2021 Álvaro Fernández Rojas * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * Copyright (c) 2020 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * */ -#ifndef _PICO_STDIO_USB_TUSB_CONFIG_H -#define _PICO_STDIO_USB_TUSB_CONFIG_H +#if !defined(_TUSB_CONFIG_H_) +#define _TUSB_CONFIG_H_ -#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) +#include -#define CFG_TUD_CDC (2) -#define CFG_TUD_CDC_RX_BUFSIZE (256) -#define CFG_TUD_CDC_TX_BUFSIZE (256) +#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE -#endif +#define CFG_TUD_CDC 2 +#define CFG_TUD_CDC_RX_BUFSIZE 256 +#define CFG_TUD_CDC_TX_BUFSIZE 256 + +#endif /* _TUSB_CONFIG_H_ */ From f2531be8794859e84707c12fbf508f15221ff68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 10:59:27 +0100 Subject: [PATCH 02/28] usb-descriptors: refactor code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- usb-descriptors.c | 177 ++++++++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 101 deletions(-) diff --git a/usb-descriptors.c b/usb-descriptors.c index caa7afd..5c10798 100644 --- a/usb-descriptors.c +++ b/usb-descriptors.c @@ -1,135 +1,110 @@ +// SPDX-License-Identifier: MIT /* + * Copyright (c) 2021 Álvaro Fernández Rojas + * * This file is based on a file originally part of the * MicroPython project, http://micropython.org/ * - * The MIT License (MIT) - * * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * Copyright (c) 2019 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. */ -#include "tusb.h" +#include -#define USBD_VID (0x2E8A) // Raspberry Pi -#define USBD_PID (0x000a) // Raspberry Pi Pico SDK CDC +#define DESC_STR_MAX 20 + +#define USBD_VID 0x2E8A /* Raspberry Pi */ +#define USBD_PID 0x000A /* Raspberry Pi Pico SDK CDC */ #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN * CFG_TUD_CDC) -#define USBD_MAX_POWER_MA (250) +#define USBD_MAX_POWER_MA 250 -enum -{ - ITF_NUM_CDC_0 = 0, - ITF_NUM_CDC_0_DATA, - ITF_NUM_CDC_1, - ITF_NUM_CDC_1_DATA, - ITF_NUM_TOTAL -}; +#define USBD_ITF_CDC_0 0 +#define USBD_ITF_CDC_1 2 +#define USBD_ITF_MAX 4 -#define USBD_ITF_CDC (0) // needs 2 interfaces -#define USBD_ITF_MAX (2) +#define USBD_CDC_0_EP_CMD 0x81 +#define USBD_CDC_1_EP_CMD 0x84 +#define USBD_CDC_0_EP_OUT 0x02 +#define USBD_CDC_1_EP_OUT 0x05 +#define USBD_CDC_0_EP_IN 0x82 +#define USBD_CDC_1_EP_IN 0x85 +#define USBD_CDC_CMD_MAX_SIZE 8 +#define USBD_CDC_IN_OUT_MAX_SIZE 64 -#define USBD_CDC_EP_CMD (0x81) -#define USBD_CDC_EP_OUT (0x02) -#define USBD_CDC_EP_IN (0x82) -#define USBD_CDC_CMD_MAX_SIZE (8) -#define USBD_CDC_IN_OUT_MAX_SIZE (64) - -#define USBD_STR_0 (0x00) -#define USBD_STR_MANUF (0x01) -#define USBD_STR_PRODUCT (0x02) -#define USBD_STR_SERIAL (0x03) -#define USBD_STR_CDC (0x04) - -#define EPNUM_CDC_0_NOTIF (0x81) -#define EPNUM_CDC_0_DATA (0x02) - -#define EPNUM_CDC_1_NOTIF (0x84) -#define EPNUM_CDC_1_DATA (0x05) - -// Note: descriptors returned from callbacks must exist long enough for transfer to complete +#define USBD_STR_0 0x00 +#define USBD_STR_MANUF 0x01 +#define USBD_STR_PRODUCT 0x02 +#define USBD_STR_SERIAL 0x03 +#define USBD_STR_CDC 0x04 static const tusb_desc_device_t usbd_desc_device = { - .bLength = sizeof(tusb_desc_device_t), - .bDescriptorType = TUSB_DESC_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = TUSB_CLASS_MISC, - .bDeviceSubClass = MISC_SUBCLASS_COMMON, - .bDeviceProtocol = MISC_PROTOCOL_IAD, - .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, - .idVendor = USBD_VID, - .idProduct = USBD_PID, - .bcdDevice = 0x0100, - .iManufacturer = USBD_STR_MANUF, - .iProduct = USBD_STR_PRODUCT, - .iSerialNumber = USBD_STR_SERIAL, - .bNumConfigurations = 1, + .bLength = sizeof(tusb_desc_device_t), + .bDescriptorType = TUSB_DESC_DEVICE, + .bcdUSB = 0x0200, + .bDeviceClass = TUSB_CLASS_MISC, + .bDeviceSubClass = MISC_SUBCLASS_COMMON, + .bDeviceProtocol = MISC_PROTOCOL_IAD, + .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, + .idVendor = USBD_VID, + .idProduct = USBD_PID, + .bcdDevice = 0x0100, + .iManufacturer = USBD_STR_MANUF, + .iProduct = USBD_STR_PRODUCT, + .iSerialNumber = USBD_STR_SERIAL, + .bNumConfigurations = 1, }; static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = { - TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, USBD_STR_0, USBD_DESC_LEN, - TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA), + TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_0, USBD_DESC_LEN, + TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA), - TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0, USBD_STR_CDC, EPNUM_CDC_0_NOTIF, - USBD_CDC_CMD_MAX_SIZE, EPNUM_CDC_0_DATA, 0x80 | EPNUM_CDC_0_DATA, USBD_CDC_IN_OUT_MAX_SIZE), + TUD_CDC_DESCRIPTOR(USBD_ITF_CDC_0, USBD_STR_CDC, USBD_CDC_0_EP_CMD, + USBD_CDC_CMD_MAX_SIZE, USBD_CDC_0_EP_OUT, USBD_CDC_0_EP_IN, + USBD_CDC_IN_OUT_MAX_SIZE), - TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_1, USBD_STR_CDC, EPNUM_CDC_1_NOTIF, - USBD_CDC_CMD_MAX_SIZE, EPNUM_CDC_1_DATA, 0x80 | EPNUM_CDC_1_DATA, USBD_CDC_IN_OUT_MAX_SIZE), + TUD_CDC_DESCRIPTOR(USBD_ITF_CDC_1, USBD_STR_CDC, USBD_CDC_1_EP_CMD, + USBD_CDC_CMD_MAX_SIZE, USBD_CDC_1_EP_OUT, USBD_CDC_1_EP_IN, + USBD_CDC_IN_OUT_MAX_SIZE), }; static const char *const usbd_desc_str[] = { - [USBD_STR_MANUF] = "Raspberry Pi", - [USBD_STR_PRODUCT] = "Pico", - [USBD_STR_SERIAL] = "000000000000", // TODO - [USBD_STR_CDC] = "Board CDC", + [USBD_STR_MANUF] = "Raspberry Pi", + [USBD_STR_PRODUCT] = "Pico", + [USBD_STR_SERIAL] = "000000000000", + [USBD_STR_CDC] = "Board CDC", }; -const uint8_t *tud_descriptor_device_cb(void) { - return (const uint8_t *)&usbd_desc_device; +const uint8_t *tud_descriptor_device_cb(void) +{ + return (const uint8_t *) &usbd_desc_device; } -const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { - (void)index; - return usbd_desc_cfg; +const uint8_t *tud_descriptor_configuration_cb(uint8_t index) +{ + return usbd_desc_cfg; } -const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { - #define DESC_STR_MAX (20) - static uint16_t desc_str[DESC_STR_MAX]; +const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) +{ + static uint16_t desc_str[DESC_STR_MAX]; + uint8_t len; - uint8_t len; - if (index == 0) { - desc_str[1] = 0x0409; // supported language is English - len = 1; - } else { - if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0])) { - return NULL; - } - const char *str = usbd_desc_str[index]; - for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len) { - desc_str[1 + len] = str[len]; - } - } + if (index == 0) { + desc_str[1] = 0x0409; + len = 1; + } else { + const char *str; - // first byte is length (including header), second byte is string type - desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * len + 2); + if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0])) + return NULL; - return desc_str; + str = usbd_desc_str[index]; + for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len) + desc_str[1 + len] = str[len]; + } + + desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * len + 2); + + return desc_str; } From 8d9d952ddefc3043e9767928a961546c7a00b18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 11:01:44 +0100 Subject: [PATCH 03/28] uart-bridge: remove unused variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/uart-bridge.c b/uart-bridge.c index 5772389..3a3be40 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -154,7 +154,6 @@ void usb_write_bytes(uint8_t itf) { void usb_cdc_process(uint8_t itf) { uart_data_t *ud = &UART_DATA[itf]; - int con = tud_cdc_n_connected(itf); tud_cdc_n_get_line_coding(itf, &ud->usb_lc); usb_read_bytes(itf); @@ -253,8 +252,6 @@ void init_uart_data(uint8_t itf) { int main(void) { - uint8_t ch; - int rc; int itf; for (itf = 0; itf < CFG_TUD_CDC; itf++) From 3f9c9fadde355188831b6d78202cb5510498f9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 11:05:12 +0100 Subject: [PATCH 04/28] uart-bridge: add LC mutex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/uart-bridge.c b/uart-bridge.c index 3a3be40..5c1271d 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -32,6 +32,7 @@ typedef struct { typedef struct { cdc_line_coding_t usb_lc; cdc_line_coding_t uart_lc; + mutex_t lc_mtx; uint8_t uart_buffer[BUFFER_SIZE]; uint32_t uart_pos; mutex_t uart_mtx; @@ -95,6 +96,8 @@ void update_uart_cfg(uint8_t itf) const uart_id_t *ui = &UART_ID[itf]; uart_data_t *ud = &UART_DATA[itf]; + mutex_enter_blocking(&ud->lc_mtx); + if (ud->usb_lc.bit_rate != ud->uart_lc.bit_rate) { uart_set_baudrate(ui->inst, ud->usb_lc.bit_rate); ud->uart_lc.bit_rate = ud->usb_lc.bit_rate; @@ -111,6 +114,8 @@ void update_uart_cfg(uint8_t itf) ud->uart_lc.parity = ud->usb_lc.parity; ud->uart_lc.stop_bits = ud->usb_lc.stop_bits; } + + mutex_exit(&ud->lc_mtx); } void usb_read_bytes(uint8_t itf) { @@ -155,7 +160,10 @@ void usb_cdc_process(uint8_t itf) { uart_data_t *ud = &UART_DATA[itf]; + mutex_enter_blocking(&ud->lc_mtx); tud_cdc_n_get_line_coding(itf, &ud->usb_lc); + mutex_exit(&ud->lc_mtx); + usb_read_bytes(itf); usb_write_bytes(itf); } @@ -239,6 +247,7 @@ void init_uart_data(uint8_t itf) { ud->usb_pos = 0; /* Mutex */ + mutex_init(&ud->lc_mtx); mutex_init(&ud->uart_mtx); mutex_init(&ud->usb_mtx); From beb34da36d1717aafe212b6bef4b8e8ef2c3d599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 11:14:31 +0100 Subject: [PATCH 05/28] build: automatically checkout pico-sdk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- build.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 31d9607..a88b320 100755 --- a/build.sh +++ b/build.sh @@ -1,14 +1,20 @@ #!/bin/sh BUILD_DIR=build +PICO_SDK_DIR=pico-sdk main () { local cur_dir=$PWD + if [ ! -d "$PICO_SDK_DIR/.git" ]; then + git submodule update --init --recursive + fi + mkdir -p $BUILD_DIR cd $BUILD_DIR - cmake .. + cmake ../ make + cd $cur_dir } From 7f8226a3a187fce4092183aec4983ce715c88e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 11:34:25 +0100 Subject: [PATCH 06/28] github: add CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ .gitmodules | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a68e126 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: + - push + - pull_request + +env: + DEFAULT_PYTHON: 3.9 + +jobs: + pico: + name: Raspberry Pi Pico compilation + runs-on: ubuntu-latest + steps: + - name: Check out code from GitHub + uses: actions/checkout@v2 + + - name: Install dependencies + run: | + sudo apt-get install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi + + - name: Generate RPi Pico binaries + run: | + ./build.sh + + - name: 'Upload RPi Pico binary' + uses: actions/upload-artifact@v2 + with: + name: pico-uart-bridge.uf2 + path: build/uart_bridge.uf2 + retention-days: 5 diff --git a/.gitmodules b/.gitmodules index 6d38f34..7733770 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "pico-sdk"] path = pico-sdk - url = git@github.com:raspberrypi/pico-sdk.git + url = https://github.com/raspberrypi/pico-sdk.git From 206b612bae85ee0d9e2a84d9396666e727f4ec20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 12:05:47 +0100 Subject: [PATCH 07/28] uart-bridge: improve usb_write_bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tud_cdc_n_write() may not be able to write the full buffer, so we need to handle that by moving the remaining bytes in the buffer to the buffer start. Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/uart-bridge.c b/uart-bridge.c index 5c1271d..8bdd592 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #if !defined(MIN) @@ -147,12 +148,15 @@ void usb_write_bytes(uint8_t itf) { mutex_enter_blocking(&ud->uart_mtx); count = tud_cdc_n_write(itf, ud->uart_buffer, ud->uart_pos); - if (count) { - ud->uart_pos -= count; - tud_cdc_n_write_flush(itf); - } + if (count < ud->uart_pos) + memcpy(ud->uart_buffer, &ud->uart_buffer[count], + ud->uart_pos - count); + ud->uart_pos -= count; mutex_exit(&ud->uart_mtx); + + if (count) + tud_cdc_n_write_flush(itf); } } From 7a8e3bf16c1a27fba7e8661f4951e16af6917391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 6 Feb 2021 12:23:07 +0100 Subject: [PATCH 08/28] github: force Ubuntu 20.04 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently, ubuntu-latest still points to Ubuntu 18.04, which uses an older and incompatible version of gcc-arm-none-eabi. Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a68e126..a489cef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,8 @@ env: jobs: pico: - name: Raspberry Pi Pico compilation - runs-on: ubuntu-latest + name: RPi Pico compilation + runs-on: ubuntu-20.04 steps: - name: Check out code from GitHub uses: actions/checkout@v2 From 2460b10523aa3b8537f16f2689c2c051c6de720f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 25 Oct 2021 18:42:30 +0200 Subject: [PATCH 09/28] uart-bridge: usb_read_bytes: fix usb_buffer access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uart-bridge.c b/uart-bridge.c index 8bdd592..9f8ed1c 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -131,7 +131,7 @@ void usb_read_bytes(uint8_t itf) { if (len) { uint32_t count; - count = tud_cdc_n_read(itf, ud->usb_buffer, len); + count = tud_cdc_n_read(itf, &ud->usb_buffer[ud->usb_pos], len); ud->usb_pos += count; } From a7d61bb4c8fee793a635f31c1eee2286e586690b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 3 May 2022 12:19:39 +0200 Subject: [PATCH 10/28] pico-sdk: update v1.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- build.sh | 1 + pico-sdk | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index a88b320..2bd88a9 100755 --- a/build.sh +++ b/build.sh @@ -7,6 +7,7 @@ main () { local cur_dir=$PWD if [ ! -d "$PICO_SDK_DIR/.git" ]; then + git submodule sync --recursive git submodule update --init --recursive fi diff --git a/pico-sdk b/pico-sdk index 2d5789e..2062372 160000 --- a/pico-sdk +++ b/pico-sdk @@ -1 +1 @@ -Subproject commit 2d5789eca89658a7f0a01e2d6010c0f254605d72 +Subproject commit 2062372d203b372849d573f252cf7c6dc2800c0a From 982b071d6cfac4af3d2da9c9028a1ade7b433342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 3 May 2022 17:05:36 +0200 Subject: [PATCH 11/28] github: update CI workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a489cef..739e317 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,27 +4,34 @@ on: - push - pull_request -env: - DEFAULT_PYTHON: 3.9 - jobs: pico: name: RPi Pico compilation runs-on: ubuntu-20.04 steps: - - name: Check out code from GitHub - uses: actions/checkout@v2 + - name: 'Check out code' + uses: actions/checkout@v3 - - name: Install dependencies + - name: 'Install dependencies' run: | sudo apt-get install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi - - name: Generate RPi Pico binaries + - name: 'Update Submodules' run: | - ./build.sh + git submodule sync --recursive + git submodule update --init --recursive - - name: 'Upload RPi Pico binary' - uses: actions/upload-artifact@v2 + - name: 'Configure' + run: | + mkdir -p build + cmake -B build + + - name: 'Build' + run: | + make -C build + + - name: 'Upload binary' + uses: actions/upload-artifact@v3 with: name: pico-uart-bridge.uf2 path: build/uart_bridge.uf2 From 71faf3097a298fc8271423c1fbabfa22e72170e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 3 May 2022 19:39:29 +0200 Subject: [PATCH 12/28] build.sh: improve script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- build.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/build.sh b/build.sh index 2bd88a9..c361db0 100755 --- a/build.sh +++ b/build.sh @@ -1,22 +1,17 @@ -#!/bin/sh +#!/bin/bash -BUILD_DIR=build -PICO_SDK_DIR=pico-sdk - -main () { - local cur_dir=$PWD +BASE_DIR="$(dirname ${BASH_SOURCE[0]})" +BUILD_DIR=$BASE_DIR/build +PICO_SDK_DIR=$BASE_DIR/pico-sdk +main() { if [ ! -d "$PICO_SDK_DIR/.git" ]; then git submodule sync --recursive git submodule update --init --recursive fi - mkdir -p $BUILD_DIR - cd $BUILD_DIR - cmake ../ - make - - cd $cur_dir + cmake -B $BUILD_DIR -S $BASE_DIR + make -C $BUILD_DIR } main $@ From ebbc862b65e2a20a8f4f5607780a35bf863e66d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 3 May 2022 19:58:12 +0200 Subject: [PATCH 13/28] uart-bridge: increase BUFFER_SIZE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uart-bridge.c b/uart-bridge.c index 9f8ed1c..3bbd4a4 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -17,7 +17,7 @@ #define LED_PIN 25 -#define BUFFER_SIZE 64 +#define BUFFER_SIZE 256 #define DEF_BIT_RATE 115200 #define DEF_STOP_BITS 1 From 05e4815f6b8fc522cbe8b42e1a18726f30f718ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 3 May 2022 19:59:18 +0200 Subject: [PATCH 14/28] uart-bridge: bump clock to 250 MHz MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uart-bridge.c b/uart-bridge.c index 3bbd4a4..aebbdf6 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -267,6 +267,8 @@ int main(void) { int itf; + set_sys_clock_khz(250000, false); + for (itf = 0; itf < CFG_TUD_CDC; itf++) init_uart_data(itf); From 6aa7cf2958de4e74688067e427138f371d051320 Mon Sep 17 00:00:00 2001 From: cxxcoder Date: Thu, 3 Nov 2022 18:12:56 +0100 Subject: [PATCH 15/28] usb-descriptors: use flash ID as USB serial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- CMakeLists.txt | 1 + tusb_config.h | 2 ++ uart-bridge.c | 2 ++ usb-descriptors.c | 17 ++++++++++++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eda4f18..e0c286d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ target_include_directories(uart_bridge PUBLIC pico-sdk/lib/tinyusb/src) target_link_libraries(uart_bridge + hardware_flash pico_multicore pico_stdlib tinyusb_device) diff --git a/tusb_config.h b/tusb_config.h index 7e0ec54..6fcb7b9 100644 --- a/tusb_config.h +++ b/tusb_config.h @@ -16,4 +16,6 @@ #define CFG_TUD_CDC_RX_BUFSIZE 256 #define CFG_TUD_CDC_TX_BUFSIZE 256 +void usbd_serial_init(void); + #endif /* _TUSB_CONFIG_H_ */ diff --git a/uart-bridge.c b/uart-bridge.c index aebbdf6..7ee6a9c 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -269,6 +269,8 @@ int main(void) set_sys_clock_khz(250000, false); + usbd_serial_init(); + for (itf = 0; itf < CFG_TUD_CDC; itf++) init_uart_data(itf); diff --git a/usb-descriptors.c b/usb-descriptors.c index 5c10798..1ccd5de 100644 --- a/usb-descriptors.c +++ b/usb-descriptors.c @@ -9,6 +9,7 @@ * Copyright (c) 2019 Damien P. George */ +#include #include #define DESC_STR_MAX 20 @@ -36,6 +37,7 @@ #define USBD_STR_MANUF 0x01 #define USBD_STR_PRODUCT 0x02 #define USBD_STR_SERIAL 0x03 +#define USBD_STR_SERIAL_LEN 17 #define USBD_STR_CDC 0x04 static const tusb_desc_device_t usbd_desc_device = { @@ -68,10 +70,12 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = { USBD_CDC_IN_OUT_MAX_SIZE), }; +static char usbd_serial[USBD_STR_SERIAL_LEN] = "000000000000"; + static const char *const usbd_desc_str[] = { [USBD_STR_MANUF] = "Raspberry Pi", [USBD_STR_PRODUCT] = "Pico", - [USBD_STR_SERIAL] = "000000000000", + [USBD_STR_SERIAL] = usbd_serial, [USBD_STR_CDC] = "Board CDC", }; @@ -95,6 +99,7 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) len = 1; } else { const char *str; + char serial[USBD_STR_SERIAL_LEN]; if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0])) return NULL; @@ -108,3 +113,13 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) return desc_str; } + +void usbd_serial_init(void) +{ + uint8_t id[8]; + + flash_get_unique_id(id); + + snprintf(usbd_serial, USBD_STR_SERIAL_LEN, "%02X%02X%02X%02X%02X%02X%02X%02X", + id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]); +} From d0925bfd33c375fa1ed25cd7e894f52ed7bc4d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Thu, 3 Nov 2022 19:33:57 +0100 Subject: [PATCH 16/28] pico-sdk: update to 1.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- pico-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pico-sdk b/pico-sdk index 2062372..2e6142b 160000 --- a/pico-sdk +++ b/pico-sdk @@ -1 +1 @@ -Subproject commit 2062372d203b372849d573f252cf7c6dc2800c0a +Subproject commit 2e6142b15b8a75c1227dd3edbe839193b2bf9041 From 71fd38df8ad389f2d8df880eeb6c9f88bfd378ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Thu, 3 Nov 2022 19:46:43 +0100 Subject: [PATCH 17/28] github: improve CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 739e317..bad1152 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,9 @@ name: CI -on: - - push - - pull_request +on: [push, pull_request] jobs: - pico: - name: RPi Pico compilation + CI: runs-on: ubuntu-20.04 steps: - name: 'Check out code' From 8db03b41acbdcb05ff5028b33a0c16ef939e6443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 4 Nov 2022 10:58:51 +0100 Subject: [PATCH 18/28] Code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- CMakeLists.txt | 2 +- uart-bridge.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0c286d..881c3f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ include(pico-sdk/pico_sdk_init.cmake) project(pico_uart_bridge) pico_sdk_init() - + add_executable(uart_bridge uart-bridge.c usb-descriptors.c) target_include_directories(uart_bridge PUBLIC diff --git a/uart-bridge.c b/uart-bridge.c index 7ee6a9c..f716ba9 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -181,7 +181,7 @@ void core1_entry(void) int con = 0; tud_task(); - + for (itf = 0; itf < CFG_TUD_CDC; itf++) { if (tud_cdc_n_connected(itf)) { con = 1; From 3e1672f2c935284623b0058ad37f957e0dd08055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 4 Nov 2022 10:59:54 +0100 Subject: [PATCH 19/28] Increase buffers and improve USB descriptors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- tusb_config.h | 4 ++-- uart-bridge.c | 2 +- usb-descriptors.c | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tusb_config.h b/tusb_config.h index 6fcb7b9..80eeb52 100644 --- a/tusb_config.h +++ b/tusb_config.h @@ -13,8 +13,8 @@ #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #define CFG_TUD_CDC 2 -#define CFG_TUD_CDC_RX_BUFSIZE 256 -#define CFG_TUD_CDC_TX_BUFSIZE 256 +#define CFG_TUD_CDC_RX_BUFSIZE 1024 +#define CFG_TUD_CDC_TX_BUFSIZE 1024 void usbd_serial_init(void); diff --git a/uart-bridge.c b/uart-bridge.c index f716ba9..7a6ccab 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -17,7 +17,7 @@ #define LED_PIN 25 -#define BUFFER_SIZE 256 +#define BUFFER_SIZE 2560 #define DEF_BIT_RATE 115200 #define DEF_STOP_BITS 1 diff --git a/usb-descriptors.c b/usb-descriptors.c index 1ccd5de..738f9d0 100644 --- a/usb-descriptors.c +++ b/usb-descriptors.c @@ -18,18 +18,21 @@ #define USBD_PID 0x000A /* Raspberry Pi Pico SDK CDC */ #define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN * CFG_TUD_CDC) -#define USBD_MAX_POWER_MA 250 +#define USBD_MAX_POWER_MA 500 #define USBD_ITF_CDC_0 0 #define USBD_ITF_CDC_1 2 #define USBD_ITF_MAX 4 #define USBD_CDC_0_EP_CMD 0x81 -#define USBD_CDC_1_EP_CMD 0x84 -#define USBD_CDC_0_EP_OUT 0x02 -#define USBD_CDC_1_EP_OUT 0x05 +#define USBD_CDC_1_EP_CMD 0x83 + +#define USBD_CDC_0_EP_OUT 0x01 +#define USBD_CDC_1_EP_OUT 0x03 + #define USBD_CDC_0_EP_IN 0x82 -#define USBD_CDC_1_EP_IN 0x85 +#define USBD_CDC_1_EP_IN 0x84 + #define USBD_CDC_CMD_MAX_SIZE 8 #define USBD_CDC_IN_OUT_MAX_SIZE 64 From 01e7831501d24f09463751b0141dd44dcf4aa2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 4 Nov 2022 11:00:31 +0100 Subject: [PATCH 20/28] uart-bridge: add UART RX interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 75 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/uart-bridge.c b/uart-bridge.c index 7a6ccab..407b676 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -26,6 +26,8 @@ typedef struct { uart_inst_t *const inst; + uint irq; + void *irq_fn; uint8_t tx_pin; uint8_t rx_pin; } uart_id_t; @@ -42,13 +44,20 @@ typedef struct { mutex_t usb_mtx; } uart_data_t; +void uart0_irq_fn(void); +void uart1_irq_fn(void); + const uart_id_t UART_ID[CFG_TUD_CDC] = { { .inst = uart0, + .irq = UART0_IRQ, + .irq_fn = &uart0_irq_fn, .tx_pin = 0, .rx_pin = 1, }, { .inst = uart1, + .irq = UART1_IRQ, + .irq_fn = &uart1_irq_fn, .tx_pin = 4, .rx_pin = 5, } @@ -119,14 +128,13 @@ void update_uart_cfg(uint8_t itf) mutex_exit(&ud->lc_mtx); } -void usb_read_bytes(uint8_t itf) { +void usb_read_bytes(uint8_t itf) +{ + uart_data_t *ud = &UART_DATA[itf]; uint32_t len = tud_cdc_n_available(itf); - if (len) { - uart_data_t *ud = &UART_DATA[itf]; - - mutex_enter_blocking(&ud->usb_mtx); - + if (len && + mutex_try_enter(&ud->usb_mtx, NULL)) { len = MIN(len, BUFFER_SIZE - ud->usb_pos); if (len) { uint32_t count; @@ -139,14 +147,14 @@ void usb_read_bytes(uint8_t itf) { } } -void usb_write_bytes(uint8_t itf) { +void usb_write_bytes(uint8_t itf) +{ uart_data_t *ud = &UART_DATA[itf]; - if (ud->uart_pos) { + if (ud->uart_pos && + mutex_try_enter(&ud->uart_mtx, NULL)) { uint32_t count; - mutex_enter_blocking(&ud->uart_mtx); - count = tud_cdc_n_write(itf, ud->uart_buffer, ud->uart_pos); if (count < ud->uart_pos) memcpy(ud->uart_buffer, &ud->uart_buffer[count], @@ -193,16 +201,16 @@ void core1_entry(void) } } -void uart_read_bytes(uint8_t itf) { +static inline void uart_read_bytes(uint8_t itf) +{ + uart_data_t *ud = &UART_DATA[itf]; const uart_id_t *ui = &UART_ID[itf]; if (uart_is_readable(ui->inst)) { - uart_data_t *ud = &UART_DATA[itf]; - mutex_enter_blocking(&ud->uart_mtx); while (uart_is_readable(ui->inst) && - ud->uart_pos < BUFFER_SIZE) { + (ud->uart_pos < BUFFER_SIZE)) { ud->uart_buffer[ud->uart_pos] = uart_getc(ui->inst); ud->uart_pos++; } @@ -211,22 +219,42 @@ void uart_read_bytes(uint8_t itf) { } } -void uart_write_bytes(uint8_t itf) { +void uart0_irq_fn(void) +{ + uart_read_bytes(0); +} + +void uart1_irq_fn(void) +{ + uart_read_bytes(1); +} + +void uart_write_bytes(uint8_t itf) +{ uart_data_t *ud = &UART_DATA[itf]; - if (ud->usb_pos) { + if (ud->usb_pos && + mutex_try_enter(&ud->usb_mtx, NULL)) { const uart_id_t *ui = &UART_ID[itf]; + uint32_t count = 0; - mutex_enter_blocking(&ud->usb_mtx); + while (uart_is_writable(ui->inst) && + count < ud->usb_pos) { + uart_putc(ui->inst, ud->usb_buffer[count]); + count++; + } - uart_write_blocking(ui->inst, ud->usb_buffer, ud->usb_pos); - ud->usb_pos = 0; + if (count < ud->usb_pos) + memcpy(ud->usb_buffer, &ud->usb_buffer[count], + ud->usb_pos - count); + ud->usb_pos -= count; mutex_exit(&ud->usb_mtx); } } -void init_uart_data(uint8_t itf) { +void init_uart_data(uint8_t itf) +{ const uart_id_t *ui = &UART_ID[itf]; uart_data_t *ud = &UART_DATA[itf]; @@ -261,6 +289,12 @@ void init_uart_data(uint8_t itf) { uart_set_format(ui->inst, databits_usb2uart(ud->usb_lc.data_bits), stopbits_usb2uart(ud->usb_lc.stop_bits), parity_usb2uart(ud->usb_lc.parity)); + uart_set_fifo_enabled(ui->inst, false); + + /* UART RX Interrupt */ + irq_set_exclusive_handler(ui->irq, ui->irq_fn); + irq_set_enabled(ui->irq, true); + uart_set_irq_enables(ui->inst, true, false); } int main(void) @@ -282,7 +316,6 @@ int main(void) while (1) { for (itf = 0; itf < CFG_TUD_CDC; itf++) { update_uart_cfg(itf); - uart_read_bytes(itf); uart_write_bytes(itf); } } From 3aa5d05fe3819d415ad5d97198fdeb00faab372d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 4 Nov 2022 11:08:49 +0100 Subject: [PATCH 21/28] Switch UART0 to GPIO 16 (TX) & GPIO 17 (RX) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- README.md | 4 ++-- uart-bridge.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c6a3967..8c5d87d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Raspberry Pi Pico Pinout | Raspberry Pi Pico GPIO | Function | |:----------------------:|:--------:| -| GPIO0 (Pin 1) | UART0 TX | -| GPIO1 (Pin 2) | UART0 RX | +| GPIO16 (Pin 21) | UART0 TX | +| GPIO17 (Pin 22) | UART0 RX | | GPIO4 (Pin 6) | UART1 TX | | GPIO5 (Pin 7) | UART1 RX | diff --git a/uart-bridge.c b/uart-bridge.c index 407b676..8564585 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -52,8 +52,8 @@ const uart_id_t UART_ID[CFG_TUD_CDC] = { .inst = uart0, .irq = UART0_IRQ, .irq_fn = &uart0_irq_fn, - .tx_pin = 0, - .rx_pin = 1, + .tx_pin = 16, + .rx_pin = 17, }, { .inst = uart1, .irq = UART1_IRQ, From 9d05ed4b1d36f5ea201051cbd1ae21d235dc9553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 4 Nov 2022 11:13:57 +0100 Subject: [PATCH 22/28] uart-bridge: avoid CR/LF conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uart-bridge.c b/uart-bridge.c index 8564585..e2aa518 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -240,7 +240,7 @@ void uart_write_bytes(uint8_t itf) while (uart_is_writable(ui->inst) && count < ud->usb_pos) { - uart_putc(ui->inst, ud->usb_buffer[count]); + uart_putc_raw(ui->inst, ud->usb_buffer[count]); count++; } From 67ce07178f1ebae63a319e3d19ab1084d64fe6e2 Mon Sep 17 00:00:00 2001 From: Michael Duda Date: Sun, 29 Jan 2023 11:49:11 -0700 Subject: [PATCH 23/28] Switch from memcpy to memmove when copying within buffers In the usb_write_bytes and uart_write_bytes routines, a memcpy was previously used to copy untransmitted bytes to the beginning of the buffer (ud->uart_buffer and ud->usb_buffer, respectively). Since the source and destination regions of memory may potentially overlap, the use of memcpy may lead to undefined results. From the draft C89 standard: 4.11.2.1 The memcpy function Synopsis #include void *memcpy(void *s1, const void *s2, size_t n); Description The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1 . If copying takes place between objects that overlap, the behavior is undefined. Returns The memcpy function returns the value of s1 . By using memmove rather than memcpy in the usb_write_bytes and uart_write_bytes routines, the potential for undefined behavior can be avoided. --- uart-bridge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uart-bridge.c b/uart-bridge.c index e2aa518..9791df6 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -157,7 +157,7 @@ void usb_write_bytes(uint8_t itf) count = tud_cdc_n_write(itf, ud->uart_buffer, ud->uart_pos); if (count < ud->uart_pos) - memcpy(ud->uart_buffer, &ud->uart_buffer[count], + memmove(ud->uart_buffer, &ud->uart_buffer[count], ud->uart_pos - count); ud->uart_pos -= count; @@ -245,7 +245,7 @@ void uart_write_bytes(uint8_t itf) } if (count < ud->usb_pos) - memcpy(ud->usb_buffer, &ud->usb_buffer[count], + memmove(ud->usb_buffer, &ud->usb_buffer[count], ud->usb_pos - count); ud->usb_pos -= count; From 2e3f10f756e1b65adf8cf05129ea14dc0eb46a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 10 Apr 2024 20:01:41 +0200 Subject: [PATCH 24/28] github: bump checkout to v4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bad1152..4a20fa5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: 'Check out code' - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 'Install dependencies' run: | From 2f05798e367f75270a55d781b9ec9d39b8a09740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 10 Apr 2024 20:02:38 +0200 Subject: [PATCH 25/28] github: bump upload-artifact to v4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a20fa5..0dfe717 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: make -C build - name: 'Upload binary' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pico-uart-bridge.uf2 path: build/uart_bridge.uf2 From b74af3b0d8aa27cb01193f1283394112809b2815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 10 Apr 2024 19:54:05 +0200 Subject: [PATCH 26/28] uart-bridge: restore clock speed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently, some boards do not support setting a higher CPU clock: https://github.com/Noltari/pico-uart-bridge/issues/11#issuecomment-2048104347 Signed-off-by: Álvaro Fernández Rojas --- uart-bridge.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/uart-bridge.c b/uart-bridge.c index 9791df6..c4e0805 100644 --- a/uart-bridge.c +++ b/uart-bridge.c @@ -301,8 +301,6 @@ int main(void) { int itf; - set_sys_clock_khz(250000, false); - usbd_serial_init(); for (itf = 0; itf < CFG_TUD_CDC; itf++) From c8a4bc513f0898e639421b10423d65e65cb81887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Thu, 11 Apr 2024 19:11:33 +0200 Subject: [PATCH 27/28] pico-sdk: update to v1.5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- pico-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pico-sdk b/pico-sdk index 2e6142b..6a7db34 160000 --- a/pico-sdk +++ b/pico-sdk @@ -1 +1 @@ -Subproject commit 2e6142b15b8a75c1227dd3edbe839193b2bf9041 +Subproject commit 6a7db34ff63345a7badec79ebea3aaef1712f374 From 9d0df3277dcbbbcc9dd5e847205407560f512194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Tue, 16 Apr 2024 12:22:25 +0200 Subject: [PATCH 28/28] github: ci: switch to ubuntu-22.04 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0dfe717..5478126 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,12 @@ name: CI -on: [push, pull_request] +on: + - push + - pull_request jobs: CI: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: 'Check out code' uses: actions/checkout@v4