| @@ -38,10 +38,11 @@ PROGS = lora.gw lora.irr | |||||
| SRCS.lora.gw = main.c | SRCS.lora.gw = main.c | ||||
| SRCS.lora.gw+= $(SRCS.NODE151) | SRCS.lora.gw+= $(SRCS.NODE151) | ||||
| SRCS.lora.gw+= $(SRCS.USB_CDC) | |||||
| SRCS.lora.gw+= $(SRCS.USB) | |||||
| SRCS.lora.irr = irr_main.c | SRCS.lora.irr = irr_main.c | ||||
| SRCS.lora.irr+= comms.c | SRCS.lora.irr+= comms.c | ||||
| SRCS.lora.irr+= strobe_rng_init.c | |||||
| SRCS.lora.irr+= $(STROBE_SRCS) | SRCS.lora.irr+= $(STROBE_SRCS) | ||||
| SRCS.lora.irr+= $(SRCS.NODE151) | SRCS.lora.irr+= $(SRCS.NODE151) | ||||
| @@ -52,6 +53,10 @@ CFLAGS+= -I$(.OBJDIR) # for shared_key.h | |||||
| WITH_STROBE=yes | WITH_STROBE=yes | ||||
| # XXX - bsd.mkopt.mk only allows an option to have one upstream, I want | |||||
| # more. | |||||
| WITH_HAL_INIT=yes | |||||
| WITH_SX1276=yes | WITH_SX1276=yes | ||||
| WITH_NODE151=yes | WITH_NODE151=yes | ||||
| @@ -44,6 +44,8 @@ | |||||
| #endif | #endif | ||||
| #include "board.h" | #include "board.h" | ||||
| #include <sysinit.h> | |||||
| #include <usb_device.h> | #include <usb_device.h> | ||||
| /*! | /*! | ||||
| @@ -123,8 +125,6 @@ void BoardInitMcu( void ) | |||||
| { | { | ||||
| if( McuInitialized == false ) | if( McuInitialized == false ) | ||||
| { | { | ||||
| HAL_Init( ); | |||||
| #if 0 | #if 0 | ||||
| // LEDs | // LEDs | ||||
| GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); | GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); | ||||
| @@ -193,8 +193,6 @@ void BoardInitMcu( void ) | |||||
| SystemClockReConfig( ); | SystemClockReConfig( ); | ||||
| } | } | ||||
| MX_USB_DEVICE_Init(); | |||||
| AdcInit( &Adc, PB_15 ); // Just initialize ADC | AdcInit( &Adc, PB_15 ); // Just initialize ADC | ||||
| /* setup routing */ | /* setup routing */ | ||||
| @@ -233,6 +231,7 @@ void BoardInitMcu( void ) | |||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| SYSINIT_VF(initmcu, SI_SUB_HAL, SI_ORDER_SECOND, BoardInitMcu); | |||||
| void BoardResetMcu( void ) | void BoardResetMcu( void ) | ||||
| { | { | ||||
| @@ -476,12 +475,6 @@ void SystemClockReConfig( void ) | |||||
| } | } | ||||
| } | } | ||||
| void SysTick_Handler( void ) | |||||
| { | |||||
| HAL_IncTick( ); | |||||
| HAL_SYSTICK_IRQHandler( ); | |||||
| } | |||||
| uint8_t GetBoardPowerSource( void ) | uint8_t GetBoardPowerSource( void ) | ||||
| { | { | ||||
| if( UsbIsConnected == false ) | if( UsbIsConnected == false ) | ||||
| @@ -33,6 +33,8 @@ | |||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <sysinit.h> | |||||
| #define nitems(x) (sizeof(x) / sizeof *(x)) | #define nitems(x) (sizeof(x) / sizeof *(x)) | ||||
| #define DEFINE_RNG_SAVE 1 | #define DEFINE_RNG_SAVE 1 | ||||
| #if DEFINE_RNG_SAVE | #if DEFINE_RNG_SAVE | ||||
| @@ -58,6 +60,7 @@ strobe_rng_init(void) | |||||
| strobe_seed_prng(sbrk(0), 2*1024); | strobe_seed_prng(sbrk(0), 2*1024); | ||||
| } | } | ||||
| SYSINIT_VF(rng_init, SI_SUB_HAL, SI_ORDER_LAST, strobe_rng_init); | |||||
| void | void | ||||
| strobe_rng_save(void) | strobe_rng_save(void) | ||||
| @@ -85,3 +88,4 @@ strobe_rng_save(void) | |||||
| __set_PRIMASK(primask); | __set_PRIMASK(primask); | ||||
| } | } | ||||
| SYSINIT_VF(rng_save, SI_SUB_LAST, SI_ORDER_LAST, strobe_rng_save); | |||||
| @@ -1,4 +1,4 @@ | |||||
| #include <stm32f1xx_hal.h> | |||||
| #include <main.h> | |||||
| void | void | ||||
| SysTick_Handler(void) | SysTick_Handler(void) | ||||
| @@ -38,6 +38,8 @@ | |||||
| #include <strobe_rng_init.h> | #include <strobe_rng_init.h> | ||||
| #include <comms.h> | #include <comms.h> | ||||
| #include <sysinit.h> | |||||
| enum { | enum { | ||||
| CMD_TERMINATE = 1, | CMD_TERMINATE = 1, | ||||
| CMD_WAITFOR = 2, | CMD_WAITFOR = 2, | ||||
| @@ -134,6 +136,7 @@ radio_seed_rng(void) | |||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| SYSINIT_VF(radio_seed_rng, SI_SUB_STANDARD, SI_ORDER_ANY, radio_seed_rng); | |||||
| static void | static void | ||||
| analog_seed_rng(void) | analog_seed_rng(void) | ||||
| @@ -155,6 +158,7 @@ analog_seed_rng(void) | |||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| SYSINIT_VF(analog_seed_rng, SI_SUB_STANDARD, SI_ORDER_ANY, analog_seed_rng); | |||||
| static inline uint32_t | static inline uint32_t | ||||
| letoh_32(uint8_t *v) | letoh_32(uint8_t *v) | ||||
| @@ -206,6 +210,7 @@ setup_gpio() | |||||
| set_chan(i, chans[i].init); | set_chan(i, chans[i].init); | ||||
| } | } | ||||
| } | } | ||||
| SYSINIT_VF(setup_gpio, SI_SUB_HAL, SI_ORDER_LAST, setup_gpio); | |||||
| static struct sched { | static struct sched { | ||||
| uint32_t cmd; | uint32_t cmd; | ||||
| @@ -339,23 +344,18 @@ procmsg(struct pktbuf inbuf, struct pktbuf *outbuf) | |||||
| outbuf->pktlen = 1; | outbuf->pktlen = 1; | ||||
| } | } | ||||
| int | |||||
| main() | |||||
| void | |||||
| radio_init(void) | |||||
| { | { | ||||
| strobe_rng_init(); | |||||
| BoardInitMcu(); | |||||
| Radio.Init(&revents); | Radio.Init(&revents); | ||||
| } | |||||
| analog_seed_rng(); | |||||
| radio_seed_rng(); | |||||
| strobe_rng_save(); | |||||
| SYSINIT_VF(radio_init, SI_SUB_HAL, SI_ORDER_MIDDLE, radio_init); | |||||
| setup_gpio(); | |||||
| int | |||||
| main() | |||||
| { | |||||
| /* turn on LED */ | /* turn on LED */ | ||||
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | ||||
| @@ -24,6 +24,7 @@ | |||||
| * | * | ||||
| */ | */ | ||||
| #include <usb_device.h> | |||||
| #include <usbd_cdc_if.h> | #include <usbd_cdc_if.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| @@ -37,6 +38,20 @@ | |||||
| /* lora-irr headers */ | /* lora-irr headers */ | ||||
| #include <misc.h> | #include <misc.h> | ||||
| #include <sysinit.h> | |||||
| /* Start up USB */ | |||||
| SYSINIT_VF(usb_cdc, SI_SUB_USB, SI_ORDER_MIDDLE, MX_USB_DEVICE_Init); | |||||
| /* XXX - where's a better place? */ | |||||
| extern PCD_HandleTypeDef hpcd_USB_FS; | |||||
| void | |||||
| USB_LP_IRQHandler(void) | |||||
| { | |||||
| HAL_PCD_IRQHandler(&hpcd_USB_FS); | |||||
| } | |||||
| char * | char * | ||||
| findeol(char *pos, size_t len) | findeol(char *pos, size_t len) | ||||
| @@ -187,16 +202,21 @@ process_line(char *start, char *end) | |||||
| fflush(vcp_usb); | fflush(vcp_usb); | ||||
| } | } | ||||
| void | |||||
| radio_init(void) | |||||
| { | |||||
| Radio.Init(&revents); | |||||
| } | |||||
| SYSINIT_VF(radio_init, SI_SUB_STANDARD, SI_ORDER_ANY, radio_init); | |||||
| int | int | ||||
| main(void) | main(void) | ||||
| { | { | ||||
| debug_printf("starting...\n"); | debug_printf("starting...\n"); | ||||
| BoardInitMcu(); | |||||
| Radio.Init(&revents); | |||||
| /* turn on LED */ | /* turn on LED */ | ||||
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | ||||
| @@ -210,7 +230,7 @@ main(void) | |||||
| * STM32 Core USB library: | * STM32 Core USB library: | ||||
| * https://github.com/STMicroelectronics/STM32CubeL1/issues/10 | * https://github.com/STMicroelectronics/STM32CubeL1/issues/10 | ||||
| */ | */ | ||||
| DelayMs(50); | |||||
| DelayMs(100); | |||||
| usb_printf("starting...\r\n"); | usb_printf("starting...\r\n"); | ||||
| #endif | #endif | ||||
| @@ -40,6 +40,11 @@ STROBE_SRCS+= strobe.c \ | |||||
| STROBE_SRCS+= strobe_f1_rng_init.c | STROBE_SRCS+= strobe_f1_rng_init.c | ||||
| .endif | .endif | ||||
| .if ${MK_STROBE} == "yes" && ${MK_NODE151} == "yes" | |||||
| .PATH: $(SRCTOP)/board | |||||
| STROBE_SRCS+= strobe_l1_rng_init.c | |||||
| .endif | |||||
| # LoRamac (SX1276) radio code | # LoRamac (SX1276) radio code | ||||
| .if ${MK_SX1276} == "yes" | .if ${MK_SX1276} == "yes" | ||||
| LORAMAC_SRC = $(SRCTOP)/loramac/src | LORAMAC_SRC = $(SRCTOP)/loramac/src | ||||
| @@ -98,6 +103,7 @@ ARMTARGET?= -mcpu=cortex-m3 -mthumb | |||||
| LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld | LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld | ||||
| SRCS+= \ | SRCS+= \ | ||||
| hal_generic.c \ | |||||
| startup_stm32l151ccux.s \ | startup_stm32l151ccux.s \ | ||||
| stm32l1xx_hal.c \ | stm32l1xx_hal.c \ | ||||
| stm32l1xx_hal_adc.c \ | stm32l1xx_hal_adc.c \ | ||||
| @@ -174,7 +180,7 @@ SRCS.USB+= \ | |||||
| .endif | .endif | ||||
| .if ${MK_USB} == "yes" && ${MK_NODE151} == "yes" | .if ${MK_USB} == "yes" && ${MK_NODE151} == "yes" | ||||
| # note that the Node151 does not need the USB reset hack in si_usb.c | |||||
| SRCS.USB_CDC+= \ | SRCS.USB_CDC+= \ | ||||
| si_usb.c \ | |||||
| stm32l1xx_ll_usb.c | stm32l1xx_ll_usb.c | ||||
| .endif | .endif | ||||
| @@ -34,7 +34,7 @@ PROGEXT = .elf | |||||
| DEPENDS += .arm_deps | DEPENDS += .arm_deps | ||||
| .for i in $(PROGS) | .for i in $(PROGS) | ||||
| ALLTGTS+= $(i)$(PROGEXT) $(i).list | |||||
| ALLTGTS+= $(i)$(PROGEXT) $(i).list $(i).sysinit | |||||
| ASRCS.$(i) = $(SRCS) $(SRCS.$(i)) | ASRCS.$(i) = $(SRCS) $(SRCS.$(i)) | ||||
| OBJS.$(i) = $(ASRCS.$(i):C/.c$/.o/) | OBJS.$(i) = $(ASRCS.$(i):C/.c$/.o/) | ||||
| @@ -43,6 +43,9 @@ ARM_DEP_SRCS+= $(ASRCS.$(i)) | |||||
| $(i)$(PROGEXT) $(i).map: $(OBJS.$(i)) | $(i)$(PROGEXT) $(i).map: $(OBJS.$(i)) | ||||
| $(ARMCC) $(ARMTARGET) -o $(i)$(PROGEXT) $(.ALLSRC) -T$(LINKER_SCRIPT) --specs=nosys.specs -Wl,-Map="$(i).map" -Wl,--gc-sections -static --specs=nano.specs -Wl,--start-group -lc -lm -Wl,--end-group | $(ARMCC) $(ARMTARGET) -o $(i)$(PROGEXT) $(.ALLSRC) -T$(LINKER_SCRIPT) --specs=nosys.specs -Wl,-Map="$(i).map" -Wl,--gc-sections -static --specs=nano.specs -Wl,--start-group -lc -lm -Wl,--end-group | ||||
| $(i).sysinit: $(ASRCS.$(i)) | |||||
| grep ^SYSINIT $(.ALLSRC) | sort -k 2 -k 3 > $@ || (rm -f $@ && false) | |||||
| $(i).list: $(i)$(PROGEXT) | $(i).list: $(i)$(PROGEXT) | ||||
| $(ARMOBJDUMP) -h -S $(.ALLSRC) > $@ || (rm -f $@ && false) | $(ARMOBJDUMP) -h -S $(.ALLSRC) > $@ || (rm -f $@ && false) | ||||
| .endfor | .endfor | ||||
| @@ -227,8 +227,6 @@ int | |||||
| main(void) | main(void) | ||||
| { | { | ||||
| sysinit_run(); | |||||
| debug_printf("starting...\n"); | debug_printf("starting...\n"); | ||||
| #if 0 | #if 0 | ||||
| @@ -413,8 +413,6 @@ main() | |||||
| debug_printf("starting..."); | debug_printf("starting..."); | ||||
| sysinit_run(); | |||||
| #if 0 | #if 0 | ||||
| /* turn on LED */ | /* turn on LED */ | ||||
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); | ||||
| @@ -7,8 +7,7 @@ | |||||
| #include <sysinit.h> | #include <sysinit.h> | ||||
| #include <stm32f1xx_hal_gpio.h> | |||||
| #include <usbd_cdc_if.h> | |||||
| #include <usb_device.h> | #include <usb_device.h> | ||||
| static void | static void | ||||
| @@ -3,6 +3,9 @@ | |||||
| ** | ** | ||||
| ** File : LinkerScript.ld | ** File : LinkerScript.ld | ||||
| ** | ** | ||||
| XXX | |||||
| ** Author : Auto-generated by STM32CubeIDE | ** Author : Auto-generated by STM32CubeIDE | ||||
| ** | ** | ||||
| ** Abstract : Linker script for STM32L151CCUx Device from stm32l1 series | ** Abstract : Linker script for STM32L151CCUx Device from stm32l1 series | ||||
| @@ -101,6 +104,9 @@ SECTIONS | |||||
| *(.rodata) /* .rodata sections (constants, strings, etc.) */ | *(.rodata) /* .rodata sections (constants, strings, etc.) */ | ||||
| *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ | ||||
| . = ALIGN(4); | . = ALIGN(4); | ||||
| __start_set_sysinit_set = .; | |||||
| KEEP(*(set_sysinit_set)) /* sysinit linker sets */ | |||||
| __stop_set_sysinit_set = .; | |||||
| } >FLASH | } >FLASH | ||||
| .ARM.extab : { | .ARM.extab : { | ||||
| @@ -184,20 +184,6 @@ void PendSV_Handler(void) | |||||
| /* please refer to the startup file (startup_stm32l1xx.s). */ | /* please refer to the startup file (startup_stm32l1xx.s). */ | ||||
| /******************************************************************************/ | /******************************************************************************/ | ||||
| /** | |||||
| * @brief This function handles USB low priority interrupt. | |||||
| */ | |||||
| void USB_LP_IRQHandler(void) | |||||
| { | |||||
| /* USER CODE BEGIN USB_LP_IRQn 0 */ | |||||
| /* USER CODE END USB_LP_IRQn 0 */ | |||||
| HAL_PCD_IRQHandler(&hpcd_USB_FS); | |||||
| /* USER CODE BEGIN USB_LP_IRQn 1 */ | |||||
| /* USER CODE END USB_LP_IRQn 1 */ | |||||
| } | |||||
| /** | /** | ||||
| * @brief This function handles TIM4 global interrupt. | * @brief This function handles TIM4 global interrupt. | ||||
| */ | */ | ||||
| @@ -31,7 +31,7 @@ | |||||
| SET_DECLARE(sysinit_set, struct sysinit); | SET_DECLARE(sysinit_set, struct sysinit); | ||||
| void | |||||
| void __attribute__ ((constructor)) | |||||
| sysinit_run(void) | sysinit_run(void) | ||||
| { | { | ||||
| const int cnt = SET_COUNT(sysinit_set); | const int cnt = SET_COUNT(sysinit_set); | ||||