Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ports/nxp: Plan to Integrate Micropython and NXP's MCU #5028

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
[submodule "lib/tinyusb"]
path = lib/tinyusb
url = https://github.com/hathach/tinyusb
[submodule "lib/nxplib"]
path = lib/nxplib
url = https://github.com/yanyao12138/nxplib.git
1 change: 1 addition & 0 deletions lib/nxplib
Submodule nxplib added at ffac81
259 changes: 259 additions & 0 deletions ports/nxp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
BOARD ?= evkmimxrt1064

BUILD ?= build-$(BOARD)

Toolchain ?= gcc

Series ?= imx

Device ?= MIMXRT1064

include board/$(BOARD)/mpconfigboard.mk

#FreeRTos variable
FreeRTOS_DIR = lib/nxplib/rtos

#NXP lib variable
NXP_DRIVER_DIR = lib/nxplib/drivers/$(Series)
NXP_MIDDLEWARE_DIR = lib/nxplib/middleware
NXP_DEVICE_DIR = lib/nxplib/devices/$(Device)
NXP_COMPONENTS_DIR = lib/nxplib/components

NXP_UTILITIES_DIR = $(NXP_DEVICE_DIR)/utilities
NXP_TOOLCHAIN_DIR = $(NXP_DEVICE_DIR)/$(Toolchain)
NXP_XIP_DIR = $(NXP_DEVICE_DIR)/xip

LVGL_SRC =
ifeq ($(LITTLEVGL_ENABLE), 1)
#littlevGL
LVGL_BINDING_DIR = $(TOP)/lib/lv_binding_micropython
LVGL_DIR += $(TOP)/$(NXP_MIDDLEWARE_DIR)/littlevgl
LVGL_INC += -I$(LVGL_DIR)
ALL_LVGL_SRC = $(shell find $(LVGL_DIR) -type f) $(TOP)/$(BOARD_DIR)/lv_conf.h
LVGL_MPY = ./modlvgl.c
LVGL_SRC_INC = $(shell find $(LVGL_DIR) -type f -name "*.h")
LVGL_SRC = $(subst $(TOP)/,,$(shell find $(LVGL_DIR) -type f -name "*.c") $(LVGL_MPY)) modSDL.c
endif

# qstr definitions (must come before including py.mk)
include ../../py/mkenv.mk
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES += $(LVGL_MPY)

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

CROSS_COMPILE = arm-none-eabi-

INC += -I.
INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(TOP)/$(NXP_DRIVER_DIR)
INC += -I$(TOP)/lib/libm_dbl
INC += -I$(TOP)/lib/cmsis/inc
INC += -I$(TOP)/py
INC += -I$(TOP)/lib
INC += -I$(TOP)/$(FreeRTOS_DIR)/amazon-freertos/lib/include
INC += -I$(TOP)/$(FreeRTOS_DIR)/amazon-freertos/lib/include/private
INC += -I$(TOP)/$(FreeRTOS_DIR)/amazon-freertos/lib/FreeRTOS/portable/GCC/ARM_CM4F
INC += -I$(TOP)/$(NXP_DEVICE_DIR)
INC += -I$(TOP)/$(NXP_MIDDLEWARE_DIR)/sdmmc/inc
INC += -I$(TOP)/$(NXP_MIDDLEWARE_DIR)/sdmmc/port
INC += -I$(TOP)/$(NXP_COMPONENTS_DIR)/list
INC += -I$(TOP)/$(NXP_COMPONENTS_DIR)/serial_manager
INC += -I$(TOP)/$(NXP_COMPONENTS_DIR)/uart
INC += -I$(TOP)/$(NXP_COMPONENTS_DIR)/ft5406_rt
INC += -I$(TOP)/$(NXP_COMPONENTS_DIR)/i2c
INC += -I$(TOP)/$(NXP_COMPONENTS_DIR)
INC += -I$(TOP)/$(NXP_XIP_DIR)
INC += -I$(TOP)/$(NXP_UTILITIES_DIR)
INC += -I$(TOP)/$(NXP_UTILITIES_DIR)/debug_console
INC += -I$(TOP)/$(NXP_UTILITIES_DIR)/str
INC += -I$(TOP)/extmod
INC += -I$(TOP)/lib/oofatfs
INC += -I$(TOP)/$(BOARD_DIR)

ifeq ($(LITTLEVGL_ENABLE), 1)
INC += -I$(LVGL_DIR)
endif

LD_DIR = $(TOP)/$(NXP_TOOLCHAIN_DIR)

FATFS_DIR=lib/oofatfs

STARTUP_FILE = $(NXP_TOOLCHAIN_DIR)/startup_$(Device).o

CFLAGS = $(INC) $(CFLAGS_CORE) $(CFLAGS_BOARD) -Wall -Werror -std=gnu99 \
-fno-tree-scev-cprop -Wpointer-arith -fdata-sections -ffunction-sections \
-DLV_CONF_INCLUDE_SIMPLE=1 \
-DFSL_RTOS_FREE_RTOS \
-D__STARTUP_CLEAR_BSS \
-D__STARTUP_INITIALIZE_NONCACHEDATA \
-DFFCONF_H=\"ports/nxp/ffconf.h\" \
--specs=nosys.specs \
--specs=nano.specs \
-D__START=main \


# ignore unused function
CFLAGS += -Wno-unused-function

LDFLAGS = --defsym=__heap_size__=0x8000 -T $(LD_DIR)/$(LINK_FILE) -Map=$(@:.elf=.map) --cref --gc-sections

# Tune for Debugging or Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -ggdb
else
CFLAGS += -Os -DNDEBUG
CFLAGS += -fdata-sections -ffunction-sections
endif

LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)

# Options for mpy-cross
MPY_CROSS_FLAGS += -march=armv7m

SRC_LIB = $(addprefix lib/,\
oofatfs/ff.c \
oofatfs/ffunicode.c \
)

SRC_FreeRTOS = $(addprefix $(FreeRTOS_DIR)/, \
amazon-freertos/lib/FreeRTOS/event_groups.c \
amazon-freertos/lib/FreeRTOS/list.c \
amazon-freertos/lib/FreeRTOS/queue.c \
amazon-freertos/lib/FreeRTOS/stream_buffer.c \
amazon-freertos/lib/FreeRTOS/tasks.c \
amazon-freertos/lib/FreeRTOS/timers.c \
amazon-freertos/lib/FreeRTOS/portable/MemMang/heap_4.c \
amazon-freertos/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c \
)

SRC_LIBM = $(addprefix lib/libm/,\
math.c \
acoshf.c \
asinfacosf.c \
asinhf.c \
atan2f.c \
atanf.c \
atanhf.c \
ef_rem_pio2.c \
erf_lgamma.c \
ef_sqrt.c \
fmodf.c \
kf_cos.c \
kf_rem_pio2.c \
kf_sin.c \
kf_tan.c \
log1pf.c \
nearbyintf.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 \
)

EXTMOD_SRC_C = $(addprefix extmod/, \
modubinascii.c \
modujson.c \
modure.c \
)

SRC_FSL_DRIVERS = $(addprefix $(NXP_DRIVER_DIR)/, \
fsl_common.c \
fsl_gpio.c \
fsl_lpuart.c \
fsl_usdhc.c \
fsl_cache.c \
fsl_lpi2c.c \
fsl_gpt.c \
$(BOARD_FSL_DRIVERS) \
)

SRC_NXP_MIDDLEWARE = $(addprefix $(NXP_MIDDLEWARE_DIR)/, \
sdmmc/port/usdhc/freertos/fsl_sdmmc_host.c \
sdmmc/port/usdhc/freertos/fsl_sdmmc_event.c \
sdmmc/src/fsl_mmc.c \
sdmmc/src/fsl_sd.c \
sdmmc/src/fsl_sdio.c \
sdmmc/src/fsl_sdmmc_common.c \
)

SRC_C = \
$(SRC_FSL_DRIVERS) \
$(SRC_BOARD) \
$(NXP_COMPONENTS_DIR)/lists/generic_list.c \
$(NXP_COMPONENTS_DIR)/serial_manager/serial_manager.c \
$(NXP_COMPONENTS_DIR)/serial_manager/serial_port_uart.c \
$(NXP_COMPONENTS_DIR)/uart/lpuart_adapter.c \
$(NXP_COMPONENTS_DIR)/i2c/lpi2c_adapter.c \
$(NXP_COMPONENTS_DIR)/ft5406_rt/fsl_ft5406_rt.c \
$(NXP_XIP_DIR)/fsl_flexspi_nor_boot.c \
$(NXP_UTILITIES_DIR)/fsl_assert.c \
$(NXP_UTILITIES_DIR)/debug_console/fsl_debug_console.c \
$(NXP_UTILITIES_DIR)/str/fsl_str.c \
$(SRC_FreeRTOS) \
$(SRC_NXP_MIDDLEWARE) \
$(EXTMOD_SRC_C) \
$(LVGL_SRC) \
$(SRC_SPECIFIC) \
main.c \
gccollect.c \
uart_core.c \
pin.c \
led.c \
sdcard.c \
mphalport.c \
pybi2c.c \
pybpinmux.c \
lib/utils/printf.c \
lib/utils/pyexec.c \
lib/libc/string0.c \
lib/mp-readline/readline.c \
lib/timeutils/timeutils.c \
moduos.c \
modpyb.c \
extmod/vfs.c \
extmod/vfs_fat.c \
extmod/vfs_fat_file.c \
extmod/vfs_posix.c \
extmod/vfs_reader.c \
extmod/vfs_fat_diskio.c

SRC_O = \
$(STARTUP_FILE) \
$(NXP_DEVICE_DIR)/system_$(Device).o \
lib/utils/gchelper_m3.o \


OBJ += $(addprefix $(BUILD)/, $(SRC_O))
OBJ += $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_LIB:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_LVGL_C:.c=.o))

$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os



# List of source for qstr extraction
SRC_QSTR += $(LVGL_SRC)
SRC_QSTR += $(SRC_C)

all: $(BUILD)/firmware.bin

$(BUILD)/firmware.elf: $(OBJ)
$(ECHO) "LINK $@"
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
$(Q)$(SIZE) $@

$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(Q)$(OBJCOPY) -O binary $^ $(BUILD)/firmware.bin

include $(TOP)/py/mkrules.mk
123 changes: 123 additions & 0 deletions ports/nxp/board/evkmimxrt1064/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* FreeRTOS Kernel V10.2.0
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

#define configUSE_PREEMPTION 1
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ (SystemCoreClock)
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES 18
#define configMINIMAL_STACK_SIZE ((unsigned short)90)
#define configMAX_TASK_NAME_LEN 10
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 1
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define configUSE_APPLICATION_TASK_TAG 0

/* Used memory allocation (heap_x.c) */
#define configFRTOS_MEMORY_SCHEME 3
/* Tasks.c additions (e.g. Thread Aware Debug capability) */
#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1

/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 46*1024
#define configAPPLICATION_ALLOCATED_HEAP 0

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0

/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1

/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 2

/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 17
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2)

/* Define to trap errors during development. */
#define configASSERT(x) if((x) == 0) {taskDISABLE_INTERRUPTS(); for (;;);}

/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 1

/****************** Macro definitions ***************/
#include "FreeRTOSConfigBoard.h"

#endif /* FREERTOS_CONFIG_H */