Skip to content

Commit

Permalink
Merge 3a44854 into 62f7537
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-hh committed May 27, 2021
2 parents 62f7537 + 3a44854 commit f3ccec6
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 35 deletions.
121 changes: 121 additions & 0 deletions ports/mimxrt/Makefile
Expand Up @@ -15,6 +15,9 @@ include $(BOARD_DIR)/mpconfigboard.mk
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h

# MicroPython feature configurations
FROZEN_MANIFEST ?= boards/manifest.py

# Include py core make definitions
include $(TOP)/py/py.mk

Expand Down Expand Up @@ -59,9 +62,25 @@ CFLAGS += -DXIP_EXTERNAL_FLASH=1 \
-D__START=main \
-DCPU_HEADER_H='<$(MCU_SERIES).h>'

# Configure floating point support
ifeq ($(MICROPY_FLOAT_IMPL),double)
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE
else
ifeq ($(MICROPY_FLOAT_IMPL),none)
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_NONE
else
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT
CFLAGS += -fsingle-precision-constant
endif
endif

SUPPORTS_HARDWARE_FP_SINGLE = 0
SUPPORTS_HARDWARE_FP_DOUBLE = 0

LDFLAGS = $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref --print-memory-usage
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)


# Tune for Debugging or Optimization
ifeq ($(DEBUG),1)
CFLAGS += -O0 -ggdb
Expand All @@ -73,6 +92,8 @@ LDFLAGS += --gc-sections
CFLAGS += -fdata-sections -ffunction-sections
endif

CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool

# TinyUSB Stack source
SRC_TINYUSB_C += \
lib/tinyusb/src/tusb.c \
Expand Down Expand Up @@ -118,9 +139,107 @@ SRC_C = \
lib/utils/printf.c \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
extmod/machine_i2c.c \
extmod/machine_spi.c \
extmod/machine_signal.c \
drivers/bus/softspi.c \
extmod/modonewire.c \
$(SRC_TINYUSB_C) \
$(SRC_TINYUSB_IMX_C) \

ifeq ($(MICROPY_FLOAT_IMPL),double)
LIBM_SRC_C += $(addprefix lib/libm_dbl/,\
__cos.c \
__expo2.c \
__fpclassify.c \
__rem_pio2.c \
__rem_pio2_large.c \
__signbit.c \
__sin.c \
__tan.c \
acos.c \
acosh.c \
asin.c \
asinh.c \
atan.c \
atan2.c \
atanh.c \
ceil.c \
cos.c \
cosh.c \
copysign.c \
erf.c \
exp.c \
expm1.c \
floor.c \
fmod.c \
frexp.c \
ldexp.c \
lgamma.c \
log.c \
log10.c \
log1p.c \
modf.c \
nearbyint.c \
pow.c \
rint.c \
round.c \
scalbn.c \
sin.c \
sinh.c \
tan.c \
tanh.c \
tgamma.c \
trunc.c \
)
ifeq ($(SUPPORTS_HARDWARE_FP_DOUBLE),1)
LIBM_SRC_C += lib/libm_dbl/thumb_vfp_sqrt.c
else
LIBM_SRC_C += lib/libm_dbl/sqrt.c
endif
else
LIBM_SRC_C += $(addprefix lib/libm/,\
math.c \
acoshf.c \
asinfacosf.c \
asinhf.c \
atan2f.c \
atanf.c \
atanhf.c \
ef_rem_pio2.c \
erf_lgamma.c \
fmodf.c \
kf_cos.c \
kf_rem_pio2.c \
kf_sin.c \
kf_tan.c \
log1pf.c \
nearbyintf.c \
roundf.c \
sf_cos.c \
sf_erf.c \
sf_frexp.c \
sf_ldexp.c \
sf_modf.c \
sf_sin.c \
sf_tan.c \
wf_lgamma.c \
wf_tgamma.c \
)
ifeq ($(SUPPORTS_HARDWARE_FP_SINGLE),1)
LIBM_SRC_C += lib/libm/thumb_vfp_sqrtf.c
else
LIBM_SRC_C += lib/libm/ef_sqrt.c
endif
endif

LIBM_O = $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o))

# Too many warnings in libm_dbl, disable for now.
ifeq ($(MICROPY_FLOAT_IMPL),double)
$(LIBM_O): CFLAGS := $(filter-out -Wdouble-promotion -Wfloat-conversion, $(CFLAGS))
endif

SRC_SS = $(MCU_DIR)/gcc/startup_$(MCU_SERIES).S

SRC_S = lib/utils/gchelper_m3.s \
Expand All @@ -132,9 +251,11 @@ SRC_QSTR += \
modutime.c \
modmachine.c \
pin.c \
extmod/modonewire.c \
$(GEN_PINS_SRC) \

OBJ += $(PY_O)
OBJ += $(LIBM_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SS:.S=.o))
Expand Down
2 changes: 2 additions & 0 deletions ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk
@@ -1,6 +1,8 @@
MCU_SERIES = MIMXRT1011
MCU_VARIANT = MIMXRT1011DAE5A

MICROPY_FLOAT_IMPL = single

JLINK_PATH = /media/RT1010-EVK/
JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink

Expand Down
2 changes: 2 additions & 0 deletions ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk
@@ -1,6 +1,8 @@
MCU_SERIES = MIMXRT1021
MCU_VARIANT = MIMXRT1021DAG5A

MICROPY_FLOAT_IMPL = double

JLINK_PATH ?= /media/RT1020-EVK/
JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink

Expand Down
2 changes: 2 additions & 0 deletions ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk
@@ -1,6 +1,8 @@
MCU_SERIES = MIMXRT1052
MCU_VARIANT = MIMXRT1052DVL6B

MICROPY_FLOAT_IMPL = double

JLINK_PATH ?= /media/RT1050-EVK/

deploy: $(BUILD)/firmware.bin
Expand Down
2 changes: 2 additions & 0 deletions ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk
@@ -1,6 +1,8 @@
MCU_SERIES = MIMXRT1062
MCU_VARIANT = MIMXRT1062DVJ6A

MICROPY_FLOAT_IMPL = double

JLINK_PATH ?= /media/RT1060-EVK/
JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink

Expand Down
2 changes: 2 additions & 0 deletions ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk
@@ -1,6 +1,8 @@
MCU_SERIES = MIMXRT1064
MCU_VARIANT = MIMXRT1064DVL6A

MICROPY_FLOAT_IMPL = double

JLINK_PATH ?= /media/RT1064-EVK/

CFLAGS += -DBOARD_FLASH_SIZE=0x400000
Expand Down
2 changes: 2 additions & 0 deletions ports/mimxrt/boards/TEENSY40/mpconfigboard.mk
@@ -1,5 +1,7 @@
MCU_SERIES = MIMXRT1062
MCU_VARIANT = MIMXRT1062DVJ6A

MICROPY_FLOAT_IMPL = double

deploy: $(BUILD)/firmware.hex
teensy_loader_cli --mcu=imxrt1062 -v -w $<
3 changes: 3 additions & 0 deletions ports/mimxrt/boards/manifest.py
@@ -0,0 +1,3 @@
freeze("$(PORT_DIR)/modules")
freeze("$(MPY_DIR)/drivers/onewire")
include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
8 changes: 4 additions & 4 deletions ports/mimxrt/machine_pin.c
Expand Up @@ -39,7 +39,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
// Class Methods
STATIC void machine_pin_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
STATIC mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
STATIC mp_obj_t machine_pin_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);

// Instance Methods
STATIC mp_obj_t machine_pin_off(mp_obj_t self_in);
Expand Down Expand Up @@ -191,7 +191,7 @@ STATIC void machine_pin_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_
}

// pin(id, mode, pull, ...)
STATIC mp_obj_t machine_pin_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);

const machine_pin_obj_t *pin = pin_find(args[0]);
Expand Down Expand Up @@ -273,7 +273,7 @@ const mp_obj_type_t machine_pin_type = {
.name = MP_QSTR_Pin,
.print = machine_pin_obj_print,
.call = machine_pin_obj_call,
.make_new = machine_pin_obj_make_new,
.make_new = mp_pin_make_new,
.locals_dict = (mp_obj_dict_t *)&machine_pin_locals_dict,
};

Expand All @@ -282,6 +282,6 @@ const mp_obj_type_t machine_pin_af_type = {
{&mp_type_type},
.name = MP_QSTR_PinAF,
.print = machine_pin_obj_print,
.make_new = machine_pin_obj_make_new,
.make_new = mp_pin_make_new,
.locals_dict = (mp_obj_dict_t *)&machine_pin_locals_dict,
};
35 changes: 35 additions & 0 deletions ports/mimxrt/main.c
Expand Up @@ -108,3 +108,38 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
}
}
#endif

const char mimxrt_help_text[] =
"Welcome to MicroPython!\n"
"\n"
"For online help please visit https://micropython.org/help/.\n"
"\n"
"For access to the hardware use the 'machine' module. \n"
"\n"
"Quick overview of some objects:\n"
" machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n"
" machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n"
" methods: init(..), value([v]), high(), low())\n"
// " machine.ADC(pin) -- make an analog object from a pin\n"
// " methods: read_u16()\n"
// " machine.PWM(pin) -- make a PWM object from a pin\n"
// " methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])\n"
// " machine.I2C(id) -- create an I2C object (id=0,1)\n"
// " methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n"
// " readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n"
// " machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)\n"
// " methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n"
// " machine.Timer(freq, callback) -- create a software timer object\n"
// " eg: machine.Timer(freq=1, callback=lambda t:print(t))\n"
"\n"
"Pin IO modes are: Pin.IN, Pin.OUT, Pin.OPEN_DRAIN\n"
"Pin pull modes are: Pin.PULL_UP, Pin.PULL_UP_47K, Pin.PULL_UP_22K, Pin.PULL_DOWN, Pin.PULL_HOLD\n"
"\n"
"Useful control commands:\n"
" CTRL-C -- interrupt a running program\n"
" CTRL-D -- on a blank line, do a soft reset of the board\n"
" CTRL-E -- on a blank line, enter paste mode\n"
"\n"
"For further help on a specific object, type help(obj)\n"
"For a list of available modules, type help('modules')\n"
;
9 changes: 8 additions & 1 deletion ports/mimxrt/modmachine.c
Expand Up @@ -27,8 +27,12 @@

#include "py/runtime.h"
#include "extmod/machine_mem.h"
#include "extmod/machine_i2c.h"
#include "extmod/machine_signal.h"
#include "extmod/machine_spi.h"
#include "led.h"
#include "pin.h"
#include "fsl_clock.h"

#include CPU_HEADER_H

Expand All @@ -39,7 +43,7 @@ STATIC mp_obj_t machine_reset(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);

STATIC mp_obj_t machine_freq(void) {
return MP_OBJ_NEW_SMALL_INT(0);
return MP_OBJ_NEW_SMALL_INT(CLOCK_GetFreq(kCLOCK_CpuClk));
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_freq_obj, machine_freq);

Expand All @@ -54,6 +58,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&machine_led_type) },
#endif
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
{ MP_ROM_QSTR(MP_QSTR_SoftI2C), MP_ROM_PTR(&mp_machine_soft_i2c_type) },
{ MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&mp_machine_soft_spi_type) },
};
STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);

Expand Down

0 comments on commit f3ccec6

Please sign in to comment.