This commit is contained in:
2021-02-07 13:47:34 +01:00
parent c691620ff7
commit a5f20fc073
7 changed files with 204 additions and 46 deletions

View File

@ -1,4 +1,4 @@
# Processed by ../tools/insertMyCode.sh
# Processed by ../tools/insertMyCode.sh
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sun Feb 07 10:58:33 CET 2021]
##########################################################################################################################
@ -36,34 +36,34 @@ BUILD_DIR = build
# source
######################################
# C sources
C_SOURCES = \
User/Src/adminCmds.c User/Src/cmdHandler.c User/Src/config.c User/Src/configCmds.c User/Src/eeprom.c User/Src/logger.c User/Src/main2.c User/Src/ports.c User/Src/regularCmds.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/spi.c \
Core/Src/tim.c \
Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \
Core/Src/stm32f1xx_hal_msp.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
C_SOURCES = \
User/Src/adminCmds.c User/Src/cmdHandler.c User/Src/config.c User/Src/configCmds.c User/Src/eeprom.c User/Src/logger.c User/Src/main2.c User/Src/ports.c User/Src/regularCmds.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/spi.c \
Core/Src/tim.c \
Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \
Core/Src/stm32f1xx_hal_msp.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
Core/Src/system_stm32f1xx.c
# ASM sources
ASM_SOURCES = \
ASM_SOURCES = \
startup_stm32f103xb.s
@ -107,8 +107,8 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32F103xB
@ -116,17 +116,18 @@ C_DEFS = \
AS_INCLUDES =
# C includes
C_INCLUDES = \
-Ihottislib \
-IUser/Inc \
-IioLibrary_Driver/Internet/DNS \
-IioLibrary_Driver/Internet/DHCP \
-IioLibrary_Driver/Ethernet \
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include \
C_INCLUDES = \
-Ihottislib \
-IUser/Inc \
-IioLibrary_Driver/Internet/DNS \
-IioLibrary_Driver/Internet/DHCP \
-IioLibrary_Driver/Internet/SNTP \
-IioLibrary_Driver/Ethernet \
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include \
-IDrivers/CMSIS/Include
@ -165,14 +166,14 @@ all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a)
OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a)
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/w5500.a:
(cd ioLibrary_Driver && $(MAKE) && cp w5500.a ../$(BUILD_DIR) && cd ..)
$(BUILD_DIR)/w5500.a:
(cd ioLibrary_Driver && $(MAKE) && cp w5500.a ../$(BUILD_DIR) && cd ..)
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

View File

@ -5,6 +5,8 @@
#include <stdint.h>
#define NTP_SERVER "0.pool.ntp.org"
int wizInit();
bool isNetworkAvailable();
uint8_t* wizGetIPAddress();

View File

@ -5,7 +5,6 @@
// on the W5500 there are eight ports available
const uint8_t DHCP_SOCK = 0;
const uint8_t MQTT_SOCK = 1;
const uint8_t SNTP_SOCK = 1;
const uint8_t CMD_SOCK = 2;
const uint8_t SYSLOG_SOCK = 3;
const uint8_t DNS_SOCK = 4;
const uint8_t DNS_SOCK = 3;

View File

@ -11,6 +11,7 @@
#include <dhcp.h>
#include <show.h>
#include <dns.h>
#include <sntp.h>
#include <config.h>
@ -25,8 +26,14 @@ static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE];
#define DNS_BUFFER_SIZE MAX_DNS_BUF_SIZE
static uint8_t dnsBuffer[DNS_BUFFER_SIZE];
static uint8_t sntpBuffer[MAX_SNTP_BUF_SIZE];
static datetime curTime;
extern const uint8_t DHCP_SOCK;
extern const uint8_t DNS_SOCK;
extern const uint8_t SNTP_SOCK;
static bool networkAvailable = false;
@ -125,12 +132,32 @@ bool wizDnsQuery(char *name, uint8_t *ip) {
return retCode;
}
static void wizSNTPHandler(void *handle) {
if (networkAvailable) {
coloredMsg(LOG_BLUE, "wizsh, about to call SNTP");
int8_t res = SNTP_run(&curTime);
coloredMsg(LOG_BLUE, "wizsh, res: %d", res);
if (res == 1) {
coloredMsg(LOG_BLUE, "wizsh, curTime: %04d-%02d-%02d %02d:%02d:%02d",
curTime.yy, curTime.mo, curTime.dd,
curTime.hh, curTime.mm, curTime.ss);
} else {
coloredMsg(LOG_BLUE, "wizsh, error when requesting time");
}
}
}
static void wizPhyLinkHandler(void *handle) {
// this handler is anyhow called with a 1s period, so we reuse it for the DNS timer
DNS_time_handler();
static uint8_t lastStablePhyLink = 255;
static bool dhcpInitialized = false;
static bool sntpInitialized = false;
uint8_t phyLink = 0;
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
@ -150,6 +177,13 @@ static void wizPhyLinkHandler(void *handle) {
coloredMsg(LOG_BLUE, "wizplh, DHCP handler scheduled");
dhcpInitialized = true;
SNTP_init(SNTP_SOCK, NTP_SERVER, 0, sntpBuffer);
schAdd(wizSNTPHandler, NULL, 0, 60*1000);
coloredMsg(LOG_BLUE, "wizplh, SNTP handler scheduled");
sntpInitialized = true;
} else {
networkAvailable = false;
show(LED_GREEN, BLINK);
@ -165,6 +199,13 @@ static void wizPhyLinkHandler(void *handle) {
dhcpInitialized = false;
}
if (sntpInitialized) {
schDel(wizSNTPHandler, NULL);
coloredMsg(LOG_BLUE, "wizplh, SNTP handler unscheduled");
sntpInitialized = false;
}
}
}
}

BIN
cube/cube.pdf Normal file

Binary file not shown.

114
cube/cube.txt Normal file
View File

@ -0,0 +1,114 @@
Configuration cube
STM32CubeMX 6.0.0
Date 02/02/2021
MCU STM32F103C8Tx
PERIPHERALS MODES FUNCTIONS PINS
RCC Crystal/Ceramic Resonator RCC_OSC_IN PD0-OSC_IN
RCC Crystal/Ceramic Resonator RCC_OSC_OUT PD1-OSC_OUT
SPI1 Full-Duplex Master SPI1_MISO PA6
SPI1 Full-Duplex Master SPI1_MOSI PA7
SPI1 Full-Duplex Master SPI1_SCK PA5
SPI2 Full-Duplex Master SPI2_MISO PB14
SPI2 Full-Duplex Master SPI2_MOSI PB15
SPI2 Full-Duplex Master SPI2_SCK PB13
SYS Serial Wire SYS_JTCK-SWCLK PA14
SYS Serial Wire SYS_JTMS-SWDIO PA13
SYS SysTick SYS_VS_Systick VP_SYS_VS_Systick
TIM1 Internal Clock TIM1_VS_ClockSourceINT VP_TIM1_VS_ClockSourceINT
TIM1 Input Capture direct mode TIM1_CH1 PA8
USART1 Asynchronous USART1_RX PA10
USART1 Asynchronous USART1_TX PA9
Pin Nb PINs FUNCTIONs LABELs
2 PC13-TAMPER-RTC GPIO_Output LED_Red
3 PC14-OSC32_IN GPIO_Output LED_Green
5 PD0-OSC_IN RCC_OSC_IN
6 PD1-OSC_OUT RCC_OSC_OUT
14 PA4 GPIO_Output EEPROM_CS
15 PA5 SPI1_SCK EEPROM_SCK
16 PA6 SPI1_MISO EEPROM_MISO
17 PA7 SPI1_MOSI EEPROM_MOSI
22 PB11 GPIO_Output ETHER_RES
25 PB12 GPIO_Output ETHER_CS
26 PB13 SPI2_SCK ETHER_SCK
27 PB14 SPI2_MISO ETHER_MISO
28 PB15 SPI2_MOSI ETHER_MOSI
29 PA8 TIM1_CH1
30 PA9 USART1_TX Debug_TX
31 PA10 USART1_RX Debug_RX
34 PA13 SYS_JTMS-SWDIO
37 PA14 SYS_JTCK-SWCLK
41 PB5 GPIO_Output Debug_Signal_2
42 PB6 GPIO_Output Debug_Signal_1
PERIPHERALS MODES FUNCTIONS PINS
RCC Crystal/Ceramic Resonator RCC_OSC_IN PD0-OSC_IN
RCC Crystal/Ceramic Resonator RCC_OSC_OUT PD1-OSC_OUT
SPI1 Full-Duplex Master SPI1_MISO PA6
SPI1 Full-Duplex Master SPI1_MOSI PA7
SPI1 Full-Duplex Master SPI1_SCK PA5
SPI2 Full-Duplex Master SPI2_MISO PB14
SPI2 Full-Duplex Master SPI2_MOSI PB15
SPI2 Full-Duplex Master SPI2_SCK PB13
SYS Serial Wire SYS_JTCK-SWCLK PA14
SYS Serial Wire SYS_JTMS-SWDIO PA13
SYS SysTick SYS_VS_Systick VP_SYS_VS_Systick
TIM1 Internal Clock TIM1_VS_ClockSourceINT VP_TIM1_VS_ClockSourceINT
TIM1 Input Capture direct mode TIM1_CH1 PA8
USART1 Asynchronous USART1_RX PA10
USART1 Asynchronous USART1_TX PA9
Pin Nb PINs FUNCTIONs LABELs
2 PC13-TAMPER-RTC GPIO_Output LED_Red
3 PC14-OSC32_IN GPIO_Output LED_Green
5 PD0-OSC_IN RCC_OSC_IN
6 PD1-OSC_OUT RCC_OSC_OUT
14 PA4 GPIO_Output EEPROM_CS
15 PA5 SPI1_SCK EEPROM_SCK
16 PA6 SPI1_MISO EEPROM_MISO
17 PA7 SPI1_MOSI EEPROM_MOSI
22 PB11 GPIO_Output ETHER_RES
25 PB12 GPIO_Output ETHER_CS
26 PB13 SPI2_SCK ETHER_SCK
27 PB14 SPI2_MISO ETHER_MISO
28 PB15 SPI2_MOSI ETHER_MOSI
29 PA8 TIM1_CH1
30 PA9 USART1_TX Debug_TX
31 PA10 USART1_RX Debug_RX
34 PA13 SYS_JTMS-SWDIO
37 PA14 SYS_JTCK-SWCLK
41 PB5 GPIO_Output Debug_Signal_2
42 PB6 GPIO_Output Debug_Signal_1
SOFTWARE PROJECT
Project Settings :
Project Name : cube
Project Folder : /home/wn/Workspaces/mains-frequency-counter-stm32/cube
Toolchain / IDE : Makefile
Firmware Package Name and Version : STM32Cube FW_F1 V1.8.3
Code Generation Settings :
STM32Cube MCU packages and embedded software packs : Copy only the necessary library files
Generate peripheral initialization as a pair of '.c/.h' files per peripheral : Yes
Backup previously generated files when re-generating : No
Delete previously generated files when not re-generated : Yes
Set all free pins as analog (to optimize the power consumption) : No
Toolchains Settings :
Compiler Optimizations :

View File

@ -73,6 +73,7 @@ cat $MAKEFILE_BAK | \
-e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Ethernet \\,' \
-e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DHCP \\,' \
-e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DNS \\,' \
-e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/SNTP \\,' \
-e 's,\(C_INCLUDES = \\\),\1\n-IUser/Inc \\,' \
-e 's,\(C_INCLUDES = \\\),\1\n-Ihottislib \\,' \
>> $MAKEFILE