Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for both uart and usb to work in parallel #312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions makefiles/samd21/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ BOARD ?= MZERO

#interface 0-USART 1-USB

INTERFACE ?= 1

# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)

Expand All @@ -105,8 +103,7 @@ BUILD_OPTIONS ?=
C_DEFS = $(BUILD_OPTIONS)\
-DSAMD21 \
-D__SAMD21E18A__ \
-DBOARD=BOARD_$(BOARD) \
-DINTERFACE=$(INTERFACE)
-DBOARD=BOARD_$(BOARD)

# AS includes
AS_INCLUDES =
Expand Down
4 changes: 2 additions & 2 deletions makefiles/samd21/samd21.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void SystemInit(void)
/* Set the correct number of wait states for 48 MHz @ 3.3v */
NVMCTRL->CTRLB.bit.RWS = 1;

#if (INTERFACE != INTERFACE_USB)
#ifndef MCU_HAS_USB
/* Crystal oscillators can take a long time to startup. This
waits the maximum amount of time (4 seconds). This can be
reduced depending on your crystal oscillator. */
Expand Down Expand Up @@ -188,7 +188,7 @@ void SystemInit(void)
{
};

#if (INTERFACE == INTERFACE_USB)
#ifdef MCU_HAS_USB
USB->DEVICE.QOSCTRL.bit.CQOS = 2;
USB->DEVICE.QOSCTRL.bit.DQOS = 2;
#endif
Expand Down
17 changes: 0 additions & 17 deletions uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ extern "C"
{
#endif

#define INTERFACE_UART 0
#define INTERFACE_USB 1

/**
* Serial COM
* Defines the serial COM baud rate
Expand All @@ -38,24 +35,10 @@ extern "C"
#define BAUDRATE 115200
#endif

#ifndef INTERFACE
#define INTERFACE INTERFACE_UART
#endif

#ifndef ENABLE_WIFI
// #define ENABLE_WIFI
#endif

/**
* uncomment to force enable synchronized TX/RX (used in USB VCP)
* enable these options to perform communications in the mcu tasks function
* call instead of being interrupt driven (sync RX may cause problems with
* hardware USART)
* */

// #define ENABLE_SYNC_TX
// #define ENABLE_SYNC_RX

/**
* Choose the board
* Check boards.h for list of available/supported boards
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/cnc_hal_config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1993,10 +1993,6 @@ extern "C"

#define SERVOS_MASK (SERVO0_MASK | SERVO1_MASK | SERVO2_MASK | SERVO3_MASK | SERVO4_MASK | SERVO5_MASK)

#if (INTERFACE < 0 || INTERFACE > 1)
#error "undefined COM interface"
#endif

#ifdef BRESENHAM_16BIT
#if (DSS_MAX_OVERSAMPLING < 0 || DSS_MAX_OVERSAMPLING > 3)
#error DSS_MAX_OVERSAMPLING invalid value! Should be set between 0 and 3
Expand Down Expand Up @@ -2130,6 +2126,10 @@ typedef uint16_t step_t;
#error "Invalid config option STATUS_AUTOMATIC_REPORT_INTERVAL must be set between 0 and 1000"
#endif

#if (defined(MCU_HAS_USB) || defined(MCU_HAS_WIFI) || defined(MCU_HAS_BLUETOOTH))
#define ENABLE_SYNC_TX
#endif

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions uCNC/src/hal/boards/esp32/boardmap_wemos_d1_r32.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ extern "C"
// #define PROBE_ISR

// Setup com pins
#if (INTERFACE == INTERFACE_UART)
#define RX_BIT 3
#define TX_BIT 1
// only uncomment this if other port other then 0 is used
// #define COM_PORT 0
#endif

// Setup PWM
#define PWM0_BIT 23 // assigns PWM0 pin
Expand Down
2 changes: 0 additions & 2 deletions uCNC/src/hal/boards/esp8266/boardmap_wemos_d1.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ extern "C"
//#define ESTOP_ISR

// Setup com pins
#if (INTERFACE == INTERFACE_UART)
#define RX_BIT 3
#define TX_BIT 1
#define RX_PORT D
#define TX_PORT D
// only uncomment this if other port other then 0 is used
// #define COM_PORT 0
#endif

// Setup PWM
#define PWM0_BIT 2 // assigns PWM0 pin
Expand Down
16 changes: 7 additions & 9 deletions uCNC/src/hal/boards/lpc176x/boardmap_mks_base13.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,18 @@ extern "C"
// #define PROBE_ISR -3

// Setup com pins
#if (INTERFACE == INTERFACE_UART)
#define RX_BIT 3
#define TX_BIT 2
#define RX_PORT 0
#define TX_PORT 0
// only uncomment this if other port other then 0 is used
//#define UART_PORT 0
#elif (INTERFACE == INTERFACE_USB)
// #define RX_BIT 3
// #define TX_BIT 2
// #define RX_PORT 0
// #define TX_PORT 0
// // only uncomment this if other port other then 0 is used
// //#define UART_PORT 0

// PIN A10 is also used because of the USB ID (USB OTG)
#define USB_DM_BIT 30
#define USB_DM_PORT 0
#define USB_DP_BIT 29
#define USB_DP_PORT 0
#endif

// // Setup PWM
#define PWM0_BIT 5 // assigns PWM0 pin
Expand Down
5 changes: 1 addition & 4 deletions uCNC/src/hal/boards/lpc176x/boardmap_re_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,17 @@ extern "C"
// #define PROBE_ISR -3

// Setup com pins
#if (INTERFACE == INTERFACE_UART)
#define RX_BIT 3
#define TX_BIT 2
#define RX_PORT 0
#define TX_PORT 0
// only uncomment this if other port other then 0 is used
//#define UART_PORT 0
#elif (INTERFACE == INTERFACE_USB)
// PIN A10 is also used because of the USB ID (USB OTG)

#define USB_DM_BIT 30
#define USB_DM_PORT 0
#define USB_DP_BIT 29
#define USB_DP_PORT 0
#endif

// // Setup PWM
#define PWM0_BIT 5 // assigns PWM0 pin
Expand Down
17 changes: 7 additions & 10 deletions uCNC/src/hal/boards/lpc176x/boardmap_skr_v14_turbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,17 @@ extern "C"
// #define PROBE_ISR -3

// Setup com pins
#if (INTERFACE == INTERFACE_UART)
#define RX_BIT 3
#define TX_BIT 2
#define RX_PORT 0
#define TX_PORT 0
// only uncomment this if other port other then 0 is used
//#define UART_PORT 0
#elif (INTERFACE == INTERFACE_USB)
// PIN A10 is also used because of the USB ID (USB OTG)
// #define RX_BIT 3
// #define TX_BIT 2
// #define RX_PORT 0
// #define TX_PORT 0
// // only uncomment this if other port other then 0 is used
// //#define UART_PORT 0

#define USB_DM_BIT 30
#define USB_DM_PORT 0
#define USB_DP_BIT 29
#define USB_DP_PORT 0
#endif

// // Setup PWM
#define PWM0_BIT 5 // assigns PWM0 pin
Expand Down
6 changes: 3 additions & 3 deletions uCNC/src/hal/boards/lpc176x/lpc176x.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ build_flags = ${common.build_flags} -D NXP_LPC17xx
[env:re_arm]
extends = common_lpc176x
board = nxp_lpc1768
build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_RE_ARM -D INTERFACE=1
build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_RE_ARM

[env:mks_base_v13]
extends = common_lpc176x
board = nxp_lpc1768
build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_MKS_BASE13 -D INTERFACE=1
build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_MKS_BASE13

[env:skr_v14_turbo]
extends = common_lpc176x
board = nxp_lpc1768
build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_SKR_V14_TURBO -D INTERFACE=1
build_flags = ${common_lpc176x.build_flags} -D BOARD=BOARD_SKR_V14_TURBO
4 changes: 1 addition & 3 deletions uCNC/src/hal/boards/samd21/boardmap_mzero.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,19 @@ extern "C"
// #define CS_RES_ISR

// On the STM32 always use sync TX UART (async doesn't work well)
#if (INTERFACE == INTERFACE_USART)
#define TX_BIT 10
#define TX_PORT A
#define RX_BIT 11
#define RX_PORT A
// set COM number. By default SERCOM2 if not set. Arduino IDE already uses SERCOM0 and SERCOM1
// #define UART_PORT 2
#elif (INTERFACE == INTERFACE_USB)

#define USB_DM_BIT 24
#define USB_DM_PORT A
#define USB_DM_MUX G
#define USB_DP_BIT 25
#define USB_DP_PORT A
#define USB_DP_MUX G
#endif

// Setup PWM
#define PWM0_BIT 16 // assigns PWM0 pin
Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/hal/boards/samd21/samd21.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ build_flags = ${common.build_flags} -nostdlib -fno-exceptions

[env:arduinoM0]
extends = common_samd21
build_flags = ${common_samd21.build_flags} -D BOARD=BOARD_MZERO -D INTERFACE=1
build_flags = ${common_samd21.build_flags} -D BOARD=BOARD_MZERO

[env:arduinoZero]
extends = common_samd21
build_flags = ${common_samd21.build_flags} -D BOARD=BOARD_ZERO -D INTERFACE=1
build_flags = ${common_samd21.build_flags} -D BOARD=BOARD_ZERO
11 changes: 1 addition & 10 deletions uCNC/src/hal/boards/stm32/boardmap_blackpill.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,17 @@ extern "C"
#define CS_RES_ISR
#define SAFETY_DOOR_ISR

#if (INTERFACE == INTERFACE_USART)
#define UART_PORT 1
#define TX_BIT 9
#define TX_PORT A
#define RX_BIT 10
#define RX_PORT A
#elif (INTERFACE == INTERFACE_USB)

// PIN A10 is also used because of the USB ID (USB OTG)
#define USB_DM_BIT 11
#define USB_DM_PORT A
#define USB_DP_BIT 12
#define USB_DP_PORT A
#define STEP4_BIT 3 // assigns STEP4 pin
#define STEP4_PORT A // assigns STEP4 port
#define DIR4_BIT 7 // assigns DIR4 pin
#define DIR4_PORT A // assigns DIR4 port
#define LIMIT_B_BIT 11 // assigns LIMIT_A pin
#define LIMIT_B_PORT B // assigns LIMIT_A port
#define LIMIT_B_ISR
#endif

// Setup PWM
#define PWM0_BIT 8 // assigns PWM0 pin
Expand Down
17 changes: 1 addition & 16 deletions uCNC/src/hal/boards/stm32/boardmap_bluepill.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,16 @@ extern "C"
#define CS_RES_ISR
#define SAFETY_DOOR_ISR

#if (INTERFACE == INTERFACE_USART)
#define UART_PORT 1
#define TX_BIT 9
#define TX_PORT A
#define RX_BIT 10
#define RX_PORT A
#elif (INTERFACE == INTERFACE_USB)

#define USB_DM_BIT 11
#define USB_DM_PORT A
#define USB_DP_BIT 12
#define USB_DP_PORT A
// #define STEP4_BIT 3 // assigns STEP4 pin
// #define STEP4_PORT A // assigns STEP4 port
// #define DIR4_BIT 7 // assigns DIR4 pin
// #define DIR4_PORT A // assigns DIR4 port
// #define LIMIT_B_BIT 11 // assigns LIMIT_A pin
// #define LIMIT_B_PORT B // assigns LIMIT_A port
// #define LIMIT_B_ISR

#define DOUT27_BIT 9
#define DOUT27_PORT A
#define DIN27_BIT 10
#define DIN27_PORT A
#define DIN27_PULLUP
#endif

// Setup PWM
#define PWM0_BIT 8 // assigns PWM0 pin
Expand Down
4 changes: 0 additions & 4 deletions uCNC/src/hal/boards/stm32/boardmap_mks_robin_nano_v1_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,11 @@ extern "C"
#define PROBE_PORT A
#define PROBE_ISR

#if (INTERFACE == INTERFACE_USART)
#define UART_PORT 3
#define TX_BIT 10
#define TX_PORT B
#define RX_BIT 11
#define RX_PORT B
#else
#error "This board uses an external USB<->Serial converter"
#endif

// Setup PWM
#define PWM0_BIT 0 // assigns PWM0 pin
Expand Down
15 changes: 7 additions & 8 deletions uCNC/src/hal/boards/stm32/boardmap_srk_pro_v1_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,17 @@ extern "C"
#define PROBE_PORT G
#define PROBE_ISR

#if (INTERFACE == INTERFACE_USART)
#define UART_PORT 3
#define TX_BIT 10
#define TX_PORT B
#define RX_BIT 11
#define RX_PORT B
#elif (INTERFACE == INTERFACE_USB)
// #define UART_PORT 3
// #define TX_BIT 10
// #define TX_PORT B
// #define RX_BIT 11
// #define RX_PORT B

#define USB_DM_BIT 11
#define USB_DM_PORT A
#define USB_DP_BIT 12
#define USB_DP_PORT A
#endif


// Setup PWM
#define PWM0_BIT 1 // assigns PWM0 pin
Expand Down
Loading