diff --git a/atmel-samd/README.md b/atmel-samd/README.md index 3a266e6224..6570ed6c84 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 d3115ca756..4a2723fc7b 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 7f41b092ba..974d78626f 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 92996e74a5..6c1e6c01e1 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 70720ca8f0..cb722cc1a3 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); + // 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 diff --git a/atmel-samd/mphalport.c b/atmel-samd/mphalport.c index a005df724f..5f21eda01f 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) {