8000 samd: Some tailoring of the SAMD51 build for convenience. · micropython/micropython@233463b · GitHub
[go: up one dir, main page]

Skip to content

Commit 233463b

Browse files
committed
samd: Some tailoring of the SAMD51 build for convenience.
- Support executing .mpy files. - Fix UART REPL config error - Enable Pull on UART RX. Now, that UART works, it avoids a crosstalk when the input not wired. - Do not use UART for REPL when not initialized. The standard behavior enables REPL on UART at boot time. That can be disabled using machine.uart_deinit() and re-enabled again with machine.uart_init(). uart_deinit() disabled until now only the gpio port configuration, but data was still sent to the UART module. This commit stops using UART after uart_deinit() was called. - use -Og for DEBUG builds, whuch creates a smaller image. - Skip mp_hal_time_ns() for regular builds. - Set the CPU freq to 120MHz for SAM51 devices. This is temporary and does not fit to the SAMD21 build with DEBUG enabled.
1 parent 8cd552f commit 233463b

File tree

9 files changed

+44
-19
lines changed

9 files changed

+44
-19
lines changed

ports/samd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
5757

5858
# Tune for Debugging or Optimization
5959
ifeq ($(DEBUG),1)
60-
CFLAGS += -O0 -ggdb
60+
CFLAGS += -Og -ggdb
6161
else
6262
CFLAGS += -Os -DNDEBUG
6363
LDFLAGS += --gc-sections

ports/samd/boards/ADAFRUIT_ITSYBITSY_M4_EXPRESS/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
// Please consult the SAM_D51 Datasheet, I/O Multiplexing and Considerations.
2121
// USART pin assignments: Tx=TX_D1=PA17=SERCOM3/PAD[0], Rx=RX_D0=PA16=SERCOM3/PAD[1]
22-
#define CPU_FREQ (48000000) // For selecting Baud from clock.
23-
#define MP_PIN_GRP 1 // A-D=0-3
22+
#define CPU_FREQ (120000000) // For selecting Baud from clock.
23+
#define MP_PIN_GRP 0 // A-D=0-3
2424
#define MP_TX_PIN 17
2525
#define MP_RX_PIN 16 // 'n'
2626
#define MP_PERIPHERAL_MUX 8 // 'n'th group of 2 pins

ports/samd/boards/MINISAM_M4/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// Please consult the SAM_D51 Datasheet, I/O Multiplexing and Considerations.
2121
// USART pin assignments: Tx=TX_D1=PA17=SERCOM3/PAD[0], Rx=RX_D0=PA16=SERCOM3/PAD[1]
22-
#define CPU_FREQ (48000000) // For selecting Baud from clock.
22+
#define CPU_FREQ (120000000) // For selecting Baud from clock.
2323
#define MP_PIN_GRP 0 // A-D=0-3
2424
#define MP_TX_PIN 17
2525
#define MP_RX_PIN 16 // 'n'

ports/samd/boards/SEEED_WIO_TERMINAL/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// Please consult the SAM_D51 Datasheet, I/O Multiplexing and Considerations.
2121
// WIO_Terminal USART pin assignments: Tx=BCM14=PB27=SERCOM2/PAD[0], Rx=BCM15=PB26=SERCOM2/PAD[1]
22-
#define CPU_FREQ (48000000) // For selecting Baud from clock.
22+
#define CPU_FREQ (120000000) // For selecting Baud from clock.
2323
#define MP_PIN_GRP 1 // A-D=0-3
2424
#define MP_TX_PIN 27
2525
#define MP_RX_PIN 26 // 'n'

ports/samd/mpconfigport.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@
2929
// Board specific definitions
3030
#include "mpconfigboard.h"
3131

32+
#ifndef MICROPY_CONFIG_ROM_LEVEL
33+
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES)
34+
#endif
35+
36+
#define MICROPY_HW_ENABLE_UART_REPL (1)
37+
3238
// Memory allocation policies
3339
#define MICROPY_GC_STACK_ENTRY_TYPE uint16_t
3440
#define MICROPY_GC_ALLOC_THRESHOLD (0)
3541
#define MICROPY_ALLOC_PARSE_CHUNK_INIT (32)
3642
#define MICROPY_ALLOC_PATH_MAX (256)
3743
#define MICROPY_QSTR_BYTES_IN_HASH (1)
3844

45+
// MicroPython emitters
46+
#define MICROPY_PERSISTENT_CODE_LOAD (1)
47+
3948
// Compiler configuration
40-
#define MICROPY_COMP_CONST (0)
49+
#define MICROPY_COMP_CONST (1)
4150

4251
// Python internal features
4352
#define MICROPY_ENABLE_GC (1)
@@ -55,21 +64,22 @@
5564
// fixes sys/usys import issue
5665
#define MICROPY_MODULE_WEAK_LINKS (1)
5766
// Control over Python builtins
67+
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
5868
#define MICROPY_PY_ASYNC_AWAIT (0)
5969
#define MICROPY_PY_BUILTINS_STR_COUNT (0)
6070
#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
6171
#define MICROPY_PY_BUILTINS_SET (0)
6272
#define MICROPY_PY_BUILTINS_FROZENSET (0)
6373
#define MICROPY_PY_BUILTINS_PROPERTY (0)
64-
#define MICROPY_PY_BUILTINS_ENUMERATE (0)
74+
#define MICROPY_PY_BUILTINS_ENUMERATE (1)
6575
#define MICROPY_PY_BUILTINS_FILTER (0)
6676
#define MICROPY_PY_BUILTINS_REVERSED (0)
6777
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
68-
#define MICROPY_PY_BUILTINS_MIN_MAX (0)
78+
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
6979
#define MICROPY_PY___FILE__ (0)
7080
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
7181
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
72-
#define MICROPY_PY_ATTRTUPLE (0)
82+
#define MICROPY_PY_ATTRTUPLE (1)
7383
#define MICROPY_PY_COLLECTIONS (0)
7484
#define MICROPY_PY_SYS (1)
7585
#define MICROPY_PY_SYS_PLATFORM "samd"

ports/samd/mphalport.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#endif
3737

3838
STATIC uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN];
39-
ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) };
39+
ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0 };
4040

4141
uint8_t cdc_itf_pending; // keep track of cdc interfaces which need attention to poll
4242

@@ -95,19 +95,21 @@ void mp_hal_delay_us(mp_uint_t us) {
9595

9696
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
9797
uintptr_t ret = 0;
98-
poll_cdc_interfaces();
99-
if ((poll_flags & MP_STREAM_POLL_RD) && ringbuf_peek(&stdin_ringbuf) != -1) {
98+
if (enable_uart_repl && USARTx->USART.INTFLAG.bit.RXC) {
10099
ret |= MP_STREAM_POLL_RD;
101100
}
102-
if (USARTx->USART.INTFLAG.bit.RXC) {
101+
102+
poll_cdc_interfaces();
103+
if ((poll_flags & MP_STREAM_POLL_RD) && ringbuf_peek(&stdin_ringbuf) != -1) {
103104
ret |= MP_STREAM_POLL_RD;
104105
}
106+
105107
return ret;
106108
}
107109

108110
int mp_hal_stdin_rx_chr(void) {
109111
for (;;) {
110-
if (USARTx->USART.INTFLAG.bit.RXC) {
112+
if (enable_uart_repl && USARTx->USART.INTFLAG.bit.RXC) {
111113
return USARTx->USART.DATA.bit.DATA;
112114
}
113115

@@ -135,9 +137,11 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
135137
i += n2;
136138
}
137139
}
138-
while (len--) {
139-
while (!(USARTx->USART.INTFLAG.bit.DRE)) {
140+
if (enable_uart_repl) {
141+
while (len--) {
142+
while (!(USARTx->USART.INTFLAG.bit.DRE)) {
143+
}
144+
USARTx->USART.DATA.bit.DATA = *str++;
140145
}
141-
USARTx->USART.DATA.bit.DATA = *str++;
142146
}
143147
}

ports/samd/mphalport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ static inline mp_uint_t mp_hal_ticks_us(void) {
4949
static inline mp_uint_t mp_hal_ticks_cpu(void) {
5050
return 0;
5151
}
52-
52+
#ifndef NDEBUG
5353
static inline uint64_t mp_hal_time_ns(void) {
5454
return systick_ms * 1000000;
5555
}
56+
#endif
5657
// C-level pin HAL
5758

5859
#include "py/obj.h"

ports/samd/samd_soc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535
#include "samd_soc.h"
3636
#include "tusb.h"
3737

38+
uint8_t enable_uart_repl = false;
39+
3840
// "MP" macros defined in "boards/$(BOARD)/mpconfigboard.h"
3941
mp_obj_t machine_uart_init(void) {
4042
// Firstly, assign alternate function SERCOM PADs to GPIO pins.
4143
PORT->Group[MP_PIN_GRP].PINCFG[MP_TX_PIN].bit.PMUXEN = 1; // Enable
42-
PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PMUXEN = 1; // Enable
44+
PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PULLEN = 1; // Enable Pull avoiding crosstalk
45+
PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PMUXEN = 1; // Enable MUX
4346
PORT->Group[MP_PIN_GRP].PMUX[MP_PERIPHERAL_MUX].reg = MP_PORT_FUNC; // Sets PMUXE & PMUXO in 1 hit.
4447
uint32_t rxpo = MP_RXPO_PAD; // 1=Pad1,3=Pad3 Rx data
4548
uint32_t txpo = MP_TXPO_PAD; // 0=pad0,1=Pad2 Tx data
@@ -90,15 +93,18 @@ mp_obj_t machine_uart_init(void) {
9093
while (USARTx->USART.SYNCBUSY.bit.ENABLE) {
9194
}
9295

96+
enable_uart_repl = true;
9397
E850 return mp_const_none;
9498
}
9599

96100
// Disconnect SERCOM from GPIO pins. (Can't SWRST, as that will totally kill USART).
97101
mp_obj_t machine_uart_deinit(void) {
98102
// Reset
103+
enable_uart_repl = false;
99104
printf("Disabling the Alt-Funct, releasing the USART pins for GPIO... \n");
100105
PORT->Group[MP_PIN_GRP].PINCFG[MP_TX_PIN].bit.PMUXEN = 0; // Disable
101106
PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PMUXEN = 0; // Disable
107+
PORT->Group[MP_PIN_GRP].PINCFG[MP_RX_PIN].bit.PULLEN = 0; // Disable Pull
102108

103109
return mp_const_none;
104110
}
@@ -168,6 +174,8 @@ void samd_init(void) {
168174
#endif
169175

170176
SysTick_Config(CPU_FREQ / 1000);
177+
#if MICROPY_HW_ENABLE_UART_REPL
171178
machine_uart_init();
179+
#endif
172180
usb_init();
173181
}

ports/samd/samd_soc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ void USB_1_Handler_wrapper(void);
3838
void USB_2_Handler_wrapper(void);
3939
void USB_3_Handler_wrapper(void);
4040

41+
extern uint8_t enable_uart_repl;
42+
4143
#endif // MICROPY_INCLUDED_SAMD_SAMD_SOC_H

0 commit comments

Comments
 (0)
0