diff options
| author | Scott Shawcroft <scott@chickadee.tech> | 2016-08-24 00:14:11 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@chickadee.tech> | 2016-08-24 00:14:11 -0700 |
| commit | 0c4f9b878a096ec4aa49f17ab7bdd23c2bf42d8e (patch) | |
| tree | c595e5619b0e8b9477743d4a72b0332f92cbb5f9 | |
| parent | 386ab580cd8a56d90da81580e6f62940cc30a457 (diff) | |
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.
| -rw-r--r-- | atmel-samd/README.md | 21 | ||||
| -rw-r--r-- | atmel-samd/boards/arduino_zero/mpconfigboard.h | 4 | ||||
| -rw-r--r-- | atmel-samd/boards/samd21x18-bootloader.ld | 22 | ||||
| -rw-r--r-- | atmel-samd/boards/samd21x18.ld | 25 | ||||
| -rw-r--r-- | atmel-samd/main.c | 29 | ||||
| -rw-r--r-- | atmel-samd/mphalport.c | 13 |
6 files changed, 48 insertions, 66 deletions
diff --git a/atmel-samd/README.md b/atmel-samd/README.md index 3a266e622..6570ed6c8 100644 --- a/atmel-samd/README.md +++ b/atmel-samd/README.md @@ -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. diff --git a/atmel-samd/boards/arduino_zero/mpconfigboard.h b/atmel-samd/boards/arduino_zero/mpconfigboard.h index d3115ca75..4a2723fc7 100644 --- a/atmel-samd/boards/arduino_zero/mpconfigboard.h +++ b/atmel-samd/boards/arduino_zero/mpconfigboard.h @@ -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" diff --git a/atmel-samd/boards/samd21x18-bootloader.ld b/atmel-samd/boards/samd21x18-bootloader.ld index 7f41b092b..974d78626 100644 --- a/atmel-samd/boards/samd21x18-bootloader.ld +++ b/atmel-samd/boards/samd21x18-bootloader.ld @@ -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) } diff --git a/atmel-samd/boards/samd21x18.ld b/atmel-samd/boards/samd21x18.ld index 92996e74a..6c1e6c01e 100644 --- a/atmel-samd/boards/samd21x18.ld +++ b/atmel-samd/boards/samd21x18.ld @@ -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) } diff --git a/atmel-samd/main.c b/atmel-samd/main.c index 70720ca8f..cb722cc1a 100644 --- a/atmel-samd/main.c +++ b/atmel-samd/main.c @@ -127,35 +127,22 @@ void samd21_init(void) { delay_init(); - 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); - - // 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); - } + // 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); + #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 diff --git a/atmel-samd/mphalport.c b/atmel-samd/mphalport.c index a005df724..5f21eda01 100644 --- a/atmel-samd/mphalport.c +++ b/atmel-samd/mphalport.c @@ -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) { |
