@@ -101,8 +101,6 @@ MICROPY_ROM_TEXT_COMPRESSION ?= 1
101101include $(TOP ) /py/py.mk
102102include $(TOP ) /extmod/extmod.mk
103103
104- CROSS_COMPILE ?= arm-none-eabi-
105-
106104INC += -I.
107105INC += -I$(TOP )
108106ifeq ($(PB_MCU_FAMILY ) ,STM32)
@@ -155,6 +153,18 @@ OPENOCD ?= openocd
155153OPENOCD_CONFIG ?= openocd_stm32$(PB_MCU_SERIES_LCASE ) .cfg
156154TEXT0_ADDR ?= 0x08000000
157155
156+ ifeq ($(PB_MCU_FAMILY ) ,desktop)
157+ UNAME_S := $(shell uname -s)
158+ LD = $(CC )
159+ CFLAGS += $(INC ) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 $(COPT ) -D_GNU_SOURCE
160+ ifeq ($(UNAME_S ) ,Linux)
161+ LDFLAGS += -Wl,-Map=$@ .map,--cref -Wl,--gc-sections
162+ else ifeq ($(UNAME_S),Darwin)
163+ LDFLAGS += -Wl,-map,$@ .map -Wl,-dead_strip
164+ endif
165+ LIBS =
166+ else # end desktop, begin embedded
167+ CROSS_COMPILE ?= arm-none-eabi-
158168ifeq ($(PB_MCU_FAMILY ) ,STM32)
159169CFLAGS_MCU_F0 = -mthumb -mtune=cortex-m0 -mcpu=cortex-m0 -msoft-float
160170CFLAGS_MCU_F4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
@@ -200,6 +210,8 @@ endif
200210# avoid doubles
201211CFLAGS += -fsingle-precision-constant -Wdouble-promotion
202212
213+ endif # end embedded, begin common
214+
203215# Tune for Debugging or Optimization
204216ifeq ($(DEBUG ) , 1)
205217CFLAGS += -Og -ggdb
@@ -233,13 +245,25 @@ include $(PBTOP)/bricks/_common/sources.mk
233245# between the top level directory and the micropython/ subdirectory.
234246
235247PY_EXTRA_SRC_C = $(addprefix shared/,\
236- libc/string0.c \
237- runtime/gchelper_native.c \
238248 runtime/interrupt_char.c \
239249 runtime/pyexec.c \
240250 runtime/stdout_helpers.c \
251+ )
252+
253+ ifeq ($(PB_MCU_FAMILY ) ,desktop)
254+ PY_EXTRA_SRC_C += $(addprefix shared/,\
255+ runtime/gchelper_generic.c \
256+ )
257+ PY_EXTRA_SRC_C += $(addprefix bricks/simhub/,\
258+ pbio_os_hook.c \
259+ )
260+ else
261+ PY_EXTRA_SRC_C += $(addprefix shared/,\
262+ libc/string0.c \
263+ runtime/gchelper_native.c \
241264 runtime/sys_stdio_mphal.c \
242265 )
266+ endif
243267
244268ifneq ($(PBIO_PLATFORM ) ,move_hub)
245269# to avoid adding unused root pointers
@@ -262,7 +286,9 @@ PY_EXTRA_SRC_C += $(addprefix bricks/_common/,\
262286endif
263287
264288# Not all MCUs support thumb2 instructions.
265- ifeq ($(PB_MCU_SERIES ) ,$(filter $(PB_MCU_SERIES ) ,AT91SAM7 F0 TIAM1808) )
289+ ifeq ($(PB_MCU_FAMILY ) ,desktop)
290+ SRC_S +=
291+ else ifeq ($(PB_MCU_SERIES),$(filter $(PB_MCU_SERIES),AT91SAM7 F0 TIAM1808))
266292SRC_S += shared/runtime/gchelper_thumb1.s
267293else
268294SRC_S += shared/runtime/gchelper_thumb2.s
@@ -561,8 +587,12 @@ CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
561587MPY_TOOL_FLAGS += -mlongint-impl none
562588endif
563589
590+ ifneq ($(PB_MCU_FAMILY ) ,desktop)
564591# Main firmware build targets
565592TARGETS := $(BUILD ) /firmware.zip
593+ else
594+ TARGETS := $(BUILD ) /firmware.elf
595+ endif
566596
567597all : $(TARGETS )
568598
@@ -673,4 +703,12 @@ deploy-openocd: $(BUILD)/firmware-base.bin
673703 $(ECHO ) " Writing $< to the board via ST-LINK using OpenOCD"
674704 $(Q )$(OPENOCD ) -f $(OPENOCD_CONFIG ) -c " stm_flash $< $( TEXT0_ADDR) "
675705
706+ # Run emulation build on a POSIX system using normal stdio
707+ run : $(BUILD ) /firmware.elf
708+ @$(BUILD ) /firmware.elf
709+ @echo " Exit status: $$ ?"
710+
711+ test : $(BUILD ) /firmware.elf
712+ $(Q ) /usr/bin/printf " print('hello world!', list(x+1 for x in range(10)), end='eol\\\\ n')\\ r\\ n\\ 004" | $(BUILD ) /firmware.elf | tail -n2 | grep " ^hello world! \\ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\ ]eol"
713+
676714include $(TOP ) /py/mkrules.mk
0 commit comments