Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

199 Zeilen
6.0 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. .if 0
  43. SRCS+= rng_save.c
  44. .endif
  45. CFLAGS+= -I$(.CURDIR)
  46. CFLAGS+= -g
  47. #CFLAGS+= -DNDEBUG
  48. # Strobe
  49. .PATH: $(.CURDIR)/strobe
  50. CFLAGS+= -I$(.CURDIR)/strobe
  51. SRCS+= strobe.c \
  52. x25519.c
  53. # LoRamac (SX1276) radio code
  54. LORAMAC_SRC = $(.CURDIR)/loramac/src
  55. .PATH: $(LORAMAC_SRC)/radio/sx1276 $(LORAMAC_SRC)/system $(LORAMAC_SRC)/boards/mcu $(LORAMAC_SRC)/boards/NucleoL152
  56. CFLAGS+= -I$(LORAMAC_SRC)/boards
  57. CFLAGS+= -I$(LORAMAC_SRC)/system
  58. CFLAGS+= -I$(LORAMAC_SRC)/radio
  59. CFLAGS+= -DUSE_HAL_DRIVER -DSX1276MB1LAS
  60. SRCS+= sx1276.c
  61. SRCS+= utilities.c
  62. SRCS+= adc.c timer.c delay.c gpio.c uart.c fifo.c
  63. 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
  64. # Microcontroller
  65. STM32=$(.CURDIR)/stm32
  66. .PATH: $(STM32)/l151ccux
  67. LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld
  68. SRCS+= \
  69. startup_stm32l151ccux.s \
  70. stm32l1xx_hal.c \
  71. stm32l1xx_hal_adc.c \
  72. stm32l1xx_hal_adc_ex.c \
  73. stm32l1xx_hal_cortex.c \
  74. stm32l1xx_hal_dma.c \
  75. stm32l1xx_hal_flash.c \
  76. stm32l1xx_hal_flash_ex.c \
  77. stm32l1xx_hal_gpio.c \
  78. stm32l1xx_hal_pcd.c \
  79. stm32l1xx_hal_pcd_ex.c \
  80. stm32l1xx_hal_pwr.c \
  81. stm32l1xx_hal_pwr_ex.c \
  82. stm32l1xx_hal_rcc.c \
  83. stm32l1xx_hal_rcc_ex.c \
  84. stm32l1xx_hal_rtc.c \
  85. stm32l1xx_hal_rtc_ex.c \
  86. stm32l1xx_hal_spi.c \
  87. stm32l1xx_hal_uart.c \
  88. system_stm32l1xx.c
  89. SRCS+= \
  90. stm32l1xx_it.c \
  91. stm32l1xx_hal_msp.c
  92. CFLAGS+= -I$(STM32)
  93. CFLAGS+= -I$(STM32)/l151ccux
  94. CFLAGS+= -DSTM32L151xC
  95. # USB
  96. .PATH: $(STM32)/usb
  97. SRCS+= \
  98. stm32l1xx_ll_usb.c \
  99. usb_device.c \
  100. usbd_cdc.c \
  101. usbd_cdc_if.c \
  102. usbd_conf.c \
  103. usbd_core.c \
  104. usbd_ctlreq.c \
  105. usbd_desc.c \
  106. usbd_ioreq.c
  107. CFLAGS+= -I$(STM32)/usb
  108. OBJS = $(SRCS:C/.c$/.o/)
  109. CFLAGS+= -Werror -Wall
  110. LIBLORA_TEST_SRCS= comms.c strobe.c x25519.c
  111. LIBLORA_TEST_OBJS= $(LIBLORA_TEST_SRCS:C/.c$/.no/)
  112. LIBLORA_TEST = liblora_test.$(SOEXT)
  113. $(LIBLORA_TEST): $(LIBLORA_TEST_OBJS)
  114. $(CC) -shared -o $@ $(.ALLSRC)
  115. .MAIN: all
  116. .PHONY: all
  117. all: $(PROG)$(PROGEXT) $(PROG).list
  118. DEPENDS = .arm_deps .test_deps
  119. .PHONY: depend
  120. depend: $(DEPENDS)
  121. .for i in $(DEPENDS)
  122. .sinclude "$i"
  123. .endfor
  124. # Temporarily disabled as OpenOCD can't program EEPROM on the STM32L1.
  125. # This could be used to add the data to flash.
  126. rng_save.c: Makefile
  127. ( echo '#include <strobe_rng_init.h>'; \
  128. echo 'const rng_word_t rng_save[roundup(32, sizeof(rng_word_t)) / sizeof(rng_word_t)] __attribute__ ((section (".eeprom"))) = {'; \
  129. dd if=/dev/random bs=32 count=1 | hexdump -e '4/4 " %3u," "\n"'; \
  130. echo '};' \
  131. ) > $@ || (rm $@ && false)
  132. .arm_deps: $(SRCS)
  133. $(ARMCC) $(ARMTARGET) $(CFLAGS) $(.ALLSRC) -MM > $@ || (rm -f $@ && false)
  134. .test_deps: $(LIBLORA_TEST_SRCS)
  135. $(CC) $(CFLAGS) $(.ALLSRC) -MM | sed -e 's/\.o:/\.no:/' > $@ || (rm -f $@ && false)
  136. $(PROG)$(PROGEXT) $(PROG).map: $(OBJS)
  137. $(ARMCC) $(ARMTARGET) -o $(PROG)$(PROGEXT) $(.ALLSRC) -T$(LINKER_SCRIPT) --specs=nosys.specs -Wl,-Map="$(PROG).map" -Wl,--gc-sections -static --specs=nano.specs -Wl,--start-group -lc -lm -Wl,--end-group
  138. $(PROG).list: $(PROG)$(PROGEXT)
  139. $(ARMOBJDUMP) -h -S $(.ALLSRC) > $@ || (rm -f $@ && false)
  140. .PHONY: runbuild
  141. runbuild: $(SRCS)
  142. 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'
  143. .PHONY: runtests
  144. runtests: Makefile lora_comms.py lora.py $(LIBLORA_TEST) $(LIBLORA_TEST_SRCS)
  145. 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)'
  146. # native objects
  147. .SUFFIXES: .no
  148. .c.no:
  149. $(CC) $(CFLAGS) -c $< -o $@
  150. .c.o:
  151. $(ARMCC) $(ARMTARGET) $(CFLAGS) -c $< -o $@
  152. STROBE_NAME = strobe
  153. STROBE_REPO = https://git.code.sf.net/p/strobe/code
  154. STROBE_BRANCH = master
  155. LORAMAC_NAME = loramac
  156. LORAMAC_REPO = https://github.com/Lora-net/LoRaMac-node.git
  157. LORAMAC_BRANCH = master
  158. .for module in STROBE LORAMAC
  159. .PHONY: init-$($(module)_NAME)
  160. init-$($(module)_NAME):
  161. git subtree add -P $($(module)_NAME) --squash $($(module)_REPO) $($(module)_BRANCH)
  162. .PHONY: update-$($(module)_NAME)
  163. update-$($(module)_NAME):
  164. git subtree pull -P $($(module)_NAME) --squash $($(module)_REPO) $($(module)_BRANCH)
  165. .endfor