166 Commits

Author SHA1 Message Date
b7071379b9 add volume 2022-10-16 19:40:34 +02:00
e524164cb5 longer watchdog period 2020-12-27 12:39:13 +01:00
98fa27256b enable watchdog 2020-12-27 12:31:51 +01:00
71e024c48a fix insert code script 2020-12-27 12:04:27 +01:00
1ed0c07c66 enable hardware watchdog 2020-12-27 11:48:10 +01:00
d6cd63083d restart on watchdog 2020-12-26 22:09:27 +01:00
dcedd1badf error logging 2020-12-19 17:15:59 +01:00
5bd953781c less logging 2020-12-18 20:18:51 +01:00
ad141d8687 Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mbusgateway3variant 2020-12-18 19:06:13 +01:00
561e189c78 logging 2020-12-18 19:06:06 +01:00
c6d47b81ed list of devices 2020-12-17 16:52:27 +01:00
cd58f5c9c2 addDevice completed 2020-12-17 16:49:23 +01:00
4d604935aa addDevice completed 2020-12-17 16:42:59 +01:00
056a9e9edc deleteDevice 2020-12-17 16:32:17 +01:00
560b08e56c listDevices 2020-12-17 16:27:54 +01:00
3bd5e59786 changeDevice 2020-12-17 16:14:15 +01:00
6f9f6d51d2 changeDevice 2020-12-17 16:11:11 +01:00
232db9cb36 changeDevie 2020-12-17 16:01:52 +01:00
29fcdb3e41 changeDevie 2020-12-17 15:59:44 +01:00
6b976f22cf incomplete changeDevice 2020-12-17 13:44:49 +01:00
12db917466 incomplete changeDevice function 2020-12-17 09:34:34 +01:00
7b79103ed8 ChangeDevice 2020-12-17 09:17:07 +01:00
9f71620697 ChangeDevice 2020-12-17 09:15:01 +01:00
a3847b8bde addDevice 2020-12-17 09:04:27 +01:00
d32eb45bea addDevice 2020-12-17 09:02:46 +01:00
39967403d9 addDevice 2020-12-17 09:00:00 +01:00
46afd83b4b still incomplete makeDevice function 2020-12-16 21:12:48 +01:00
f5400dc18f Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mbusgateway3variant 2020-12-16 20:25:12 +01:00
434dece345 incomplete addDevice function 2020-12-16 20:25:06 +01:00
017e56c9fe set int32 value 2020-12-15 10:19:29 +01:00
296c6270c0 set int32 value 2020-12-15 10:14:16 +01:00
9bd23218d5 Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mbusgateway3variant 2020-12-14 20:47:07 +01:00
f91cefb3bf wrong length check 2020-12-14 20:47:00 +01:00
e3e6d0bb7b uint32_t in offset test 2020-12-13 23:04:23 +01:00
64999eaefc string config done 2020-12-13 22:26:39 +01:00
634c17530f Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mbusgateway3variant 2020-12-12 22:41:01 +01:00
9225de70e9 not yet working offsetof stuff 2020-12-12 22:40:56 +01:00
6c0848ab01 offsetof related experiments 2020-12-12 20:24:58 +01:00
2ee6360820 incomplete change 2020-12-11 22:48:22 +01:00
66395f4d15 fix 2020-12-11 12:55:23 +01:00
1285ebd562 devicename in prompt 2020-12-11 12:54:40 +01:00
4726d845b3 fix 2020-12-11 12:48:49 +01:00
4f6aa1156a fix 2020-12-11 12:46:50 +01:00
6f855faec2 fix 2020-12-11 12:46:09 +01:00
36becf0e5c fix 2020-12-11 12:45:06 +01:00
8843791fc9 set devicename 2020-12-11 12:42:16 +01:00
cfb1dc7d9a disable mbus requests, fix set cmd 2020-12-11 12:18:22 +01:00
7b7a866652 fix 2020-12-11 12:13:51 +01:00
22e10e82fc definition of set 2020-12-11 12:12:57 +01:00
5a24e47d77 include string.h 2020-12-11 12:10:26 +01:00
afb792a4fe start set command 2020-12-11 12:09:32 +01:00
b126217dab handle error when waiting for connection 2020-12-11 11:58:29 +01:00
e2384d01ec command changes 2020-12-01 12:52:04 +01:00
fe1b2e5b40 split commands 2020-12-01 12:43:43 +01:00
765c3b077c device configuration prepared 2020-12-01 12:43:18 +01:00
f019f7eb77 device configuration prepared 2020-12-01 12:23:26 +01:00
0ed710e652 device configuration prepared 2020-12-01 12:20:02 +01:00
24f2d0a01d device configuration prepared 2020-12-01 12:05:35 +01:00
78d32a7cc9 device configuration prepared 2020-12-01 11:39:12 +01:00
a14928b035 device configuration prepared 2020-11-30 19:07:26 +01:00
11265fc979 device configuration prepared 2020-11-30 19:06:37 +01:00
fe694e75d2 device configuration prepared 2020-11-30 19:05:19 +01:00
bde9f148a0 device configuration prepared 2020-11-30 19:03:43 +01:00
77141319ea device configuration prepared 2020-11-30 19:01:53 +01:00
b4170ec6dc device configuration prepared 2020-11-30 18:57:56 +01:00
6a2646b93c device configuration prepared 2020-11-30 18:57:19 +01:00
243c487546 device configuration prepared 2020-11-30 18:55:40 +01:00
7d03900ada device configuration prepared 2020-11-30 18:52:56 +01:00
98c0a9d7a2 device configuration prepared 2020-11-30 18:48:48 +01:00
f22c821ca3 device configuration prepared 2020-11-30 18:29:53 +01:00
76ff0d8e24 rename config mode to admin mode 2020-11-28 22:33:15 +01:00
518abe4e1c configuration 2020-11-27 16:55:09 +01:00
bc15e23f10 configuration 2020-11-27 16:36:46 +01:00
2c392cce53 configuration 2020-11-27 16:33:58 +01:00
a26a2878f4 configuration 2020-11-27 16:33:03 +01:00
6e96a27141 configuration 2020-11-27 16:24:14 +01:00
a43e42a99f configuration 2020-11-27 16:23:34 +01:00
d2c5943014 configuration 2020-11-27 16:23:14 +01:00
f409d3fb22 configuration 2020-11-27 16:19:33 +01:00
ba6ac21069 configuration 2020-11-27 16:19:01 +01:00
39ca9d963b configuration 2020-11-27 16:17:28 +01:00
4e3f086fa0 configuration 2020-11-27 16:16:40 +01:00
44523a4ed3 configuration 2020-11-27 16:14:46 +01:00
9a7e8ee297 configuration 2020-11-27 16:14:34 +01:00
eaf658de51 configuration 2020-11-27 16:07:23 +01:00
9e99d5510d configuration 2020-11-27 16:06:16 +01:00
159750bcf6 configuration 2020-11-27 16:05:36 +01:00
aaad534d21 configuration 2020-11-27 16:02:42 +01:00
e0c3394725 configuration 2020-11-27 15:58:17 +01:00
638171b494 configuration 2020-11-27 15:56:59 +01:00
d4b00cf391 configuration 2020-11-27 15:56:09 +01:00
544163f4a3 configuration 2020-11-27 15:54:16 +01:00
6d7119c0e2 configuration 2020-11-27 15:25:19 +01:00
cb5dd5f79a configuration 2020-11-27 13:37:57 +01:00
9223cbda73 configuration 2020-11-27 13:33:41 +01:00
975ecf40f9 configuration 2020-11-27 13:32:12 +01:00
0b1c6217c4 configuration 2020-11-27 13:27:24 +01:00
3c25a7d9e1 introduce dns for syslog too 2020-11-27 12:50:45 +01:00
b4ef9d29f9 introduce dns for syslog too 2020-11-27 12:49:03 +01:00
7aded82145 prepare configuration 2020-11-27 12:29:21 +01:00
8894036679 introduce dns 2020-11-27 12:28:56 +01:00
3e1a7946c2 disable show debug output 2020-11-26 11:52:54 +01:00
4e04ad6567 consider noise as real error too 2020-11-26 09:50:44 +01:00
cbc3ca6f20 Merge branch 'master' of ssh://home.hottis.de:2922/wolutator/mbusgateway3variant 2020-11-26 09:43:07 +01:00
73c1360978 delay enabling frontend after end of sending 2020-11-26 09:42:51 +01:00
56ac741079 adjust insert script 2020-11-25 15:15:27 +01:00
7a12bba4df change 2020-11-25 13:38:44 +01:00
397c3d2a56 do not consider noise error 2020-11-25 13:35:54 +01:00
f5f8aa0660 consider noise error 2020-11-25 13:33:46 +01:00
1357b17bb8 changes 2020-11-25 13:25:33 +01:00
e2ed18e71d start refactoring transmitting 2020-11-25 13:20:37 +01:00
c9b5f16542 start refactoring transmitting 2020-11-25 13:15:02 +01:00
7b8535e84e start refactoring transmitting 2020-11-25 12:56:24 +01:00
3b3894b3f0 start refactoring transmitting 2020-11-25 12:55:10 +01:00
03cadcdd58 start refactoring transmitting 2020-11-25 12:46:09 +01:00
8fe627e6b0 start refactoring transmitting 2020-11-25 12:42:33 +01:00
e1640be4c0 start refactoring transmitting 2020-11-25 12:36:36 +01:00
b328e41984 start refactoring transmitting 2020-11-25 12:08:13 +01:00
02c093723e start refactoring transmitting 2020-11-25 12:04:27 +01:00
802fec74e2 start refactoring transmitting 2020-11-25 12:00:01 +01:00
96d0599e20 start refactoring transmitting 2020-11-25 11:57:54 +01:00
d86f767dc3 start refactoring transmitting 2020-11-25 11:56:09 +01:00
3e31693cf8 start refactoring transmitting 2020-11-25 11:51:55 +01:00
4bae6dce3c start refactoring transmitting 2020-11-25 11:43:27 +01:00
f5d33445d9 start refactoring transmitting 2020-11-25 11:34:45 +01:00
30cfa20855 start refactoring transmitting 2020-11-25 11:33:09 +01:00
d8bd9eae5d start refactoring transmitting 2020-11-25 11:32:48 +01:00
c308b0ba89 start refactoring transmitting 2020-11-25 11:32:24 +01:00
622aad3cc1 start refactoring transmitting 2020-11-25 11:24:25 +01:00
ab6fc41acf start refactoring transmitting 2020-11-25 11:23:05 +01:00
081fe26daf start refactoring transmitting 2020-11-25 11:06:10 +01:00
354a1670ee start refactoring transmitting 2020-11-25 11:04:36 +01:00
c14d4fe892 working now? 2020-11-25 10:08:20 +01:00
edf1942ad3 working now? 2020-11-25 10:02:38 +01:00
7c63579390 debug 2020-11-25 09:16:00 +01:00
d171dced70 debug 2020-11-25 08:58:59 +01:00
b15321d774 changes 2020-11-25 08:55:54 +01:00
a05598d89a works better now 2020-11-24 22:57:33 +01:00
950c7b07d2 not yet working correctly again 2020-11-24 22:43:02 +01:00
d5c568a63c refactoring meterbus 2020-11-24 19:38:52 +01:00
14bf178664 refactoring meterbus 2020-11-24 19:36:47 +01:00
bdba2a79cd refactoring meterbus 2020-11-24 15:03:09 +01:00
53ccd32a0c refactoring meterbus 2020-11-24 15:00:56 +01:00
f88a4984be refactoring meterbus 2020-11-24 15:00:36 +01:00
9198753e4b refactoring meterbus 2020-11-24 14:54:57 +01:00
6d3b3e12ca refactoring meterbus 2020-11-24 14:51:05 +01:00
ae9c397e85 refactoring meterbus 2020-11-24 14:50:20 +01:00
a9b71f481a refactoring meterbus 2020-11-24 14:47:21 +01:00
0397d61e56 refactoring meterbus 2020-11-24 14:31:37 +01:00
a1c602a021 refactoring meterbus 2020-11-24 14:21:05 +01:00
d2c4efc8db refactoring meterbus 2020-11-24 14:19:12 +01:00
f37361b659 changes 2020-11-24 14:13:51 +01:00
7a088f19f2 refactoring meterbus 2020-11-24 13:50:06 +01:00
eb47d41e5a refactoring meterbus 2020-11-24 13:48:19 +01:00
7d816f6ed0 refactoring meterbus 2020-11-24 13:46:51 +01:00
89edf7f7bb refactoring meterbus 2020-11-24 13:42:26 +01:00
5cae5a1de3 refactoring meterbus 2020-11-24 13:18:18 +01:00
c1949f4cd3 start refactoring 2 2020-11-23 22:23:53 +01:00
491a60f515 start refactoring 2020-11-23 19:30:57 +01:00
b8513b2112 additional debug output 2020-11-23 19:14:22 +01:00
04405d1b84 faster requests 2020-11-23 18:50:03 +01:00
3dd954d379 log all meterbus uart errors 2020-11-22 22:59:41 +01:00
bd435dd5d6 overrun error in meterbus uart handled 2020-11-22 21:23:52 +01:00
3fd30aaa36 debug failing receive process 2020-11-21 18:23:16 +01:00
eea6b7de3b meterbus debug 2020-11-20 22:05:46 +01:00
1408c4942c spi settings for display 2020-11-20 17:25:17 +01:00
60 changed files with 5609 additions and 553 deletions

View File

@ -0,0 +1,58 @@
/**
******************************************************************************
* File Name : ADC.h
* Description : This file provides code for the configuration
* of the ADC instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __adc_H
#define __adc_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern ADC_HandleTypeDef hadc1;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_ADC1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ adc_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,57 @@
/**
******************************************************************************
* File Name : gpio.h
* Description : This file contains all the functions prototypes for
* the gpio
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __gpio_H
#define __gpio_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ pinoutConfig_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

137
Core-20201227-01/Inc/main.h Normal file
View File

@ -0,0 +1,137 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define debugUart huart4
#define mbusUart huart5
#define frontendAdc hadc1
#define eepromSpi hspi2
#define etherSpi hspi1
#define displaySpi hspi3
#define debugUartIRQn UART4_IRQn
#define Loop_Enable_Pin GPIO_PIN_2
#define Loop_Enable_GPIO_Port GPIOE
#define Loop_Disable_Pin GPIO_PIN_3
#define Loop_Disable_GPIO_Port GPIOE
#define Loop_Status_Pin GPIO_PIN_4
#define Loop_Status_GPIO_Port GPIOE
#define Loop_Status_EXTI_IRQn EXTI4_IRQn
#define LED_Green_Pin GPIO_PIN_5
#define LED_Green_GPIO_Port GPIOE
#define LED_Red_Pin GPIO_PIN_6
#define LED_Red_GPIO_Port GPIOE
#define Frontend_In_Pin GPIO_PIN_1
#define Frontend_In_GPIO_Port GPIOA
#define ETHER_RES_Pin GPIO_PIN_2
#define ETHER_RES_GPIO_Port GPIOA
#define ETHER_INT_Pin GPIO_PIN_3
#define ETHER_INT_GPIO_Port GPIOA
#define ETHER_CS_Pin GPIO_PIN_4
#define ETHER_CS_GPIO_Port GPIOA
#define ETHER_SCLK_Pin GPIO_PIN_5
#define ETHER_SCLK_GPIO_Port GPIOA
#define ETHER_MISO_Pin GPIO_PIN_6
#define ETHER_MISO_GPIO_Port GPIOA
#define ETHER_MOSI_Pin GPIO_PIN_7
#define ETHER_MOSI_GPIO_Port GPIOA
#define Debug_Signal_2_Pin GPIO_PIN_12
#define Debug_Signal_2_GPIO_Port GPIOE
#define Debug_Signal_1_Pin GPIO_PIN_10
#define Debug_Signal_1_GPIO_Port GPIOB
#define EEPROM_CS_Pin GPIO_PIN_12
#define EEPROM_CS_GPIO_Port GPIOB
#define EEPROM_SCLK_Pin GPIO_PIN_13
#define EEPROM_SCLK_GPIO_Port GPIOB
#define EEPROM_MISO_Pin GPIO_PIN_14
#define EEPROM_MISO_GPIO_Port GPIOB
#define EEPROM_MOSI_Pin GPIO_PIN_15
#define EEPROM_MOSI_GPIO_Port GPIOB
#define Debug_TX_Pin GPIO_PIN_10
#define Debug_TX_GPIO_Port GPIOC
#define Debug_RX_Pin GPIO_PIN_11
#define Debug_RX_GPIO_Port GPIOC
#define MBus_TX_Pin GPIO_PIN_12
#define MBus_TX_GPIO_Port GPIOC
#define Frontend_Out_Pin GPIO_PIN_1
#define Frontend_Out_GPIO_Port GPIOD
#define MBus_RX_Pin GPIO_PIN_2
#define MBus_RX_GPIO_Port GPIOD
#define Display_CS_Pin GPIO_PIN_7
#define Display_CS_GPIO_Port GPIOD
#define Display_SCLK_Pin GPIO_PIN_3
#define Display_SCLK_GPIO_Port GPIOB
#define Display_MISO_Pin GPIO_PIN_4
#define Display_MISO_GPIO_Port GPIOB
#define Display_MOSI_Pin GPIO_PIN_5
#define Display_MOSI_GPIO_Port GPIOB
#define Display_DC_Pin GPIO_PIN_6
#define Display_DC_GPIO_Port GPIOB
#define Display_RES_Pin GPIO_PIN_7
#define Display_RES_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,62 @@
/**
******************************************************************************
* File Name : SPI.h
* Description : This file provides code for the configuration
* of the SPI instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __spi_H
#define __spi_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern SPI_HandleTypeDef hspi1;
extern SPI_HandleTypeDef hspi2;
extern SPI_HandleTypeDef hspi3;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_SPI1_Init(void);
void MX_SPI2_Init(void);
void MX_SPI3_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ spi_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,391 @@
/**
******************************************************************************
* @file stm32f1xx_hal_conf.h
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F1xx_HAL_CONF_H
#define __STM32F1xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_CAN_MODULE_ENABLED */
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
/*#define HAL_CEC_MODULE_ENABLED */
/*#define HAL_CORTEX_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_DMA_MODULE_ENABLED */
/*#define HAL_ETH_MODULE_ENABLED */
/*#define HAL_FLASH_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_NOR_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_PCCARD_MODULE_ENABLED */
/*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_HCD_MODULE_ENABLED */
/*#define HAL_PWR_MODULE_ENABLED */
/*#define HAL_RCC_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SD_MODULE_ENABLED */
/*#define HAL_MMC_MODULE_ENABLED */
/*#define HAL_SDRAM_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/*#define HAL_SRAM_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature. */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## Ethernet peripheral configuration ##################### */
/* Section 1 : Ethernet peripheral configuration */
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
#define MAC_ADDR0 2U
#define MAC_ADDR1 0U
#define MAC_ADDR2 0U
#define MAC_ADDR3 0U
#define MAC_ADDR4 0U
#define MAC_ADDR5 0U
/* Definition of the Ethernet driver buffers size and count */
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
#define ETH_RXBUFNB 8U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
/* Section 2: PHY configuration section */
/* DP83848_PHY_ADDRESS Address*/
#define DP83848_PHY_ADDRESS 0x01U
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
#define PHY_RESET_DELAY 0x000000FFU
/* PHY Configuration delay */
#define PHY_CONFIG_DELAY 0x00000FFFU
#define PHY_READ_TO 0x0000FFFFU
#define PHY_WRITE_TO 0x0000FFFFU
/* Section 3: Common PHY Registers */
#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
/* Section 4: Extended PHY Registers */
#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */
#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32f1xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32f1xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32f1xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32f1xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_ETH_MODULE_ENABLED
#include "stm32f1xx_hal_eth.h"
#endif /* HAL_ETH_MODULE_ENABLED */
#ifdef HAL_CAN_MODULE_ENABLED
#include "stm32f1xx_hal_can.h"
#endif /* HAL_CAN_MODULE_ENABLED */
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
#include "Legacy/stm32f1xx_hal_can_legacy.h"
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
#ifdef HAL_CEC_MODULE_ENABLED
#include "stm32f1xx_hal_cec.h"
#endif /* HAL_CEC_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32f1xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32f1xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32f1xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32f1xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32f1xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32f1xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32f1xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32f1xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32f1xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32f1xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32f1xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32f1xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_PCCARD_MODULE_ENABLED
#include "stm32f1xx_hal_pccard.h"
#endif /* HAL_PCCARD_MODULE_ENABLED */
#ifdef HAL_SD_MODULE_ENABLED
#include "stm32f1xx_hal_sd.h"
#endif /* HAL_SD_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32f1xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32f1xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32f1xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32f1xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32f1xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32f1xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32f1xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32f1xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32f1xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_HCD_MODULE_ENABLED
#include "stm32f1xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */
#ifdef HAL_MMC_MODULE_ENABLED
#include "stm32f1xx_hal_mmc.h"
#endif /* HAL_MMC_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F1xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,74 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F1xx_IT_H
#define __STM32F1xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void EXTI4_IRQHandler(void);
void ADC1_2_IRQHandler(void);
void SPI2_IRQHandler(void);
void UART4_IRQHandler(void);
void UART5_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F1xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,60 @@
/**
******************************************************************************
* File Name : USART.h
* Description : This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __usart_H
#define __usart_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern UART_HandleTypeDef huart4;
extern UART_HandleTypeDef huart5;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_UART4_Init(void);
void MX_UART5_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ usart_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

116
Core-20201227-01/Src/adc.c Normal file
View File

@ -0,0 +1,116 @@
/**
******************************************************************************
* File Name : ADC.c
* Description : This file provides code for the configuration
* of the ADC instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "adc.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
ADC_HandleTypeDef hadc1;
/* ADC1 init function */
void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/* ADC1 clock enable */
__HAL_RCC_ADC1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**ADC1 GPIO Configuration
PA1 ------> ADC1_IN1
*/
GPIO_InitStruct.Pin = Frontend_In_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(Frontend_In_GPIO_Port, &GPIO_InitStruct);
/* ADC1 interrupt Init */
HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
{
if(adcHandle->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC1_CLK_DISABLE();
/**ADC1 GPIO Configuration
PA1 ------> ADC1_IN1
*/
HAL_GPIO_DeInit(Frontend_In_GPIO_Port, Frontend_In_Pin);
/* ADC1 interrupt Deinit */
HAL_NVIC_DisableIRQ(ADC1_2_IRQn);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

117
Core-20201227-01/Src/gpio.c Normal file
View File

@ -0,0 +1,117 @@
/**
******************************************************************************
* File Name : gpio.c
* Description : This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure GPIO */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOE, Loop_Enable_Pin|Loop_Disable_Pin|LED_Green_Pin|LED_Red_Pin
|Debug_Signal_2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, ETHER_RES_Pin|ETHER_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, Debug_Signal_1_Pin|EEPROM_CS_Pin|Display_DC_Pin|Display_RES_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, Frontend_Out_Pin|Display_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : PEPin PEPin PEPin PEPin
PEPin */
GPIO_InitStruct.Pin = Loop_Enable_Pin|Loop_Disable_Pin|LED_Green_Pin|LED_Red_Pin
|Debug_Signal_2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = Loop_Status_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(Loop_Status_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PAPin PAPin */
GPIO_InitStruct.Pin = ETHER_RES_Pin|ETHER_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = ETHER_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ETHER_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
GPIO_InitStruct.Pin = Debug_Signal_1_Pin|EEPROM_CS_Pin|Display_DC_Pin|Display_RES_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : PDPin PDPin */
GPIO_InitStruct.Pin = Frontend_Out_Pin|Display_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

203
Core-20201227-01/Src/main.c Normal file
View File

@ -0,0 +1,203 @@
// Processed by ../tools/insertMyCode.sh
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "spi.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "main2.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
my_setup_1();
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_SPI2_Init();
MX_SPI3_Init();
MX_UART4_Init();
MX_UART5_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
my_setup_2();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
my_loop();
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
my_errorHandler();
/* User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
while(1) { };
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,190 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "spi.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_SPI2_Init();
MX_SPI3_Init();
MX_UART4_Init();
MX_UART5_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

259
Core-20201227-01/Src/spi.c Normal file
View File

@ -0,0 +1,259 @@
/**
******************************************************************************
* File Name : SPI.c
* Description : This file provides code for the configuration
* of the SPI instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "spi.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
SPI_HandleTypeDef hspi1;
SPI_HandleTypeDef hspi2;
SPI_HandleTypeDef hspi3;
/* SPI1 init function */
void MX_SPI1_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
/* SPI2 init function */
void MX_SPI2_Init(void)
{
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
}
/* SPI3 init function */
void MX_SPI3_Init(void)
{
hspi3.Instance = SPI3;
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi3.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi3) != HAL_OK)
{
Error_Handler();
}
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(spiHandle->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* SPI1 clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = ETHER_SCLK_Pin|ETHER_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = ETHER_MISO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ETHER_MISO_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
else if(spiHandle->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspInit 0 */
/* USER CODE END SPI2_MspInit 0 */
/* SPI2 clock enable */
__HAL_RCC_SPI2_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**SPI2 GPIO Configuration
PB13 ------> SPI2_SCK
PB14 ------> SPI2_MISO
PB15 ------> SPI2_MOSI
*/
GPIO_InitStruct.Pin = EEPROM_SCLK_Pin|EEPROM_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = EEPROM_MISO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(EEPROM_MISO_GPIO_Port, &GPIO_InitStruct);
/* SPI2 interrupt Init */
HAL_NVIC_SetPriority(SPI2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(SPI2_IRQn);
/* USER CODE BEGIN SPI2_MspInit 1 */
/* USER CODE END SPI2_MspInit 1 */
}
else if(spiHandle->Instance==SPI3)
{
/* USER CODE BEGIN SPI3_MspInit 0 */
/* USER CODE END SPI3_MspInit 0 */
/* SPI3 clock enable */
__HAL_RCC_SPI3_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**SPI3 GPIO Configuration
PB3 ------> SPI3_SCK
PB4 ------> SPI3_MISO
PB5 ------> SPI3_MOSI
*/
GPIO_InitStruct.Pin = Display_SCLK_Pin|Display_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = Display_MISO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(Display_MISO_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN SPI3_MspInit 1 */
/* USER CODE END SPI3_MspInit 1 */
}
}
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
{
if(spiHandle->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspDeInit 0 */
/* USER CODE END SPI1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI1_CLK_DISABLE();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
HAL_GPIO_DeInit(GPIOA, ETHER_SCLK_Pin|ETHER_MISO_Pin|ETHER_MOSI_Pin);
/* USER CODE BEGIN SPI1_MspDeInit 1 */
/* USER CODE END SPI1_MspDeInit 1 */
}
else if(spiHandle->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspDeInit 0 */
/* USER CODE END SPI2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI2_CLK_DISABLE();
/**SPI2 GPIO Configuration
PB13 ------> SPI2_SCK
PB14 ------> SPI2_MISO
PB15 ------> SPI2_MOSI
*/
HAL_GPIO_DeInit(GPIOB, EEPROM_SCLK_Pin|EEPROM_MISO_Pin|EEPROM_MOSI_Pin);
/* SPI2 interrupt Deinit */
HAL_NVIC_DisableIRQ(SPI2_IRQn);
/* USER CODE BEGIN SPI2_MspDeInit 1 */
/* USER CODE END SPI2_MspDeInit 1 */
}
else if(spiHandle->Instance==SPI3)
{
/* USER CODE BEGIN SPI3_MspDeInit 0 */
/* USER CODE END SPI3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI3_CLK_DISABLE();
/**SPI3 GPIO Configuration
PB3 ------> SPI3_SCK
PB4 ------> SPI3_MISO
PB5 ------> SPI3_MOSI
*/
HAL_GPIO_DeInit(GPIOB, Display_SCLK_Pin|Display_MISO_Pin|Display_MOSI_Pin);
/* USER CODE BEGIN SPI3_MspDeInit 1 */
/* USER CODE END SPI3_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,88 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : stm32f1xx_hal_msp.c
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
*/
__HAL_AFIO_REMAP_SWJ_NOJTAG();
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,286 @@
// Processed by ../tools/insertMyCode.sh
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "main2.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern ADC_HandleTypeDef hadc1;
extern SPI_HandleTypeDef hspi2;
extern UART_HandleTypeDef huart4;
extern UART_HandleTypeDef huart5;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M3 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
}
/**
* @brief This function handles Prefetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/* USER CODE END SVCall_IRQn 0 */
/* USER CODE BEGIN SVCall_IRQn 1 */
/* USER CODE END SVCall_IRQn 1 */
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
/* USER CODE END DebugMonitor_IRQn 1 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
SYSTICK_Callback();
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32F1xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f1xx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
/* USER CODE BEGIN EXTI4_IRQn 1 */
/* USER CODE END EXTI4_IRQn 1 */
}
/**
* @brief This function handles ADC1 and ADC2 global interrupts.
*/
void ADC1_2_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_2_IRQn 0 */
/* USER CODE END ADC1_2_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
/* USER CODE BEGIN ADC1_2_IRQn 1 */
/* USER CODE END ADC1_2_IRQn 1 */
}
/**
* @brief This function handles SPI2 global interrupt.
*/
void SPI2_IRQHandler(void)
{
/* USER CODE BEGIN SPI2_IRQn 0 */
/* USER CODE END SPI2_IRQn 0 */
HAL_SPI_IRQHandler(&hspi2);
/* USER CODE BEGIN SPI2_IRQn 1 */
/* USER CODE END SPI2_IRQn 1 */
}
/**
* @brief This function handles UART4 global interrupt.
*/
void UART4_IRQHandler(void)
{
/* USER CODE BEGIN UART4_IRQn 0 */
/* USER CODE END UART4_IRQn 0 */
HAL_UART_IRQHandler(&huart4);
/* USER CODE BEGIN UART4_IRQn 1 */
/* USER CODE END UART4_IRQn 1 */
}
void mbusCommISR();
/**
* @brief This function handles UART5 global interrupt.
*/
void UART5_IRQHandler(void)
{
/* USER CODE BEGIN UART5_IRQn 0 */
/* USER CODE END UART5_IRQn 0 */
// HAL_UART_IRQHandler(&huart5);
/* USER CODE BEGIN UART5_IRQn 1 */
mbusCommISR();
/* USER CODE END UART5_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,276 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern ADC_HandleTypeDef hadc1;
extern SPI_HandleTypeDef hspi2;
extern UART_HandleTypeDef huart4;
extern UART_HandleTypeDef huart5;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M3 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
}
/**
* @brief This function handles Prefetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/* USER CODE END SVCall_IRQn 0 */
/* USER CODE BEGIN SVCall_IRQn 1 */
/* USER CODE END SVCall_IRQn 1 */
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
/* USER CODE END DebugMonitor_IRQn 1 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32F1xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f1xx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
/* USER CODE BEGIN EXTI4_IRQn 1 */
/* USER CODE END EXTI4_IRQn 1 */
}
/**
* @brief This function handles ADC1 and ADC2 global interrupts.
*/
void ADC1_2_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_2_IRQn 0 */
/* USER CODE END ADC1_2_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
/* USER CODE BEGIN ADC1_2_IRQn 1 */
/* USER CODE END ADC1_2_IRQn 1 */
}
/**
* @brief This function handles SPI2 global interrupt.
*/
void SPI2_IRQHandler(void)
{
/* USER CODE BEGIN SPI2_IRQn 0 */
/* USER CODE END SPI2_IRQn 0 */
HAL_SPI_IRQHandler(&hspi2);
/* USER CODE BEGIN SPI2_IRQn 1 */
/* USER CODE END SPI2_IRQn 1 */
}
/**
* @brief This function handles UART4 global interrupt.
*/
void UART4_IRQHandler(void)
{
/* USER CODE BEGIN UART4_IRQn 0 */
/* USER CODE END UART4_IRQn 0 */
HAL_UART_IRQHandler(&huart4);
/* USER CODE BEGIN UART4_IRQn 1 */
/* USER CODE END UART4_IRQn 1 */
}
/**
* @brief This function handles UART5 global interrupt.
*/
void UART5_IRQHandler(void)
{
/* USER CODE BEGIN UART5_IRQn 0 */
/* USER CODE END UART5_IRQn 0 */
HAL_UART_IRQHandler(&huart5);
/* USER CODE BEGIN UART5_IRQn 1 */
/* USER CODE END UART5_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,408 @@
/**
******************************************************************************
* @file system_stm32f1xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
*
* 1. This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
* factors, AHB/APBx prescalers and Flash settings).
* This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32f1xx_xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
* configure the system clock before to branch to main program.
*
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
* the product used), refer to "HSE_VALUE".
* When HSE is used as system clock source, directly or through PLL, and you
* are using different crystal you have to adapt the HSE value to your own
* configuration.
*
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f1xx_system
* @{
*/
/** @addtogroup STM32F1xx_System_Private_Includes
* @{
*/
#include "stm32f1xx.h"
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Defines
* @{
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSI_VALUE */
/*!< Uncomment the following line if you need to use external SRAM */
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/* #define DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
/* #define USER_VECT_TAB_ADDRESS */
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Variables
* @{
*/
/* This variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = 16000000;
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
* @{
*/
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
#ifdef DATA_IN_ExtSRAM
static void SystemInit_ExtMemCtl(void);
#endif /* DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemCoreClock variable.
* @note This function should be used only after reset.
* @param None
* @retval None
*/
void SystemInit (void)
{
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
#ifdef DATA_IN_ExtSRAM
SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM */
#endif
/* Configure the Vector Table location -------------------------------------*/
#if defined(USER_VECT_TAB_ADDRESS)
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#endif /* USER_VECT_TAB_ADDRESS */
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
* or HSI_VALUE(*) multiplied by the PLL factors.
*
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
* 8 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
* that HSE_VALUE is same as the real frequency of the crystal used.
* Otherwise, this function may have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
* @param None
* @retval None
*/
void SystemCoreClockUpdate (void)
{
uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
#if defined(STM32F105xC) || defined(STM32F107xC)
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
#endif /* STM32F105xC */
#if defined(STM32F100xB) || defined(STM32F100xE)
uint32_t prediv1factor = 0U;
#endif /* STM32F100xB or STM32F100xE */
/* Get SYSCLK source -------------------------------------------------------*/
tmp = RCC->CFGR & RCC_CFGR_SWS;
switch (tmp)
{
case 0x00U: /* HSI used as system clock */
SystemCoreClock = HSI_VALUE;
break;
case 0x04U: /* HSE used as system clock */
SystemCoreClock = HSE_VALUE;
break;
case 0x08U: /* PLL used as system clock */
/* Get PLL clock source and multiplication factor ----------------------*/
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
#if !defined(STM32F105xC) && !defined(STM32F107xC)
pllmull = ( pllmull >> 18U) + 2U;
if (pllsource == 0x00U)
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
}
else
{
#if defined(STM32F100xB) || defined(STM32F100xE)
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
/* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
#else
/* HSE selected as PLL clock entry */
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
{/* HSE oscillator clock divided by 2 */
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
}
else
{
SystemCoreClock = HSE_VALUE * pllmull;
}
#endif
}
#else
pllmull = pllmull >> 18U;
if (pllmull != 0x0DU)
{
pllmull += 2U;
}
else
{ /* PLL multiplication factor = PLL input clock * 6.5 */
pllmull = 13U / 2U;
}
if (pllsource == 0x00U)
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
}
else
{/* PREDIV1 selected as PLL clock entry */
/* Get PREDIV1 clock source and division factor */
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
if (prediv1source == 0U)
{
/* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
}
else
{/* PLL2 clock selected as PREDIV1 clock entry */
/* Get PREDIV2 division factor and PLL2 multiplication factor */
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
}
}
#endif /* STM32F105xC */
break;
default:
SystemCoreClock = HSI_VALUE;
break;
}
/* Compute HCLK clock frequency ----------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/**
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
* before jump to __main
* @param None
* @retval None
*/
#ifdef DATA_IN_ExtSRAM
/**
* @brief Setup the external memory controller.
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
* This function configures the external SRAM mounted on STM3210E-EVAL
* board (STM32 High density devices). This SRAM will be used as program
* data memory (including heap and stack).
* @param None
* @retval None
*/
void SystemInit_ExtMemCtl(void)
{
__IO uint32_t tmpreg;
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
required, then adjust the Register Addresses */
/* Enable FSMC clock */
RCC->AHBENR = 0x00000114U;
/* Delay after an RCC peripheral clock enabling */
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
RCC->APB2ENR = 0x000001E0U;
/* Delay after an RCC peripheral clock enabling */
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
(void)(tmpreg);
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
/*---------------- SRAM Address lines configuration -------------------------*/
/*---------------- NOE and NWE configuration --------------------------------*/
/*---------------- NE3 configuration ----------------------------------------*/
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
GPIOD->CRL = 0x44BB44BBU;
GPIOD->CRH = 0xBBBBBBBBU;
GPIOE->CRL = 0xB44444BBU;
GPIOE->CRH = 0xBBBBBBBBU;
GPIOF->CRL = 0x44BBBBBBU;
GPIOF->CRH = 0xBBBB4444U;
GPIOG->CRL = 0x44BBBBBBU;
GPIOG->CRH = 0x444B4B44U;
/*---------------- FSMC Configuration ---------------------------------------*/
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
FSMC_Bank1->BTCR[4U] = 0x00001091U;
FSMC_Bank1->BTCR[5U] = 0x00110212U;
}
#endif /* DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,185 @@
/**
******************************************************************************
* File Name : USART.c
* Description : This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
UART_HandleTypeDef huart4;
UART_HandleTypeDef huart5;
/* UART4 init function */
void MX_UART4_Init(void)
{
huart4.Instance = UART4;
huart4.Init.BaudRate = 115200;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
}
/* UART5 init function */
void MX_UART5_Init(void)
{
huart5.Instance = UART5;
huart5.Init.BaudRate = 2400;
huart5.Init.WordLength = UART_WORDLENGTH_9B;
huart5.Init.StopBits = UART_STOPBITS_1;
huart5.Init.Parity = UART_PARITY_EVEN;
huart5.Init.Mode = UART_MODE_TX_RX;
huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart5.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart5) != HAL_OK)
{
Error_Handler();
}
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(uartHandle->Instance==UART4)
{
/* USER CODE BEGIN UART4_MspInit 0 */
/* USER CODE END UART4_MspInit 0 */
/* UART4 clock enable */
__HAL_RCC_UART4_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**UART4 GPIO Configuration
PC10 ------> UART4_TX
PC11 ------> UART4_RX
*/
GPIO_InitStruct.Pin = Debug_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(Debug_TX_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = Debug_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(Debug_RX_GPIO_Port, &GPIO_InitStruct);
/* UART4 interrupt Init */
HAL_NVIC_SetPriority(UART4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART4_IRQn);
/* USER CODE BEGIN UART4_MspInit 1 */
/* USER CODE END UART4_MspInit 1 */
}
else if(uartHandle->Instance==UART5)
{
/* USER CODE BEGIN UART5_MspInit 0 */
/* USER CODE END UART5_MspInit 0 */
/* UART5 clock enable */
__HAL_RCC_UART5_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/**UART5 GPIO Configuration
PC12 ------> UART5_TX
PD2 ------> UART5_RX
*/
GPIO_InitStruct.Pin = MBus_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(MBus_TX_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = MBus_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(MBus_RX_GPIO_Port, &GPIO_InitStruct);
/* UART5 interrupt Init */
HAL_NVIC_SetPriority(UART5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART5_IRQn);
/* USER CODE BEGIN UART5_MspInit 1 */
/* USER CODE END UART5_MspInit 1 */
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
{
if(uartHandle->Instance==UART4)
{
/* USER CODE BEGIN UART4_MspDeInit 0 */
/* USER CODE END UART4_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_UART4_CLK_DISABLE();
/**UART4 GPIO Configuration
PC10 ------> UART4_TX
PC11 ------> UART4_RX
*/
HAL_GPIO_DeInit(GPIOC, Debug_TX_Pin|Debug_RX_Pin);
/* UART4 interrupt Deinit */
HAL_NVIC_DisableIRQ(UART4_IRQn);
/* USER CODE BEGIN UART4_MspDeInit 1 */
/* USER CODE END UART4_MspDeInit 1 */
}
else if(uartHandle->Instance==UART5)
{
/* USER CODE BEGIN UART5_MspDeInit 0 */
/* USER CODE END UART5_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_UART5_CLK_DISABLE();
/**UART5 GPIO Configuration
PC12 ------> UART5_TX
PD2 ------> UART5_RX
*/
HAL_GPIO_DeInit(MBus_TX_GPIO_Port, MBus_TX_Pin);
HAL_GPIO_DeInit(MBus_RX_GPIO_Port, MBus_RX_Pin);
/* UART5 interrupt Deinit */
HAL_NVIC_DisableIRQ(UART5_IRQn);
/* USER CODE BEGIN UART5_MspDeInit 1 */
/* USER CODE END UART5_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

214
Makefile-20201227-01 Normal file
View File

@ -0,0 +1,214 @@
# Processed by ../tools/insertMyCode.sh
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Nov 19 18:53:40 CET 2020]
##########################################################################################################################
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
# 2017-02-10 - Several enhancements + project update mode
# 2015-07-22 - first version
# ------------------------------------------------
######################################
# target
######################################
TARGET = cube
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_SOURCES = \
User/Src/regularCmds.c User/Src/adminCmds.c User/Src/configCmds.c User/Src/config.c User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
libmbus/mbus/mbus-protocol.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/adc.c \
Core/Src/spi.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_adc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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 = \
startup_stm32f103xe.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m3
# fpu
# NONE for Cortex-M0/M0+/M3
# float-abi
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32F103xE
# AS includes
AS_INCLUDES =
# C includes
C_INCLUDES = \
-Ihottislib \
-Ipubsubc/src \
-Ilibmbus \
-IUser/Inc \
-IioLibrary_Driver/Internet/DHCP \
-IioLibrary_Driver/Internet/DNS \
-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
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -Werror -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32F103VCTx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -u _printf_float -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a pubsubc.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)/pubsubc.a:
(cd pubsubc && $(MAKE) && cp pubsubc.a ../$(BUILD_DIR) && cd ..)
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***

View File

@ -1,5 +1,5 @@
[PreviousLibFiles]
LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_sc300.h;
LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_iwdg.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_iwdg.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.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;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_adc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_iwdg.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm7.h;
[PreviousUsedIarFiles]
SourceFiles=../Core/Src/main.c;../Core/Src/gpio.c;../Core/Src/adc.c;../Core/Src/spi.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_adc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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;../Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;;
@ -7,31 +7,33 @@ HeaderPath=../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/I
CDefines=USE_HAL_DRIVER;STM32F103xE;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousUsedMakefileFiles]
SourceFiles=Core/Src/main.c;Core/Src/gpio.c;Core/Src/adc.c;Core/Src/spi.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_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;;
SourceFiles=Core/Src/main.c;Core/Src/gpio.c;Core/Src/adc.c;Core/Src/iwdg.c;Core/Src/spi.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_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_iwdg.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.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;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_iwdg.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.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;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;;
HeaderPath=Drivers/STM32F1xx_HAL_Driver/Inc;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;Drivers/CMSIS/Device/ST/STM32F1xx/Include;Drivers/CMSIS/Include;Core/Inc;
CDefines=USE_HAL_DRIVER;STM32F103xE;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=7
HeaderFileListSize=8
HeaderFiles#0=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/gpio.h
HeaderFiles#1=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/adc.h
HeaderFiles#2=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/spi.h
HeaderFiles#3=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/usart.h
HeaderFiles#4=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/stm32f1xx_it.h
HeaderFiles#5=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/stm32f1xx_hal_conf.h
HeaderFiles#6=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/main.h
HeaderFiles#2=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/iwdg.h
HeaderFiles#3=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/spi.h
HeaderFiles#4=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/usart.h
HeaderFiles#5=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/stm32f1xx_it.h
HeaderFiles#6=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/stm32f1xx_hal_conf.h
HeaderFiles#7=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc/main.h
HeaderFolderListSize=1
HeaderPath#0=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Inc
HeaderFiles=;
SourceFileListSize=7
SourceFileListSize=8
SourceFiles#0=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/gpio.c
SourceFiles#1=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/adc.c
SourceFiles#2=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/spi.c
SourceFiles#3=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/usart.c
SourceFiles#4=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/stm32f1xx_it.c
SourceFiles#5=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/stm32f1xx_hal_msp.c
SourceFiles#6=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/main.c
SourceFiles#2=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/iwdg.c
SourceFiles#3=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/spi.c
SourceFiles#4=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/usart.c
SourceFiles#5=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/stm32f1xx_it.c
SourceFiles#6=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/stm32f1xx_hal_msp.c
SourceFiles#7=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src/main.c
SourceFolderListSize=1
SourcePath#0=/home/wn/Workspaces/mbusgateway3variant/cube/Core/Src
SourceFiles=;

58
cube/Core/Inc/iwdg.h Normal file
View File

@ -0,0 +1,58 @@
/**
******************************************************************************
* File Name : IWDG.h
* Description : This file provides code for the configuration
* of the IWDG instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __iwdg_H
#define __iwdg_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern IWDG_HandleTypeDef hiwdg;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_IWDG_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ iwdg_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -48,7 +48,7 @@
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
#define HAL_IWDG_MODULE_ENABLED
/*#define HAL_NOR_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_PCCARD_MODULE_ENABLED */

47
cube/Core/Src/iwdg.c Normal file
View File

@ -0,0 +1,47 @@
/**
******************************************************************************
* File Name : IWDG.c
* Description : This file provides code for the configuration
* of the IWDG instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "iwdg.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
IWDG_HandleTypeDef hiwdg;
/* IWDG init function */
void MX_IWDG_Init(void)
{
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
hiwdg.Init.Reload = 4095;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -21,6 +21,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "iwdg.h"
#include "spi.h"
#include "usart.h"
#include "gpio.h"
@ -99,6 +100,7 @@ int main(void)
MX_UART4_Init();
MX_UART5_Init();
MX_SPI1_Init();
MX_IWDG_Init();
/* USER CODE BEGIN 2 */
my_setup_2();
@ -131,10 +133,11 @@ void SystemClock_Config(void)
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

View File

@ -20,6 +20,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "iwdg.h"
#include "spi.h"
#include "usart.h"
#include "gpio.h"
@ -94,6 +95,7 @@ int main(void)
MX_UART4_Init();
MX_UART5_Init();
MX_SPI1_Init();
MX_IWDG_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
@ -122,10 +124,11 @@ void SystemClock_Config(void)
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

View File

@ -80,8 +80,8 @@ void MX_SPI3_Init(void)
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi3.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;

View File

@ -49,7 +49,9 @@
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE BEGIN PFP */
void mbusCommISR();
/* USER CODE END PFP */
@ -269,8 +271,10 @@ void UART5_IRQHandler(void)
/* USER CODE BEGIN UART5_IRQn 0 */
/* USER CODE END UART5_IRQn 0 */
HAL_UART_IRQHandler(&huart5);
/* USER CODE BEGIN UART5_IRQn 1 */
// HAL_UART_IRQHandler(&huart5);
/* USER CODE BEGIN UART5_IRQn 1 */
mbusCommISR();
/* USER CODE END UART5_IRQn 1 */
}

View File

@ -0,0 +1,226 @@
/**
******************************************************************************
* @file stm32f1xx_hal_iwdg.h
* @author MCD Application Team
* @brief Header file of IWDG HAL module.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32F1xx_HAL_IWDG_H
#define STM32F1xx_HAL_IWDG_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal_def.h"
/** @addtogroup STM32F1xx_HAL_Driver
* @{
*/
/** @defgroup IWDG IWDG
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup IWDG_Exported_Types IWDG Exported Types
* @{
*/
/**
* @brief IWDG Init structure definition
*/
typedef struct
{
uint32_t Prescaler; /*!< Select the prescaler of the IWDG.
This parameter can be a value of @ref IWDG_Prescaler */
uint32_t Reload; /*!< Specifies the IWDG down-counter reload value.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
} IWDG_InitTypeDef;
/**
* @brief IWDG Handle Structure definition
*/
typedef struct
{
IWDG_TypeDef *Instance; /*!< Register base address */
IWDG_InitTypeDef Init; /*!< IWDG required parameters */
} IWDG_HandleTypeDef;
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup IWDG_Exported_Constants IWDG Exported Constants
* @{
*/
/** @defgroup IWDG_Prescaler IWDG Prescaler
* @{
*/
#define IWDG_PRESCALER_4 0x00000000U /*!< IWDG prescaler set to 4 */
#define IWDG_PRESCALER_8 IWDG_PR_PR_0 /*!< IWDG prescaler set to 8 */
#define IWDG_PRESCALER_16 IWDG_PR_PR_1 /*!< IWDG prescaler set to 16 */
#define IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 32 */
#define IWDG_PRESCALER_64 IWDG_PR_PR_2 /*!< IWDG prescaler set to 64 */
#define IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 128 */
#define IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< IWDG prescaler set to 256 */
/**
* @}
*/
/**
* @}
*/
/* Exported macros -----------------------------------------------------------*/
/** @defgroup IWDG_Exported_Macros IWDG Exported Macros
* @{
*/
/**
* @brief Enable the IWDG peripheral.
* @param __HANDLE__ IWDG handle
* @retval None
*/
#define __HAL_IWDG_START(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
/**
* @brief Reload IWDG counter with value defined in the reload register
* (write access to IWDG_PR and IWDG_RLR registers disabled).
* @param __HANDLE__ IWDG handle
* @retval None
*/
#define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup IWDG_Exported_Functions IWDG Exported Functions
* @{
*/
/** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
* @{
*/
/* Initialization/Start functions ********************************************/
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
/**
* @}
*/
/** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
* @{
*/
/* I/O operation functions ****************************************************/
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
/**
* @}
*/
/**
* @}
*/
/* Private constants ---------------------------------------------------------*/
/** @defgroup IWDG_Private_Constants IWDG Private Constants
* @{
*/
/**
* @brief IWDG Key Register BitMask
*/
#define IWDG_KEY_RELOAD 0x0000AAAAU /*!< IWDG Reload Counter Enable */
#define IWDG_KEY_ENABLE 0x0000CCCCU /*!< IWDG Peripheral Enable */
#define IWDG_KEY_WRITE_ACCESS_ENABLE 0x00005555U /*!< IWDG KR Write Access Enable */
#define IWDG_KEY_WRITE_ACCESS_DISABLE 0x00000000U /*!< IWDG KR Write Access Disable */
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup IWDG_Private_Macros IWDG Private Macros
* @{
*/
/**
* @brief Enable write access to IWDG_PR and IWDG_RLR registers.
* @param __HANDLE__ IWDG handle
* @retval None
*/
#define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
/**
* @brief Disable write access to IWDG_PR and IWDG_RLR registers.
* @param __HANDLE__ IWDG handle
* @retval None
*/
#define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
/**
* @brief Check IWDG prescaler value.
* @param __PRESCALER__ IWDG prescaler value
* @retval None
*/
#define IS_IWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == IWDG_PRESCALER_4) || \
((__PRESCALER__) == IWDG_PRESCALER_8) || \
((__PRESCALER__) == IWDG_PRESCALER_16) || \
((__PRESCALER__) == IWDG_PRESCALER_32) || \
((__PRESCALER__) == IWDG_PRESCALER_64) || \
((__PRESCALER__) == IWDG_PRESCALER_128)|| \
((__PRESCALER__) == IWDG_PRESCALER_256))
/**
* @brief Check IWDG reload value.
* @param __RELOAD__ IWDG reload value
* @retval None
*/
#define IS_IWDG_RELOAD(__RELOAD__) ((__RELOAD__) <= IWDG_RLR_RL)
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32F1xx_HAL_IWDG_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,258 @@
/**
******************************************************************************
* @file stm32f1xx_hal_iwdg.c
* @author MCD Application Team
* @brief IWDG HAL module driver.
* This file provides firmware functions to manage the following
* functionalities of the Independent Watchdog (IWDG) peripheral:
* + Initialization and Start functions
* + IO operation functions
*
@verbatim
==============================================================================
##### IWDG Generic features #####
==============================================================================
[..]
(+) The IWDG can be started by either software or hardware (configurable
through option byte).
(+) The IWDG is clocked by the Low-Speed Internal clock (LSI) and thus stays
active even if the main clock fails.
(+) Once the IWDG is started, the LSI is forced ON and both cannot be
disabled. The counter starts counting down from the reset value (0xFFF).
When it reaches the end of count value (0x000) a reset signal is
generated (IWDG reset).
(+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
the IWDG_RLR value is reloaded into the counter and the watchdog reset
is prevented.
(+) The IWDG is implemented in the VDD voltage domain that is still functional
in STOP and STANDBY mode (IWDG reset can wake up the CPU from STANDBY).
IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
reset occurs.
(+) Debug mode: When the microcontroller enters debug mode (core halted),
the IWDG counter either continues to work normally or stops, depending
on DBG_IWDG_STOP configuration bit in DBG module, accessible through
__HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros.
[..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
The IWDG timeout may vary due to LSI clock frequency dispersion.
STM32F1xx devices provide the capability to measure the LSI clock
frequency (LSI clock is internally connected to TIM5 CH4 input capture).
The measured value can be used to have an IWDG timeout with an
acceptable accuracy.
[..] Default timeout value (necessary for IWDG_SR status register update):
Constant LSI_VALUE is defined based on the nominal LSI clock frequency.
This frequency being subject to variations as mentioned above, the
default timeout value (defined through constant HAL_IWDG_DEFAULT_TIMEOUT
below) may become too short or too long.
In such cases, this default timeout value can be tuned by redefining
the constant LSI_VALUE at user-application level (based, for instance,
on the measured LSI clock frequency as explained above).
##### How to use this driver #####
==============================================================================
[..]
(#) Use IWDG using HAL_IWDG_Init() function to :
(++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
clock is forced ON and IWDG counter starts counting down.
(++) Enable write access to configuration registers:
IWDG_PR and IWDG_RLR.
(++) Configure the IWDG prescaler and counter reload value. This reload
value will be loaded in the IWDG counter each time the watchdog is
reloaded, then the IWDG will start counting down from this value.
(++) Wait for status flags to be reset.
(#) Then the application program must refresh the IWDG counter at regular
intervals during normal operation to prevent an MCU reset, using
HAL_IWDG_Refresh() function.
*** IWDG HAL driver macros list ***
====================================
[..]
Below the list of most used macros in IWDG HAL driver:
(+) __HAL_IWDG_START: Enable the IWDG peripheral
(+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in
the reload register
@endverbatim
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
/** @addtogroup STM32F1xx_HAL_Driver
* @{
*/
#ifdef HAL_IWDG_MODULE_ENABLED
/** @addtogroup IWDG
* @brief IWDG HAL module driver.
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/** @defgroup IWDG_Private_Defines IWDG Private Defines
* @{
*/
/* Status register needs up to 5 LSI clock periods divided by the clock
prescaler to be updated. The number of LSI clock periods is upper-rounded to
6 for the timeout value calculation.
The timeout value is also calculated using the highest prescaler (256) and
the LSI_VALUE constant. The value of this constant can be changed by the user
to take into account possible LSI clock period variations.
The timeout value is multiplied by 1000 to be converted in milliseconds. */
#define HAL_IWDG_DEFAULT_TIMEOUT ((6UL * 256UL * 1000UL) / LSI_VALUE)
/**
* @}
*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup IWDG_Exported_Functions
* @{
*/
/** @addtogroup IWDG_Exported_Functions_Group1
* @brief Initialization and Start functions.
*
@verbatim
===============================================================================
##### Initialization and Start functions #####
===============================================================================
[..] This section provides functions allowing to:
(+) Initialize the IWDG according to the specified parameters in the
IWDG_InitTypeDef of associated handle.
(+) Once initialization is performed in HAL_IWDG_Init function, Watchdog
is reloaded in order to exit function with correct time base.
@endverbatim
* @{
*/
/**
* @brief Initialize the IWDG according to the specified parameters in the
* IWDG_InitTypeDef and start watchdog. Before exiting function,
* watchdog is refreshed in order to have correct time base.
* @param hiwdg pointer to a IWDG_HandleTypeDef structure that contains
* the configuration information for the specified IWDG module.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
{
uint32_t tickstart;
/* Check the IWDG handle allocation */
if (hiwdg == NULL)
{
return HAL_ERROR;
}
/* Check the parameters */
assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
/* Enable IWDG. LSI is turned on automatically */
__HAL_IWDG_START(hiwdg);
/* Enable write access to IWDG_PR and IWDG_RLR registers by writing
0x5555 in KR */
IWDG_ENABLE_WRITE_ACCESS(hiwdg);
/* Write to IWDG registers the Prescaler & Reload values to work with */
hiwdg->Instance->PR = hiwdg->Init.Prescaler;
hiwdg->Instance->RLR = hiwdg->Init.Reload;
/* Check pending flag, if previous update not done, return timeout */
tickstart = HAL_GetTick();
/* Wait for register to be updated */
while (hiwdg->Instance->SR != 0x00u)
{
if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
{
return HAL_TIMEOUT;
}
}
/* Reload IWDG counter with value defined in the reload register */
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
/* Return function status */
return HAL_OK;
}
/**
* @}
*/
/** @addtogroup IWDG_Exported_Functions_Group2
* @brief IO operation functions
*
@verbatim
===============================================================================
##### IO operation functions #####
===============================================================================
[..] This section provides functions allowing to:
(+) Refresh the IWDG.
@endverbatim
* @{
*/
/**
* @brief Refresh the IWDG.
* @param hiwdg pointer to a IWDG_HandleTypeDef structure that contains
* the configuration information for the specified IWDG module.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
{
/* Reload IWDG counter with value defined in the reload register */
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
/* Return function status */
return HAL_OK;
}
/**
* @}
*/
/**
* @}
*/
#endif /* HAL_IWDG_MODULE_ENABLED */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -1,6 +1,6 @@
# Processed by ../tools/insertMyCode.sh
# Processed by ../tools/insertMyCode.sh
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Nov 19 18:53:40 CET 2020]
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sun Dec 27 12:34:13 CET 2020]
##########################################################################################################################
# ------------------------------------------------
@ -36,37 +36,39 @@ BUILD_DIR = build
# source
######################################
# C sources
C_SOURCES = \
User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
libmbus/mbus/mbus-protocol.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/adc.c \
Core/Src/spi.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_adc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_spi.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/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/oled.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 \
libmbus/mbus/mbus-protocol.c \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/adc.c \
Core/Src/iwdg.c \
Core/Src/spi.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_adc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.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_iwdg.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.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_stm32f103xe.s
@ -110,8 +112,8 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32F103xE
@ -119,18 +121,19 @@ C_DEFS = \
AS_INCLUDES =
# C includes
C_INCLUDES = \
-Ihottislib \
-Ipubsubc/src \
-Ilibmbus \
-IUser/Inc \
-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 \
-Ipubsubc/src \
-Ilibmbus \
-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 \
-IDrivers/CMSIS/Include
@ -169,17 +172,17 @@ 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 pubsubc.a)
OBJECTS += $(addprefix $(BUILD_DIR)/,w5500.a pubsubc.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)/pubsubc.a:
(cd pubsubc && $(MAKE) && cp pubsubc.a ../$(BUILD_DIR) && cd ..)
$(BUILD_DIR)/w5500.a:
(cd ioLibrary_Driver && $(MAKE) && cp w5500.a ../$(BUILD_DIR) && cd ..)
$(BUILD_DIR)/pubsubc.a:
(cd pubsubc && $(MAKE) && cp pubsubc.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

@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Nov 19 18:53:40 CET 2020]
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Sun Dec 27 12:34:13 CET 2020]
##########################################################################################################################
# ------------------------------------------------
@ -39,6 +39,7 @@ C_SOURCES = \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/adc.c \
Core/Src/iwdg.c \
Core/Src/spi.c \
Core/Src/usart.c \
Core/Src/stm32f1xx_it.c \
@ -56,6 +57,7 @@ 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_iwdg.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \

23
cube/User/Inc/cmdHelper.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _CMDHELPER_H_
#define _CMDHELPER_H_
#include <stdint.h>
#include <stdbool.h>
typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
typedef struct {
char name[24];
char help[512];
cmdFunc_t cmdFunc;
} cmd_t;
void sendString(const char *buf);
bool sendFormatString(const char *format, ...);
const cmd_t *getRegularCommands();
const cmd_t *getAdminCommands();
const cmd_t *getConfigCommands();
#endif /* _CMDHELPER_H_ */

43
cube/User/Inc/config.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include <stdint.h>
#include <spi.h>
#include <assert.h>
#define CONFIG_MAGIC 0xdead000a
#define DEVICE_MAGIC 0xaffe0000
typedef struct __attribute__((__packed__)) s_configBlock {
uint32_t configMagic;
char deviceName[16];
uint8_t macAddress[6];
int32_t frontendThreshold;
char brokerName[64];
char watchdogTopic[64];
char startupTopic[64];
char statusTopic[64];
char mbusDataTopic[64];
char syslogServerName[64];
uint8_t numOfDeviceBlocks;
uint8_t filler[1];
} t_configBlock;
#define MAX_MBUS_DEVICES 16
#define MBUSDEVICE_NAMELENGTH 16
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
typedef struct __attribute__((__packed__)) s_deviceBlock {
uint32_t deviceMagic;
char deviceName[MBUSDEVICE_NAMELENGTH];
uint8_t address;
int8_t consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
int32_t period;
uint8_t filler[3];
} t_deviceBlock;
void configInit();
t_configBlock* getConfig();
#endif /* _CONFIG_H_ */

View File

@ -3,20 +3,48 @@
#include <stdint.h>
#include <spi.h>
#include <config.h>
#include <assert.h>
#define EEPROM_WRITE_BLOCK_SIZE 32
#define EEPROM_AFTER_WRITE_DELAY 7
typedef struct __attribute__((__packed__)) s_eepromHeader {
uint32_t magic;
uint32_t writeCounter;
} t_eepromHeader;
static_assert((sizeof(t_eepromHeader) <= EEPROM_WRITE_BLOCK_SIZE), "t_eepromHeader has illegal size, must be less than or equal 32");
typedef struct __attribute__((__packed__)) s_deviceStats {
uint32_t totalRunningHours;
uint32_t totalPowercycles;
uint32_t totalRequests;
uint32_t totalFailures;
} t_deviceStats;
static_assert((sizeof(t_deviceStats) <= EEPROM_WRITE_BLOCK_SIZE), "t_deviceStats has illegal size, must be less than or equal 32");
static_assert((sizeof(t_configBlock) % 32 == 0), "t_configBlock has illegal size, must be dividable by 32");
static_assert((sizeof(t_deviceBlock) % 32 == 0), "t_deviceBlock has illegal size, must be dividable by 32");
#define EEPROM_BASE_ADDR 0
#define EEPROM_DEVICE_STATS_ADDR 32
#define EEPROM_CONFIG_BLOCK_ADDR 64
#define EEPROM_DEVICE_BLOCK_BASE_ADDR (EEPROM_CONFIG_BLOCK_ADDR + sizeof(t_configBlock))
void eepromInit();
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi);
t_deviceStats* getGlobalDeviceStats();
void eepromReadConfigBlock(t_configBlock *destConfigBlock);
void eepromWriteConfigBlock(t_configBlock *srcConfigBlock);
void eepromReadDeviceBlock(uint8_t blockNum, t_deviceBlock *destDeviceBlock);
void eepromWriteDeviceBlock(uint8_t blockNum, t_deviceBlock *srcDeviceBlock);
#endif /* EEPROM_H_ */

View File

@ -9,6 +9,5 @@ void frontendInit();
void frontendAdcCallback(ADC_HandleTypeDef* hadc);
void frontendEnable();
void frontendDisable();
void frontendSetThreshold(int32_t threshold);
#endif // _FRONTEND_H_

View File

@ -4,10 +4,9 @@
#include <main.h>
#include <stdint.h>
#include <stdbool.h>
#include <config.h>
#define MBUSDEVICE_NAMELENGTH 24
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
typedef struct {
char deviceName[MBUSDEVICE_NAMELENGTH];
uint8_t address;
@ -17,6 +16,7 @@ typedef struct {
int32_t period;
int32_t delay;
bool waiting;
bool active;
} t_mbusDevice;
typedef enum {
@ -26,16 +26,25 @@ typedef enum {
} e_mbusCommRequestResult;
typedef struct {
uint32_t requestCnt;
uint32_t errorCnt;
uint32_t mbusRequestCnt;
uint32_t mbusErrorCnt;
uint32_t uartOctetCnt;
uint32_t uartOverrunCnt;
uint32_t uartFramingErrCnt;
uint32_t uartParityErrCnt;
uint32_t uartNoiseErrCnt;
} t_mbusCommStats;
// e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
void mbusCommInit();
void mbusCommExec();
void mbusCommEnable(bool enable);
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
void mbusCommErrorCallback(UART_HandleTypeDef *huart);
void mbusCommSetStats(t_mbusCommStats stats);
t_mbusCommStats *mbusCommGetStats();
void mbusCommAddDevice(t_deviceBlock *deviceBlock);
#endif // _MBUSCOMM_H_

View File

@ -4,9 +4,10 @@
#include <stdbool.h>
#include <stdint.h>
int wizInit();
bool isNetworkAvailable();
uint8_t* wizGetIPAddress();
bool wizDnsQuery(char *name, uint8_t *ip);
#endif // _WIZHELPER_H_

81
cube/User/Src/adminCmds.c Normal file
View File

@ -0,0 +1,81 @@
#include <cmdHelper.h>
#include <logger.h>
#include <string.h>
#include <mbusComm.h>
#include <loopCtrl.h>
// clear statistics
static bool clearCmd(uint8_t argc, char **args) {
t_mbusCommStats zeroedStats = { .mbusRequestCnt = 0, .mbusErrorCnt = 0, .uartOctetCnt = 0, .uartOverrunCnt = 0, .uartFramingErrCnt = 0, .uartParityErrCnt = 0, .uartNoiseErrCnt = 0 };
mbusCommSetStats(zeroedStats);
coloredMsg(LOG_YELLOW, true, "ch cc global statistics cleared");
return true;
}
static bool mbusCommEnableCmd(uint8_t argc, char **args) {
bool retCode = true;
if (argc == 2) {
if (0 == strcmp("false", args[1])) {
mbusCommEnable(false);
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication disabled");
} else if (0 == strcmp("true", args[1])) {
mbusCommEnable(true);
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication enabled");
} else {
retCode = false;
}
} else {
retCode = false;
}
return retCode;
}
static bool loopEnableCmd(uint8_t argc, char **args) {
bool retCode = true;
if (argc == 2) {
if (0 == strcmp("false", args[1])) {
loopDisable();
coloredMsg(LOG_YELLOW, true, "ch lec loop disabled");
} else if (0 == strcmp("true", args[1])) {
loopEnable();
coloredMsg(LOG_YELLOW, true, "ch lec loop enabled");
} else {
retCode = false;
}
} else {
retCode = false;
}
return retCode;
}
const cmd_t ADMIN_COMMANDS[] = {
{ .name = "clear", .cmdFunc = clearCmd,
.help = \
"clear ................................ Clears the global Meterbus\n\r" \
" statistics\n\r"
},
{ .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd,
.help = \
"mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \
" communication\n\r"
},
{ .name = "loopEnable", .cmdFunc = loopEnableCmd,
.help = \
"loopEnable true|false ................ Enables or disables the loop.\n\r" \
" Disable Meterbus communication\n\r" \
" first if you want to disable the\n\r" \
" for a longer time, otherwise the\n\r" \
" request will enable it again\n\r"
},
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
};
const cmd_t *getAdminCommands() {
return ADMIN_COMMANDS;
}

View File

@ -1,18 +1,19 @@
#include <cmdHandler.h>
#include <cmdHelper.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <socket.h>
#include <logger.h>
#include <PontCoopScheduler.h>
#include <wizHelper.h>
#include <mbusComm.h>
#include <loopCtrl.h>
#include <config.h>
extern const uint8_t CMD_SOCK;
@ -31,129 +32,66 @@ typedef enum {
CH_ERROR
} chState_t;
typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
typedef struct {
bool requiredConfigMode;
char name[16];
char help[512];
cmdFunc_t cmdFunc;
} cmd_t;
// clear statistics
bool clearCmd(uint8_t argc, char **args) {
t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 };
mbusCommSetStats(zeroedStats);
coloredMsg(LOG_YELLOW, true, "ch cc global statistics cleared");
return true;
void sendString(const char *buf) {
send(CMD_SOCK, (uint8_t*)buf, strlen(buf));
}
bool globalStatsCmd(uint8_t argc, char **args) {
t_mbusCommStats *stats = mbusCommGetStats();
char buf[256];
sprintf(buf, \
"Global statistics\n\r" \
" Requests: %ld\n\r" \
" Errors: %ld\n\r",
stats->requestCnt, stats->errorCnt
);
send(CMD_SOCK, (uint8_t*)buf, strlen(buf));
return true;
}
bool mbusCommEnableCmd(uint8_t argc, char **args) {
bool sendFormatString(const char *format, ...) {
bool retCode = true;
if (argc == 2) {
if (0 == strcmp("false", args[1])) {
mbusCommEnable(false);
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication disabled");
} else if (0 == strcmp("true", args[1])) {
mbusCommEnable(true);
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication enabled");
} else {
retCode = false;
}
} else {
retCode = false;
}
va_list vl;
va_start(vl, format);
char buf[4096];
int vcnt = vsnprintf(buf, sizeof(buf), format, vl);
retCode = (vcnt < sizeof(buf));
va_end(vl);
sendString(buf);
return retCode;
}
bool loopEnableCmd(uint8_t argc, char **args) {
bool retCode = true;
if (argc == 2) {
if (0 == strcmp("false", args[1])) {
loopDisable();
coloredMsg(LOG_YELLOW, true, "ch lec loop disabled");
} else if (0 == strcmp("true", args[1])) {
loopEnable();
coloredMsg(LOG_YELLOW, true, "ch lec loop enabled");
} else {
retCode = false;
}
} else {
retCode = false;
}
return retCode;
}
const static cmd_t COMMANDS[] = {
{ .requiredConfigMode = true, .name = "clear", .cmdFunc = clearCmd,
.help = \
"clear ................................ Clears the global Meterbus\n\r" \
" statistics\n\r" \
" Required configuration mode\n\r"
},
{ .requiredConfigMode = true, .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd,
.help = \
"mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \
" communication\n\r"
},
{ .requiredConfigMode = true, .name = "loopEnable", .cmdFunc = loopEnableCmd,
.help = \
"loopEnable true|false ................ Enables or disables the loop.\n\r" \
" Disable Meterbus communication\n\r" \
" first if you want to disable the\n\r" \
" for a longer time, otherwise the\n\r" \
" request will enable it again\n\r"
},
{ .requiredConfigMode = false, .name = "globalStats", .cmdFunc = globalStatsCmd,
.help = \
"globalStats .......................... Show the global statistics\n\r" \
" counters requestCnt and errorCnt\n\r"
},
{ .requiredConfigMode = false, .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
};
// returns 0 to continue waiting for input
// returns -1 to close the connection
// returns 1 to toggle to config mode
// returns 2 to toggle back to default mode
int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
// returns 1 to toggle to admin mode
// returns 2 to toggle to config mode
// returns 3 to toggle back to default mode
static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
const static char HELP_MSG[] = \
"Usage\n\r" \
"\n\r" \
"help ................................. Show this help page\n\r" \
"quit ................................. Terminate the console session\n\r" \
"enable ............................... Enable configuration mode\n\r" \
"disable .............................. Disable configuration mode\n\r" \
"enable ............................... Enable admin mode\n\r" \
"config ............................... Enter configuration mode\n\r" \
"disable .............................. Disable admin/config mode\n\r" \
;
const static char CONFIG_INTRO_MSG[] = \
"In configuration mode each command changing the configuration\n\r" \
"will save changes directly to the EEPROM.\n\r" \
"However, the system will only consider these changes after a\n\r" \
"restart since only in this sitution the EEPROM is read.\n\r" \
"\n\r" \
;
const static char GOODBYE_MSG[] = "Good bye\n\r";
const static char OK_MSG[] = "OK\n\r";
const static char FAILED_MSG[] = "Failed\n\r";
const static char REQUIRES_CONFIG_MODE_MGS[] = "Not executed, requires config mode\n\r";
const static char UNKNOWN_COMMAND[] = "Unknown command\n\r";
uint8_t *messageToSend = NULL;
static bool adminMode = false;
static bool configMode = false;
if (resetConfigMode) {
if (resetSpecialModes) {
adminMode = false;
configMode = false;
}
coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);;
cmd_t const * commands = getRegularCommands();
if (adminMode) {
commands = getAdminCommands();
} else if (configMode) {
commands = getConfigCommands();
}
coloredMsg(LOG_YELLOW, true, "ch cec cmdLine is %s", cmdLine);;
#define MAX_NUM_OF_ARGS 8
char *args[MAX_NUM_OF_TASKS];
@ -169,61 +107,68 @@ int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetConfigMode) {
char *cmd = args[0];
int8_t retCode = 0;
coloredMsg(LOG_YELLOW, false, "ch cec cmd is %s, number of arguments %d", cmd, argc);
coloredMsg(LOG_YELLOW, true, "ch cec cmd is %s, number of arguments %d", cmd, argc);
if (0 == strcmp(cmd, "quit")) {
messageToSend = (uint8_t*)GOODBYE_MSG;
retCode = -1;
} else if (0 == strcmp(cmd, "help")) {
send(CMD_SOCK, (uint8_t*)HELP_MSG, strlen(HELP_MSG));
if (configMode) {
sendString(CONFIG_INTRO_MSG);
}
sendString(HELP_MSG);
uint8_t cmdIdx = 0;
while (true) {
cmd_t command = COMMANDS[cmdIdx];
cmd_t command = commands[cmdIdx];
if (0 == strcmp("END_OF_CMDS", command.name)) {
break;
}
send(CMD_SOCK, (uint8_t*)command.help, strlen(command.help));
sendString(command.help);
cmdIdx++;
}
messageToSend = NULL;
} else if (0 == strcmp(cmd, "enable")) {
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");
configMode = true;
coloredMsg(LOG_YELLOW, true, "ch cec enable admin mode");
adminMode = true;
retCode = 1;
} else if (0 == strcmp(cmd, "disable")) {
coloredMsg(LOG_YELLOW, true, "ch cec disable config mode");
coloredMsg(LOG_YELLOW, true, "ch cec disable admin mode");
adminMode = false;
configMode = false;
retCode = 3;
} else if (0 == strcmp(cmd, "config")) {
coloredMsg(LOG_YELLOW, true, "ch cec enable config mode");
configMode = true;
retCode = 2;
} else {
uint8_t cmdIdx = 0;
while (true) {
cmd_t command = COMMANDS[cmdIdx];
cmd_t command = commands[cmdIdx];
if (0 == strcmp("END_OF_CMDS", command.name)) {
messageToSend = (uint8_t*) UNKNOWN_COMMAND;
break;
}
if (0 == strcmp(cmd, command.name)) {
if (command.requiredConfigMode && !configMode) {
messageToSend = (uint8_t*)REQUIRES_CONFIG_MODE_MGS;
} else {
messageToSend = command.cmdFunc(argc, args) ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG;
}
messageToSend = command.cmdFunc(argc, args) ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG;
break;
}
cmdIdx++;
}
}
if (messageToSend) {
coloredMsg(LOG_YELLOW, true, "ch cec command finally returns %s", messageToSend);
send(CMD_SOCK, messageToSend, strlen((char*)messageToSend));
}
return retCode;
}
void cmdHandlerEngine(void *handle) {
static void cmdHandlerEngine(void *handle) {
static uint8_t receiveBuffer[256];
static chState_t state = CH_INIT;
static bool resetConfigMode = false;
static bool resetSpecialModes = false;
static char banner[] = \
"MBGW3\n\r" \
@ -231,8 +176,9 @@ void cmdHandlerEngine(void *handle) {
"or quit to close the connection.\n\r";
static char *prompt;
static char defaultPrompt[] = "MBGW3 # ";
static char elevatedPrompt[] = "MBGW3 (admin) > ";
static char defaultPrompt[] = " > ";
static char adminPrompt[] = " (admin) # ";
static char configPrompt[] = " (config) $ ";
int8_t res = 0;
@ -277,6 +223,7 @@ void cmdHandlerEngine(void *handle) {
sockState = getSn_SR(CMD_SOCK);
if (sockState != SOCK_LISTEN) {
coloredMsg(LOG_YELLOW, false, "ch che socket state is 0x%02x", sockState);
state = CH_DISCONNECT;
}
if (sockState == SOCK_ESTABLISHED) {
@ -295,7 +242,7 @@ void cmdHandlerEngine(void *handle) {
resultSend = send(CMD_SOCK, (uint8_t*)banner, strlen(banner));
coloredMsg(LOG_YELLOW, false, "ch che sent banner, send returns 0x%02x", resultSend);
prompt = defaultPrompt;
resetConfigMode = true;
resetSpecialModes = true;
state = CH_PROMPT;
}
break;
@ -307,8 +254,8 @@ void cmdHandlerEngine(void *handle) {
coloredMsg(LOG_YELLOW, true, "ch che sockState is 0x%02x when trying to send promt", sockState);
state = CH_DISCONNECT;
} else {
resultSend = send(CMD_SOCK, (uint8_t*)prompt, strlen(prompt));
coloredMsg(LOG_YELLOW, false, "ch che sent prompt %s, send returns 0x%02x", prompt, resultSend);
sendFormatString("%s %s", getConfig()->deviceName, prompt);
coloredMsg(LOG_YELLOW, false, "ch che sent prompt %s %s", getConfig()->deviceName, prompt);
state = CH_RECEIVE;
}
break;
@ -335,8 +282,8 @@ void cmdHandlerEngine(void *handle) {
receiveBuffer[strlen((char*)receiveBuffer) - 1] = 0;
}
coloredMsg(LOG_YELLOW, false, "ch che received: %s", receiveBuffer);
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetConfigMode);
resetConfigMode = false;
int8_t resCEC = cmdExecuteCommand(receiveBuffer, resetSpecialModes);
resetSpecialModes = false;
switch (resCEC) {
case 0:
state = CH_PROMPT;
@ -345,10 +292,14 @@ void cmdHandlerEngine(void *handle) {
state = CH_DISCONNECT;
break;
case 1:
prompt = elevatedPrompt;
prompt = adminPrompt;
state = CH_PROMPT;
break;
case 2:
prompt = configPrompt;
state = CH_PROMPT;
break;
case 3:
prompt = defaultPrompt;
state = CH_PROMPT;
break;
@ -366,9 +317,9 @@ void cmdHandlerEngine(void *handle) {
break;
case CH_DISCONNECT_WAIT:
coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
//coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
sockState = getSn_SR(CMD_SOCK);
coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
//coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
if (sockState == SOCK_CLOSED) {
coloredMsg(LOG_YELLOW, true, "ch che socket is closed now");
state = CH_INIT;
@ -379,6 +330,9 @@ void cmdHandlerEngine(void *handle) {
case CH_ERROR:
coloredMsg(LOG_YELLOW, true, "ch che error state, will stop here");
schDel(cmdHandlerEngine, NULL);
state = CH_INIT;
schAdd(cmdHandlerEngine, NULL, 5000, 100);
coloredMsg(LOG_YELLOW, true, "ch che restart command handler engine in 5s");
break;
}
}

164
cube/User/Src/config.c Normal file
View File

@ -0,0 +1,164 @@
#include <stdint.h>
#include <stdbool.h>
#include <config.h>
#include <eeprom.h>
#include <logger.h>
#include <mbusComm.h>
#define NUM_OF_DEFAULT_DEVICES 8
t_deviceBlock defaultDeviceBlock[] = {
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Total",
.address = 80,
.consideredField = { 0, 17, -1, -1 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Computer",
.address = 85,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Dryer",
.address = 81,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Laundry",
.address = 82,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Dishwasher",
.address = 83,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Light",
.address = 84,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Freezer",
.address = 86,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
},
{
.deviceMagic = DEVICE_MAGIC,
.deviceName = "Fridge",
.address = 87,
.consideredField = { 0, 4, 2, 3 },
.period = 10,
.filler = { 0, 0, 0 }
}
};
t_configBlock defaultConfigBlock = {
.configMagic = CONFIG_MAGIC,
.deviceName = "MBGW3",
.macAddress = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
.frontendThreshold = 240,
.brokerName = "mqttbroker",
.watchdogTopic = "IoT/Watchdog",
.startupTopic = "IoT/MBGW3/Startup",
.statusTopic = "IoT/MBGW3/Status",
.mbusDataTopic = "IoT/MBGW3/Measurement",
.syslogServerName = "syslogserver",
.numOfDeviceBlocks = NUM_OF_DEFAULT_DEVICES,
.filler = { 0 }
};
t_configBlock mainConfigBlock;
t_configBlock* getConfig() {
return &mainConfigBlock;
}
void configInit() {
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom");
eepromReadConfigBlock(&mainConfigBlock);
if (mainConfigBlock.configMagic != CONFIG_MAGIC) {
coloredMsg(LOG_BLUE, false, "cfg ci Invalid configuration block read from eeprom");
eepromWriteConfigBlock(&defaultConfigBlock);
coloredMsg(LOG_BLUE, false, "cfg ci Default configuration block written to eeprom");
for (uint8_t i = 0; i < NUM_OF_DEFAULT_DEVICES; i++) {
eepromWriteDeviceBlock(i, &defaultDeviceBlock[i]);
}
coloredMsg(LOG_BLUE, false, "cfg ci Default device blocks written to eeprom");
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom again");
eepromReadConfigBlock(&mainConfigBlock);
}
coloredMsg(LOG_BLUE, false, "cfg ci configMagic: %lx", mainConfigBlock.configMagic);
coloredMsg(LOG_BLUE, false, "cfg ci deviceName: %s", mainConfigBlock.deviceName);
coloredMsg(LOG_BLUE, false, "cfg ci MAC address: %02x:%02x:%02x:%02x:%02x:%02x", mainConfigBlock.macAddress[0],
mainConfigBlock.macAddress[1],
mainConfigBlock.macAddress[2],
mainConfigBlock.macAddress[3],
mainConfigBlock.macAddress[4],
mainConfigBlock.macAddress[5]);
coloredMsg(LOG_BLUE, false, "cfg ci frontend threshold: %ld", mainConfigBlock.frontendThreshold);
coloredMsg(LOG_BLUE, false, "cfg ci broker: %s", mainConfigBlock.brokerName);
coloredMsg(LOG_BLUE, false, "cfg ci watchdogTopic: %s", mainConfigBlock.watchdogTopic);
coloredMsg(LOG_BLUE, false, "cfg ci startupTopic: %s", mainConfigBlock.startupTopic);
coloredMsg(LOG_BLUE, false, "cfg ci statusTopic: %s", mainConfigBlock.statusTopic);
coloredMsg(LOG_BLUE, false, "cfg ci mbusDataTopic: %s", mainConfigBlock.mbusDataTopic);
coloredMsg(LOG_BLUE, false, "cfg ci syslog server: %s", mainConfigBlock.syslogServerName);
coloredMsg(LOG_BLUE, false, "cfg ci device block cnt: %d", mainConfigBlock.numOfDeviceBlocks);
for (uint8_t i = 0; i < mainConfigBlock.numOfDeviceBlocks; i++) {
t_deviceBlock tmpDeviceBlock;
eepromReadDeviceBlock(i, &tmpDeviceBlock);
if (tmpDeviceBlock.deviceMagic == DEVICE_MAGIC) {
coloredMsg(LOG_BLUE, false, "cfg ci device %d: ", i);
coloredMsg(LOG_BLUE, false, " Name: %s, Address: %d, Period: %d",
tmpDeviceBlock.deviceName, tmpDeviceBlock.address, tmpDeviceBlock.period);
coloredMsg(LOG_BLUE, false, " Considered Fields: %d %d %d %d",
tmpDeviceBlock.consideredField[0],
tmpDeviceBlock.consideredField[1],
tmpDeviceBlock.consideredField[2],
tmpDeviceBlock.consideredField[3]);
if (tmpDeviceBlock.period == 0) {
coloredMsg(LOG_BLUE, false, " device is marked as inactive");
} else if (tmpDeviceBlock.period == -1) {
coloredMsg(LOG_BLUE, false, " device is marked as deleted");
} else {
mbusCommAddDevice(&tmpDeviceBlock);
}
} else {
coloredMsg(LOG_BLUE, false, "magic of device %d does not match, ignored", i);
}
}
}

447
cube/User/Src/configCmds.c Normal file
View File

@ -0,0 +1,447 @@
#include <cmdHelper.h>
#include <logger.h>
#include <eeprom.h>
#include <config.h>
#include <string.h>
#include <stdlib.h>
static bool showConfigCmd(uint8_t argc, char **args) {
bool retCode = true;
t_configBlock configBlock;
eepromReadConfigBlock(&configBlock);
sendString("This is the saved configuration.\n\r");
sendString("It is not necessarily the active configuration.\n\r");
sendFormatString("configMagic: %lx\n\r", configBlock.configMagic);
sendFormatString("deviceName: %s\n\r", configBlock.deviceName);
sendFormatString("MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n\r", configBlock.macAddress[0],
configBlock.macAddress[1],
configBlock.macAddress[2],
configBlock.macAddress[3],
configBlock.macAddress[4],
configBlock.macAddress[5]);
sendFormatString("frontend threshold: %ld\n\r", configBlock.frontendThreshold);
sendFormatString("broker: %s\n\r", configBlock.brokerName);
sendFormatString("watchdogTopic: %s\n\r", configBlock.watchdogTopic);
sendFormatString("startupTopic: %s\n\r", configBlock.startupTopic);
sendFormatString("statusTopic: %s\n\r", configBlock.statusTopic);
sendFormatString("mbusDataTopic: %s\n\r", configBlock.mbusDataTopic);
sendFormatString("syslog server: %s\n\r", configBlock.syslogServerName);
sendFormatString("device block cnt: %d\n\r", configBlock.numOfDeviceBlocks);
for (uint8_t i = 0; i < configBlock.numOfDeviceBlocks; i++) {
t_deviceBlock tmpDeviceBlock;
eepromReadDeviceBlock(i, &tmpDeviceBlock);
if (tmpDeviceBlock.deviceMagic == DEVICE_MAGIC) {
sendFormatString("device %d: \n\r", i);
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
tmpDeviceBlock.deviceName, tmpDeviceBlock.address, tmpDeviceBlock.period);
sendFormatString(" Considered Fields: %d %d %d %d\n\r",
tmpDeviceBlock.consideredField[0],
tmpDeviceBlock.consideredField[1],
tmpDeviceBlock.consideredField[2],
tmpDeviceBlock.consideredField[3]);
if (tmpDeviceBlock.deviceMagic != DEVICE_MAGIC) {
sendString(" DEVICE MAGIC DOES NOT MATCH\n\r");
}
}
}
return retCode;
}
static bool setStringParameterCmd(uint8_t argc, char **args, size_t offset, size_t length) {
bool retCode = true;
t_configBlock configBlock;
char *parameterName = args[1];
char *newParameterValue = args[2];
if (strlen(newParameterValue) >= length) {
sendString("given new value for is too long\n\r");
retCode = false;
} else {
sendFormatString("set %s to %s\n\r", parameterName, newParameterValue);
eepromReadConfigBlock(&configBlock);
strcpy((((char*)&configBlock) + offset), newParameterValue);
eepromWriteConfigBlock(&configBlock);
}
return retCode;
}
static bool setInt32ParameterCmd(uint8_t argc, char **args, size_t offset, int32_t minV, int32_t maxV) {
bool retCode = true;
t_configBlock configBlock;
char *parameterName = args[1];
char *newParameterValue = args[2];
long int value = strtol(newParameterValue, NULL, 10);
if (value < minV) {
sendString("value is too small\n\r");
retCode = false;
} else if (value > maxV) {
sendString("value is too large\n\r");
} else {
int32_t v = (int32_t) value;
sendFormatString("set %s to %ld\n\r", parameterName, v);
eepromReadConfigBlock(&configBlock);
*((int32_t*)(((uint8_t*)&configBlock) + offset)) = v;
eepromWriteConfigBlock(&configBlock);
}
return retCode;
}
static bool setDeviceNameCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, deviceName),
sizeof(((t_configBlock*)0)->deviceName));
}
static bool setBrokerNameCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, brokerName),
sizeof(((t_configBlock*)0)->brokerName));
}
static bool setSyslogServerCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, syslogServerName),
sizeof(((t_configBlock*)0)->syslogServerName));
}
static bool setWatchdogTopicCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, watchdogTopic),
sizeof(((t_configBlock*)0)->watchdogTopic));
}
static bool setStartupTopicCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, startupTopic),
sizeof(((t_configBlock*)0)->startupTopic));
}
static bool setStatusTopicCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, statusTopic),
sizeof(((t_configBlock*)0)->statusTopic));
}
static bool setMbusDataTopicCmd(uint8_t argc, char **args) {
return setStringParameterCmd(argc, args,
offsetof(t_configBlock, mbusDataTopic),
sizeof(((t_configBlock*)0)->mbusDataTopic));
}
static bool setFrontendThresholdCmd(uint8_t argc, char **args) {
return setInt32ParameterCmd(argc, args,
offsetof(t_configBlock, frontendThreshold),
0, 1023);
}
static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlock *deviceBlock) {
if (strcmp(args[1], "help") == 0) {
sendString("deviceName address period field1 field2 field3 field4\n\r");
sendString("deviceName: max. length = 16\n\r");
sendString("address: between 1 and 254\n\r");
sendString("period: in seconds, between 0 (disabled) and 86400 (1 day)\n\r");
sendString("fields: between -1 (not considered) and 254\n\r");
return false;
}
if ((argc - argOffset) != 8) {
sendString("wrong number of arguments\n\r");
return false;
}
char *deviceName = args[1 + argOffset];
if (strcmp(deviceName, "*") != 0) {
if (strlen(deviceName) >= sizeof(deviceBlock->deviceName)) {
sendString("devicename too long\n\r");
return false;
}
strcpy(deviceBlock->deviceName, deviceName);
}
char *rawAddressStr = args[2 + argOffset];
if (strcmp(rawAddressStr, "*") != 0) {
long int rawAddress = strtol(rawAddressStr, NULL, 10);
if (rawAddress < 1 || rawAddress > 254) {
sendString("illegal address\n\r");
return false;
}
deviceBlock->address = (uint8_t)rawAddress;
}
char *rawPeriodStr = args[3 + argOffset];
if (strcmp(rawPeriodStr, "*") != 0) {
long int rawPeriod = strtol(rawPeriodStr, NULL, 10);
if (rawPeriod < 0 || rawPeriod > 86400) {
sendString("illegal period\n\r");
return false;
}
deviceBlock->period = (int32_t) rawPeriod;
}
for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) {
char *rawFieldNumStr = args[4 + i + argOffset];
if (strcmp(rawFieldNumStr, "*") != 0) {
long int rawFieldNum = strtol(rawFieldNumStr, NULL, 10);
if (rawFieldNum < -1 || rawFieldNum > 127) {
sendString("illegal considered field index\n\r");
return false;
}
deviceBlock->consideredField[i] = (int8_t) rawFieldNum;
}
}
return true;
}
static bool addDeviceCmd(uint8_t argc, char **args) {
t_deviceBlock deviceBlock = { .deviceName = "", .address = 0, .period = 0, .consideredField = { -1, -1, -1, -1}};
bool retCode = makeDevice(0, argc, args, &deviceBlock);
if (retCode) {
sendString("New device would be:\n\r");
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
deviceBlock.deviceName, deviceBlock.address, deviceBlock.period);
for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) {
sendFormatString(" Considered field: %d\n\r", deviceBlock.consideredField[i]);
}
}
deviceBlock.deviceMagic = DEVICE_MAGIC;
uint8_t index = getConfig()->numOfDeviceBlocks;
for (uint8_t i = 0; i < getConfig()->numOfDeviceBlocks; i++) {
t_deviceBlock tmpDeviceBlock;
eepromReadDeviceBlock(i, &tmpDeviceBlock);
if (tmpDeviceBlock.period == -1) {
index = i;
break;
}
}
eepromWriteDeviceBlock(index, &deviceBlock);
if (index == getConfig()->numOfDeviceBlocks) {
t_configBlock configBlock;
eepromReadConfigBlock(&configBlock);
configBlock.numOfDeviceBlocks += 1;
eepromWriteConfigBlock(&configBlock);
}
return retCode;
}
static bool deleteDeviceCmd(uint8_t argc, char **args) {
long int rawIndex = strtol(args[1], NULL, 10);
if (rawIndex < 0 || rawIndex > getConfig()->numOfDeviceBlocks) {
sendFormatString("illegal index, must be greater 0 and less %d\n\r", getConfig()->numOfDeviceBlocks);
return false;
}
uint8_t index = (uint8_t) rawIndex;
t_deviceBlock deviceBlock;
eepromReadDeviceBlock(index, &deviceBlock);
deviceBlock.period = -1;
eepromWriteDeviceBlock(index, &deviceBlock);
return true;
}
static bool changeDeviceCmd(uint8_t argc, char **args) {
if (strcmp(args[1], "help") == 0) {
sendString("First argument: index of device in list\n\r");
sendFormatString("Between 0 and %d\n\r", getConfig()->numOfDeviceBlocks);
sendString("For further arguments use a * to keep the value\n\r");
return makeDevice(0, argc, args, NULL);
}
long int rawIndex = strtol(args[1], NULL, 10);
if (rawIndex < 0 || rawIndex > getConfig()->numOfDeviceBlocks) {
sendFormatString("illegal index, must be greater 0 and less %d\n\r", getConfig()->numOfDeviceBlocks);
return false;
}
uint8_t index = (uint8_t) rawIndex;
t_deviceBlock deviceBlock;
eepromReadDeviceBlock(index, &deviceBlock);
bool retCode = makeDevice(1, argc, args, &deviceBlock);
if (retCode) {
sendString("Changed device will be:\n\r");
sendFormatString(" Index: %d\n\r", index);
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
deviceBlock.deviceName, deviceBlock.address, deviceBlock.period);
for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) {
sendFormatString(" Considered field: %d\n\r", deviceBlock.consideredField[i]);
}
if (deviceBlock.period == 0) {
sendString(" Device is marked as inactive\n\r");
}
eepromWriteDeviceBlock(index, &deviceBlock);
}
return retCode;
}
static bool listDevicesCmd(uint8_t argc, char **args) {
for (uint8_t i = 0; i < getConfig()->numOfDeviceBlocks; i++) {
t_deviceBlock deviceBlock;
eepromReadDeviceBlock(i, &deviceBlock);
sendFormatString("Index: %d\n\r", i);
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
deviceBlock.deviceName, deviceBlock.address, deviceBlock.period);
for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) {
sendFormatString(" Considered field: %d\n\r", deviceBlock.consideredField[i]);
}
if (deviceBlock.period == 0) {
sendString(" Device is marked as inactive\n\r");
} else if (deviceBlock.period == -1) {
sendString(" Device is marked as deleted\n\r");
}
}
return true;
}
const static cmd_t SET_COMMANDS[] = {
{ .name = "devicename", .cmdFunc = setDeviceNameCmd,
.help = \
"devicename ........................... Name of this device\n\r"
},
{ .name = "brokername", .cmdFunc = setBrokerNameCmd,
.help = \
"brokername ........................... Hostname of the MQTT broker\n\r"
},
{ .name = "syslogserver", .cmdFunc = setSyslogServerCmd,
.help = \
"syslogserver ......................... Hostname of the Syslog server\n\r"
},
{ .name = "watchdogtopic", .cmdFunc = setWatchdogTopicCmd,
.help = \
"watchdogtopic ........................ Watchdog Topic\n\r"
},
{ .name = "startuptopic", .cmdFunc = setStartupTopicCmd,
.help = \
"startuptopic ......................... Startup Topic\n\r"
},
{ .name = "statustopic", .cmdFunc = setStatusTopicCmd,
.help = \
"statustopic .......................... Status Topic\n\r"
},
{ .name = "mbusdatatopic", .cmdFunc = setMbusDataTopicCmd,
.help = \
"mbusdatatopic ........................ MBus Data Topic\n\r"
},
{ .name = "frontendthreshold", .cmdFunc = setFrontendThresholdCmd,
.help = \
"frontendthreshold .................... Frontend Threshold (default: 240)\n\r"
},
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
};
const static char UNKNOWN_PARAMETER[] = "unknown parameter\n\r";
const static char OK_MSG[] = "OK\n\r";
const static char FAILED_MSG[] = "Failed\n\r";
static bool setCmd(uint8_t argc, char **args) {
bool retCode = false;
uint8_t *messageToSend = NULL;
char *cmd = args[1];
if (argc >= 2) {
if (0 == strcmp("help", cmd)) {
sendString("You can set the following parameters:\n\r");
uint8_t cmdIdx = 0;
while (true) {
cmd_t command = SET_COMMANDS[cmdIdx];
if (0 == strcmp("END_OF_CMDS", command.name)) {
break;
}
sendString(command.help);
cmdIdx++;
}
retCode = true;
} else {
uint8_t cmdIdx = 0;
while (true) {
cmd_t command = SET_COMMANDS[cmdIdx];
if (0 == strcmp("END_OF_CMDS", command.name)) {
messageToSend = (uint8_t*) UNKNOWN_PARAMETER;
break;
}
if (0 == strcmp(cmd, command.name)) {
retCode = command.cmdFunc(argc, args);
messageToSend = retCode ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG;
sendString("Remember you need to restart to active this change.\n\r");
break;
}
cmdIdx++;
}
sendString((const char*)messageToSend);
}
}
return retCode;
}
static bool restartCmd(uint8_t argc, char **args) {
HAL_NVIC_SystemReset();
// you won't come here ...
return true;
}
const cmd_t CONFIG_COMMANDS[] = {
{ .name = "show", .cmdFunc = showConfigCmd,
.help = \
"show ................................. Show the configuration\n\r"
},
{ .name = "set", .cmdFunc = setCmd,
.help = \
"set .................................. Set configuration parameters\n\r" \
" Argument help gives a list of \n\r" \
" parameters\n\r"
},
{ .name = "addDevice", .cmdFunc = addDeviceCmd,
.help = \
"addDevice ............................ Add a new device to the end of the list\n\r"
},
{ .name = "changeDevice", .cmdFunc = changeDeviceCmd,
.help = \
"changeDevice ......................... Change a new device by index\n\r"
},
{ .name = "listDevices", .cmdFunc = listDevicesCmd,
.help = \
"listDevices .......................... List the configured devices\n\r"
},
{ .name = "deleteDevice", .cmdFunc = deleteDeviceCmd,
.help = \
"deleteDevice ......................... Delete a device\n\r" \
" Argument: index\n\r"
},
{ .name = "restart", .cmdFunc = restartCmd,
.help = \
"restart .............................. Restart the system,\n\r" \
" Required to reload config\n\r"
},
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
};
const cmd_t *getConfigCommands() {
return CONFIG_COMMANDS;
}

View File

@ -7,6 +7,8 @@
#include <PontCoopScheduler.h>
#include <utils.h>
#include <assert.h>
#define HIGH GPIO_PIN_SET
#define LOW GPIO_PIN_RESET
@ -20,21 +22,18 @@ static const uint8_t EEPROM_WREN = 0x06;
// static const uint8_t EEPROM_WRSR = 0x01;
static const uint32_t EEPROM_MAGIC = 0xaffe0006;
static const uint32_t EEPROM_MAGIC = 0xaffe0009;
static const uint16_t EEPROM_HEADER_ADDR = EEPROM_BASE_ADDR;
typedef union {
struct __attribute__((__packed__)) s_eepromHeader {
uint32_t magic;
uint32_t writeCounter;
uint8_t activeBlock;
} s;
t_eepromHeader s;
uint8_t b[sizeof(struct s_eepromHeader)];
} t_eepromHeader;
static const uint16_t EEPROM_HEADER_ADDR = 0;
static t_eepromHeader eepromHeader;
} t_eepromHeaderBlock;
static t_eepromHeaderBlock eepromHeader;
typedef union {
@ -42,11 +41,13 @@ typedef union {
uint8_t b[sizeof(t_deviceStats)];
} t_deviceStatsBlock;
static const uint16_t DEVICE_STATS_ADDR = 32;
static const uint16_t DEVICE_STATS_ADDR = EEPROM_DEVICE_STATS_ADDR;
static t_deviceStatsBlock deviceStats;
static const uint8_t NUM_OF_BLOCKS = 2;
static const uint16_t BLOCK_ADDR[] = { 64, 4128 };
static const uint16_t CONFIG_BLOCK_ADDR = EEPROM_CONFIG_BLOCK_ADDR;
static const uint16_t DEVICE_BLOCK_ADDR = EEPROM_DEVICE_BLOCK_BASE_ADDR;
typedef union {
@ -58,7 +59,6 @@ typedef union {
uint8_t b[sizeof(struct s_spiMsg)];
} t_spiMsg;
t_deviceStats* getGlobalDeviceStats() {
return &(deviceStats.s);
}
@ -72,6 +72,11 @@ static uint16_t swap(uint16_t i) {
}
// active waiting, use only during initialization!
static void eepromActiveDelay(uint8_t delay_ms) {
activeDelay(delay_ms);
}
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) {
t_spiMsg msg = {
.s.cmd = EEPROM_WRITE,
@ -114,8 +119,8 @@ static void eepromHourlyUpdateDeviceStats(void *handle) {
t_mbusCommStats *stats = mbusCommGetStats();
deviceStats.s.totalRequests = stats->requestCnt;
deviceStats.s.totalFailures = stats->errorCnt;
deviceStats.s.totalRequests += stats->mbusRequestCnt;
deviceStats.s.totalFailures += stats->mbusErrorCnt;
logMsg("eeHUDS, about to write updated device stats");
logMsg("eeHUDS, total powercycles so far: %d", deviceStats.s.totalPowercycles);
@ -126,11 +131,42 @@ static void eepromHourlyUpdateDeviceStats(void *handle) {
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
}
// active waiting, use only during initialization!
static void eepromActiveDelay(uint8_t delay_ms) {
activeDelay(delay_ms);
void eepromReadConfigBlock(t_configBlock *destConfigBlock) {
// static_assert((sizeof(*destConfigBlock) % EEPROM_WRITE_BLOCK_SIZE == 0), "config block has illegal size, must be dividable by 32");
for (uint8_t i = 0; i < (sizeof(*destConfigBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
eepromRead(CONFIG_BLOCK_ADDR + (i * EEPROM_WRITE_BLOCK_SIZE), ((uint8_t*)destConfigBlock) + (i * EEPROM_WRITE_BLOCK_SIZE), EEPROM_WRITE_BLOCK_SIZE);
}
}
void eepromWriteConfigBlock(t_configBlock *srcConfigBlock) {
for (uint8_t i = 0; i < (sizeof(*srcConfigBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
eepromWrite(CONFIG_BLOCK_ADDR + (i * EEPROM_WRITE_BLOCK_SIZE), ((uint8_t*)srcConfigBlock) + (i * EEPROM_WRITE_BLOCK_SIZE), EEPROM_WRITE_BLOCK_SIZE);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
}
}
void eepromReadDeviceBlock(uint8_t blockNum, t_deviceBlock *destDeviceBlock) {
static_assert((sizeof(*destDeviceBlock) % EEPROM_WRITE_BLOCK_SIZE == 0), "device block has illegal size, must be dividable by 32");
for (uint8_t i = 0; i < (sizeof(*destDeviceBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
eepromRead(DEVICE_BLOCK_ADDR + (blockNum * sizeof(*destDeviceBlock)) + (i * EEPROM_WRITE_BLOCK_SIZE),
((uint8_t*)destDeviceBlock) + (i * EEPROM_WRITE_BLOCK_SIZE),
EEPROM_WRITE_BLOCK_SIZE);
}
}
void eepromWriteDeviceBlock(uint8_t blockNum, t_deviceBlock *srcDeviceBlock) {
for (uint8_t i = 0; i < (sizeof(*srcDeviceBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
eepromWrite(DEVICE_BLOCK_ADDR + (blockNum * sizeof(*srcDeviceBlock)) + (i * EEPROM_WRITE_BLOCK_SIZE),
((uint8_t*)srcDeviceBlock) + (i * EEPROM_WRITE_BLOCK_SIZE),
EEPROM_WRITE_BLOCK_SIZE);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
}
}
void eepromInit() {
__EEPROM_CS(HIGH);
@ -147,26 +183,19 @@ void eepromInit() {
deviceStats.s.totalFailures = 0;
logMsg("eeI, about to write device stats for the first time");
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
eepromActiveDelay(7);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
uint8_t emptyBlock[32];
uint8_t emptyBlock[EEPROM_WRITE_BLOCK_SIZE];
memset(emptyBlock, 0, sizeof(emptyBlock));
for (uint8_t i = 0; i < NUM_OF_BLOCKS; i++) {
for (uint8_t j = 0; j <= 127; j++) {
uint16_t addr = BLOCK_ADDR[i] + sizeof(emptyBlock) * j;
eepromWrite(addr, emptyBlock, sizeof(emptyBlock));
eepromActiveDelay(7);
}
}
logMsg("eeI, storage blocks initialized");
eepromWrite(CONFIG_BLOCK_ADDR, emptyBlock, EEPROM_WRITE_BLOCK_SIZE);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
logMsg("eeI, config block initialized");
eepromHeader.s.magic = EEPROM_MAGIC;
eepromHeader.s.activeBlock = 0;
eepromHeader.s.writeCounter = 1;
logMsg("eeI, about to write header for the first time");
eepromWrite(EEPROM_HEADER_ADDR, eepromHeader.b, sizeof(eepromHeader));
eepromActiveDelay(7);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
logMsg("eeI, eeprom has been initialized");
} else {
logMsg("eeI, eeprom is initialized");
@ -179,13 +208,10 @@ void eepromInit() {
logMsg("eeI, total requests so far: %d", deviceStats.s.totalRequests);
logMsg("eeI, total failures so far: %d", deviceStats.s.totalFailures);
t_mbusCommStats stats = { .requestCnt = deviceStats.s.totalRequests, .errorCnt = deviceStats.s.totalFailures};
mbusCommSetStats(stats);
deviceStats.s.totalPowercycles += 1;
logMsg("eeI, about to write device stats with updated power cycles counter");
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
eepromActiveDelay(7);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
schAdd(eepromHourlyUpdateDeviceStats, NULL, 0, 60 * 60 * 1000);
logMsg("eeI, hourly device stats update scheduled");

View File

@ -6,9 +6,10 @@
#include <frontend.h>
#include <logger.h>
#include <show.h>
#include <config.h>
static t_configBlock *config;
static volatile int32_t frontendAdcThreshold = 0;
@ -16,16 +17,15 @@ static volatile bool frontendEnabled = false;
void frontendInit() {
config = getConfig();
frontendAdcThreshold = config->frontendThreshold;
HAL_ADCEx_Calibration_Start(&frontendAdc);
logMsg("frontendInit, calibration done");
HAL_ADC_Start_IT(&frontendAdc);
logMsg("frontendInit, adc started");
}
void frontendSetThreshold(int32_t threshold) {
frontendAdcThreshold = threshold;
}
void frontendEnable() {
frontendEnabled = true;
}
@ -37,8 +37,6 @@ void frontendDisable() {
void frontendAdcCallback(ADC_HandleTypeDef* hadc) {
static int32_t holdValue = 0;
show(DEBUG_2, TOGGLE);
if (frontendEnabled) {
int32_t currentValue = (int32_t) HAL_ADC_GetValue(hadc);

View File

@ -6,6 +6,7 @@
#include <ringbuffer.h>
#include <wizHelper.h>
#include <socket.h>
#include <config.h>
#include <stdint.h>
#include <stdlib.h>
@ -22,18 +23,21 @@
#endif //LOGGER_OUTPUT_BY_INTERRUPT
#define LOGBUFFER_SIZE 2048
#define LOGBUFFER_SIZE 4096
#define MSGBUFFER_SIZE 256
static t_configBlock *config;
extern const uint8_t SYSLOG_SOCK;
uint8_t syslogAddr[] = { 172, 16, 11, 15 };
uint8_t syslogAddr[4];
uint8_t singleOctetTXBuffer;
static ringbuffer_t logBuffer;
void logInit() {
void logInit() {
config = getConfig();
ringbufferInit(&logBuffer, LOGBUFFER_SIZE);
}
@ -69,16 +73,31 @@ int logExec() {
void syslog(char *msg) {
static uint8_t state = 0;
int8_t res8 = 0;
int32_t res32 = 0;
if (isNetworkAvailable()) {
switch (state) {
case 0:
res8 = socket(SYSLOG_SOCK, Sn_MR_UDP, 514, SF_IO_NONBLOCK);
if (res8 == SYSLOG_SOCK) {
state = 1;
if (res8 != SYSLOG_SOCK) {
break;
}
break;
state = 1;
// no break
case 1:
sendto(SYSLOG_SOCK, (uint8_t*)msg, strlen(msg), syslogAddr, 514);
if (! wizDnsQuery(config->syslogServerName, syslogAddr)) {
disconnect(SYSLOG_SOCK);
state = 0;
break;
}
state = 2;
// no break
case 2:
res32 = sendto(SYSLOG_SOCK, (uint8_t*)msg, strlen(msg), syslogAddr, 514);
if (res32 != strlen(msg)) {
disconnect(SYSLOG_SOCK);
state = 0;
}
break;
}
}

View File

@ -20,6 +20,7 @@
#include <mqttComm.h>
#include <cmdHandler.h>
#include <oled.h>
#include <config.h>
void my_setup_1() {
@ -45,6 +46,9 @@ void my_setup_2() {
eepromInit();
oledPrint(OLED_SCREEN0, "eeprom init");
configInit();
oledPrint(OLED_SCREEN0, "config init");
wizInit();
oledPrint(OLED_SCREEN0, "network init");
@ -55,7 +59,6 @@ void my_setup_2() {
oledPrint(OLED_SCREEN0, "cmdhandler init");
frontendInit();
frontendSetThreshold(240);
oledPrint(OLED_SCREEN0, "frontend init");
mbusCommInit();
@ -64,13 +67,15 @@ void my_setup_2() {
}
void my_loop() {
show(DEBUG_1, TOGGLE);
// show(DEBUG_2, TOGGLE);
schExec();
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
logExec();
#endif //LOGGER_OUTPUT_BY_INTERRUPT
mbusCommExec();
}
void SYSTICK_Callback() {
@ -90,22 +95,13 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
if (huart == &mbusUart) {
mbusCommTxCpltCallback(huart);
}
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
else if (huart == &debugUart) {
if (huart == &debugUart) {
debugTxCpltCallback(huart);
}
#endif //LOGGER_OUTPUT_BY_INTERRUPT
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if (huart == &mbusUart) {
mbusCommRxCpltCallback(huart);
}
}
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
if (hspi == &eepromSpi) {
eepromSpiTxCpltCallback(hspi);

View File

@ -16,13 +16,22 @@
#include <mbusParserExt.h>
#include <mqttComm.h>
#include <oled.h>
#include <ringbuffer.h>
#include <config.h>
#include <mbus/mbus-protocol.h>
static const char MBUS_TOPIC[] = "IoT/MBGW3/Measurement";
static t_configBlock *config;
static const uint8_t MBUS_QUERY_CMD = 0x5b;
// Delay between end of last bit of sent request telegram
// and enabling the frontend for receiving the response.
// Standard says client must wait at least 11 bit times.
// 1 / 2400 * 11 = 4.5e-3ms
static const uint32_t DELAY_AFTER_SENDING = 4; // ms
typedef enum {
MBCR_SUCCESS = 0,
MBCR_ERROR_TIMEOUT,
@ -44,7 +53,9 @@ typedef enum {
MBCS_IDLE,
MBCS_SEND,
MBCS_SEND_CONTINUED,
MBCS_SENDING,
MBCS_SENDING_DONE,
MBCS_WAIT_AFTER_SENDING,
MBCS_ENABLE_FRONTEND,
MBCS_START1,
MBCS_LENGTH1,
@ -77,25 +88,33 @@ typedef struct {
uint8_t stop;
} t_longframe;
typedef struct {
uint16_t size;
uint16_t readIdx;
uint16_t writeIdx;
uint8_t *buffer;
} linearBuffer_t;
typedef struct {
uint32_t requestId;
e_mbusCommState state;
uint8_t retryCnt;
uint8_t cmd;
uint8_t addr;
uint8_t sendBuf[5];
linearBuffer_t sendBuffer;
linearBuffer_t receiveBuffer;
uint32_t startTime;
uint8_t receiveCnt;
uint8_t receivedOctet;
bool receiving;
bool waitForOctet;
e_mbusCommResult result;
t_longframe frame;
t_mbusDevice *device;
} t_mbusCommHandle;
static t_mbusCommHandle mbusCommHandle = { .requestId = 0, .state = MBCS_IDLE, .retryCnt = 0, .cmd = 0, .addr = 0, .receiveCnt = 0, .receivedOctet = 0, .receiving = false };
static t_mbusCommHandle mbusCommHandle = { .requestId = 0, .state = MBCS_IDLE, .retryCnt = 0, .cmd = 0, .addr = 0, .startTime = 0, .receiveCnt = 0, .waitForOctet = false };
static t_mbusCommStats mbusCommStats = { .requestCnt = 0, .errorCnt = 0 };
static t_mbusCommStats mbusCommStats = { .mbusRequestCnt = 0, .mbusErrorCnt = 0, .uartOctetCnt = 0, .uartOverrunCnt = 0, .uartFramingErrCnt = 0, .uartParityErrCnt = 0, .uartNoiseErrCnt = 0 };
static bool mbusCommEnabled = true;
@ -108,21 +127,21 @@ t_mbusCommStats *mbusCommGetStats() {
}
static void printError(t_mbusCommHandle *localMbusCommHandle) {
float errorRatio = ((float) localMbusCommHandle->device->failures) / ((float) localMbusCommHandle->device->requests);
coloredMsg(LOG_YELLOW, true, "mbc pe [%d] Error ratio is %.2f",
localMbusCommHandle->requestId,
static void printError() {
float errorRatio = ((float) mbusCommHandle.device->failures) / ((float) mbusCommHandle.device->requests);
coloredMsg(LOG_YELLOW, false, "mbc pe [%d] Error ratio is %.2f",
mbusCommHandle.requestId,
errorRatio);
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio);
oledPrintf(OLED_SCREEN0, "Err:%d/%d", localMbusCommHandle->device->failures, localMbusCommHandle->device->requests);
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Error\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\"}",
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
oledPrintf(OLED_SCREEN0, "Err:%d/%d %.2f", mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
}
static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
t_longframe *frame = &(localMbusCommHandle->frame);
static void parseAndPrintFrame() {
t_longframe *frame = &(mbusCommHandle.frame);
mbus_frame reply;
memset(&reply, 0, sizeof(reply));
@ -147,30 +166,42 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
int r = mbus_frame_data_parse(&reply, &frame_data);
if (r == 0) {
mbus_data_variable *data_var = &(frame_data.data_var);
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] sts: %02x", localMbusCommHandle->requestId, data_var->header.status);
if (data_var->header.status) {
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address,
data_var->header.status);
}
if ((data_var->header.status & 0x01)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Application Busy", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Application Busy",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x02)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Any Application Error", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Any Application Error",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x04)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Power Low", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Power Low",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x08)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Permanent Error", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Permanent Error",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x10)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Temporary Error", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Temporary Error",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x20)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 1", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Specific to manufacturer Error 1",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x40)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 2", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Specific to manufacturer Error 2",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
if ((data_var->header.status & 0x80)) {
coloredMsg(LOG_RED, true, "mbc papf [%d] sts: Specific to manufacturer Error 3", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] sts: Specific to manufacturer Error 3",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
mbus_data_record *record;
int i;
@ -181,24 +212,24 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
record;
record = record->next, i++) {
for (uint8_t j = 0; j < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; j++) {
if (localMbusCommHandle->device->consideredField[j] == i) {
if (mbusCommHandle.device->consideredField[j] == i) {
parsedVIB_t parsedVIB = parseVIB(record->drh.vib);
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
localMbusCommHandle->requestId,
parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
// coloredMsg(LOG_YELLOW, false, "mbc papf [%d] parsed VIB N: %s, U: %s, E: %d",
// mbusCommHandle.requestId,
// parsedVIB.name, parsedVIB.unit, parsedVIB.exponent);
if (parsedVIB.found) {
uint32_t value = strtol(mbus_data_record_value(record), NULL, 10);
float weightedValue = ((float) value) * powf(10.0, ((float) parsedVIB.exponent));
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] %s is %.1f %s (%d * 10^%d)",
localMbusCommHandle->requestId, parsedVIB.name, weightedValue, parsedVIB.unit,
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] %s is %.1f %s (%d * 10^%d)",
mbusCommHandle.requestId, parsedVIB.name, weightedValue, parsedVIB.unit,
value, parsedVIB.exponent);
keys[numOfConsideredFields] = parsedVIB.name;
values[numOfConsideredFields] = weightedValue;
numOfConsideredFields++;
} else {
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] L:%d, VIF: 0x%02x U:%s V:%s",
localMbusCommHandle->requestId,
localMbusCommHandle->device->consideredField[j],
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] L:%d, VIF: 0x%02x U:%s V:%s",
mbusCommHandle.requestId,
mbusCommHandle.device->consideredField[j],
record->drh.vib.vif,
mbus_data_record_unit(record),
mbus_data_record_value(record));
@ -207,296 +238,359 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
}
}
}
float errorRatio = ((float) localMbusCommHandle->device->failures) / ((float) localMbusCommHandle->device->requests);
coloredMsg(LOG_YELLOW, true, "mbc papf [%d] Error ratio is %.2f",
localMbusCommHandle->requestId,
float errorRatio = ((float) mbusCommHandle.device->failures) / ((float) mbusCommHandle.device->requests);
coloredMsg(LOG_YELLOW, false, "mbc papf [%d] Error ratio is %.2f",
mbusCommHandle.requestId,
errorRatio);
if (numOfConsideredFields == 1) {
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
"\"Values\":{\"%s\":\"%.1f\"}}",
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio,
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
keys[0], values[0]);
} else if (numOfConsideredFields == 2) {
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio,
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
keys[0], values[0], keys[1], values[1]);
} else if (numOfConsideredFields == 3) {
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio,
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
keys[0], values[0], keys[1], values[1], keys[2], values[2]);
} else if (numOfConsideredFields == 4) {
mqttPublishf(MBUS_TOPIC, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
mqttPublishf(config->mbusDataTopic, "{\"Status\":\"Ok\", \"RequestId\":\"%d\", \"Device\":\"%s\", \"Errors\":\"%d\", \"Requests\":\"%d\", \"ErrorRatio\":\"%.2f\", " \
"\"Values\":{\"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\", \"%s\":\"%.1f\"}}",
localMbusCommHandle->requestId, localMbusCommHandle->device->deviceName,
localMbusCommHandle->device->failures, localMbusCommHandle->device->requests, errorRatio,
mbusCommHandle.requestId, mbusCommHandle.device->deviceName,
mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio,
keys[0], values[0], keys[1], values[1], keys[2], values[2], keys[3], values[3]);
}
oledPrintf(OLED_SCREEN0, "Ok:%d/%d", localMbusCommHandle->device->failures, localMbusCommHandle->device->requests);
oledPrintf(OLED_SCREEN0, "Ok:%d/%d %.2f", mbusCommHandle.device->failures, mbusCommHandle.device->requests, errorRatio);
mbus_data_record_free(data_var->record);
} else {
coloredMsg(LOG_RED, true, "mbc papf [%d] err: unable to parse frame", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc papf [%d %d] err: unable to parse frame",
mbusCommHandle.requestId, mbusCommHandle.device->address);
}
}
static void handleRequestEngine(void *handle);
static void timeoutHandler(void *handle) {
t_mbusCommHandle *localMbusCommHandle = (t_mbusCommHandle*) handle;
// coloredMsg(LOG_RED, true, "mbc th [%d] timeout", localMbusCommHandle->requestId);
localMbusCommHandle->state = MBCS_TIMEOUT;
localMbusCommHandle->receiving = false;
handleRequestEngine(handle);
void mbusCommISR() {
uint32_t isrflags = READ_REG(mbusUart.Instance->SR);
uint32_t cr1its = READ_REG(mbusUart.Instance->CR1);
// RXNEIE doesn't need to be considered since it is always on and more over the
// RXNE flag is cleared by reading the DR, which is done in any case
if (((isrflags & USART_SR_RXNE) != RESET) || ((isrflags & (USART_SR_ORE | USART_SR_FE | USART_SR_PE | USART_SR_NE)) != RESET)) {
// Error flags are only valid together with the RX flag.
// They will be cleared by reading SR (already done above) followed by reading DR (below).
bool errorFound = false;
if ((isrflags & USART_SR_ORE) != RESET) {
mbusCommStats.uartOverrunCnt += 1;
errorFound = true;
}
if ((isrflags & USART_SR_FE) != RESET) {
mbusCommStats.uartFramingErrCnt += 1;
errorFound = true;
}
if ((isrflags & USART_SR_PE) != RESET) {
mbusCommStats.uartParityErrCnt += 1;
errorFound = true;
}
if ((isrflags & USART_SR_NE) != RESET) {
mbusCommStats.uartNoiseErrCnt += 1;
errorFound = true;
}
mbusCommStats.uartOctetCnt += 1;
// it is required to read the DR in any case here, not only when the buffer has space
// otherwise the interrupt flag won't be reset, particularly important in case of ORE
uint8_t data = (uint8_t)(mbusUart.Instance->DR & (uint8_t)0x00FF);
if ((! errorFound) &&
(mbusCommHandle.receiveBuffer.writeIdx < mbusCommHandle.receiveBuffer.size)) {
mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.writeIdx] = data;
mbusCommHandle.receiveBuffer.writeIdx += 1;
}
}
// TXEIE needs to be considered since TXE is cleared by writing the DR, which isn't done
// after the last octet sent
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) {
if (mbusCommHandle.sendBuffer.readIdx < mbusCommHandle.sendBuffer.writeIdx) {
mbusUart.Instance->DR = mbusCommHandle.sendBuffer.buffer[mbusCommHandle.sendBuffer.readIdx];
mbusCommHandle.sendBuffer.readIdx += 1;
if (mbusCommHandle.sendBuffer.readIdx == mbusCommHandle.sendBuffer.writeIdx) {
__HAL_UART_DISABLE_IT(&mbusUart, UART_IT_TXE);
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_TC);
}
}
}
// advance the state for the engine only when the last octet is shifted out completely
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) {
__HAL_UART_DISABLE_IT(&mbusUart, UART_IT_TC);
mbusCommHandle.state = MBCS_SENDING_DONE;
}
}
static void receiveNext(t_mbusCommHandle *localMbusCommHandle) {
localMbusCommHandle->receiving = true;
HAL_UART_Receive_IT(&mbusUart, &(localMbusCommHandle->receivedOctet), 1);
}
static void handleRequestEngine(void *handle) {
t_mbusCommHandle *localMbusCommHandle = (t_mbusCommHandle*) handle;
void mbusCommExec() {
static uint8_t userdataIdx = 0;
static uint8_t calculatedChksum = 0;
uint8_t receivedOctet = 0;
static uint32_t delayAfterSendStartTime = 0;
switch (localMbusCommHandle->state) {
if ((mbusCommHandle.startTime != 0) && ((mbusCommHandle.startTime + 2500) < HAL_GetTick())) {
mbusCommHandle.state = MBCS_TIMEOUT;
} else if (mbusCommHandle.waitForOctet) {
if (mbusCommHandle.receiveBuffer.readIdx >= mbusCommHandle.receiveBuffer.writeIdx) {
return; // no data available, wait
}
receivedOctet = mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.readIdx];
mbusCommHandle.receiveBuffer.readIdx += 1;
mbusCommHandle.waitForOctet = false;
}
switch (mbusCommHandle.state) {
case MBCS_IDLE:
coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state IDLE", localMbusCommHandle->requestId);
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state IDLE", mbusCommHandle.requestId);
break;
case MBCS_SEND:
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND", localMbusCommHandle->requestId);
localMbusCommHandle->sendBuf[0] = 0x10;
localMbusCommHandle->sendBuf[1] = localMbusCommHandle->cmd;
localMbusCommHandle->sendBuf[2] = localMbusCommHandle->addr;
localMbusCommHandle->sendBuf[3] = localMbusCommHandle->cmd + localMbusCommHandle->addr; // checksum
localMbusCommHandle->sendBuf[4] = 0x16;
localMbusCommHandle->state = MBCS_SEND_CONTINUED;
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND", mbusCommHandle.requestId);
mbusCommHandle.sendBuffer.buffer[0] = 0x10;
mbusCommHandle.sendBuffer.buffer[1] = mbusCommHandle.cmd;
mbusCommHandle.sendBuffer.buffer[2] = mbusCommHandle.addr;
mbusCommHandle.sendBuffer.buffer[3] = mbusCommHandle.cmd + mbusCommHandle.addr; // checksum
mbusCommHandle.sendBuffer.buffer[4] = 0x16;
mbusCommHandle.sendBuffer.readIdx = 0;
mbusCommHandle.sendBuffer.writeIdx = 5;
mbusCommHandle.state = MBCS_SEND_CONTINUED;
// no break !!
case MBCS_SEND_CONTINUED:
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND_CONTINUED", localMbusCommHandle->requestId);
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SEND_CONTINUED", mbusCommHandle.requestId);
show(LED_RED, OFF);
if (! loopActive) {
coloredMsg(LOG_YELLOW, true, "mbc hre [%d] enabling loop, try %d", localMbusCommHandle->requestId, localMbusCommHandle->retryCnt);
localMbusCommHandle->retryCnt++;
coloredMsg(LOG_YELLOW, true, "mbc hre [%d %d] enabling loop, try %d",
mbusCommHandle.requestId, mbusCommHandle.device->address,
mbusCommHandle.retryCnt);
mbusCommHandle.retryCnt++;
loopEnable();
schAdd(handleRequestEngine, handle, 100, 0); // give 100ms to settled the loop
} else {
localMbusCommHandle->retryCnt = 0;
HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5);
// transition from here to SENDING_DONE is initiate by mbusCommTxCpltCallback
// interrupt callback
localMbusCommHandle->state = MBCS_SENDING_DONE;
mbusCommHandle.retryCnt = 0;
// enable transmitter interrupt
//coloredMsg(LOG_YELLOW, false, "mbc hre [%d] enable transmitter interrupt", mbusCommHandle.requestId);
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_TXE);
mbusCommHandle.state = MBCS_SENDING;
}
break;
case MBCS_SENDING:
// transition from here to MBCS_SENDING_DONE is done by TX ISR
break;
case MBCS_SENDING_DONE:
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SENDING_DONE", localMbusCommHandle->requestId);
localMbusCommHandle->state = MBCS_ENABLE_FRONTEND;
schAdd(handleRequestEngine, handle, 3, 0);
//coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state SENDING_DONE", mbusCommHandle.requestId);
delayAfterSendStartTime = HAL_GetTick();
mbusCommHandle.state = MBCS_WAIT_AFTER_SENDING;
break;
case MBCS_WAIT_AFTER_SENDING:
// Avoids switching on the frontend while there is still noise from sending on the loop
// Make sure to wait not too long otherwise the beginning of the response is missed
if ((delayAfterSendStartTime + DELAY_AFTER_SENDING) < HAL_GetTick()) {
mbusCommHandle.state = MBCS_ENABLE_FRONTEND;
}
break;
case MBCS_ENABLE_FRONTEND:
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state ENABLE_FRONTEND", localMbusCommHandle->requestId);
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state ENABLE_FRONTEND", mbusCommHandle.requestId);
frontendEnable();
schAdd(timeoutHandler, handle, 2500, 0);
calculatedChksum = 0;
userdataIdx = 0;
localMbusCommHandle->state = MBCS_START1;
receiveNext(localMbusCommHandle);
mbusCommHandle.receiveBuffer.readIdx = 0;
mbusCommHandle.receiveBuffer.writeIdx = 0;
mbusCommHandle.waitForOctet = true; // start receiver
mbusCommHandle.startTime = HAL_GetTick(); // start receiver timeout
mbusCommHandle.state = MBCS_START1;
break;
case MBCS_START1:
if (localMbusCommHandle->receivedOctet == 0x68) {
localMbusCommHandle->frame.start1 = localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_LENGTH1;
receiveNext(localMbusCommHandle);
if (receivedOctet == 0x68) {
mbusCommHandle.frame.start1 = receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_LENGTH1;
} else {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid start1 symbol %02x", localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__START1;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: invalid start1 symbol %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address,
receivedOctet);
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__START1;
mbusCommHandle.state = MBCS_ERROR;
}
break;
case MBCS_LENGTH1:
if (localMbusCommHandle->receivedOctet <= 3) {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: length to small %02x", localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__LENGTH1;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
if (receivedOctet <= 3) {
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: length to small %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address,
receivedOctet);
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__LENGTH1;
mbusCommHandle.state = MBCS_ERROR;
} else {
localMbusCommHandle->frame.length1 = localMbusCommHandle->receivedOctet;
localMbusCommHandle->frame.userdata = (uint8_t*) malloc(localMbusCommHandle->frame.length1 - 3);
if (! localMbusCommHandle->frame.userdata) {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: unable to allocate memory for userdata", localMbusCommHandle->requestId);
localMbusCommHandle->result = MBCR_ERROR_OUT_OF_MEMORY__USERDATA;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
mbusCommHandle.frame.length1 = receivedOctet;
mbusCommHandle.frame.userdata = (uint8_t*) malloc(mbusCommHandle.frame.length1 - 3);
if (! mbusCommHandle.frame.userdata) {
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: unable to allocate memory for userdata",
mbusCommHandle.requestId, mbusCommHandle.device->address);
mbusCommHandle.result = MBCR_ERROR_OUT_OF_MEMORY__USERDATA;
mbusCommHandle.state = MBCS_ERROR;
} else {
localMbusCommHandle->state = MBCS_LENGTH2;
receiveNext(localMbusCommHandle);
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_LENGTH2;
}
}
break;
case MBCS_LENGTH2:
if (localMbusCommHandle->frame.length1 != localMbusCommHandle->receivedOctet) {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid length2 %02x vs. %02x",
localMbusCommHandle->requestId, localMbusCommHandle->frame.length1, localMbusCommHandle->receivedOctet);
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__LENGTH2;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
if (mbusCommHandle.frame.length1 != receivedOctet) {
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: invalid length2 %02x vs. %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address,
mbusCommHandle.frame.length1, receivedOctet);
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__LENGTH2;
mbusCommHandle.state = MBCS_ERROR;
} else {
localMbusCommHandle->frame.length2 = localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_START2;
receiveNext(localMbusCommHandle);
mbusCommHandle.frame.length2 = receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_START2;
}
break;
case MBCS_START2:
if (localMbusCommHandle->receivedOctet == 0x68) {
localMbusCommHandle->frame.start2 = localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_C_FIELD;
receiveNext(localMbusCommHandle);
if (receivedOctet == 0x68) {
mbusCommHandle.frame.start2 = receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_C_FIELD;
} else {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid start2 symbol %02x",
localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__START2;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: invalid start2 symbol %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address, receivedOctet);
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__START2;
mbusCommHandle.state = MBCS_ERROR;
}
break;
case MBCS_C_FIELD:
localMbusCommHandle->frame.c = localMbusCommHandle->receivedOctet;
calculatedChksum += localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_A_FIELD;
receiveNext(localMbusCommHandle);
mbusCommHandle.frame.c = receivedOctet;
calculatedChksum += receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_A_FIELD;
break;
case MBCS_A_FIELD:
localMbusCommHandle->frame.a = localMbusCommHandle->receivedOctet;
calculatedChksum += localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_CI_FIELD;
receiveNext(localMbusCommHandle);
mbusCommHandle.frame.a = receivedOctet;
calculatedChksum += receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_CI_FIELD;
break;
case MBCS_CI_FIELD:
localMbusCommHandle->frame.ci = localMbusCommHandle->receivedOctet;
calculatedChksum += localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_USERDATA;
receiveNext(localMbusCommHandle);
mbusCommHandle.frame.ci = receivedOctet;
calculatedChksum += receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_USERDATA;
break;
case MBCS_USERDATA:
localMbusCommHandle->frame.userdata[userdataIdx] = localMbusCommHandle->receivedOctet;
calculatedChksum += localMbusCommHandle->receivedOctet;
mbusCommHandle.frame.userdata[userdataIdx] = receivedOctet;
calculatedChksum += receivedOctet;
userdataIdx++;
if (userdataIdx == (localMbusCommHandle->frame.length1 - 3)) {
localMbusCommHandle->state = MBCS_CHKSUM;
mbusCommHandle.waitForOctet = true;
if (userdataIdx == (mbusCommHandle.frame.length1 - 3)) {
mbusCommHandle.state = MBCS_CHKSUM;
}
receiveNext(localMbusCommHandle);
break;
case MBCS_CHKSUM:
if (localMbusCommHandle->receivedOctet != calculatedChksum) {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid checksum %02x vs %02x",
localMbusCommHandle->requestId, calculatedChksum, localMbusCommHandle->receivedOctet);
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
if (receivedOctet != calculatedChksum) {
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: invalid checksum %02x vs %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address,
calculatedChksum, receivedOctet);
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM;
mbusCommHandle.state = MBCS_ERROR;
} else {
localMbusCommHandle->frame.chksum = localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_STOP;
receiveNext(localMbusCommHandle);
mbusCommHandle.frame.chksum = receivedOctet;
mbusCommHandle.waitForOctet = true;
mbusCommHandle.state = MBCS_STOP;
}
break;
case MBCS_STOP:
if (localMbusCommHandle->receivedOctet == 0x16) {
localMbusCommHandle->frame.stop = localMbusCommHandle->receivedOctet;
localMbusCommHandle->state = MBCS_DONE;
schAdd(handleRequestEngine, handle, 0, 0);
if (receivedOctet == 0x16) {
mbusCommHandle.frame.stop = receivedOctet;
mbusCommHandle.state = MBCS_DONE;
} else {
coloredMsg(LOG_RED, true, "mbc hre [%d] err: invalid stop symbol %02x",
localMbusCommHandle->requestId, localMbusCommHandle->receivedOctet);
localMbusCommHandle->result = MBCR_ERROR_STATE_ENGINE__STOP;
localMbusCommHandle->state = MBCS_ERROR;
schAdd(handleRequestEngine, handle, 0, 0);
coloredMsg(LOG_RED, true, "mbc hre [%d %d] err: invalid stop symbol %02x",
mbusCommHandle.requestId, mbusCommHandle.device->address, receivedOctet);
mbusCommHandle.result = MBCR_ERROR_STATE_ENGINE__STOP;
mbusCommHandle.state = MBCS_ERROR;
}
break;
case MBCS_DONE:
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DONE", localMbusCommHandle->requestId);
parseAndPrintFrame(localMbusCommHandle);
if (localMbusCommHandle->frame.userdata != NULL) {
free(localMbusCommHandle->frame.userdata);
localMbusCommHandle->frame.userdata = NULL;
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DONE", mbusCommHandle.requestId);
parseAndPrintFrame();
if (mbusCommHandle.frame.userdata != NULL) {
free(mbusCommHandle.frame.userdata);
mbusCommHandle.frame.userdata = NULL;
}
localMbusCommHandle->result = MBCR_SUCCESS;
localMbusCommHandle->state = MBCS_DISABLE_FRONTEND;
schDel(timeoutHandler, handle);
schAdd(handleRequestEngine, handle, 0, 0);
mbusCommHandle.result = MBCR_SUCCESS;
mbusCommHandle.state = MBCS_DISABLE_FRONTEND;
break;
case MBCS_ERROR:
coloredMsg(LOG_RED, false, "mbc hre [%d] state ERROR", localMbusCommHandle->requestId);
// coloredMsg(LOG_RED, false, "mbc hre [%d] state ERROR", mbusCommHandle.requestId);
coloredMsg(LOG_RED, true, "mbc hre [%d %d] error", mbusCommHandle.requestId, mbusCommHandle.device->address);
show(LED_RED, ON);
localMbusCommHandle->state = MBCS_ERROR_CONTINUED;
// disable frontend immediately in case of error since no more data in relevant
// this avoids strange noise on RX line/led
frontendDisable();
mbusCommHandle.state = MBCS_ERROR_CONTINUED;
// no break
case MBCS_ERROR_CONTINUED:
receiveNext(localMbusCommHandle);
// every error will be collected by a timeout to receive all data still on the wire
// to avoid leaking old data in responses for new requests
break;
case MBCS_TIMEOUT:
coloredMsg(LOG_RED, false, "mbc hre [%d] state TIMEOUT", localMbusCommHandle->requestId);
mbusCommStats.errorCnt += 1;
localMbusCommHandle->device->failures += 1;
printError(localMbusCommHandle);
localMbusCommHandle->receiving = false;
if (localMbusCommHandle->frame.userdata != NULL) {
free(localMbusCommHandle->frame.userdata);
localMbusCommHandle->frame.userdata = NULL;
// coloredMsg(LOG_RED, false, "mbc hre [%d] state TIMEOUT", mbusCommHandle.requestId);
coloredMsg(LOG_RED, true, "mbc hre [%d %d] timeout", mbusCommHandle.requestId, mbusCommHandle.device->address);
mbusCommStats.mbusErrorCnt += 1;
mbusCommHandle.device->failures += 1;
mbusCommHandle.startTime = 0; // disable timeout
mbusCommHandle.waitForOctet = false; // disable receiver
printError();
if (mbusCommHandle.frame.userdata != NULL) {
free(mbusCommHandle.frame.userdata);
mbusCommHandle.frame.userdata = NULL;
}
HAL_UART_AbortReceive(&mbusUart);
uint8_t kitchenSink[16];
memset(kitchenSink, 0, 16);
HAL_StatusTypeDef r = HAL_UART_Receive(&mbusUart, kitchenSink, 16, 100);
coloredMsg(LOG_RED, false, "mbc hre [%d] abort, last receive result: %02x", localMbusCommHandle->requestId, r);
// no break
case MBCS_DISABLE_FRONTEND:
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DISABLE_FRONTEND", localMbusCommHandle->requestId);
// coloredMsg(LOG_YELLOW, false, "mbc hre [%d] state DISABLE_FRONTEND", mbusCommHandle.requestId);
frontendDisable();
localMbusCommHandle->state = MBCS_IDLE;
mbusCommHandle.startTime = 0; // disable timeout
mbusCommHandle.state = MBCS_IDLE;
break;
default:
localMbusCommHandle->state = MBCS_IDLE;
mbusCommHandle.state = MBCS_IDLE;
break;
}
}
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart) {
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
}
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart) {
if (mbusCommHandle.receiving) {
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
mbusCommHandle.receiving = false;
}
}
void mbusCommEnable(bool enable) {
mbusCommEnabled = enable;
}
@ -514,19 +608,14 @@ static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
mbusCommHandle.device = mbusDevice;
mbusDevice->requests += 1;
coloredMsg(LOG_YELLOW, true, "mbc mcr [%d] new request %s R:%d F:%d GRC:%d GEC:%d",
coloredMsg(LOG_YELLOW, false, "mbc mcr [%d] new request %s (%d)",
mbusCommHandle.requestId,
mbusDevice->deviceName,
mbusDevice->requests,
mbusDevice->failures,
mbusCommStats.requestCnt,
mbusCommStats.errorCnt);
mbusDevice->deviceName, mbusDevice->address);
oledPrint(OLED_SCREEN0, mbusDevice->deviceName);
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
res = MBCRR_TRIGGERED;
mbusCommStats.requestCnt += 1;
mbusCommStats.mbusRequestCnt += 1;
}
} else {
res = MBCRR_DISABLED;
@ -536,89 +625,120 @@ static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
}
static uint8_t numOfDevices = 8;
#define PERIOD 10
static uint8_t numOfDevices = 0;
static t_mbusDevice *devices = NULL;
void mbusCommAddDevice(t_deviceBlock *deviceBlock) {
devices = (t_mbusDevice*) realloc((void*) devices, (numOfDevices + 1) * sizeof(t_mbusDevice));
strcpy(devices[numOfDevices].deviceName, deviceBlock->deviceName);
devices[numOfDevices].address = deviceBlock->address;
memcpy(devices[numOfDevices].consideredField, deviceBlock->consideredField, sizeof(deviceBlock->consideredField));
devices[numOfDevices].period = deviceBlock->period;
devices[numOfDevices].requests = 0;
devices[numOfDevices].failures = 0;
devices[numOfDevices].delay = 0;
devices[numOfDevices].waiting = false;
devices[numOfDevices].active = true;
coloredMsg(LOG_YELLOW, false, "mbc mbcad device added %d %s %d", numOfDevices, devices[numOfDevices].deviceName, devices[numOfDevices].address);
numOfDevices += 1;
}
/*
static t_mbusDevice devices[] = {
{
.deviceName = "TotalPower",
.deviceName = "Total",
.address = 80,
.consideredField = { 0, 17, -1, -1 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "ComputerPower",
.deviceName = "Computer",
.address = 85,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "DryerPower",
.deviceName = "Dryer",
.address = 81,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "LaundryPower",
.deviceName = "Laundry",
.address = 82,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "DishwasherPower",
.deviceName = "Dishwasher",
.address = 83,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "LightPower",
.deviceName = "Light",
.address = 84,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 15,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "FreezerPower",
.deviceName = "Freezer",
.address = 86,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
},
{
.deviceName = "FridgePower",
.deviceName = "Fridge",
.address = 87,
.consideredField = { 0, 4, 2, 3 },
.requests = 0,
.failures = 0,
.period = 60,
.period = PERIOD,
.delay = 0,
.waiting = false
.waiting = false,
.active = true
}
};
*/
static void triggerMBusRequest(void *handle) {
@ -673,18 +793,52 @@ static void mbusCommScheduler(void *handle) {
state = 1;
}
for (uint8_t i = 0; i < numOfDevices; i++) {
devices[i].delay -= 1;
if (devices[i].delay <= 0) {
devices[i].delay = devices[i].period;
devices[i].waiting = true;
coloredMsg(LOG_YELLOW, false, "mbc mcs scheduled: %s", devices[i].deviceName);
if (devices[i].active) {
devices[i].delay -= 1;
if (devices[i].delay <= 0) {
devices[i].delay = devices[i].period;
devices[i].waiting = true;
coloredMsg(LOG_YELLOW, false, "mbc mcs scheduled: %s", devices[i].deviceName);
}
}
}
// FIXME
// state = 3;
break;
case 3:
coloredMsg(LOG_YELLOW, false, "mbc mcs waiting for godot");
state = 4;
// no break
case 4:
break;
}
}
void mbusCommInit() {
config = getConfig();
coloredMsg(LOG_GREEN, true, "mbc mci initializing Meterbus communication");
// enable receive interrupts
// __HAL_UART_ENABLE_IT(&mbusUart, UART_IT_PE);
// __HAL_UART_ENABLE_IT(&mbusUart, UART_IT_ERR);
__HAL_UART_ENABLE_IT(&mbusUart, UART_IT_RXNE);
// init buffers
mbusCommHandle.receiveBuffer.size = 256;
mbusCommHandle.receiveBuffer.buffer = (uint8_t*) malloc(mbusCommHandle.receiveBuffer.size);
mbusCommHandle.receiveBuffer.readIdx = 0;
mbusCommHandle.receiveBuffer.writeIdx = 0;
mbusCommHandle.sendBuffer.size = 8;
mbusCommHandle.sendBuffer.buffer = (uint8_t*) malloc(mbusCommHandle.sendBuffer.size);
mbusCommHandle.sendBuffer.readIdx = 0;
mbusCommHandle.sendBuffer.writeIdx = 0;
// FIXME
schAdd(mbusCommScheduler, NULL, 0, 1000);
}

View File

@ -12,12 +12,14 @@ static const char NAME_VOLTAGE[] = "Voltage";
static const char NAME_CURRENT[] = "Current";
static const char NAME_POWER[] = "Power";
static const char NAME_ENERGY[] = "Energy";
static const char NAME_VOLUME[] = "Volume";
static const char NAME_UNKNOWN[] = "unknown";
static const char UNIT_VOLT[] = "V";
static const char UNIT_AMPERE[] = "A";
static const char UNIT_WATT[] = "W";
static const char UNIT_WATTHOUR[] = "Wh";
static const char UNIT_QUBICMETER[] = "m3";
static const char UNIT_UNKNOWN[] = "?";
static parsedVIB_t parseVIB_FB(mbus_value_information_block vib) {
@ -61,6 +63,11 @@ static parsedVIB_t parseVIB_default(mbus_value_information_block vib) {
parsedVIB.unit = UNIT_WATT;
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
parsedVIB.found = true;
} else if ((vib.vif & 0b01111000) == 0b00010000) {
parsedVIB.name = NAME_VOLUME;
parsedVIB.unit = UNIT_QUBICMETER;
parsedVIB.exponent = (vib.vif & 0b0111) - 3;
parsedVIB.found = true;
} else {
coloredMsg(LOG_RED, true, "mpe pvd unknown vif 0x%02x", vib.vif);
}

View File

@ -1,6 +1,7 @@
#include <mqttComm.h>
#include <logger.h>
#include <main.h>
#include <iwdg.h>
#include <pubsubc.h>
#include <platformAdaption.h>
@ -9,6 +10,7 @@
#include <mbusComm.h>
#include <oled.h>
#include <eeprom.h>
#include <config.h>
#include <stdint.h>
#include <stdlib.h>
@ -19,17 +21,14 @@
extern const uint8_t MQTT_SOCK;
static t_configBlock *config;
client_t client;
mqttClient_t mqttClient;
uint8_t brokerAddress[] = { 172, 16, 2, 16 };
uint8_t brokerAddress[4];
uint16_t brokerPort = 1883;
const static char WatchdogTopic[] = "IoT/Watchdog";
const static char StartupTopic[] = "IoT/MBGW3/Startup";
const static char StatusTopic[] = "IoT/MBGW3/Status";
static uint32_t watchdogCounter = 0;
void watchdogHandler(void *handle) {
@ -39,12 +38,15 @@ void watchdogHandler(void *handle) {
} else {
coloredMsg(LOG_RED, true, "No watchdog received in between, booting the system ...");
// boot the system
HAL_NVIC_SystemReset();
}
}
// typedef void (*callback_t)(char*, uint8_t*, uint16_t);
static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength) {
if (0 == strcmp(topic, WatchdogTopic)) {
if (0 == strcmp(topic, config->watchdogTopic)) {
HAL_IWDG_Refresh(&hiwdg);
watchdogCounter++;
} else {
coloredMsg(LOG_GREEN, false, "mqcb: %s : %.*s", topic, payloadLength, payload);
@ -56,11 +58,12 @@ static void mqttStatusPublisher(void *handle) {
t_mbusCommStats *mbusCommStats = mbusCommGetStats();
t_deviceStats* globalDeviceStats = getGlobalDeviceStats();
char buf[128];
char buf[256];
uint32_t uptime = HAL_GetTick() / 1000;
snprintf(buf, sizeof(buf), "{\"uptime\":\"%ld\", \"runningHours\":\"%ld\", \"powerCycles\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\"}",
uptime, globalDeviceStats->totalRunningHours, globalDeviceStats->totalPowercycles, schTaskCnt(), mbusCommStats->requestCnt, mbusCommStats->errorCnt);
bool res = publish(&mqttClient, StatusTopic, (const uint8_t*)buf, strlen(buf), false);
snprintf(buf, sizeof(buf), "{\"uptime\":\"%ld\", \"runningHours\":\"%ld\", \"powerCycles\":\"%ld\", \"tasks\":\"%d\", \"requests\":\"%ld\", \"errors\":\"%ld\", \"octets\":\"%ld\", \"overrun\":\"%ld\", \"framing\":\"%ld\", \"parity\":\"%ld\", \"noise\":\"%ld\"}",
uptime, globalDeviceStats->totalRunningHours, globalDeviceStats->totalPowercycles, schTaskCnt(), mbusCommStats->mbusRequestCnt, mbusCommStats->mbusErrorCnt,
mbusCommStats->uartOctetCnt, mbusCommStats->uartOverrunCnt, mbusCommStats->uartFramingErrCnt, mbusCommStats->uartParityErrCnt, mbusCommStats->uartNoiseErrCnt);
bool res = publish(&mqttClient, config->statusTopic, (const uint8_t*)buf, strlen(buf), false);
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
oledSetActiveScreen(OLED_SCREEN1);
@ -69,11 +72,10 @@ static void mqttStatusPublisher(void *handle) {
oledPrintf(OLED_SCREEN1, "Addr:%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
oledPrintf(OLED_SCREEN1, "Network available:%d", isNetworkAvailable());
oledPrintf(OLED_SCREEN1, "Uptime:%ld", uptime);
oledPrintf(OLED_SCREEN1, "RunHours:%d", globalDeviceStats->totalRunningHours);
oledPrintf(OLED_SCREEN1, "PowerCycl:%d", globalDeviceStats->totalPowercycles);
oledPrintf(OLED_SCREEN1, "Req:%ld", mbusCommStats->requestCnt);
oledPrintf(OLED_SCREEN1, "Err:%ld", mbusCommStats->errorCnt);
oledPrintf(OLED_SCREEN1, "Req:%ld", mbusCommStats->mbusRequestCnt);
oledPrintf(OLED_SCREEN1, "Err:%ld", mbusCommStats->mbusErrorCnt);
oledPrintf(OLED_SCREEN1, "Uart:%d", mbusCommStats->uartOverrunCnt + mbusCommStats->uartFramingErrCnt + mbusCommStats->uartParityErrCnt + mbusCommStats->uartNoiseErrCnt);
}
void mqttCommHandler(void *handle) {
@ -92,6 +94,11 @@ void mqttCommHandler(void *handle) {
break;
case 1:
coloredMsg(LOG_GREEN, false, "mqch, resolving broker name");
if (! wizDnsQuery(config->brokerName, brokerAddress)) {
coloredMsg(LOG_GREEN, false, "mqch, query for broker address failed, going to error state");
state = 255;
}
coloredMsg(LOG_GREEN, false, "mqch, connecting to broker ");
bool res = mqttConnect(&mqttClient, brokerAddress, 1883, "mbv3gw-client", NULL, NULL, NULL, 0, false, NULL, false);
coloredMsg(LOG_GREEN, false, "mqch, mqttConnect returns %d", res);
@ -106,7 +113,7 @@ void mqttCommHandler(void *handle) {
case 2:
coloredMsg(LOG_GREEN, false, "mqch, publish start-up");
res = publish(&mqttClient, StartupTopic, (const uint8_t*)message, strlen((char*)message), false);
res = publish(&mqttClient, config->startupTopic, (const uint8_t*)message, strlen((char*)message), false);
coloredMsg(LOG_GREEN, false, "mqch, publish returned %d", res);
schAdd(mqttStatusPublisher, NULL, 0, 60000);
coloredMsg(LOG_GREEN, false, "mqch, status publisher scheduled");
@ -115,9 +122,9 @@ void mqttCommHandler(void *handle) {
case 3:
coloredMsg(LOG_GREEN, false, "mqch, subscribe watchdog");
res = subscribe(&mqttClient, WatchdogTopic, MQTTQOS0);
res = subscribe(&mqttClient, config->watchdogTopic, MQTTQOS0);
coloredMsg(LOG_GREEN, false, "mqch, subscribe returned %d", res);
schAdd(watchdogHandler, NULL, 60000, 60000);
schAdd(watchdogHandler, NULL, 15000, 15000);
coloredMsg(LOG_GREEN, false, "mqch, watchdogHandler scheduled");
state = 4;
break;
@ -145,6 +152,7 @@ void mqttCommHandler(void *handle) {
}
void mqttCommInit() {
config = getConfig();
schAdd(mqttCommHandler, NULL, 0, 100);
}

View File

@ -8,3 +8,4 @@ const uint8_t DHCP_SOCK = 0;
const uint8_t MQTT_SOCK = 1;
const uint8_t CMD_SOCK = 2;
const uint8_t SYSLOG_SOCK = 3;
const uint8_t DNS_SOCK = 4;

View File

@ -0,0 +1,57 @@
#include <cmdHelper.h>
#include <logger.h>
#include <mbusComm.h>
#include <eeprom.h>
static bool globalStatsCmd(uint8_t argc, char **args) {
uint32_t uptime = HAL_GetTick() / 1000;
sendFormatString(\
"Current uptime: %ld\n\r" \
"\n\r",
uptime
);
t_deviceStats *deviceStats = getGlobalDeviceStats();
sendFormatString(\
"Global Device statistics\n\r" \
" Total running hours: %ld\n\r" \
" Total power cycles: %ld\n\r" \
" Total requests: %ld\n\r" \
" Total failures: %ld\n\r" \
"\n\r",
deviceStats->totalRunningHours, deviceStats->totalPowercycles,
deviceStats->totalRequests, deviceStats->totalFailures
);
t_mbusCommStats *mbusStats = mbusCommGetStats();
sendFormatString(\
"Global Meterbus/UART statistics\n\r" \
" Meterbus Requests: %ld\n\r" \
" Meterbus Errors: %ld\n\r" \
" UART Octets: %ld\n\r" \
" UART Overruns: %ld\n\r" \
" UART Framing Errs: %ld\n\r" \
" UART Parity Errs: %ld\n\r" \
" UART Noise Errs: %ld\n\r",
mbusStats->mbusRequestCnt, mbusStats->mbusErrorCnt,
mbusStats->uartOctetCnt, mbusStats->uartOverrunCnt, mbusStats->uartFramingErrCnt, mbusStats->uartParityErrCnt, mbusStats->uartNoiseErrCnt
);
return true;
}
const cmd_t COMMANDS[] = {
{ .name = "globalStats", .cmdFunc = globalStatsCmd,
.help = \
"globalStats .......................... Show the global statistics\n\r" \
" counters requestCnt and errorCnt\n\r"
},
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
};
const cmd_t *getRegularCommands() {
return COMMANDS;
}

View File

@ -19,6 +19,7 @@ void ringbufferFree(ringbuffer_t *handle) {
handle->bufferWriteIdx = 0;
}
int ringbufferPut(ringbuffer_t *handle, uint8_t *data, uint32_t dataLen) {
uint32_t freeSpace = 0;
if (handle->bufferReadIdx == handle->bufferWriteIdx) {
@ -61,7 +62,7 @@ uint8_t *ringbufferGet(ringbuffer_t *handle, uint32_t dataLen) {
int ringbufferGetOne(ringbuffer_t *handle) {
int res = -1;
if (! ringbufferEmpty(handle)) {
if (handle->bufferReadIdx != handle->bufferWriteIdx) {
uint8_t r = *(handle->buffer + handle->bufferReadIdx);
handle->bufferReadIdx += 1;
if (handle->bufferReadIdx == handle->bufferSize) {

View File

@ -11,16 +11,23 @@
#include <dhcp.h>
#include <show.h>
#include <oled.h>
#include <dns.h>
#include <config.h>
wiz_NetInfo netInfo = {
.mac = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
.dhcp = NETINFO_DHCP
};
static t_configBlock *config;
wiz_NetInfo netInfo;
#define DHCP_BUFFER_SIZE 2048
static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE];
#define DNS_BUFFER_SIZE MAX_DNS_BUF_SIZE
static uint8_t dnsBuffer[DNS_BUFFER_SIZE];
extern const uint8_t DHCP_SOCK;
extern const uint8_t DNS_SOCK;
static bool networkAvailable = false;
@ -109,7 +116,22 @@ static void wizDHCPHandler(void *handle) {
}
}
bool wizDnsQuery(char *name, uint8_t *ip) {
bool retCode = false;
coloredMsg(LOG_BLUE, false, "wizdq, querying for %s", name);
int8_t res = DNS_run(netInfo.dns, (uint8_t*) name, ip);
coloredMsg(LOG_BLUE, false, "wizdq, DNS_run returns %d", res);
retCode = (res == 1);
if (retCode) {
coloredMsg(LOG_BLUE, false, "wizdq, got address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
}
return retCode;
}
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;
@ -153,7 +175,12 @@ static void wizPhyLinkHandler(void *handle) {
}
}
int wizInit() {
config = getConfig();
netInfo.dhcp = NETINFO_DHCP;
memcpy(netInfo.mac, config->macAddress, 6);
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
wizReset(true);
activeDelay(2);
@ -196,6 +223,7 @@ int wizInit() {
res = ctlwizchip(CW_GET_ID, (void*) buf);
coloredMsg(LOG_BLUE, false, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
DNS_init(DNS_SOCK, dnsBuffer);
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");

View File

@ -9,18 +9,21 @@ ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_71CYCLES_5
ADC1.master=1
File.Version=6
GPIO.groupedBy=Group By Peripherals
IWDG.IPParameters=Prescaler
IWDG.Prescaler=IWDG_PRESCALER_256
KeepUserPlacement=false
Mcu.Family=STM32F1
Mcu.IP0=ADC1
Mcu.IP1=NVIC
Mcu.IP2=RCC
Mcu.IP3=SPI1
Mcu.IP4=SPI2
Mcu.IP5=SPI3
Mcu.IP6=SYS
Mcu.IP7=UART4
Mcu.IP8=UART5
Mcu.IPNb=9
Mcu.IP1=IWDG
Mcu.IP2=NVIC
Mcu.IP3=RCC
Mcu.IP4=SPI1
Mcu.IP5=SPI2
Mcu.IP6=SPI3
Mcu.IP7=SYS
Mcu.IP8=UART4
Mcu.IP9=UART5
Mcu.IPNb=10
Mcu.Name=STM32F103V(C-D-E)Tx
Mcu.Package=LQFP100
Mcu.Pin0=PE2
@ -50,14 +53,15 @@ Mcu.Pin3=PE5
Mcu.Pin30=PB5
Mcu.Pin31=PB6
Mcu.Pin32=PB7
Mcu.Pin33=VP_SYS_VS_Systick
Mcu.Pin33=VP_IWDG_VS_IWDG
Mcu.Pin34=VP_SYS_VS_Systick
Mcu.Pin4=PE6
Mcu.Pin5=OSC_IN
Mcu.Pin6=OSC_OUT
Mcu.Pin7=PA1
Mcu.Pin8=PA2
Mcu.Pin9=PA3
Mcu.PinsNb=34
Mcu.PinsNb=35
Mcu.ThirdPartyNb=0
Mcu.UserConstants=debugUart,huart4;mbusUart,huart5;frontendAdc,hadc1;eepromSpi,hspi2;etherSpi,hspi1;displaySpi,hspi3;debugUartIRQn,UART4_IRQn
Mcu.UserName=STM32F103VCTx
@ -232,7 +236,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_UART5_Init-UART5-false-HAL-true,8-MX_SPI1_Init-SPI1-false-HAL-true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_UART5_Init-UART5-false-HAL-true,8-MX_SPI1_Init-SPI1-false-HAL-true,9-MX_IWDG_Init-IWDG-false-HAL-true
RCC.ADCFreqValue=4500000
RCC.ADCPresc=RCC_ADCPCLK2_DIV8
RCC.AHBFreq_Value=72000000
@ -292,6 +296,8 @@ UART5.IPParameters=VirtualMode,BaudRate,Parity,WordLength
UART5.Parity=PARITY_EVEN
UART5.VirtualMode=Asynchronous
UART5.WordLength=WORDLENGTH_9B
VP_IWDG_VS_IWDG.Mode=IWDG_Activate
VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom

48
devices.txt Normal file
View File

@ -0,0 +1,48 @@
Index: 0
Name: Total, Address: 80, Period: 10
Considered field: 0
Considered field: 17
Considered field: -1
Considered field: -1
Index: 1
Name: Computer, Address: 85, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3
Index: 2
Name: Dryer, Address: 81, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3
Index: 3
Name: Laundry, Address: 82, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3
Index: 4
Name: Dishwasher, Address: 83, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3
Index: 5
Name: Light, Address: 84, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3
Index: 6
Name: Freezer, Address: 86, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3
Index: 7
Name: Fridge, Address: 87, Period: 10
Considered field: 0
Considered field: 4
Considered field: 2
Considered field: 3

23
error1.txt Normal file
View File

@ -0,0 +1,23 @@
mbc papf [55591 83] sts: Specific to manufacturer Error 1
mbc papf [55591] Energy is 4412980.0 Wh (441298 * 10^1)
mbc papf [55591] Voltage is 227.0 V (227 * 10^0)
mbc papf [55591] Current is 0.2 A (2 * 10^-1)
mbc papf [55591] Power is 110.0 W (11 * 10^1)
mbc papf [55591] Error ratio is 0.00
mqp: {"Status":"Ok", "RequestId":"55591", "Device":"Dishwasher", "Errors":"3", d
mbc mcr [55592] new request Light (84)
mbc papf [55592] Energy is 4374680.0 Wh (437468 * 10^1)
mbc papf [55592] Voltage is 224.0 V (224 * 10^0)
mbc papf [55592] Current is 0.6 A (6 * 10^-1)
mbc papf [55592] Power is 120.0 W (12 * 10^1)
mbc papf [55592] Error ratio is 0.00
mqp: {"Status":"Ok", "RequestId":"55592", "Device":"Light", "Errors":"2", "Requd
mqsp: publishing status
mqch, publish returned 1
Watchdog received in between
clientStop: disconnect returns 0xfffffffb, invalid response, ignore it
ch che socket state is 0x00
mqch, initializing mqtt client
mqch: mqtt c
CTRL-A Z for help | 115200 8N1 | NOR | Minicom 2.7.1 | VT102 | Offline | tyUSB0

17
offsetTest/Makefile Normal file
View File

@ -0,0 +1,17 @@
CFLAGS=
test: test.o
gcc -o $@ $^
test.o: test.c
gcc -c -o $@ $(CFLAGS) $^
.PHONY: run
run: test
./test
.PHONY: clean
clean:
rm -f *.o test

55
offsetTest/test.c Normal file
View File

@ -0,0 +1,55 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stddef.h>
typedef struct {
uint8_t id;
char a[16];
uint8_t length;
uint32_t x;
} t_testObj;
t_testObj testObj = { .id = 0, .a = "test123", .length = 25, .x = 123456 };
void printTestObj(t_testObj *testObj) {
printf("testObj: id=%d, a=%s, length=%d, x=%d\n", testObj->id, testObj->a, testObj->length, testObj->x);
}
int main() {
printf("id: %ld\n", offsetof(t_testObj, id));
printf("a: %ld\n", offsetof(t_testObj, a));
printf("length: %ld\n", offsetof(t_testObj, length));
printf("x: %ld\n", offsetof(t_testObj, x));
printTestObj(&testObj);
strcpy(testObj.a, "demo234");
printTestObj(&testObj);
uint8_t *a1 = (uint8_t*)&testObj;
printf("a1: %p\n", a1);
uint8_t *a2 = ((uint8_t*)&testObj) + offsetof(t_testObj, length);
printf("a2: %p\n", a2);
*a2 = 35;
printTestObj(&testObj);
uint8_t *a3 = ((uint8_t*)&testObj) + offsetof(t_testObj, a);
printf("a3: %p\n", a3);
strcpy((char*)a3, "Wolfgang");
printTestObj(&testObj);
uint32_t *a4 = (uint32_t*) (((uint8_t*)&testObj) + offsetof(t_testObj, x));
printf("a4: %p\n", a4);
*a4 = 1234567890;
printTestObj(&testObj);
}

View File

@ -1,6 +1,6 @@
CFLAGS=-I../cube/User/Inc -DTEST
test: ringbuffer.o logger.o test.o
test: ringbuffer.o test.o
gcc -o $@ -lcunit $^
ringbuffer.o: ../cube/User/Src/ringbuffer.c

View File

@ -2,7 +2,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <ringbuffer.h>
#include <logger.h>
//#include <logger.h>
// #define DEBUG
@ -10,6 +10,7 @@
ringbuffer_t rb;
void printRingbuffer(ringbuffer_t *rb) {
printf("Ringbuffer:\n");
printf(" Size: %u\n", rb->bufferSize);
@ -817,8 +818,75 @@ void testRingbuffer99() {
}
void testRingbuffer100() {
#ifdef DEBUG
printf("Initialize ringbuffer\n");
#endif
ringbufferInit(&rb, 16);
#ifdef DEBUG
printRingbuffer(&rb);
#endif
CU_ASSERT(rb.buffer != NULL);
CU_ASSERT(rb.bufferSize == 16);
CU_ASSERT(rb.bufferWriteIdx == 0);
CU_ASSERT(rb.bufferReadIdx == 0);
CU_ASSERT(rb.buffer[0] == 0);
CU_ASSERT(rb.buffer[1] == 0);
CU_ASSERT(rb.buffer[2] == 0);
CU_ASSERT(rb.buffer[3] == 0);
CU_ASSERT(rb.buffer[4] == 0);
CU_ASSERT(rb.buffer[5] == 0);
CU_ASSERT(rb.buffer[6] == 0);
CU_ASSERT(rb.buffer[7] == 0);
CU_ASSERT(rb.buffer[8] == 0);
CU_ASSERT(rb.buffer[9] == 0);
CU_ASSERT(rb.buffer[10] == 0);
CU_ASSERT(rb.buffer[11] == 0);
CU_ASSERT(rb.buffer[12] == 0);
CU_ASSERT(rb.buffer[13] == 0);
CU_ASSERT(rb.buffer[14] == 0);
CU_ASSERT(rb.buffer[15] == 0);
}
void testRingbuffer101() {
#ifdef DEBUG
printf("\nPut 1 chars in buffer\n");
#endif
int r = ringbufferPutOne(&rb, 'a');
#ifdef DEBUG
printf("r = %d\n", r);
printRingbuffer(&rb);
#endif
CU_ASSERT(r == 0);
CU_ASSERT(rb.buffer != NULL);
CU_ASSERT(rb.bufferSize == 16);
CU_ASSERT(rb.bufferWriteIdx == 1);
CU_ASSERT(rb.bufferReadIdx == 0);
CU_ASSERT(rb.buffer[0] == 'a');
CU_ASSERT(rb.buffer[1] == 0);
CU_ASSERT(rb.buffer[2] == 0);
CU_ASSERT(rb.buffer[3] == 0);
CU_ASSERT(rb.buffer[4] == 0);
CU_ASSERT(rb.buffer[5] == 0);
CU_ASSERT(rb.buffer[6] == 0);
CU_ASSERT(rb.buffer[7] == 0);
CU_ASSERT(rb.buffer[8] == 0);
CU_ASSERT(rb.buffer[9] == 0);
CU_ASSERT(rb.buffer[10] == 0);
CU_ASSERT(rb.buffer[11] == 0);
CU_ASSERT(rb.buffer[12] == 0);
CU_ASSERT(rb.buffer[13] == 0);
CU_ASSERT(rb.buffer[14] == 0);
CU_ASSERT(rb.buffer[15] == 0);
}
/*
int init_suite_logger(void) {
logInit();
return 0;
@ -949,7 +1017,7 @@ void testLogger2() {
CU_ASSERT(strcmp(goldValueFullNotOk, buffer) != 0);
CU_ASSERT(strcmp(goldValueFullOk, buffer) == 0);
}
*/
int main() {
@ -980,11 +1048,14 @@ int main() {
(NULL == CU_add_test(ringbufferSuite, "test 14 of ringbuffer", testRingbuffer15)) ||
(NULL == CU_add_test(ringbufferSuite, "test 14 of ringbuffer", testRingbuffer16)) ||
(NULL == CU_add_test(ringbufferSuite, "test 99 of ringbuffer, free", testRingbuffer99)) ||
(NULL == CU_add_test(ringbufferSuite, "test 100 of ringbuffer, free", testRingbuffer100)) ||
(NULL == CU_add_test(ringbufferSuite, "test 101 of ringbuffer, free", testRingbuffer101)) ||
0 ) {
CU_cleanup_registry();
return CU_get_error();
}
/*
CU_pSuite loggerSuite = CU_add_suite("Suite_Logger", init_suite_logger, clean_suite_logger);
if (NULL == loggerSuite) {
CU_cleanup_registry();
@ -999,7 +1070,7 @@ int main() {
CU_cleanup_registry();
return CU_get_error();
}
*/
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();

View File

@ -47,8 +47,12 @@ cat $MAIN_C_BAK | \
cp $IT_C $IT_C_BAK
echo "// $PROCESSED" > $IT_C
cat $IT_C_BAK | \
sed -e 's,\(/\* USER CODE BEGIN Includes \*/\),\1\n#include "main2.h"\n,' | \
sed -e 's,\(/\* USER CODE BEGIN SysTick_IRQn 1 \*/\),\1\n SYSTICK_Callback();\n,' >> $IT_C
sed -e 's,\(/\* USER CODE BEGIN Includes \*/\),\1\n#include "main2.h"\n,' \
-e 's,\(/\* USER CODE BEGIN PFP \*/\),\1\nvoid mbusCommISR();\n,' \
-e 's,\(/\* USER CODE BEGIN SysTick_IRQn 1 \*/\),\1\n SYSTICK_Callback();\n,' \
-e 's,\(HAL_UART_IRQHandler(&huart5);\),// \1,' \
-e 's,\(/\* USER CODE BEGIN UART5_IRQn 1 \*/\),\1\n mbusCommISR();\n,' \
>> $IT_C
# mkdir w5500
# pushd ioLibrary_Driver
@ -81,6 +85,7 @@ cat $MAKEFILE_BAK | \
sed -e 's,\(C_SOURCES = \\\),\1\n'"$SRC_EXT"' \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Ethernet \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DHCP \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-IioLibrary_Driver/Internet/DNS \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-IUser/Inc \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ilibmbus \\,' | \
sed -e 's,\(C_INCLUDES = \\\),\1\n-Ipubsubc/src \\,' | \