atmel-samd: Support raw repl and soft reset to support ampy.
Closes #1. Also adds TX and RX led support on the Arduino Zero.
This commit is contained in:
parent
7d8929c470
commit
7fd84e93f4
@ -150,6 +150,7 @@ SRC_C = \
|
||||
asf/sam0/utils/cmsis/samd21/source/gcc/startup_samd21.c \
|
||||
asf/sam0/utils/cmsis/samd21/source/system_samd21.c \
|
||||
asf/sam0/utils/syscalls/gcc/syscalls.c \
|
||||
boards/$(BOARD)/init.c \
|
||||
boards/$(BOARD)/pins.c \
|
||||
lib/fatfs/ff.c \
|
||||
lib/fatfs/option/ccsbcs.c \
|
||||
|
@ -8,9 +8,10 @@
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <asf.h>
|
||||
#include <board.h>
|
||||
#include <conf_board.h>
|
||||
#include "board.h"
|
||||
#include "conf_board.h"
|
||||
#include "mpconfigboard.h"
|
||||
#include "asf/sam0/drivers/port/port.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
@ -18,4 +19,13 @@ void board_init(void)
|
||||
* for, e.g., the I/O pins. The initialization can rely on application-
|
||||
* specific board configuration, found in conf_board.h.
|
||||
*/
|
||||
struct port_config pin_conf;
|
||||
port_get_config_defaults(&pin_conf);
|
||||
|
||||
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
|
||||
port_pin_set_config(MICROPY_HW_LED_TX, &pin_conf);
|
||||
port_pin_set_output_level(MICROPY_HW_LED_TX, true);
|
||||
|
||||
port_pin_set_config(MICROPY_HW_LED_RX, &pin_conf);
|
||||
port_pin_set_output_level(MICROPY_HW_LED_RX, true);
|
||||
}
|
||||
|
@ -5,3 +5,6 @@
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "Arduino Zero"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
#define MICROPY_HW_LED_TX PIN_PA27
|
||||
#define MICROPY_HW_LED_RX PIN_PB03
|
||||
|
@ -8,9 +8,8 @@
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <asf.h>
|
||||
#include <board.h>
|
||||
#include <conf_board.h>
|
||||
#include "board.h"
|
||||
#include "conf_board.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "asf/sam0/drivers/port/port.h"
|
||||
#include "asf/sam0/drivers/sercom/usart/usart.h"
|
||||
#include "asf/sam0/drivers/system/system.h"
|
||||
#include <board.h>
|
||||
|
||||
#include "mpconfigboard.h"
|
||||
#include "modmachine_pin.h"
|
||||
@ -158,16 +159,7 @@ void init_flash_fs() {
|
||||
static char *stack_top;
|
||||
static char heap[8192];
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// initialise the cpu and peripherals
|
||||
#if MICROPY_MIN_USE_SAMD21_MCU
|
||||
void samd21_init(void);
|
||||
samd21_init();
|
||||
#endif
|
||||
|
||||
int stack_dummy;
|
||||
stack_top = (char*)&stack_dummy;
|
||||
|
||||
void reset_mp() {
|
||||
#if MICROPY_ENABLE_GC
|
||||
gc_init(heap, heap + sizeof(heap));
|
||||
#endif
|
||||
@ -176,11 +168,22 @@ int main(int argc, char **argv) {
|
||||
MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
|
||||
|
||||
pin_init0();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// initialise the cpu and peripherals
|
||||
#if MICROPY_MIN_USE_SAMD21_MCU
|
||||
void samd21_init(void);
|
||||
samd21_init();
|
||||
#endif
|
||||
|
||||
// Initialise the local flash filesystem.
|
||||
// Create it if needed, mount in on /flash, and set it as current dir.
|
||||
init_flash_fs();
|
||||
|
||||
int stack_dummy;
|
||||
reset_mp();
|
||||
|
||||
#if MICROPY_REPL_EVENT_DRIVEN
|
||||
pyexec_event_repl_init();
|
||||
for (;;) {
|
||||
@ -190,10 +193,24 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
#else
|
||||
pyexec_friendly_repl();
|
||||
// Main script is finished, so now go into REPL mode.
|
||||
// The REPL mode can change, or it can request a soft reset.
|
||||
int exit_code = 0;
|
||||
for (;;) {
|
||||
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
|
||||
exit_code = pyexec_raw_repl();
|
||||
} else {
|
||||
exit_code = pyexec_friendly_repl();
|
||||
}
|
||||
if (exit_code == PYEXEC_FORCED_EXIT) {
|
||||
mp_hal_stdout_tx_str("soft reboot\r\n");
|
||||
stack_top = (char*)&stack_dummy;
|
||||
reset_mp();
|
||||
} else if (exit_code != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
|
||||
//do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT);
|
||||
mp_deinit();
|
||||
return 0;
|
||||
}
|
||||
@ -239,7 +256,6 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
|
||||
struct usart_module usart_instance;
|
||||
|
||||
void samd21_init(void) {
|
||||
|
||||
irq_initialize_vectors();
|
||||
cpu_irq_enable();
|
||||
|
||||
@ -250,6 +266,8 @@ void samd21_init(void) {
|
||||
|
||||
delay_init();
|
||||
|
||||
board_init();
|
||||
|
||||
// Uncomment to init PIN_PA17 for debugging.
|
||||
// struct port_config pin_conf;
|
||||
// port_get_config_defaults(&pin_conf);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "asf/common/services/usb/class/cdc/device/udi_cdc.h"
|
||||
#include "asf/common2/services/delay/delay.h"
|
||||
#include "asf/sam0/drivers/port/port.h"
|
||||
#include "asf/sam0/drivers/sercom/usart/usart.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/mpstate.h"
|
||||
@ -107,12 +108,18 @@ int mp_hal_stdin_rx_chr(void) {
|
||||
for (;;) {
|
||||
#ifdef USB_REPL
|
||||
if (mp_cdc_enabled && usb_rx_count > 0) {
|
||||
#ifdef MICROPY_HW_LED_RX
|
||||
port_pin_toggle_output_level(MICROPY_HW_LED_RX);
|
||||
#endif
|
||||
return receive_usb();
|
||||
}
|
||||
#endif
|
||||
#ifdef UART_REPL
|
||||
uint16_t temp;
|
||||
if (usart_read_wait(&usart_instance, &temp) == STATUS_OK) {
|
||||
#ifdef MICROPY_HW_LED_RX
|
||||
port_pin_toggle_output_level(MICROPY_HW_LED_RX);
|
||||
#endif
|
||||
return temp;
|
||||
}
|
||||
#endif
|
||||
@ -123,6 +130,10 @@ int mp_hal_stdin_rx_chr(void) {
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
#ifdef MICROPY_HW_LED_TX
|
||||
port_pin_toggle_output_level(MICROPY_HW_LED_TX);
|
||||
#endif
|
||||
|
||||
#ifdef UART_REPL
|
||||
usart_write_buffer_wait(&usart_instance, (uint8_t*) str, len);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user