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.
 
 
 
 
 
 

185 lines
5.5 KiB

  1. # Copyright 2021 John-Mark Gurney.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions
  5. # are met:
  6. # 1. Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # 2. Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  13. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  16. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  18. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  19. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. # SUCH DAMAGE.
  23. #
  24. ARMOBJDUMP?= arm-none-eabi-objdump
  25. ARMCC?= arm-none-eabi-gcc
  26. ARMTARGET?= -mcpu=cortex-m3 -mthumb -DSTROBE_SINGLE_THREAD=1
  27. # Clang doesn't work due to no-nano libc
  28. #ARMCC?=clang-mp-9.0
  29. #ARMTARGET?= -nostdlib -ffreestanding -target arm-none-eabi -mcpu=cortex-m3 -mfloat-abi=soft -mthumb
  30. PLATFORM != uname -s
  31. .if $(PLATFORM) == "Darwin"
  32. SOEXT=dylib
  33. .else
  34. .error Unsupported platform: $(PLATFORM)
  35. .endif
  36. PROG = lora.irr
  37. PROGEXT = .elf
  38. SRCS = main.c
  39. SRCS+= board.c
  40. SRCS+= misc.c
  41. SRCS+= strobe_rng_init.c
  42. CFLAGS+= -I$(.CURDIR)
  43. CFLAGS+= -g
  44. #CFLAGS+= -DNDEBUG
  45. # Strobe
  46. .PATH: $(.CURDIR)/strobe
  47. CFLAGS+= -I$(.CURDIR)/strobe
  48. SRCS+= strobe.c \
  49. x25519.c
  50. # LoRamac (SX1276) radio code
  51. LORAMAC_SRC = $(.CURDIR)/loramac/src
  52. .PATH: $(LORAMAC_SRC)/radio/sx1276 $(LORAMAC_SRC)/system $(LORAMAC_SRC)/boards/mcu $(LORAMAC_SRC)/boards/NucleoL152
  53. CFLAGS+= -I$(LORAMAC_SRC)/boards
  54. CFLAGS+= -I$(LORAMAC_SRC)/system
  55. CFLAGS+= -I$(LORAMAC_SRC)/radio
  56. CFLAGS+= -DUSE_HAL_DRIVER -DSX1276MB1LAS
  57. SRCS+= sx1276.c
  58. SRCS+= utilities.c
  59. SRCS+= adc.c timer.c delay.c gpio.c uart.c fifo.c
  60. 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
  61. # Microcontroller
  62. STM32=$(.CURDIR)/stm32
  63. .PATH: $(STM32)/l151ccux
  64. LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld
  65. SRCS+= \
  66. startup_stm32l151ccux.s \
  67. stm32l1xx_hal.c \
  68. stm32l1xx_hal_adc.c \
  69. stm32l1xx_hal_adc_ex.c \
  70. stm32l1xx_hal_cortex.c \
  71. stm32l1xx_hal_dma.c \
  72. stm32l1xx_hal_gpio.c \
  73. stm32l1xx_hal_pcd.c \
  74. stm32l1xx_hal_pcd_ex.c \
  75. stm32l1xx_hal_pwr.c \
  76. stm32l1xx_hal_pwr_ex.c \
  77. stm32l1xx_hal_rcc.c \
  78. stm32l1xx_hal_rcc_ex.c \
  79. stm32l1xx_hal_rtc.c \
  80. stm32l1xx_hal_rtc_ex.c \
  81. stm32l1xx_hal_spi.c \
  82. stm32l1xx_hal_uart.c \
  83. system_stm32l1xx.c
  84. SRCS+= \
  85. stm32l1xx_it.c \
  86. stm32l1xx_hal_msp.c
  87. CFLAGS+= -I$(STM32)
  88. CFLAGS+= -I$(STM32)/l151ccux
  89. CFLAGS+= -DSTM32L151xC
  90. # USB
  91. .PATH: $(STM32)/usb
  92. SRCS+= \
  93. stm32l1xx_ll_usb.c \
  94. usb_device.c \
  95. usbd_cdc.c \
  96. usbd_cdc_if.c \
  97. usbd_conf.c \
  98. usbd_core.c \
  99. usbd_ctlreq.c \
  100. usbd_desc.c \
  101. usbd_ioreq.c
  102. CFLAGS+= -I$(STM32)/usb
  103. OBJS = $(SRCS:C/.c$/.o/)
  104. CFLAGS+= -Werror -Wall
  105. LIBLORA_TEST_SRCS= comms.c strobe.c x25519.c
  106. LIBLORA_TEST_OBJS= $(LIBLORA_TEST_SRCS:C/.c$/.no/)
  107. LIBLORA_TEST = liblora_test.$(SOEXT)
  108. $(LIBLORA_TEST): $(LIBLORA_TEST_OBJS)
  109. $(CC) -shared -o $@ $(.ALLSRC)
  110. .MAIN: all
  111. .PHONY: all
  112. all: $(PROG)$(PROGEXT) $(PROG).list
  113. DEPENDS = .arm_deps .test_deps
  114. .PHONY: depend
  115. depend: $(DEPENDS)
  116. .for i in $(DEPENDS)
  117. .sinclude "$i"
  118. .endfor
  119. .arm_deps: $(SRCS)
  120. $(ARMCC) $(ARMTARGET) $(CFLAGS) $(.ALLSRC) -MM > $@ || (rm -f $@ && false)
  121. .test_deps: $(LIBLORA_TEST_SRCS)
  122. $(CC) $(CFLAGS) $(.ALLSRC) -MM | sed -e 's/\.o:/\.no:/' > $@ || (rm -f $@ && false)
  123. $(PROG)$(PROGEXT): $(OBJS)
  124. $(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
  125. $(PROG).list: $(PROG)$(PROGEXT)
  126. $(ARMOBJDUMP) -h -S $(.ALLSRC) > $@ || (rm -f $@ && false)
  127. .PHONY: runbuild
  128. runbuild: $(SRCS)
  129. for i in $(.MAKEFILE_LIST) $(.ALLSRC) $$(cat $(DEPENDS) | gsed ':x; /\\$$/ { N; s/\\\n//; tx }' | 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'
  130. .PHONY: runtests
  131. runtests: Makefile lora_comms.py lora.py $(LIBLORA_TEST) $(LIBLORA_TEST_SRCS)
  132. 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)'
  133. # native objects
  134. .SUFFIXES: .no
  135. .c.no:
  136. $(CC) $(CFLAGS) -c $< -o $@
  137. .c.o:
  138. $(ARMCC) $(ARMTARGET) $(CFLAGS) -c $< -o $@
  139. STROBE_NAME = strobe
  140. STROBE_REPO = https://git.code.sf.net/p/strobe/code
  141. STROBE_BRANCH = master
  142. LORAMAC_NAME = loramac
  143. LORAMAC_REPO = https://github.com/Lora-net/LoRaMac-node.git
  144. LORAMAC_BRANCH = master
  145. .for module in STROBE LORAMAC
  146. .PHONY: init-$($(module)_NAME)
  147. init-$($(module)_NAME):
  148. git subtree add -P $($(module)_NAME) --squash $($(module)_REPO) $($(module)_BRANCH)
  149. .PHONY: update-$($(module)_NAME)
  150. update-$($(module)_NAME):
  151. git subtree pull -P $($(module)_NAME) --squash $($(module)_REPO) $($(module)_BRANCH)
  152. .endfor