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.
This commit is contained in:
Scott Shawcroft 2016-08-24 00:14:11 -07:00
parent 386ab580cd
commit 0c4f9b878a
6 changed files with 47 additions and 65 deletions

View File

@ -7,11 +7,13 @@ M0 BLE.
## Building
The Makefile has the ability to build for a SAMD21x18, and by default
includes some start-up code and also enables a UART for communication. To build:
includes some start-up code and also enables a UART for communication. To
build:
make CROSS=1
It will build for the Arduino Zero by default. You may change it by setting `BOARD`. For example:
It will build for the Arduino Zero by default. You may change it by setting
`BOARD`. For example:
make CROSS=1 BOARD=feather_m0_ble
@ -20,14 +22,17 @@ Board names are the directory names in the `boards` folder.
## Deploying
### Arduino Bootloader
If your board has an existing Arduino bootloader on it then you can use bossac to flash MicroPython. After building run:
If your board has an existing Arduino bootloader on it then you can use bossac
to flash MicroPython. After building run:
tools/bossac_osx -e -w -v -b build-feather_m0_ble/firmware.bin
### No Bootloader via GDB
This method works for loading MicroPython onto the Arduino Zero via the programming port rather than the native USB port.
This method works for loading MicroPython onto the Arduino Zero via the
programming port rather than the native USB port.
Note: These instructions are tested on Mac OSX and will vary for different platforms.
Note: These instructions are tested on Mac OSX and will vary for different
platforms.
openocd -f ~/Library/Arduino15/packages/arduino/hardware/samd/1.6.6/variants/arduino_zero/openocd_scripts/arduino_zero.cfg
@ -43,8 +48,10 @@ In another terminal from `micropython/atmel-samd`:
(gdb) continue
## Connecting
The current Atmel SAMD implementation only works over UART. To connect to it from OSX do something like this:
All boards are currently configured to work over USB rather than UART. To
connect to it from OSX do something like this:
screen /dev/tty.usbmodem142422 115200
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.
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.

View File

@ -1,7 +1,7 @@
// LEDs
#define MICROPY_HW_LED1 PIN_PA17 // red
#define UART_REPL
// #define USB_REPL
// #define UART_REPL
#define USB_REPL
#define MICROPY_HW_BOARD_NAME "Arduino Zero"
#define MICROPY_HW_MCU_NAME "samd21g18"

View File

@ -40,6 +40,8 @@ SECTIONS
{
. = ALIGN(4);
_srelocate = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
*(.ramfunc)
*(.ramfunc*)
*(.data) /* .data sections */
*(.data*) /* .data* sections */
@ -48,28 +50,18 @@ SECTIONS
} >RAM
/* Uninitialized data section */
.ramfunc :
{
. = ALIGN(4);
_sramfunc = .; /* define a global symbol at ramfunc start; used by startup code */
*(.ramfunc)
*(.ramfunc*)
. = ALIGN(4);
_eramfunc = .; /* define a global symbol at ramfunc end; used by startup code */
} >RAM
/* Uninitialized data section */
.zero :
.bss :
{
. = ALIGN(4);
_sbss = .;
_szero = .; /* define a global symbol at bss start; used by startup code */
*(.zero)
*(.zero*)
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ezero = .; /* define a global symbol at bss end; used by startup code */
_ebss = .;
} >RAM
.ARM.attributes 0 : { *(.ARM.attributes) }

View File

@ -28,10 +28,9 @@ SECTIONS
. = ALIGN(4);
_etext = .; /* define a global symbol at end of code */
_sidata = _etext; /* This is used by the startup in order to initialize the .data secion */
_sidata = _etext; /* This is used by the startup in order to initialize the .data section */
} >FLASH
/* This is the initialized data section
The program executes knowing that the data is in the RAM
but the loader puts the initial values in the FLASH (inidata).
@ -40,6 +39,8 @@ SECTIONS
{
. = ALIGN(4);
_srelocate = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */
*(.ramfunc)
*(.ramfunc*)
*(.data) /* .data sections */
*(.data*) /* .data* sections */
@ -48,28 +49,18 @@ SECTIONS
} >RAM
/* Uninitialized data section */
.ramfunc :
{
. = ALIGN(4);
_sramfunc = .; /* define a global symbol at ramfunc start; used by startup code */
*(.ramfunc)
*(.ramfunc*)
. = ALIGN(4);
_eramfunc = .; /* define a global symbol at ramfunc end; used by startup code */
} >RAM
/* Uninitialized data section */
.zero :
.bss :
{
. = ALIGN(4);
_sbss = .;
_szero = .; /* define a global symbol at bss start; used by startup code */
*(.zero)
*(.zero*)
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ezero = .; /* define a global symbol at bss end; used by startup code */
_ebss = .;
} >RAM
.ARM.attributes 0 : { *(.ARM.attributes) }

View File

@ -127,35 +127,22 @@ void samd21_init(void) {
delay_init();
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);
// Uncomment to init PIN_PA17 for debugging.
// struct port_config pin_conf;
// port_get_config_defaults(&pin_conf);
//
// pin_conf.direction = PORT_PIN_DIR_OUTPUT;
// port_pin_set_config(MICROPY_HW_LED1, &pin_conf);
// port_pin_set_output_level(MICROPY_HW_LED1, false);
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
port_pin_set_config(MICROPY_HW_LED1, &pin_conf);
port_pin_set_output_level(MICROPY_HW_LED1, false);
// Start USB stack to authorize VBus monitoring
for (int i = 0; i < 10; i++) {
port_pin_toggle_output_level(MICROPY_HW_LED1);
delay_ms(100);
}
#ifdef USB_REPL
udc_start();
#endif
for (int i = 0; i < 10; i++) {
port_pin_toggle_output_level(MICROPY_HW_LED1);
delay_ms(200);
}
// TODO(tannewt): Switch to proper pyb based UARTs.
#ifdef UART_REPL
configure_usart();
#endif
for (int i = 0; i < 10; i++) {
port_pin_toggle_output_level(MICROPY_HW_LED1);
delay_ms(500);
}
}
#endif

View File

@ -27,7 +27,7 @@ int mp_hal_stdin_rx_chr(void) {
for (;;) {
#ifdef USB_REPL
if (mp_cdc_enabled && udi_cdc_is_rx_ready()) {
return udi_cdc_getc();
return udi_cdc_getc();
}
#endif
#ifdef UART_REPL
@ -47,10 +47,15 @@ int mp_hal_stdin_rx_chr(void) {
//}
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
#ifdef UART_REPL
usart_write_buffer_wait(&usart_instance, (uint8_t*) str, len);
// if (mp_cdc_enabled && udi_cdc_is_tx_ready()) {
// udi_cdc_write_buf(str, len);
// }
#endif
#ifdef USB_REPL
if (mp_cdc_enabled && udi_cdc_is_tx_ready()) {
udi_cdc_write_buf(str, len);
}
#endif
}
//void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {