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

@ -121,6 +121,7 @@ C_INCLUDES = \
-IUser/Inc \
-IioLibrary_Driver/Internet/DNS \
-IioLibrary_Driver/Internet/DHCP \
-IioLibrary_Driver/Internet/SNTP \
-IioLibrary_Driver/Ethernet \
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \

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