Skip to content

Commit 0c4f9b8

Browse files
committed
Enable REPL over USB.
All of the code was there except the linker was failing to clear the bss section because I added too many .zeros. The should have only been the exported globals that start with _ like _szero = .. Fixing that and turn on the usb transmit fixed everything.
1 parent 386ab58 commit 0c4f9b8

File tree

6 files changed

+48
-66
lines changed

6 files changed

+48
-66
lines changed

atmel-samd/README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ M0 BLE.
77
## Building
88

99
The Makefile has the ability to build for a SAMD21x18, and by default
10-
includes some start-up code and also enables a UART for communication. To build:
10+
includes some start-up code and also enables a UART for communication. To
11+
build:
1112

1213
make CROSS=1
1314

14-
It will build for the Arduino Zero by default. You may change it by setting `BOARD`. For example:
15+
It will build for the Arduino Zero by default. You may change it by setting
16+
`BOARD`. For example:
1517

1618
make CROSS=1 BOARD=feather_m0_ble
1719

@@ -20,14 +22,17 @@ Board names are the directory names in the `boards` folder.
2022
## Deploying
2123

2224
### Arduino Bootloader
23-
If your board has an existing Arduino bootloader on it then you can use bossac to flash MicroPython. After building run:
25+
If your board has an existing Arduino bootloader on it then you can use bossac
26+
to flash MicroPython. After building run:
2427

2528
tools/bossac_osx -e -w -v -b build-feather_m0_ble/firmware.bin
2629

2730
### No Bootloader via GDB
28-
This method works for loading MicroPython onto the Arduino Zero via the programming port rather than the native USB port.
31+
This method works for loading MicroPython onto the Arduino Zero via the
32+
programming port rather than the native USB port.
2933

30-
Note: These instructions are tested on Mac OSX and will vary for different platforms.
34+
Note: These instructions are tested on Mac OSX and will vary for different
35+
platforms.
3136

3237
openocd -f ~/Library/Arduino15/packages/arduino/hardware/samd/1.6.6/variants/arduino_zero/openocd_scripts/arduino_zero.cfg
3338

@@ -43,8 +48,10 @@ In another terminal from `micropython/atmel-samd`:
4348
(gdb) continue
4449

4550
## Connecting
46-
The current Atmel SAMD implementation only works over UART. To connect to it from OSX do something like this:
51+
All boards are currently configured to work over USB rather than UART. To
52+
connect to it from OSX do something like this:
4753

4854
screen /dev/tty.usbmodem142422 115200
4955

50-
You may not see a prompt immediately because it doesn't know you connected. To get one either hit enter to get `>>>` or do CTRL-B to get the full header.
56+
You may not see a prompt immediately because it doesn't know you connected. To
57+
get one either hit enter to get `>>>` or do CTRL-B to get the full header.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// LEDs
22
#define MICROPY_HW_LED1 PIN_PA17 // red
3-
#define UART_REPL
4-
// #define USB_REPL
3+
// #define UART_REPL
4+
#define USB_REPL
55

66
#define MICROPY_HW_BOARD_NAME "Arduino Zero"
77
#define MICROPY_HW_MCU_NAME "samd21g18"

atmel-samd/boards/samd21x18-bootloader.ld

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ SECTIONS
4040
{
4141
. = ALIGN(4);
4242
_srelocate = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
43+
*(.ramfunc)
44+
*(.ramfunc*)
4345
*(.data) /* .data sections */
4446
*(.data*) /* .data* sections */
4547

@@ -48,28 +50,18 @@ SECTIONS
4850
} >RAM
4951

5052
/* Uninitialized data section */
51-
.ramfunc :
52-
{
53-
. = ALIGN(4);
54-
_sramfunc = .; /* define a global symbol at ramfunc start; used by startup code */
55-
*(.ramfunc)
56-
*(.ramfunc*)
57-
58-
. = ALIGN(4);
59-
_eramfunc = .; /* define a global symbol at ramfunc end; used by startup code */
60-
} >RAM
61-
62-
/* Uninitialized data section */
63-
.zero :
53+
.bss :
6454
{
6555
. = ALIGN(4);
56+
_sbss = .;
6657
_szero = .; /* define a global symbol at bss start; used by startup code */
67-
*(.zero)
68-
*(.zero*)
58+
*(.bss)
59+
*(.bss*)
6960
*(COMMON)
7061

7162
. = ALIGN(4);
7263
_ezero = .; /* define a global symbol at bss end; used by startup code */
64+
_ebss = .;
7365
} >RAM
7466

7567
.ARM.attributes 0 : { *(.ARM.attributes) }

atmel-samd/boards/samd21x18.ld

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ SECTIONS
2828

2929
. = ALIGN(4);
3030
_etext = .; /* define a global symbol at end of code */
31-
_sidata = _etext; /* This is used by the startup in order to initialize the .data secion */
31+
_sidata = _etext; /* This is used by the startup in order to initialize the .data section */
3232
} >FLASH
3333

34-
3534
/* This is the initialized data section
3635
The program executes knowing that the data is in the RAM
3736
but the loader puts the initial values in the FLASH (inidata).
@@ -40,6 +39,8 @@ SECTIONS
4039
{
4140
. = ALIGN(4);
4241
_srelocate = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
42+
*(.ramfunc)
43+
*(.ramfunc*)
4344
*(.data) /* .data sections */
4445
*(.data*) /* .data* sections */
4546

@@ -48,28 +49,18 @@ SECTIONS
4849
} >RAM
4950

5051
/* Uninitialized data section */
51-
.ramfunc :
52-
{
53-
. = ALIGN(4);
54-
_sramfunc = .; /* define a global symbol at ramfunc start; used by startup code */
55-
*(.ramfunc)
56-
*(.ramfunc*)
57-
58-
. = ALIGN(4);
59-
_eramfunc = .; /* define a global symbol at ramfunc end; used by startup code */
60-
} >RAM
61-
62-
/* Uninitialized data section */
63-
.zero :
52+
.bss :
6453
{
6554
. = ALIGN(4);
55+
_sbss = .;
6656
_szero = .; /* define a global symbol at bss start; used by startup code */
67-
*(.zero)
68-
*(.zero*)
57+
*(.bss)
58+
*(.bss*)
6959
*(COMMON)
7060

7161
. = ALIGN(4);
7262
_ezero = .; /* define a global symbol at bss end; used by startup code */
63+
_ebss = .;
7364
} >RAM
7465

7566
.ARM.attributes 0 : { *(.ARM.attributes) }

atmel-samd/main.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,22 @@ void samd21_init(void) {
127127

128128
delay_init();
129129

130-
struct port_config pin_conf;
131-
port_get_config_defaults(&pin_conf);
132-
133-
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
134-
port_pin_set_config(MICROPY_HW_LED1, &pin_conf);
135-
port_pin_set_output_level(MICROPY_HW_LED1, false);
136-
137-
// Start USB stack to authorize VBus monitoring
138-
for (int i = 0; i < 10; i++) {
139-
port_pin_toggle_output_level(MICROPY_HW_LED1);
140-
delay_ms(100);
141-
}
130+
// Uncomment to init PIN_PA17 for debugging.
131+
// struct port_config pin_conf;
132+
// port_get_config_defaults(&pin_conf);
133+
//
134+
// pin_conf.direction = PORT_PIN_DIR_OUTPUT;
135+
// port_pin_set_config(MICROPY_HW_LED1, &pin_conf);
136+
// port_pin_set_output_level(MICROPY_HW_LED1, false);
137+
142138
#ifdef USB_REPL
143139
udc_start();
144140
#endif
145-
for (int i = 0; i < 10; i++) {
146-
port_pin_toggle_output_level(MICROPY_HW_LED1);
147-
delay_ms(200);
148-
}
149141

150142
// TODO(tannewt): Switch to proper pyb based UARTs.
151143
#ifdef UART_REPL
152144
configure_usart();
153145
#endif
154-
for (int i = 0; i < 10; i++) {
155-
port_pin_toggle_output_level(MICROPY_HW_LED1);
156-
delay_ms(500);
157-
}
158-
159146
}
160147

161148
#endif

atmel-samd/mphalport.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int mp_hal_stdin_rx_chr(void) {
2727
for (;;) {
2828
#ifdef USB_REPL
2929
if (mp_cdc_enabled && udi_cdc_is_rx_ready()) {
30-
return udi_cdc_getc();
30+
return udi_cdc_getc();
3131
}
3232
#endif
3333
#ifdef UART_REPL
@@ -47,10 +47,15 @@ int mp_hal_stdin_rx_chr(void) {
4747
//}
4848

4949
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
50+
#ifdef UART_REPL
5051
usart_write_buffer_wait(&usart_instance, (uint8_t*) str, len);
51-
// if (mp_cdc_enabled && udi_cdc_is_tx_ready()) {
52-
// udi_cdc_write_buf(str, len);
53-
// }
52+
#endif
53+
54+
#ifdef USB_REPL
55+
if (mp_cdc_enabled && udi_cdc_is_tx_ready()) {
56+
udi_cdc_write_buf(str, len);
57+
}
58+
#endif
5459
}
5560

5661
//void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {

0 commit comments

Comments
 (0)