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.
This commit is contained in:
@@ -9,20 +9,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -14,19 +14,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) //
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -9,19 +9,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -14,19 +14,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) //
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -9,20 +9,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -14,19 +14,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0x1FFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in "pins.h" reflects # of Pins defined here.
|
// Ensure Declaration in "pins.h" reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -9,19 +9,4 @@
|
|||||||
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
#define MICROPY_HW_FLASH_STORAGE_BYTES (0xFFFF)
|
||||||
#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages;
|
#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 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
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modmachine.h"
|
#include "modmachine.h"
|
||||||
|
#include "sam.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
|
|
||||||
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
// Ensure Declaration in 'pins.h' reflects # of Pins defined here.
|
||||||
|
|||||||
@@ -45,9 +45,6 @@
|
|||||||
#define DBL_TAP_MAGIC_LOADER 0xf01669ef
|
#define DBL_TAP_MAGIC_LOADER 0xf01669ef
|
||||||
#define DBL_TAP_MAGIC_RESET 0xf02669ef
|
#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) {
|
STATIC mp_obj_t machine_reset(void) {
|
||||||
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
|
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
|
||||||
NVIC_SystemReset();
|
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_mem16), MP_ROM_PTR(&machine_mem16_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_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_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_Pin), MP_ROM_PTR(&machine_pin_type) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) },
|
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,4 @@
|
|||||||
extern const mp_obj_type_t machine_pin_type;
|
extern const mp_obj_type_t machine_pin_type;
|
||||||
extern const mp_obj_type_t machine_led_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
|
#endif // MICROPY_INCLUDED_SAMD_MODMACHINE_H
|
||||||
|
|||||||
@@ -71,9 +71,6 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
|
|||||||
|
|
||||||
int mp_hal_stdin_rx_chr(void) {
|
int mp_hal_stdin_rx_chr(void) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (USARTx->USART.INTFLAG.bit.RXC) {
|
|
||||||
return USARTx->USART.DATA.bit.DATA;
|
|
||||||
}
|
|
||||||
if (tud_cdc_connected() && tud_cdc_available()) {
|
if (tud_cdc_connected() && tud_cdc_available()) {
|
||||||
uint8_t buf[1];
|
uint8_t buf[1];
|
||||||
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
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;
|
i += n2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (len--) {
|
|
||||||
while (!(USARTx->USART.INTFLAG.bit.DRE)) {
|
|
||||||
}
|
|
||||||
USARTx->USART.DATA.bit.DATA = *str++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,75 +35,6 @@
|
|||||||
#include "samd_soc.h"
|
#include "samd_soc.h"
|
||||||
#include "tusb.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) {
|
static void usb_init(void) {
|
||||||
// Init USB clock
|
// Init USB clock
|
||||||
#if defined(MCU_SAMD21)
|
#if defined(MCU_SAMD21)
|
||||||
@@ -168,6 +99,5 @@ void samd_init(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SysTick_Config(CPU_FREQ / 1000);
|
SysTick_Config(CPU_FREQ / 1000);
|
||||||
machine_uart_init();
|
|
||||||
usb_init();
|
usb_init();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user