summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-05-27 15:43:48 +0200
committerDamien George <damien@micropython.org>2022-10-06 22:29:06 +1100
commit85afed569d3d435b2611856356ff9c78d244f25c (patch)
tree2cc71880093d528c01b194db8172b9440fc33de2
parent46d02c2469ec7947fe3aae2d68e07236baf5c72e (diff)
samd: Remove the existing provisional support for REPL on UART.
It was only partially working and will be rpelaced later by a full machine.UART class implementation.
-rw-r--r--ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h16
-rw-r--r--ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.c1
-rw-r--r--ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h15
-rw-r--r--ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.c1
-rw-r--r--ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h15
-rw-r--r--ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.c1
-rw-r--r--ports/samd/boards/MINISAM_M4/mpconfigboard.h15
-rw-r--r--ports/samd/boards/MINISAM_M4/pins.c1
-rw-r--r--ports/samd/boards/SAMD21_XPLAINED_PRO/mpconfigboard.h16
-rw-r--r--ports/samd/boards/SAMD21_XPLAINED_PRO/pins.c1
-rw-r--r--ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h15
-rw-r--r--ports/samd/boards/SEEED_WIO_TERMINAL/pins.c1
-rw-r--r--ports/samd/boards/SEEED_XIAO/mpconfigboard.h15
-rw-r--r--ports/samd/boards/SEEED_XIAO/pins.c1
-rw-r--r--ports/samd/modmachine.c5
-rw-r--r--ports/samd/modmachine.h3
-rw-r--r--ports/samd/mphalport.c8
-rw-r--r--ports/samd/samd_soc.c70
18 files changed, 7 insertions, 193 deletions
diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h
index 6d3b7987e..bdb22d2e0 100644
--- a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h
+++ b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/mpconfigboard.h
@@ -9,20 +9,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
-// ASF4 MCU package specific Pin definitions
-#include "samd21g18a.h"
-
-// Please consult the SAM_D21 Datasheet, I/O Multiplexing and Considerations.
-// On this board (see https://learn.adafruit.com/assets/40553) TX is D1 (PA10) and RX is D0 (PA11)
-// USART pin assignments: Tx=PA10=SERCOM0/PAD[2], Rx=PA11==SERCOM0/PAD[3]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 0 // A=0, B=1
-#define MP_TX_PIN 10 // 'n'
-#define MP_RX_PIN 11
-#define MP_PERIPHERAL_MUX 5 // 'n'th group of 2 pins
-#define USARTx SERCOM0 // SERCOM0: tx/rx
-#define MP_PORT_FUNC 0x22 // Sets PMUXE & PMUXO to the Alternative Function.(A-H=0-7)
-#define MP_RXPO_PAD 3 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 1 // TXPO- Transmit Data Pinout
-#define MP_SERCOMx SERCOM0_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE GCLK_CLKCTRL_ID_SERCOM0_CORE // Generic Clock Control
diff --git a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.c b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.c
index e0dd752ec..fbb5032a4 100644
--- a/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.c
+++ b/ports/samd/boards/ADAFRUIT_FEATHER_M0_EXPRESS/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h
index c1c4fd8ca..80baf39e5 100644
--- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h
+++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h
@@ -14,19 +14,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) //
-// ASF4 MCU package specific Pin definitions
-#include "samd51g19a.h"
-
-// Please consult the SAM_D51 Datasheet, I/O Multiplexing and Considerations.
-// USART pin assignments: Tx=TX_D1=PA17=SERCOM3/PAD[0], Rx=RX_D0=PA16=SERCOM3/PAD[1]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 1 // A-D=0-3
-#define MP_TX_PIN 17
-#define MP_RX_PIN 16 // 'n'
-#define MP_PERIPHERAL_MUX 8 // 'n'th group of 2 pins
-#define USARTx SERCOM3 //
-#define MP_PORT_FUNC 0x33 // Sets PMUXE & PMUXO to the Alternative Function.A-N=0-13
-#define MP_RXPO_PAD 1 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 0 // TXPO- Tranmit Data Pinout
-#define MP_SERCOMx SERCOM3_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE SERCOM3_GCLK_ID_CORE
diff --git a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.c b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.c
index 82948ccbc..0342b0d00 100644
--- a/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.c
+++ b/ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
diff --git a/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h
index 128689f4f..066c7ee14 100644
--- a/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h
+++ b/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h
@@ -9,19 +9,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
-// ASF4 MCU package specific Pin definitions
-#include "samd21e18a.h"
-
-// Please consult the SAM_D21 Datasheet, I/O Multiplexing and Considerations.
-// USART pin assignments: Tx=D4=PA06=SERCOM0/PAD[2], Rx=D3=PA07=SERCOM0/PAD[3]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 1 // A=0, B=1
-#define MP_TX_PIN 6 // 'n'
-#define MP_RX_PIN 7
-#define MP_PERIPHERAL_MUX 3 // 'n'th group of 2 pins
-#define USARTx SERCOM0 // SERCOM0: tx/rx
-#define MP_PORT_FUNC 0x33 // Sets PMUXE & PMUXO to the Alternative Function.A-H=0-7
-#define MP_RXPO_PAD 3 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 2 // TXPO- Tranmit Data Pinout
-#define MP_SERCOMx SERCOM0_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE GCLK_CLKCTRL_ID_SERCOM0_CORE // Generic Clock Control
diff --git a/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.c b/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.c
index 9fecddb6c..676b4794e 100644
--- a/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.c
+++ b/ports/samd/boards/ADAFRUIT_TRINKET_M0/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
diff --git a/ports/samd/boards/MINISAM_M4/mpconfigboard.h b/ports/samd/boards/MINISAM_M4/mpconfigboard.h
index a65eb54b4..a8f1f9624 100644
--- a/ports/samd/boards/MINISAM_M4/mpconfigboard.h
+++ b/ports/samd/boards/MINISAM_M4/mpconfigboard.h
@@ -14,19 +14,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) //
-// ASF4 MCU package specific Pin definitions
-#include "samd51g19a.h"
-
-// Please consult the SAM_D51 Datasheet, I/O Multiplexing and Considerations.
-// USART pin assignments: Tx=TX_D1=PA17=SERCOM3/PAD[0], Rx=RX_D0=PA16=SERCOM3/PAD[1]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 0 // A-D=0-3
-#define MP_TX_PIN 17
-#define MP_RX_PIN 16 // 'n'
-#define MP_PERIPHERAL_MUX 8 // 'n'th group of 2 pins
-#define USARTx SERCOM3 //
-#define MP_PORT_FUNC 0x33 // Sets PMUXE & PMUXO to the Alternative Function.A-N=0-13
-#define MP_RXPO_PAD 1 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 0 // TXPO- Tranmit Data Pinout
-#define MP_SERCOMx SERCOM3_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE SERCOM3_GCLK_ID_CORE
diff --git a/ports/samd/boards/MINISAM_M4/pins.c b/ports/samd/boards/MINISAM_M4/pins.c
index 6cdd840b6..17ed58d3c 100644
--- a/ports/samd/boards/MINISAM_M4/pins.c
+++ b/ports/samd/boards/MINISAM_M4/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
diff --git a/ports/samd/boards/SAMD21_XPLAINED_PRO/mpconfigboard.h b/ports/samd/boards/SAMD21_XPLAINED_PRO/mpconfigboard.h
index a7dbf7614..860cb6b97 100644
--- a/ports/samd/boards/SAMD21_XPLAINED_PRO/mpconfigboard.h
+++ b/ports/samd/boards/SAMD21_XPLAINED_PRO/mpconfigboard.h
@@ -9,20 +9,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
-// ASF4 MCU package specific Pin definitions
-#include "samd21j18a.h"
-
-// Please consult the SAM_D21 Datasheet, I/O Multiplexing and Considerations.
-// USART pin assignments: (This board has 3 USARTS brought out to the pins. See https://docs.zephyrproject.org/1.14.1/boards/arm/atsamd21_xpro/doc/index.html#serial-port )
-// Tx=PA10=SERCOM0/PAD[2], Rx=PA11=SERCOM0/PAD[3]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 1 // A=0, B=1
-#define MP_TX_PIN 10 // 'n'
-#define MP_RX_PIN 11
-#define MP_PERIPHERAL_MUX 5 // 'n'th group of 2 pins
-#define USARTx SERCOM0 // SERCOM0: tx/rx
-#define MP_PORT_FUNC 0x22 // Sets PMUXE & PMUXO to the Alternative Function.(A-H=0-7)
-#define MP_RXPO_PAD 3 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 2 // TXPO- Tranmit Data Pinout
-#define MP_SERCOMx SERCOM0_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE GCLK_CLKCTRL_ID_SERCOM0_CORE // Generic Clock Control
diff --git a/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.c b/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.c
index 2a2d50eb4..35718ea7f 100644
--- a/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.c
+++ b/ports/samd/boards/SAMD21_XPLAINED_PRO/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h b/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h
index 290bd802b..bb0f1c828 100644
--- a/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h
+++ b/ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h
@@ -14,19 +14,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
-// ASF4 MCU package specific Pin definitions
-#include "samd51p19a.h"
-
-// Please consult the SAM_D51 Datasheet, I/O Multiplexing and Considerations.
-// WIO_Terminal USART pin assignments: Tx=BCM14=PB27=SERCOM2/PAD[0], Rx=BCM15=PB26=SERCOM2/PAD[1]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 1 // A-D=0-3
-#define MP_TX_PIN 27
-#define MP_RX_PIN 26 // 'n'
-#define MP_PERIPHERAL_MUX 13 // 'n'th group of 2 pins
-#define USARTx SERCOM2 //
-#define MP_PORT_FUNC 0x22 // Sets PMUXE & PMUXO to the Alternative Function.A-N=0-13
-#define MP_RXPO_PAD 1 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 0 // TXPO- Tranmit Data Pinout
-#define MP_SERCOMx SERCOM2_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE SERCOM2_GCLK_ID_CORE
diff --git a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.c b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.c
index 9862552fa..d7833416d 100644
--- a/ports/samd/boards/SEEED_WIO_TERMINAL/pins.c
+++ b/ports/samd/boards/SEEED_WIO_TERMINAL/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in "pins.h" reflects # of Pins defined here.
diff --git a/ports/samd/boards/SEEED_XIAO/mpconfigboard.h b/ports/samd/boards/SEEED_XIAO/mpconfigboard.h
index 6422d7ea0..a2f2a9fb0 100644
--- a/ports/samd/boards/SEEED_XIAO/mpconfigboard.h
+++ b/ports/samd/boards/SEEED_XIAO/mpconfigboard.h
@@ -9,19 +9,4 @@
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
-// ASF4 MCU package specific Pin definitions
-#include "samd21g18a.h"
-
-// Please consult the SAM_D21 Datasheet, I/O Multiplexing and Considerations.
-// XIAO_M0 USART pin assignments: Tx=A6=PB8=SERCOM4/PAD[0], Rx=PB9=A7=SERCOM4/PAD[1]
#define CPU_FREQ (48000000) // For selecting Baud from clock.
-#define MP_PIN_GRP 1 // A=0, B=1
-#define MP_TX_PIN 8 // 'n'
-#define MP_RX_PIN 9
-#define MP_PERIPHERAL_MUX 4 // 'n'th group of 2 pins
-#define USARTx SERCOM4 // SERCOM4:XIAO_M0 tx/rx
-#define MP_PORT_FUNC 0x33 // Sets PMUXE & PMUXO to the Alternative Function.A-H=0-7
-#define MP_RXPO_PAD 1 // RXPO- Receive Data Pinout
-#define MP_TXPO_PAD 0 // TXPO- Tranmit Data Pinout
-#define MP_SERCOMx SERCOM4_ // APBCMASK
-#define MP_SERCOM_GCLK_ID_x_CORE GCLK_CLKCTRL_ID_SERCOM4_CORE // Generic Clock Control
diff --git a/ports/samd/boards/SEEED_XIAO/pins.c b/ports/samd/boards/SEEED_XIAO/pins.c
index 6043913d2..e2f7c264b 100644
--- a/ports/samd/boards/SEEED_XIAO/pins.c
+++ b/ports/samd/boards/SEEED_XIAO/pins.c
@@ -27,6 +27,7 @@
*/
#include "modmachine.h"
+#include "sam.h"
#include "pins.h"
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c
index 74e357175..1b78b687e 100644
--- a/ports/samd/modmachine.c
+++ b/ports/samd/modmachine.c
@@ -45,9 +45,6 @@
#define DBL_TAP_MAGIC_LOADER 0xf01669ef
#define DBL_TAP_MAGIC_RESET 0xf02669ef
-MP_DEFINE_CONST_FUN_OBJ_0(machine_uart_init_obj, machine_uart_init);
-MP_DEFINE_CONST_FUN_OBJ_0(machine_uart_deinit_obj, machine_uart_deinit);
-
STATIC mp_obj_t machine_reset(void) {
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
NVIC_SystemReset();
@@ -119,8 +116,6 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) },
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) },
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
- { MP_ROM_QSTR(MP_QSTR_uart_init), MP_ROM_PTR(&machine_uart_init_obj) },
- { MP_ROM_QSTR(MP_QSTR_uart_deinit), MP_ROM_PTR(&machine_uart_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) },
};
diff --git a/ports/samd/modmachine.h b/ports/samd/modmachine.h
index 61bd2f4d2..f7ad2b5e5 100644
--- a/ports/samd/modmachine.h
+++ b/ports/samd/modmachine.h
@@ -31,7 +31,4 @@
extern const mp_obj_type_t machine_pin_type;
extern const mp_obj_type_t machine_led_type;
-mp_obj_t machine_uart_init(void);
-mp_obj_t machine_uart_deinit(void);
-
#endif // MICROPY_INCLUDED_SAMD_MODMACHINE_H
diff --git a/ports/samd/mphalport.c b/ports/samd/mphalport.c
index c19d542a8..beade14a6 100644
--- a/ports/samd/mphalport.c
+++ b/ports/samd/mphalport.c
@@ -71,9 +71,6 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
int mp_hal_stdin_rx_chr(void) {
for (;;) {
- if (USARTx->USART.INTFLAG.bit.RXC) {
- return USARTx->USART.DATA.bit.DATA;
- }
if (tud_cdc_connected() && tud_cdc_available()) {
uint8_t buf[1];
uint32_t count = tud_cdc_read(buf, sizeof(buf));
@@ -100,9 +97,4 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
i += n2;
}
}
- while (len--) {
- while (!(USARTx->USART.INTFLAG.bit.DRE)) {
- }
- USARTx->USART.DATA.bit.DATA = *str++;
- }
}
diff --git a/ports/samd/samd_soc.c b/ports/samd/samd_soc.c
index 7f4df1bb1..7a96cbb48 100644
--- a/ports/samd/samd_soc.c
+++ b/ports/samd/samd_soc.c
@@ -35,75 +35,6 @@
#include "samd_soc.h"
#include "tusb.h"
-// "MP" macros defined in "boards/$(BOARD)/mpconfigboard.h"
-mp_obj_t machine_uart_init(void) {
- // Firstly, assign alternate function SERCOM PADs to GPIO pins.
- PORT->Group[MP_PIN_GRP].PINCFG[MP_TX_PIN].bit.PMUXEN = 1; // Enable
- PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PMUXEN = 1; // Enable
- PORT->Group[MP_PIN_GRP].PMUX[MP_PERIPHERAL_MUX].reg = MP_PORT_FUNC; // Sets PMUXE & PMUXO in 1 hit.
- uint32_t rxpo = MP_RXPO_PAD; // 1=Pad1,3=Pad3 Rx data
- uint32_t txpo = MP_TXPO_PAD; // 0=pad0,1=Pad2 Tx data
-
- // Initialise the clocks
- #if defined(MCU_SAMD21)
- PM->APBCMASK.bit.MP_SERCOMx = 1; // Enable synchronous clock
- GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | MP_SERCOM_GCLK_ID_x_CORE; // Select multiplexer generic clock source and enable.
- // Wait while it updates synchronously.
- while (GCLK->STATUS.bit.SYNCBUSY) {
- }
- #elif defined(MCU_SAMD51)
- GCLK->PCHCTRL[MP_SERCOM_GCLK_ID_x_CORE].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN_GCLK0;
- MCLK->APBBMASK.bit.MP_SERCOMx = 1;
- #endif
-
- // Setup the Peripheral.
- // Reset (clear) the peripheral registers.
- while (USARTx->USART.SYNCBUSY.bit.SWRST) {
- }
- USARTx->USART.CTRLA.bit.SWRST = 1; // Reset all Registers, disable peripheral
- while (USARTx->USART.SYNCBUSY.bit.SWRST) {
- }
-
- // Set the register bits as needed
- // (CMODE (async),CHSIZE (8),FORM (no parity),SBMODE (1 stop) already 0).
- USARTx->USART.CTRLA.reg = // USARTx = SERCOMx set in "boards/$(BOARD)/mpconfigboard.h"
- SERCOM_USART_CTRLA_DORD // Data order
- | SERCOM_USART_CTRLA_RXPO(rxpo) // Set Pad#
- | SERCOM_USART_CTRLA_TXPO(txpo) // Set Pad#
- | SERCOM_USART_CTRLA_MODE(1) // USART with internal clock
- ;
- USARTx->USART.CTRLB.reg = SERCOM_USART_CTRLB_RXEN | SERCOM_USART_CTRLB_TXEN; // Enable Rx & Tx
- while (USARTx->USART.SYNCBUSY.bit.CTRLB) {
- }
-
- // Baud rate is clock dependant.
- #if CPU_FREQ == 8000000
- uint32_t baud = 50437; // 115200 baud; 65536*(1 - 16 * 115200/8e6)
- #elif CPU_FREQ == 48000000
- uint32_t baud = 63019; // 115200 baud; 65536*(1 - 16 * 115200/48e6)
- #elif CPU_FREQ == 120000000
- uint32_t baud = 64529; // 115200 baud; 65536*(1 - 16 * 115200/120e6)
- #endif
- USARTx->USART.BAUD.bit.BAUD = baud; // Set Baud
- USARTx->USART.CTRLA.bit.ENABLE = 1; // Enable the peripheral
- // Wait for the Registers to update.
- while (USARTx->USART.SYNCBUSY.bit.ENABLE) {
- }
-
- return mp_const_none;
-}
-
-// Disconnect SERCOM from GPIO pins. (Can't SWRST, as that will totally kill USART).
-mp_obj_t machine_uart_deinit(void) {
- // Reset
- printf("Disabling the Alt-Funct, releasing the USART pins for GPIO... \n");
- PORT->Group[MP_PIN_GRP].PINCFG[MP_TX_PIN].bit.PMUXEN = 0; // Disable
- PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PMUXEN = 0; // Disable
-
- return mp_const_none;
-}
-
-
static void usb_init(void) {
// Init USB clock
#if defined(MCU_SAMD21)
@@ -168,6 +99,5 @@ void samd_init(void) {
#endif
SysTick_Config(CPU_FREQ / 1000);
- machine_uart_init();
usb_init();
}