Makefile 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. include ../../py/mkenv.mk
  2. CROSS = 0
  3. # qstr definitions (must come before including py.mk)
  4. QSTR_DEFS = qstrdefsport.h
  5. # include py core make definitions
  6. include $(TOP)/py/py.mk
  7. ifeq ($(CROSS), 1)
  8. CROSS_COMPILE = arm-none-eabi-
  9. endif
  10. INC += -I.
  11. INC += -I$(TOP)
  12. INC += -I$(BUILD)
  13. ifeq ($(CROSS), 1)
  14. DFU = $(TOP)/tools/dfu.py
  15. PYDFU = $(TOP)/tools/pydfu.py
  16. CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
  17. CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT)
  18. LDFLAGS = -nostdlib -T stm32f405.ld -Map=$@.map --cref --gc-sections
  19. else
  20. LD = gcc
  21. CFLAGS = -m32 $(INC) -Wall -Werror -std=c99 $(COPT)
  22. LDFLAGS = -m32 -Wl,-Map=$@.map,--cref -Wl,--gc-sections
  23. endif
  24. # Tune for Debugging or Optimization
  25. ifeq ($(DEBUG), 1)
  26. CFLAGS += -O0 -ggdb
  27. else
  28. CFLAGS += -Os -DNDEBUG
  29. CFLAGS += -fdata-sections -ffunction-sections
  30. endif
  31. LIBS =
  32. SRC_C = \
  33. main.c \
  34. uart_core.c \
  35. lib/utils/printf.c \
  36. lib/utils/stdout_helpers.c \
  37. lib/utils/pyexec.c \
  38. lib/libc/string0.c \
  39. lib/mp-readline/readline.c \
  40. $(BUILD)/_frozen_mpy.c \
  41. OBJ = $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
  42. ifeq ($(CROSS), 1)
  43. all: $(BUILD)/firmware.dfu
  44. else
  45. all: $(BUILD)/firmware.elf
  46. endif
  47. $(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
  48. $(ECHO) "MISC freezing bytecode"
  49. $(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@
  50. $(BUILD)/firmware.elf: $(OBJ)
  51. $(ECHO) "LINK $@"
  52. $(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
  53. $(Q)$(SIZE) $@
  54. $(BUILD)/firmware.bin: $(BUILD)/firmware.elf
  55. $(Q)$(OBJCOPY) -O binary -j .isr_vector -j .text -j .data $^ $(BUILD)/firmware.bin
  56. $(BUILD)/firmware.dfu: $(BUILD)/firmware.bin
  57. $(ECHO) "Create $@"
  58. $(Q)$(PYTHON) $(DFU) -b 0x08000000:$(BUILD)/firmware.bin $@
  59. deploy: $(BUILD)/firmware.dfu
  60. $(ECHO) "Writing $< to the board"
  61. $(Q)$(PYTHON) $(PYDFU) -u $<
  62. # Run emulation build on a POSIX system with suitable terminal settings
  63. run:
  64. stty raw opost -echo
  65. build/firmware.elf
  66. @echo Resetting terminal...
  67. # This sleep is useful to spot segfaults
  68. sleep 1
  69. reset
  70. test: $(BUILD)/firmware.elf
  71. $(Q)/bin/echo -e "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\x04" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol"
  72. include $(TOP)/py/mkrules.mk