From e09ebea7b99e3385bc1b1d326923b0a36003275d Mon Sep 17 00:00:00 2001 From: Jan Dümpelmann Date: Fri, 4 Sep 2020 17:25:32 +0200 Subject: Remove tud_cdc_connected check from examples --- examples/device/cdc_dual_ports/src/main.c | 15 ++++++--------- examples/device/cdc_msc/src/main.c | 29 +++++++++++++---------------- examples/device/cdc_msc_freertos/src/main.c | 29 +++++++++++++---------------- 3 files changed, 32 insertions(+), 41 deletions(-) (limited to 'examples') diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index d6e38df85..813639179 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -83,18 +83,15 @@ static void cdc_task(void) for (itf = 0; itf < CFG_TUD_CDC; itf++) { - if ( tud_cdc_n_connected(itf) ) + if ( tud_cdc_n_available(itf) ) { - if ( tud_cdc_n_available(itf) ) - { - uint8_t buf[64]; + uint8_t buf[64]; - uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); + uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); - // echo back to both serial ports - echo_serial_port(0, buf, count); - echo_serial_port(1, buf, count); - } + // echo back to both serial ports + echo_serial_port(0, buf, count); + echo_serial_port(1, buf, count); } } } diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index a407e2ddd..bcf05eaac 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -105,34 +105,31 @@ void tud_resume_cb(void) //--------------------------------------------------------------------+ void cdc_task(void) { - if ( tud_cdc_connected() ) + // is data available to read from rx fifo + if ( tud_cdc_available() ) { - // connected and there are data available - if ( tud_cdc_available() ) - { - uint8_t buf[64]; - - // read and echo back - uint32_t count = tud_cdc_read(buf, sizeof(buf)); + uint8_t buf[64]; - for(uint32_t i=0; i Date: Wed, 18 Nov 2020 09:47:39 +0100 Subject: Reset CDC examples to original state --- examples/device/cdc_dual_ports/src/main.c | 15 +++++++++------ examples/device/cdc_msc/src/main.c | 29 ++++++++++++++++------------- examples/device/cdc_msc_freertos/src/main.c | 29 ++++++++++++++++------------- 3 files changed, 41 insertions(+), 32 deletions(-) (limited to 'examples') diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index 813639179..d6e38df85 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -83,15 +83,18 @@ static void cdc_task(void) for (itf = 0; itf < CFG_TUD_CDC; itf++) { - if ( tud_cdc_n_available(itf) ) + if ( tud_cdc_n_connected(itf) ) { - uint8_t buf[64]; + if ( tud_cdc_n_available(itf) ) + { + uint8_t buf[64]; - uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); + uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); - // echo back to both serial ports - echo_serial_port(0, buf, count); - echo_serial_port(1, buf, count); + // echo back to both serial ports + echo_serial_port(0, buf, count); + echo_serial_port(1, buf, count); + } } } } diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index bcf05eaac..a407e2ddd 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -105,31 +105,34 @@ void tud_resume_cb(void) //--------------------------------------------------------------------+ void cdc_task(void) { - // is data available to read from rx fifo - if ( tud_cdc_available() ) + if ( tud_cdc_connected() ) { - uint8_t buf[64]; + // connected and there are data available + if ( tud_cdc_available() ) + { + uint8_t buf[64]; - // read and echo back - uint32_t count = tud_cdc_read(buf, sizeof(buf)); + // read and echo back + uint32_t count = tud_cdc_read(buf, sizeof(buf)); - for(uint32_t i=0; i Date: Wed, 18 Nov 2020 10:16:32 +0100 Subject: Changes to CDC example code: - auto flush welcome message at connection event - provide information to the user if the terminal did not set DTR --- examples/device/cdc_msc/src/main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'examples') diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index a407e2ddd..e4477927f 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -137,6 +137,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { // print initial message when connected tud_cdc_write_str("\r\nTinyUSB CDC MSC device example\r\n"); + tud_cdc_write_flush(); } } @@ -144,6 +145,16 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) void tud_cdc_rx_cb(uint8_t itf) { (void) itf; + uint8_t const line_state = tud_cdc_get_line_state(); + + // Provide information that terminal did not set DTR bit + if( !(line_state & 0x01) ) + { + tud_cdc_write_str("\r\nTinyUSB example: Your terminal did not set DTR bit\r\n"); + tud_cdc_write_flush(); + // Clear rx fifo since we do not read the data + tud_cdc_read_flush(); + } } //--------------------------------------------------------------------+ -- cgit v1.3.1 From 61ad7bef7140d8e06343a5ce4e15d3a2fe7f158a Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Nov 2020 15:50:11 +0700 Subject: migrate vendor device to new control xfer cb --- examples/device/webusb_serial/src/main.c | 19 +++++++------------ src/device/usbd.c | 3 +-- src/device/usbd.h | 4 ---- 3 files changed, 8 insertions(+), 18 deletions(-) (limited to 'examples') diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c index e1a098048..9309bbf6e 100644 --- a/examples/device/webusb_serial/src/main.c +++ b/examples/device/webusb_serial/src/main.c @@ -143,9 +143,14 @@ void tud_resume_cb(void) // WebUSB use vendor class //--------------------------------------------------------------------+ -// Invoked when received VENDOR control request -bool tud_vendor_control_request_cb(uint8_t rhport, tusb_control_request_t const * request) +// Invoked when a control transfer occurred on an interface of this class +// Driver response accordingly to the request and the transfer stage (setup/data/ack) +// return false to stall control endpoint (e.g unsupported request) +bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) { + // nothing to with DATA & ACK stage + if (stage != CONTROL_STAGE_SETUP ) return true; + switch (request->bRequest) { case VENDOR_REQUEST_WEBUSB: @@ -194,16 +199,6 @@ bool tud_vendor_control_request_cb(uint8_t rhport, tusb_control_request_t const return true; } -// Invoked when DATA Stage of VENDOR's request is complete -bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_request_t const * request) -{ - (void) rhport; - (void) request; - - // nothing to do - return true; -} - void webserial_task(void) { if ( web_serial_connected ) diff --git a/src/device/usbd.c b/src/device/usbd.c index b629a1ff8..9773245c8 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -158,8 +158,7 @@ static usbd_class_driver_t const _usbd_driver[] = .init = vendord_init, .reset = vendord_reset, .open = vendord_open, - .control_xfer_cb = tud_vendor_control_request_cb, - .control_complete = tud_vendor_control_complete_cb, + .control_xfer_cb = tud_vendor_control_xfer_cb, .xfer_cb = vendord_xfer_cb, .sof = NULL }, diff --git a/src/device/usbd.h b/src/device/usbd.h index cf7e9f0db..ef248e4ca 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -127,10 +127,6 @@ TU_ATTR_WEAK void tud_resume_cb(void); // Invoked when received control request with VENDOR TYPE TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); -// Invoked when vendor control request is complete -TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_request_t const * request); - - //--------------------------------------------------------------------+ // Binary Device Object Store (BOS) Descriptor Templates //--------------------------------------------------------------------+ -- cgit v1.3.1 From 4b4f88078503648b38444feee1fda322b65baa43 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 23 Nov 2020 23:40:13 +0700 Subject: add tud_ready() check in tud_cdc_n_write_flush() other clean up --- examples/device/cdc_msc/src/main.c | 10 ---------- src/class/cdc/cdc_device.c | 19 +++++++++++++------ src/common/tusb_fifo.c | 2 +- src/common/tusb_fifo.h | 2 +- 4 files changed, 15 insertions(+), 18 deletions(-) (limited to 'examples') diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index e4477927f..cf2bfd7c9 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -145,16 +145,6 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) void tud_cdc_rx_cb(uint8_t itf) { (void) itf; - uint8_t const line_state = tud_cdc_get_line_state(); - - // Provide information that terminal did not set DTR bit - if( !(line_state & 0x01) ) - { - tud_cdc_write_str("\r\nTinyUSB example: Your terminal did not set DTR bit\r\n"); - tud_cdc_write_flush(); - // Clear rx fifo since we do not read the data - tud_cdc_read_flush(); - } } //--------------------------------------------------------------------+ diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index bd1d9b0d4..58f485a5d 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -178,6 +178,9 @@ uint32_t tud_cdc_n_write_flush (uint8_t itf) { cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; + // Skip if usb is not ready yet + TU_VERIFY( tud_ready(), 0 ); + // No data to send if ( !tu_fifo_count(&p_cdc->tx_ff) ) return 0; @@ -231,9 +234,10 @@ void cdcd_init(void) p_cdc->line_coding.parity = 0; p_cdc->line_coding.data_bits = 8; - // config fifo + // Config RX fifo tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1, false); - // tx fifo is set to overwritable at initialization and will be changed to not overwritable + + // Config TX fifo as overwritable at initialization and will be changed to non-overwritable // if terminal supports DTR bit. Without DTR we do not know if data is actually polled by terminal. // In this way, the most current data is prioritized. tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true); @@ -251,9 +255,12 @@ void cdcd_reset(uint8_t rhport) for(uint8_t i=0; irx_ff); + tu_fifo_clear(&p_cdc->tx_ff); + tu_fifo_set_overwritable(&p_cdc->tx_ff, true); } } @@ -381,7 +388,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t p_cdc->line_state = (uint8_t) request->wValue; // Disable fifo overwriting if DTR bit is set - tu_fifo_set_mode(&p_cdc->tx_ff, !dtr); + tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr); TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts); diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 444c60f96..608bfd081 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -607,7 +607,7 @@ bool tu_fifo_clear(tu_fifo_t *f) Overwritable mode the fifo is set to */ /******************************************************************************/ -bool tu_fifo_set_mode(tu_fifo_t *f, bool overwritable) +bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable) { tu_fifo_lock(f); diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h index abb301b5f..b965386ab 100644 --- a/src/common/tusb_fifo.h +++ b/src/common/tusb_fifo.h @@ -89,7 +89,7 @@ typedef struct .non_used_index_space = 0xFFFF - 2*_depth-1, \ } -bool tu_fifo_set_mode(tu_fifo_t *f, bool overwritable); +bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable); bool tu_fifo_clear(tu_fifo_t *f); bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable); -- cgit v1.3.1 From 7860469661711bc9f73b2ae84529511693245d7b Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Nov 2020 00:06:59 +0700 Subject: comment out and add note for tud_cdc_connected() in cdc_msc examples --- examples/device/cdc_dual_ports/src/main.c | 2 ++ examples/device/cdc_msc/src/main.c | 6 ++++-- examples/device/cdc_msc_freertos/src/main.c | 9 ++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index d6e38df85..198c4252b 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -83,6 +83,8 @@ static void cdc_task(void) for (itf = 0; itf < CFG_TUD_CDC; itf++) { + // connected() check for DTR bit + // Most but not all terminal client set this when making connection if ( tud_cdc_n_connected(itf) ) { if ( tud_cdc_n_available(itf) ) diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index cf2bfd7c9..6b13ba5a4 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -105,7 +105,9 @@ void tud_resume_cb(void) //--------------------------------------------------------------------+ void cdc_task(void) { - if ( tud_cdc_connected() ) + // connected() check for DTR bit + // Most but not all terminal client set this when making connection + // if ( tud_cdc_connected() ) { // connected and there are data available if ( tud_cdc_available() ) @@ -133,7 +135,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) (void) itf; // connected - if ( dtr && rts ) + if ( dtr ) { // print initial message when connected tud_cdc_write_str("\r\nTinyUSB CDC MSC device example\r\n"); diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index 1371b84c3..3d2e6dc49 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -168,9 +168,11 @@ void cdc_task(void* params) // RTOS forever loop while ( 1 ) { - if ( tud_cdc_connected() ) + // connected() check for DTR bit + // Most but not all terminal client set this when making connection + // if ( tud_cdc_connected() ) { - // connected and there are data available + // There are data available if ( tud_cdc_available() ) { uint8_t buf[64]; @@ -200,10 +202,11 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) (void) itf; // connected - if ( dtr && rts ) + if ( dtr ) { // print initial message when connected tud_cdc_write_str("\r\nTinyUSB CDC MSC device with FreeRTOS example\r\n"); + tud_cdc_write_flush(); } } -- cgit v1.3.1 From 409a5fb7fc772b9f5f0c590c1688f5c5d001d167 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Nov 2020 00:18:18 +0700 Subject: fix ci build --- examples/device/cdc_msc_freertos/src/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index 3d2e6dc49..e90c3f0d9 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -200,6 +200,7 @@ void cdc_task(void* params) void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { (void) itf; + (void) rts; // connected if ( dtr ) -- cgit v1.3.1 From 494e125432ca3eb6faa5de2896cfb8e2e7143ddb Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 24 Nov 2020 00:47:06 +0700 Subject: more ci --- examples/device/cdc_msc/src/main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index 6b13ba5a4..a20a80fcd 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -133,6 +133,7 @@ void cdc_task(void) void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { (void) itf; + (void) rts; // connected if ( dtr ) -- cgit v1.3.1 From 94527951a0fef9c1383ff9a3bbc8167f21008f4e Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 27 Nov 2020 15:54:55 +0700 Subject: add bus suspend & resume support for esp32s2 --- examples/device/hid_composite_freertos/src/main.c | 7 ++++++- src/portable/espressif/esp32s2/dcd_esp32s2.c | 18 +++++++++++++++++- src/portable/st/synopsys/dcd_synopsys.c | 8 ++++---- 3 files changed, 27 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c index de065ee64..83c68b515 100644 --- a/examples/device/hid_composite_freertos/src/main.c +++ b/examples/device/hid_composite_freertos/src/main.c @@ -58,7 +58,12 @@ StaticTimer_t blinky_tmdef; TimerHandle_t blinky_tm; // static task for usbd -#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) +#if CFG_TUSB_DEBUG + #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE) +#else + #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) +#endif + StackType_t usb_device_stack[USBD_STACK_SIZE]; StaticTask_t usb_device_taskdef; diff --git a/src/portable/espressif/esp32s2/dcd_esp32s2.c b/src/portable/espressif/esp32s2/dcd_esp32s2.c index 58d92e728..81e63816e 100644 --- a/src/portable/espressif/esp32s2/dcd_esp32s2.c +++ b/src/portable/espressif/esp32s2/dcd_esp32s2.c @@ -218,6 +218,9 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) void dcd_remote_wakeup(uint8_t rhport) { (void)rhport; + + // TODO must manually clear this bit after 1-15 ms + // USB0.DCTL |= USB_RMTWKUPSIG_M; } // connect by enabling internal pull-up resistor on D+/D- @@ -670,6 +673,7 @@ static void handle_epin_ints(void) static void _dcd_int_handler(void* arg) { (void) arg; + uint8_t const rhport = 0; const uint32_t int_status = USB0.gintsts; //const uint32_t int_msk = USB0.gintmsk; @@ -695,7 +699,19 @@ static void _dcd_int_handler(void* arg) // the end of reset. USB0.gintsts = USB_ENUMDONE_M; enum_done_processing(); - dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true); + dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true); + } + + if(int_status & USB_USBSUSP_M) + { + USB0.gintsts = USB_USBSUSP_M; + dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true); + } + + if(int_status & USB_WKUPINT_M) + { + USB0.gintsts = USB_WKUPINT_M; + dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true); } if (int_status & USB_OTGINT_M) diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c index 9aeec79e6..c18dcde51 100644 --- a/src/portable/st/synopsys/dcd_synopsys.c +++ b/src/portable/st/synopsys/dcd_synopsys.c @@ -507,21 +507,21 @@ void dcd_set_address (uint8_t rhport, uint8_t dev_addr) void dcd_remote_wakeup(uint8_t rhport) { (void) rhport; + + // TODO must manually clear this bit after 1-15 ms + // USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport); + // dev->DCTL |= USB_OTG_DCTL_RWUSIG; } void dcd_connect(uint8_t rhport) { - (void) rhport; USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport); - dev->DCTL &= ~USB_OTG_DCTL_SDIS; } void dcd_disconnect(uint8_t rhport) { - (void) rhport; USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport); - dev->DCTL |= USB_OTG_DCTL_SDIS; } -- cgit v1.3.1 From fc18cd4cbbd7307548f54f3e7f27c031e6e3c926 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 25 Dec 2020 23:20:45 +0700 Subject: skip overflow sram examples for kl25 --- examples/device/cdc_msc_freertos/.skip.MCU_MKL25ZXX | 0 examples/device/msc_dual_lun/.skip.MCU_MKL25ZXX | 0 examples/device/net_lwip_webserver/.skip.MCU_MKL25ZXX | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/device/cdc_msc_freertos/.skip.MCU_MKL25ZXX create mode 100644 examples/device/msc_dual_lun/.skip.MCU_MKL25ZXX create mode 100644 examples/device/net_lwip_webserver/.skip.MCU_MKL25ZXX (limited to 'examples') diff --git a/examples/device/cdc_msc_freertos/.skip.MCU_MKL25ZXX b/examples/device/cdc_msc_freertos/.skip.MCU_MKL25ZXX new file mode 100644 index 000000000..e69de29bb diff --git a/examples/device/msc_dual_lun/.skip.MCU_MKL25ZXX b/examples/device/msc_dual_lun/.skip.MCU_MKL25ZXX new file mode 100644 index 000000000..e69de29bb diff --git a/examples/device/net_lwip_webserver/.skip.MCU_MKL25ZXX b/examples/device/net_lwip_webserver/.skip.MCU_MKL25ZXX new file mode 100644 index 000000000..e69de29bb -- cgit v1.3.1 From 8fa083d79e1325c19f2bc0af894fdf7f8ab5e84c Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Sun, 10 Jan 2021 20:46:29 +0900 Subject: added support for cmd.exe as a shell on make. --- examples/make.mk | 5 +++++ examples/rules.mk | 10 ++++++++++ tools/top.mk | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/make.mk b/examples/make.mk index 6743044fd..ee4ed640e 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -34,9 +34,14 @@ CXX = $(CROSS_COMPILE)g++ OBJCOPY = $(CROSS_COMPILE)objcopy SIZE = $(CROSS_COMPILE)size MKDIR = mkdir +ifeq ($(UNAME),Windows) +CP = copy +RM = del +else SED = sed CP = cp RM = rm +endif #-------------- Source files and compiler flags -------------- diff --git a/examples/rules.mk b/examples/rules.mk index 37e0e7a19..a445f0339 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -81,7 +81,11 @@ uf2: $(BUILD)/$(BOARD)-firmware.uf2 OBJ_DIRS = $(sort $(dir $(OBJ))) $(OBJ): | $(OBJ_DIRS) $(OBJ_DIRS): +ifeq ($(UNAME),Windows) + @$(MKDIR) $(subst /,\,$@) +else @$(MKDIR) -p $@ +endif $(BUILD)/$(BOARD)-firmware.elf: $(OBJ) @echo LINK $@ @@ -107,6 +111,7 @@ vpath %.c . $(TOP) $(BUILD)/obj/%.o: %.c @echo CC $(notdir $@) @$(CC) $(CFLAGS) -c -MD -o $@ $< +ifneq ($(UNAME),Windows) @# The following fixes the dependency file. @# See http://make.paulandlesley.org/autodep.html for details. @# Regex adjusted from the above to play better with Windows paths, etc. @@ -114,6 +119,7 @@ $(BUILD)/obj/%.o: %.c $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ $(RM) $(@:.o=.d) +endif # ASM sources lower case .s vpath %.s . $(TOP) @@ -134,7 +140,11 @@ size: $(BUILD)/$(BOARD)-firmware.elf .PHONY: clean clean: +ifeq ($(UNAME),Windows) + rd /S /Q $(subst /,\,$(BUILD)) +else $(RM) -rf $(BUILD) +endif # Print out the value of a make variable. # https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile diff --git a/tools/top.mk b/tools/top.mk index be51b3f4f..d276f5814 100644 --- a/tools/top.mk +++ b/tools/top.mk @@ -2,6 +2,12 @@ ifneq ($(lastword a b),b) $(error This Makefile require make 3.81 or newer) endif +# Detect windows or not +# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 +ifeq '$(findstring ;,$(PATH))' ';' +UNAME := Windows +endif + # Set TOP to be the path to get from the current directory (where make was # invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns # the name of this makefile relative to where make was invoked. @@ -9,9 +15,16 @@ endif THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) +ifeq ($(UNAME),Windows) +TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) +else TOP := $(shell realpath $(TOP)) - +endif #$(info Top directory is $(TOP)) +ifeq ($(UNAME),Windows) +CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) +else CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`) +endif #$(info Path from top is $(CURRENT_PATH)) -- cgit v1.3.1 From d7cfd8b91db127459d61aa8b8d091cb08e732208 Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Thu, 14 Jan 2021 01:19:43 +0900 Subject: replaced variable name to CMDEXE from UNAME. removed the rule that .d files are converted to .P files. --- examples/make.mk | 2 +- examples/rules.mk | 13 ++----------- hw/bsp/adafruit_clue/board.mk | 2 +- hw/bsp/arduino_nano33_ble/board.mk | 2 +- hw/bsp/circuitplayground_bluefruit/board.mk | 2 +- hw/bsp/feather_nrf52840_express/board.mk | 2 +- hw/bsp/feather_nrf52840_sense/board.mk | 2 +- hw/bsp/itsybitsy_nrf52840/board.mk | 2 +- hw/bsp/nrf52840_mdk_dongle/board.mk | 2 +- hw/bsp/pca10056/board.mk | 2 +- hw/bsp/pca10059/board.mk | 2 +- hw/bsp/pca10100/board.mk | 2 +- hw/bsp/raytac_mdbt50q_rx/board.mk | 2 +- tools/top.mk | 8 ++++---- 14 files changed, 18 insertions(+), 27 deletions(-) (limited to 'examples') diff --git a/examples/make.mk b/examples/make.mk index ee4ed640e..992a4e60e 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -34,7 +34,7 @@ CXX = $(CROSS_COMPILE)g++ OBJCOPY = $(CROSS_COMPILE)objcopy SIZE = $(CROSS_COMPILE)size MKDIR = mkdir -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) CP = copy RM = del else diff --git a/examples/rules.mk b/examples/rules.mk index a445f0339..2274d1cd2 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -81,7 +81,7 @@ uf2: $(BUILD)/$(BOARD)-firmware.uf2 OBJ_DIRS = $(sort $(dir $(OBJ))) $(OBJ): | $(OBJ_DIRS) $(OBJ_DIRS): -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) @$(MKDIR) $(subst /,\,$@) else @$(MKDIR) -p $@ @@ -111,15 +111,6 @@ vpath %.c . $(TOP) $(BUILD)/obj/%.o: %.c @echo CC $(notdir $@) @$(CC) $(CFLAGS) -c -MD -o $@ $< -ifneq ($(UNAME),Windows) - @# The following fixes the dependency file. - @# See http://make.paulandlesley.org/autodep.html for details. - @# Regex adjusted from the above to play better with Windows paths, etc. - @$(CP) $(@:.o=.d) $(@:.o=.P); \ - $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ - -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ - $(RM) $(@:.o=.d) -endif # ASM sources lower case .s vpath %.s . $(TOP) @@ -140,7 +131,7 @@ size: $(BUILD)/$(BOARD)-firmware.elf .PHONY: clean clean: -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) rd /S /Q $(subst /,\,$(BUILD)) else $(RM) -rf $(BUILD) diff --git a/hw/bsp/adafruit_clue/board.mk b/hw/bsp/adafruit_clue/board.mk index ef6e093f5..3db045ac0 100644 --- a/hw/bsp/adafruit_clue/board.mk +++ b/hw/bsp/adafruit_clue/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/arduino_nano33_ble/board.mk b/hw/bsp/arduino_nano33_ble/board.mk index 63d1550d1..1ee8867e6 100644 --- a/hw/bsp/arduino_nano33_ble/board.mk +++ b/hw/bsp/arduino_nano33_ble/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/circuitplayground_bluefruit/board.mk b/hw/bsp/circuitplayground_bluefruit/board.mk index ef6e093f5..3db045ac0 100644 --- a/hw/bsp/circuitplayground_bluefruit/board.mk +++ b/hw/bsp/circuitplayground_bluefruit/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/feather_nrf52840_express/board.mk b/hw/bsp/feather_nrf52840_express/board.mk index 2feb070a8..059e55dff 100644 --- a/hw/bsp/feather_nrf52840_express/board.mk +++ b/hw/bsp/feather_nrf52840_express/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/feather_nrf52840_sense/board.mk b/hw/bsp/feather_nrf52840_sense/board.mk index ef6e093f5..3db045ac0 100644 --- a/hw/bsp/feather_nrf52840_sense/board.mk +++ b/hw/bsp/feather_nrf52840_sense/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/itsybitsy_nrf52840/board.mk b/hw/bsp/itsybitsy_nrf52840/board.mk index 2feb070a8..059e55dff 100644 --- a/hw/bsp/itsybitsy_nrf52840/board.mk +++ b/hw/bsp/itsybitsy_nrf52840/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/nrf52840_mdk_dongle/board.mk b/hw/bsp/nrf52840_mdk_dongle/board.mk index baa4cc22e..3c44e402c 100644 --- a/hw/bsp/nrf52840_mdk_dongle/board.mk +++ b/hw/bsp/nrf52840_mdk_dongle/board.mk @@ -13,7 +13,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/pca10056/board.mk b/hw/bsp/pca10056/board.mk index 3ea85983d..b8691525b 100644 --- a/hw/bsp/pca10056/board.mk +++ b/hw/bsp/pca10056/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/pca10059/board.mk b/hw/bsp/pca10059/board.mk index e9bc890cf..178f09474 100644 --- a/hw/bsp/pca10059/board.mk +++ b/hw/bsp/pca10059/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/pca10100/board.mk b/hw/bsp/pca10100/board.mk index 0b4d42f22..8ada94ba0 100644 --- a/hw/bsp/pca10100/board.mk +++ b/hw/bsp/pca10100/board.mk @@ -14,7 +14,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/hw/bsp/raytac_mdbt50q_rx/board.mk b/hw/bsp/raytac_mdbt50q_rx/board.mk index 6ff079dd7..2c29acfa6 100644 --- a/hw/bsp/raytac_mdbt50q_rx/board.mk +++ b/hw/bsp/raytac_mdbt50q_rx/board.mk @@ -13,7 +13,7 @@ CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align # due to tusb_hal_nrf_power_event GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion))) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) ifeq ($(shell if $(GCCVERSION) geq 8 echo 1), 1) CFLAGS += -Wno-error=cast-function-type endif diff --git a/tools/top.mk b/tools/top.mk index d276f5814..84523a557 100644 --- a/tools/top.mk +++ b/tools/top.mk @@ -2,10 +2,10 @@ ifneq ($(lastword a b),b) $(error This Makefile require make 3.81 or newer) endif -# Detect windows or not +# Detect whether shell style is windows or not # https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 ifeq '$(findstring ;,$(PATH))' ';' -UNAME := Windows +CMDEXE := 1 endif # Set TOP to be the path to get from the current directory (where make was @@ -15,14 +15,14 @@ endif THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) else TOP := $(shell realpath $(TOP)) endif #$(info Top directory is $(TOP)) -ifeq ($(UNAME),Windows) +ifeq ($(CMDEXE),1) CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) else CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`) -- cgit v1.3.1