Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

159 lines
4.1 KiB

  1. ARMOBJDUMP?= arm-none-eabi-objdump
  2. ARMCC?= arm-none-eabi-gcc
  3. ARMTARGET?= -mcpu=cortex-m3 -mthumb -DSTROBE_SINGLE_THREAD=1
  4. # Clang doesn't work due to no-nano libc
  5. #ARMCC?=clang-mp-9.0
  6. #ARMTARGET?= -nostdlib -ffreestanding -target arm-none-eabi -mcpu=cortex-m3 -mfloat-abi=soft -mthumb
  7. PLATFORM != uname -s
  8. .if $(PLATFORM) == "Darwin"
  9. SOEXT=dylib
  10. .else
  11. .error Unsupported platform: $(PLATFORM)
  12. .endif
  13. PROG = lora.irr
  14. PROGEXT = .elf
  15. SRCS = main.c
  16. SRCS+= board.c
  17. SRCS+= misc.c
  18. SRCS+= strobe_rng_init.c
  19. CFLAGS+= -I$(.CURDIR)
  20. CFLAGS+= -g
  21. #CFLAGS+= -DNDEBUG
  22. # Strobe
  23. .PATH: $(.CURDIR)/strobe
  24. CFLAGS+= -I$(.CURDIR)/strobe
  25. SRCS+= strobe.c \
  26. x25519.c
  27. # LoRamac (SX1276) radio code
  28. LORAMAC_SRC = $(.CURDIR)/loramac/src
  29. .PATH: $(LORAMAC_SRC)/radio/sx1276 $(LORAMAC_SRC)/system $(LORAMAC_SRC)/boards/mcu $(LORAMAC_SRC)/boards/NucleoL152
  30. CFLAGS+= -I$(LORAMAC_SRC)/boards
  31. CFLAGS+= -I$(LORAMAC_SRC)/system
  32. CFLAGS+= -I$(LORAMAC_SRC)/radio
  33. CFLAGS+= -DUSE_HAL_DRIVER -DSX1276MB1LAS
  34. SRCS+= sx1276.c
  35. SRCS+= utilities.c
  36. SRCS+= adc.c timer.c delay.c gpio.c uart.c fifo.c
  37. SRCS+= adc-board.c delay-board.c gpio-board.c rtc-board.c lpm-board.c sx1276mb1las-board.c spi-board.c uart-board.c
  38. # Microcontroller
  39. STM32=$(.CURDIR)/stm32
  40. .PATH: $(STM32)/l151ccux
  41. LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld
  42. SRCS+= \
  43. startup_stm32l151ccux.s \
  44. stm32l1xx_hal.c \
  45. stm32l1xx_hal_adc.c \
  46. stm32l1xx_hal_adc_ex.c \
  47. stm32l1xx_hal_cortex.c \
  48. stm32l1xx_hal_dma.c \
  49. stm32l1xx_hal_gpio.c \
  50. stm32l1xx_hal_spi.c \
  51. stm32l1xx_hal_pwr.c \
  52. stm32l1xx_hal_pwr_ex.c \
  53. stm32l1xx_hal_pcd.c \
  54. stm32l1xx_hal_pcd_ex.c \
  55. stm32l1xx_hal_rcc.c \
  56. stm32l1xx_hal_rcc_ex.c \
  57. stm32l1xx_hal_rtc.c \
  58. stm32l1xx_hal_rtc_ex.c \
  59. stm32l1xx_hal_uart.c \
  60. system_stm32l1xx.c
  61. SRCS+= \
  62. stm32l1xx_it.c \
  63. stm32l1xx_hal_msp.c
  64. CFLAGS+= -I$(STM32)
  65. CFLAGS+= -I$(STM32)/l151ccux
  66. CFLAGS+= -DSTM32L151xC
  67. # USB
  68. .PATH: $(STM32)/usb
  69. SRCS+= \
  70. stm32l1xx_ll_usb.c \
  71. usb_device.c \
  72. usbd_cdc.c \
  73. usbd_cdc_if.c \
  74. usbd_conf.c \
  75. usbd_core.c \
  76. usbd_ctlreq.c \
  77. usbd_desc.c \
  78. usbd_ioreq.c
  79. CFLAGS+= -I$(STM32)/usb
  80. OBJS = $(SRCS:C/.c$/.o/)
  81. CFLAGS+= -Werror -Wall
  82. LIBLORA_TEST_SRCS= comms.c strobe.c x25519.c
  83. LIBLORA_TEST_OBJS= $(LIBLORA_TEST_SRCS:C/.c$/.no/)
  84. LIBLORA_TEST = liblora_test.$(SOEXT)
  85. $(LIBLORA_TEST): $(LIBLORA_TEST_OBJS)
  86. $(CC) -shared -o $@ $(.ALLSRC)
  87. .MAIN: all
  88. .PHONY: all
  89. all: $(PROG)$(PROGEXT) $(PROG).list
  90. .PHONY: depend
  91. depend: .arm_deps .test_deps
  92. .sinclude ".arm_deps"
  93. .sinclude ".test_deps"
  94. .arm_deps: $(SRCS)
  95. $(ARMCC) $(ARMTARGET) $(CFLAGS) $(.ALLSRC) -MM > $@ || rm -f $@
  96. .test_deps: $(LIBLORA_TEST_SRCS)
  97. $(CC) $(CFLAGS) $(.ALLSRC) -MM | sed -e 's/\.o:/\.no:/' > $@ || rm -f $@
  98. $(PROG)$(PROGEXT): $(OBJS)
  99. $(ARMCC) $(ARMTARGET) -o $@ $(.ALLSRC) -T$(LINKER_SCRIPT) --specs=nosys.specs -Wl,--gc-sections -static --specs=nano.specs -Wl,--start-group -lc -lm -Wl,--end-group
  100. $(PROG).list: $(PROG)$(PROGEXT)
  101. $(ARMOBJDUMP) -h -S $(.ALLSRC) > $@ || rm -f $@
  102. .PHONY: runbuild
  103. runbuild: $(SRCS)
  104. for i in $(.MAKEFILE_LIST) $(.ALLSRC) $$(gsed ':x; /\\$$/ { N; s/\\\n//; tx }' < .depend | sed -e 's/^[^:]*://'); do if [ "$$i" != ".." ]; then echo $$i; fi; done | entr -d sh -c 'echo starting...; cd $(.CURDIR) && $(MAKE) $(.MAKEFLAGS) depend && $(MAKE) $(.MAKEFLAGS) all'
  105. .PHONY: runtests
  106. runtests: Makefile lora_comms.py lora.py $(LIBLORA_TEST) $(LIBLORA_TEST_SRCS)
  107. ls $(.ALLSRC) | entr sh -c '(cd $(.CURDIR) && $(MAKE) $(.MAKEFLAGS) $(LIBLORA_TEST)) && ((PYTHONPATH="$(.CURDIR)" python -m coverage run -m unittest lora && coverage report --omit=p/\* -m -i) 2>&1 | head -n 30)'
  108. # native objects
  109. .SUFFIXES: .no
  110. .c.no:
  111. $(CC) $(CFLAGS) -c $< -o $@
  112. .c.o:
  113. $(ARMCC) $(ARMTARGET) $(CFLAGS) -c $< -o $@
  114. STROBE_NAME = strobe
  115. STROBE_REPO = https://git.code.sf.net/p/strobe/code
  116. STROBE_BRANCH = master
  117. LORAMAC_NAME = loramac
  118. LORAMAC_REPO = https://github.com/Lora-net/LoRaMac-node.git
  119. LORAMAC_BRANCH = master
  120. .for module in STROBE LORAMAC
  121. .PHONY: init-$($(module)_NAME)
  122. init-$($(module)_NAME):
  123. git subtree add -P $($(module)_NAME) --squash $($(module)_REPO) $($(module)_BRANCH)
  124. .PHONY: update-$($(module)_NAME)
  125. update-$($(module)_NAME):
  126. git subtree pull -P $($(module)_NAME) --squash $($(module)_REPO) $($(module)_BRANCH)
  127. .endfor