From b455848ee62b06ba73801cff477c6ff214c4053e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 11 Oct 2022 19:16:26 +0200 Subject: stm32 esp code merged --- stm32f091/esp/Inc/main.h | 68 ----- stm32f091/esp/Inc/stm32f0xx_hal_conf.h | 322 --------------------- stm32f091/esp/Inc/stm32f0xx_it.h | 63 ---- stm32f091/esp/Src/main.c | 510 --------------------------------- stm32f091/esp/Src/stm32f0xx_hal_msp.c | 193 ------------- stm32f091/esp/Src/stm32f0xx_it.c | 159 ---------- stm32f091/esp/Src/syscalls.c | 155 ---------- stm32f091/esp/Src/sysmem.c | 79 ----- stm32f091/esp/Src/system_stm32f0xx.c | 246 ---------------- stm32f091/esp8266.c | 209 ++++++++++++++ stm32f091/esp8266.h | 16 ++ stm32f091/server.c | 57 ++++ stm32f091/server.h | 6 + stm32f091/setup.c | 177 +++++++----- stm32f091/setup.h | 15 +- 15 files changed, 405 insertions(+), 1870 deletions(-) delete mode 100644 stm32f091/esp/Inc/main.h delete mode 100644 stm32f091/esp/Inc/stm32f0xx_hal_conf.h delete mode 100644 stm32f091/esp/Inc/stm32f0xx_it.h delete mode 100644 stm32f091/esp/Src/main.c delete mode 100644 stm32f091/esp/Src/stm32f0xx_hal_msp.c delete mode 100644 stm32f091/esp/Src/stm32f0xx_it.c delete mode 100644 stm32f091/esp/Src/syscalls.c delete mode 100644 stm32f091/esp/Src/sysmem.c delete mode 100644 stm32f091/esp/Src/system_stm32f0xx.c create mode 100644 stm32f091/esp8266.c create mode 100644 stm32f091/esp8266.h create mode 100644 stm32f091/server.c create mode 100644 stm32f091/server.h (limited to 'stm32f091') diff --git a/stm32f091/esp/Inc/main.h b/stm32f091/esp/Inc/main.h deleted file mode 100644 index f14fa83..0000000 --- a/stm32f091/esp/Inc/main.h +++ /dev/null @@ -1,68 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H -#define __MAIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f0xx_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 -----------------------------------------------------------*/ -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/stm32f091/esp/Inc/stm32f0xx_hal_conf.h b/stm32f091/esp/Inc/stm32f0xx_hal_conf.h deleted file mode 100644 index e61394a..0000000 --- a/stm32f091/esp/Inc/stm32f0xx_hal_conf.h +++ /dev/null @@ -1,322 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_hal_conf.h - * @brief HAL configuration file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2016 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F0xx_HAL_CONF_H -#define __STM32F0xx_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_CEC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CRC_MODULE_ENABLED */ -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_TSC_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_LCD_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -#define HAL_UART_MODULE_ENABLED -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_WWDG_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -#define HAL_CORTEX_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_GPIO_MODULE_ENABLED -#define HAL_EXTI_MODULE_ENABLED -#define HAL_PWR_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED -#define HAL_I2C_MODULE_ENABLED - -/* ########################## HSE/HSI 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 ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -/** - * @brief In the following line adjust the External High Speed oscillator (HSE) Startup - * Timeout value - */ -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< 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 ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup - * Timeout value - */ -#if !defined (HSI_STARTUP_TIMEOUT) - #define HSI_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSI start up */ -#endif /* HSI_STARTUP_TIMEOUT */ - -/** - * @brief Internal High Speed oscillator for ADC (HSI14) value. - */ -#if !defined (HSI14_VALUE) -#define HSI14_VALUE ((uint32_t)14000000) /*!< Value of the Internal High Speed oscillator for ADC in Hz. - The real value may vary depending on the variations - in voltage and temperature. */ -#endif /* HSI14_VALUE */ - -/** - * @brief Internal High Speed oscillator for USB (HSI48) value. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz. - The real value may vary depending on the variations - in voltage and temperature. */ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) - #define LSI_VALUE ((uint32_t)40000) -#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 (LSI) value. - */ -#if !defined (LSE_VALUE) - #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -/** - * @brief Time out for LSE start up value in ms. - */ -#if !defined (LSE_STARTUP_TIMEOUT) - #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< 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 ((uint32_t)3300) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY ((uint32_t)3) /*!< tick interrupt priority (lowest by default) */ - /* Warning: Must be set to higher priority for HAL_Delay() */ - /* and HAL_GetTick() usage under interrupt context */ -#define USE_RTOS 0 -#define PREFETCH_ENABLE 1 -#define INSTRUCTION_CACHE_ENABLE 0 -#define DATA_CACHE_ENABLE 0 -#define USE_SPI_CRC 0U - -#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_COMP_REGISTER_CALLBACKS 0U /* COMP 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_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS 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_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ -#define USE_HAL_TSC_REGISTER_CALLBACKS 0U /* TSC register callback disabled */ -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD 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 */ - -/* Includes ------------------------------------------------------------------*/ -/** - * @brief Include module's header file - */ - -#ifdef HAL_RCC_MODULE_ENABLED - #include "stm32f0xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED - #include "stm32f0xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED - #include "stm32f0xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED - #include "stm32f0xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED - #include "stm32f0xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED - #include "stm32f0xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_CAN_MODULE_ENABLED - #include "stm32f0xx_hal_can.h" -#endif /* HAL_CAN_MODULE_ENABLED */ - -#ifdef HAL_CEC_MODULE_ENABLED - #include "stm32f0xx_hal_cec.h" -#endif /* HAL_CEC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED - #include "stm32f0xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED - #include "stm32f0xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED - #include "stm32f0xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED - #include "stm32f0xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED - #include "stm32f0xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED - #include "stm32f0xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED - #include "stm32f0xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED - #include "stm32f0xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED - #include "stm32f0xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED - #include "stm32f0xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED - #include "stm32f0xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED - #include "stm32f0xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED - #include "stm32f0xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED - #include "stm32f0xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED - #include "stm32f0xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_TSC_MODULE_ENABLED - #include "stm32f0xx_hal_tsc.h" -#endif /* HAL_TSC_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED - #include "stm32f0xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED - #include "stm32f0xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED - #include "stm32f0xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* __STM32F0xx_HAL_CONF_H */ - diff --git a/stm32f091/esp/Inc/stm32f0xx_it.h b/stm32f091/esp/Inc/stm32f0xx_it.h deleted file mode 100644 index 33b912c..0000000 --- a/stm32f091/esp/Inc/stm32f0xx_it.h +++ /dev/null @@ -1,63 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F0xx_IT_H -#define __STM32F0xx_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 SVC_Handler(void); -void PendSV_Handler(void); -void SysTick_Handler(void); -void USART1_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F0xx_IT_H */ diff --git a/stm32f091/esp/Src/main.c b/stm32f091/esp/Src/main.c deleted file mode 100644 index 52ca7ee..0000000 --- a/stm32f091/esp/Src/main.c +++ /dev/null @@ -1,510 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.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 ---------------------------------------------------------*/ -UART_HandleTypeDef huart1; -UART_HandleTypeDef huart2; - -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -static void MX_GPIO_Init(void); -static void MX_USART1_UART_Init(void); -static void MX_USART2_UART_Init(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -void ATsendCommand(uint8_t* data){ - char dataChar[20]; - uint8_t Tx_send[]="AT+CIPSEND=0,"; - - itoa(strlen((char*)data),dataChar,10); - strcat((char*)Tx_send,dataChar); - strcat((char*)Tx_send,"\r\n"); - HAL_UART_Transmit(&huart1, Tx_send, strlen((char*)Tx_send),1000); - HAL_Delay(2000); - HAL_UART_Transmit(&huart1, data, strlen((char*)data),1000); - HAL_Delay(1000); - HAL_UART_Transmit(&huart2, data, strlen((char*)data),1000); - HAL_Delay(5000); -} -int checkOK(uint8_t *receiveData,int length){ - char *ret=""; - char *ret1=""; - HAL_UART_Transmit(&huart2, receiveData,length,1000); - ret = strstr((char*)receiveData,"OK"); - // ret = strstr((char*)receiveData,"change"); - // memset(receiveData,0,30); - if((ret[0]='O') && (ret[1]=='K')){ - //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); - return 1; - - } -// else if((ret1[0]='c') && (ret1[1]=='h')){ -// //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); -// return 1; -// -// } - else{ - return 0; - } - -} -int receivingMsg(uint8_t *receiveData,int length){ - char *ret=""; - HAL_UART_Transmit(&huart2, receiveData,length,1000); - ret = strstr((char*)receiveData,"+IPD"); - // memset(receiveData,0,30); - if((ret[0]='+') && (ret[1]=='I')){ - //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); - return 1; - - } - else{ - return 0; - } - -} -int unlink(uint8_t *receiveData,int length){ - char *ret=""; - HAL_UART_Transmit(&huart2, receiveData,length,1000); - ret = strstr((char*)receiveData,"UNLINK"); - // memset(receiveData,0,30); - if((ret[0]='U') && (ret[1]=='N')){ - //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); - return 1; - - } - else{ - return 0; - } - -} - -void StartEsp(){ - - uint8_t Tx_AT[]="AT\r\n"; - uint8_t Rx_buffer[10]={0}; - for(int i=0;i<3;i++){ - // HAL_UART_Transmit(&huart2, hier,sizeof(hier),100); - HAL_UART_Transmit_IT(&huart1, Tx_AT,strlen((char*)Tx_AT)); - HAL_UART_Receive_IT(&huart1, Rx_buffer, 10); - - - HAL_UART_Transmit(&huart2, Rx_buffer,10,100); - HAL_Delay(5000); - //memset(Rx_buffer,0,sizeof(Rx_buffer)); - } - -} -void disconnect(){ - int ret; - uint8_t Tx_disconnect[]="AT+CWQAP\r\n";uint8_t buffer[17]={0}; - while(ret!=1){ - - HAL_UART_Transmit_IT(&huart1, Tx_disconnect,strlen((char*)Tx_disconnect)); - HAL_UART_Receive_IT(&huart1, buffer, 17); - HAL_Delay(2000); - - if(checkOK(buffer,17)==1){ - ret=1; - } - - } - - HAL_Delay(5000); -} -void mode(){ - int ret; - uint8_t buffer1[20]={0}; uint8_t Tx_mode[]="AT+CWMODE=1\r\n"; - - while(ret!=1){ - - HAL_UART_Transmit_IT(&huart1, Tx_mode,strlen((char*)Tx_mode)); - HAL_UART_Receive_IT(&huart1, buffer1, 20); - HAL_Delay(1000); - - if(checkOK(buffer1,20)==1){ - ret=1; - - } - - } - - HAL_Delay(1000); -} -void connect(){ - uint8_t Tx_network[]="AT+CWJAP=\"Test\",\"12345678\"\r\n"; - - - HAL_UART_Transmit(&huart1, Tx_network,strlen((char*)Tx_network),1000); - HAL_Delay(10000); -// HAL_UART_Transmit(&huart1, Tx_network,sizeof(Tx_network),1000); -// HAL_Delay(10000); - - - - - -} -void serveraan(){ - int ret; - uint8_t buffer1[30]={0}; uint8_t Tx_server[]="AT+CIPSERVER=1,80\r\n"; - - while(ret!=1){ - - HAL_UART_Transmit_IT(&huart1, Tx_server,strlen((char*)Tx_server)); - HAL_UART_Receive_IT(&huart1, buffer1, 30); - HAL_Delay(2000); - - if(checkOK(buffer1,30)==1){ - ret=1; - - } - - } - - HAL_Delay(1000); -} -void serveruit(){ - int ret; - uint8_t buffer1[27]={0}; uint8_t Tx_server[]="AT+CIPSERVER=0\r\n"; -// -// while(ret!=1){ - - HAL_UART_Transmit_IT(&huart1, Tx_server,strlen((char*)Tx_server)); -// HAL_UART_Receive_IT(&huart1, buffer1, 27); - HAL_Delay(3000); - -// if(unlink(buffer1,27)==1){ -// ret=1; -// -// } -// -// } - - HAL_Delay(1000); -} -void mux(){ - int ret; - uint8_t buffer2[20]={0}; uint8_t Tx_mux[]="AT+CIPMUX=1\r\n"; - - while(ret!=1){ - - HAL_UART_Transmit_IT(&huart1, Tx_mux,strlen((char*)Tx_mux)); - HAL_UART_Receive_IT(&huart1, buffer2, 20); - HAL_Delay(2000); - - if(checkOK(buffer2,20)==1){ - ret=1; - - } - - } - - HAL_Delay(5000); -} -void close(){ - - uint8_t Tx_close[]="AT+CIPCLOSE=0\r\n"; - - - HAL_UART_Transmit_IT(&huart1, Tx_close,strlen((char*)Tx_close)); - - HAL_Delay(3000); - -} - -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_USART1_UART_Init(); - MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ -uint8_t ok[]= "ok\r\n"; -uint8_t hier[]= "hier\r\n"; -//disconnect();//connect();// - -StartEsp(); -HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); -close(); -HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); -serveruit(); -HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); -mux(); -HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); -mode(); -HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); - -serveraan(); -HAL_UART_Transmit(&huart2, ok,sizeof(ok),1000); -uint8_t receive[24]={0}; -uint8_t sendToQTData[]="gelukt"; -uint8_t test[]="test"; -int ret; -//ATsendCommand(sendToQTData); - while (1) - { - - if(receive[0]=='\0') - { - HAL_UART_Receive_IT(&huart1, receive, 24); - } - else - { - HAL_UART_Transmit(&huart2, test,strlen((char*)test),1000); - HAL_Delay(5000); - -// if(receivingMsg(receive, 24)==1) -// { -// ret=1; - ATsendCommand(sendToQTData); - close(); - memset(receive,0,24); - //} - } - - - - } - - - - - -} - -/** - * @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_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - 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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) - { - Error_Handler(); - } - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2; - PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; - PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - Error_Handler(); - } -} - -/** - * @brief USART1 Initialization Function - * @param None - * @retval None - */ -static void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; - huart1.Init.WordLength = UART_WORDLENGTH_8B; - huart1.Init.StopBits = UART_STOPBITS_1; - huart1.Init.Parity = UART_PARITY_NONE; - huart1.Init.Mode = UART_MODE_TX_RX; - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart1.Init.OverSampling = UART_OVERSAMPLING_16; - huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&huart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ - -} - -/** - * @brief USART2 Initialization Function - * @param None - * @retval None - */ -static void MX_USART2_UART_Init(void) -{ - - /* USER CODE BEGIN USART2_Init 0 */ - - /* USER CODE END USART2_Init 0 */ - - /* USER CODE BEGIN USART2_Init 1 */ - - /* USER CODE END USART2_Init 1 */ - huart2.Instance = USART2; - huart2.Init.BaudRate = 115200; - huart2.Init.WordLength = UART_WORDLENGTH_8B; - huart2.Init.StopBits = UART_STOPBITS_1; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&huart2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USART2_Init 2 */ - - /* USER CODE END USART2_Init 2 */ - -} - -/** - * @brief GPIO Initialization Function - * @param None - * @retval None - */ -static void MX_GPIO_Init(void) -{ - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOA_CLK_ENABLE(); - -} - -/* 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 */ - __disable_irq(); - while (1) - { - } - /* 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, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/stm32f091/esp/Src/stm32f0xx_hal_msp.c b/stm32f091/esp/Src/stm32f0xx_hal_msp.c deleted file mode 100644 index 805c9cf..0000000 --- a/stm32f091/esp/Src/stm32f0xx_hal_msp.c +++ /dev/null @@ -1,193 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* 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_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); - - /* System interrupt init*/ - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/** -* @brief UART MSP Initialization -* This function configures the hardware resources used in this example -* @param huart: UART handle pointer -* @retval None -*/ -void HAL_UART_MspInit(UART_HandleTypeDef* huart) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(huart->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspInit 0 */ - - /* USER CODE END USART1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_USART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USART1 GPIO Configuration - PA9 ------> USART1_TX - PA10 ------> USART1_RX - */ - GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF1_USART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USART1 interrupt Init */ - HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(USART1_IRQn); - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ - } - else if(huart->Instance==USART2) - { - /* USER CODE BEGIN USART2_MspInit 0 */ - - /* USER CODE END USART2_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_USART2_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ - GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF1_USART2; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN USART2_MspInit 1 */ - - /* USER CODE END USART2_MspInit 1 */ - } - -} - -/** -* @brief UART MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param huart: UART handle pointer -* @retval None -*/ -void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) -{ - if(huart->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspDeInit 0 */ - - /* USER CODE END USART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART1_CLK_DISABLE(); - - /**USART1 GPIO Configuration - PA9 ------> USART1_TX - PA10 ------> USART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); - - /* USART1 interrupt DeInit */ - HAL_NVIC_DisableIRQ(USART1_IRQn); - /* USER CODE BEGIN USART1_MspDeInit 1 */ - - /* USER CODE END USART1_MspDeInit 1 */ - } - else if(huart->Instance==USART2) - { - /* USER CODE BEGIN USART2_MspDeInit 0 */ - - /* USER CODE END USART2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART2_CLK_DISABLE(); - - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); - - /* USER CODE BEGIN USART2_MspDeInit 1 */ - - /* USER CODE END USART2_MspDeInit 1 */ - } - -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/stm32f091/esp/Src/stm32f0xx_it.c b/stm32f091/esp/Src/stm32f0xx_it.c deleted file mode 100644 index 7f9dd99..0000000 --- a/stm32f091/esp/Src/stm32f0xx_it.c +++ /dev/null @@ -1,159 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "stm32f0xx_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 UART_HandleTypeDef huart1; -/* USER CODE BEGIN EV */ - -/* USER CODE END EV */ - -/******************************************************************************/ -/* Cortex-M0 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 */ - while (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 System service call via SWI instruction. - */ -void SVC_Handler(void) -{ - /* USER CODE BEGIN SVC_IRQn 0 */ - - /* USER CODE END SVC_IRQn 0 */ - /* USER CODE BEGIN SVC_IRQn 1 */ - - /* USER CODE END SVC_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 */ -} - -/******************************************************************************/ -/* STM32F0xx 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_stm32f0xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25. - */ -void USART1_IRQHandler(void) -{ - /* USER CODE BEGIN USART1_IRQn 0 */ - - /* USER CODE END USART1_IRQn 0 */ - HAL_UART_IRQHandler(&huart1); - /* USER CODE BEGIN USART1_IRQn 1 */ - - /* USER CODE END USART1_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/stm32f091/esp/Src/syscalls.c b/stm32f091/esp/Src/syscalls.c deleted file mode 100644 index fadb992..0000000 --- a/stm32f091/esp/Src/syscalls.c +++ /dev/null @@ -1,155 +0,0 @@ -/** - ****************************************************************************** - * @file syscalls.c - * @author Auto-generated by STM32CubeIDE - * @brief STM32CubeIDE Minimal System calls file - * - * For more information about which c-functions - * need which of these lowlevel functions - * please consult the Newlib libc-manual - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes */ -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Variables */ -extern int __io_putchar(int ch) __attribute__((weak)); -extern int __io_getchar(void) __attribute__((weak)); - - -char *__env[1] = { 0 }; -char **environ = __env; - - -/* Functions */ -void initialise_monitor_handles() -{ -} - -int _getpid(void) -{ - return 1; -} - -int _kill(int pid, int sig) -{ - errno = EINVAL; - return -1; -} - -void _exit (int status) -{ - _kill(status, -1); - while (1) {} /* Make sure we hang here */ -} - -__attribute__((weak)) int _read(int file, char *ptr, int len) -{ - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - *ptr++ = __io_getchar(); - } - -return len; -} - -__attribute__((weak)) int _write(int file, char *ptr, int len) -{ - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - __io_putchar(*ptr++); - } - return len; -} - -int _close(int file) -{ - return -1; -} - - -int _fstat(int file, struct stat *st) -{ - st->st_mode = S_IFCHR; - return 0; -} - -int _isatty(int file) -{ - return 1; -} - -int _lseek(int file, int ptr, int dir) -{ - return 0; -} - -int _open(char *path, int flags, ...) -{ - /* Pretend like we always fail */ - return -1; -} - -int _wait(int *status) -{ - errno = ECHILD; - return -1; -} - -int _unlink(char *name) -{ - errno = ENOENT; - return -1; -} - -int _times(struct tms *buf) -{ - return -1; -} - -int _stat(char *file, struct stat *st) -{ - st->st_mode = S_IFCHR; - return 0; -} - -int _link(char *old, char *new) -{ - errno = EMLINK; - return -1; -} - -int _fork(void) -{ - errno = EAGAIN; - return -1; -} - -int _execve(char *name, char **argv, char **env) -{ - errno = ENOMEM; - return -1; -} diff --git a/stm32f091/esp/Src/sysmem.c b/stm32f091/esp/Src/sysmem.c deleted file mode 100644 index 54081ac..0000000 --- a/stm32f091/esp/Src/sysmem.c +++ /dev/null @@ -1,79 +0,0 @@ -/** - ****************************************************************************** - * @file sysmem.c - * @author Generated by STM32CubeIDE - * @brief STM32CubeIDE System Memory calls file - * - * For more information about which C functions - * need which of these lowlevel functions - * please consult the newlib libc manual - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes */ -#include -#include - -/** - * Pointer to the current high watermark of the heap usage - */ -static uint8_t *__sbrk_heap_end = NULL; - -/** - * @brief _sbrk() allocates memory to the newlib heap and is used by malloc - * and others from the C library - * - * @verbatim - * ############################################################################ - * # .data # .bss # newlib heap # MSP stack # - * # # # # Reserved by _Min_Stack_Size # - * ############################################################################ - * ^-- RAM start ^-- _end _estack, RAM end --^ - * @endverbatim - * - * This implementation starts allocating at the '_end' linker symbol - * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack - * The implementation considers '_estack' linker symbol to be RAM end - * NOTE: If the MSP stack, at any point during execution, grows larger than the - * reserved size, please increase the '_Min_Stack_Size'. - * - * @param incr Memory size - * @return Pointer to allocated memory - */ -void *_sbrk(ptrdiff_t incr) -{ - extern uint8_t _end; /* Symbol defined in the linker script */ - extern uint8_t _estack; /* Symbol defined in the linker script */ - extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ - const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; - const uint8_t *max_heap = (uint8_t *)stack_limit; - uint8_t *prev_heap_end; - - /* Initialize heap end at first call */ - if (NULL == __sbrk_heap_end) - { - __sbrk_heap_end = &_end; - } - - /* Protect heap from growing into the reserved MSP stack */ - if (__sbrk_heap_end + incr > max_heap) - { - errno = ENOMEM; - return (void *)-1; - } - - prev_heap_end = __sbrk_heap_end; - __sbrk_heap_end += incr; - - return (void *)prev_heap_end; -} diff --git a/stm32f091/esp/Src/system_stm32f0xx.c b/stm32f091/esp/Src/system_stm32f0xx.c deleted file mode 100644 index add4405..0000000 --- a/stm32f091/esp/Src/system_stm32f0xx.c +++ /dev/null @@ -1,246 +0,0 @@ -/** - ****************************************************************************** - * @file system_stm32f0xx.c - * @author MCD Application Team - * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File. - * - * 1. This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32f0xx.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. - * - * - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2016 STMicroelectronics. - * All rights reserved.

- * - * 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 stm32f0xx_system - * @{ - */ - -/** @addtogroup STM32F0xx_System_Private_Includes - * @{ - */ - -#include "stm32f0xx.h" - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Defines - * @{ - */ -#if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)8000000) /*!< 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 ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz. - This value can be provided and adapted by the user application. */ -#endif /* HSI_VALUE */ - -#if !defined (HSI48_VALUE) -#define HSI48_VALUE ((uint32_t)48000000) /*!< Default value of the HSI48 Internal oscillator in Hz. - This value can be provided and adapted by the user application. */ -#endif /* HSI48_VALUE */ -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F0xx_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 = 8000000; - -const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; -const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F0xx_System_Private_Functions - * @{ - */ - -/** - * @brief Setup the microcontroller system - * @param None - * @retval None - */ -void SystemInit(void){ - /* NOTE :SystemInit(): This function is called at startup just after reset and - before branch to main program. This call is made inside - the "startup_stm32f0xx.s" file. - User can setups the default system clock (System clock source, PLL Multiplier - and Divider factors, AHB/APBx prescalers and Flash settings). - */ -} - -/** - * @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/divided by the PLL factors. - * - * (*) HSI_VALUE is a constant defined in stm32f0xx_hal_conf.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 stm32f0xx_hal_conf.h file (its value - * depends on the application requirements), 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 = 0, pllmull = 0, pllsource = 0, predivfactor = 0; - - /* Get SYSCLK source -------------------------------------------------------*/ - tmp = RCC->CFGR & RCC_CFGR_SWS; - - switch (tmp) - { - case RCC_CFGR_SWS_HSI: /* HSI used as system clock */ - SystemCoreClock = HSI_VALUE; - break; - case RCC_CFGR_SWS_HSE: /* HSE used as system clock */ - SystemCoreClock = HSE_VALUE; - break; - case RCC_CFGR_SWS_PLL: /* PLL used as system clock */ - /* Get PLL clock source and multiplication factor ----------------------*/ - pllmull = RCC->CFGR & RCC_CFGR_PLLMUL; - pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; - pllmull = ( pllmull >> 18) + 2; - predivfactor = (RCC->CFGR2 & RCC_CFGR2_PREDIV) + 1; - - if (pllsource == RCC_CFGR_PLLSRC_HSE_PREDIV) - { - /* HSE used as PLL clock source : SystemCoreClock = HSE/PREDIV * PLLMUL */ - SystemCoreClock = (HSE_VALUE/predivfactor) * pllmull; - } -#if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) - else if (pllsource == RCC_CFGR_PLLSRC_HSI48_PREDIV) - { - /* HSI48 used as PLL clock source : SystemCoreClock = HSI48/PREDIV * PLLMUL */ - SystemCoreClock = (HSI48_VALUE/predivfactor) * pllmull; - } -#endif /* STM32F042x6 || STM32F048xx || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx */ - else - { -#if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6) \ - || defined(STM32F078xx) || defined(STM32F071xB) || defined(STM32F072xB) \ - || defined(STM32F070xB) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC) - /* HSI used as PLL clock source : SystemCoreClock = HSI/PREDIV * PLLMUL */ - SystemCoreClock = (HSI_VALUE/predivfactor) * pllmull; -#else - /* HSI used as PLL clock source : SystemCoreClock = HSI/2 * PLLMUL */ - SystemCoreClock = (HSI_VALUE >> 1) * pllmull; -#endif /* STM32F042x6 || STM32F048xx || STM32F070x6 || - STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB || - STM32F091xC || STM32F098xx || STM32F030xC */ - } - break; - default: /* HSI used as system clock */ - SystemCoreClock = HSI_VALUE; - break; - } - /* Compute HCLK clock frequency ----------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c new file mode 100644 index 0000000..6f12191 --- /dev/null +++ b/stm32f091/esp8266.c @@ -0,0 +1,209 @@ +#include +#include +#include +#include + +#include "esp8266.h" +#include "setup.h" + +void ws_esp8266_ATsendCommand(uint8_t* data){ + char dataChar[20]; + uint8_t Tx_send[]="AT+CIPSEND=0,"; + + itoa(strlen((char*)data),dataChar,10); + strcat((char*)Tx_send,dataChar); + strcat((char*)Tx_send,"\r\n"); + HAL_UART_Transmit(&huart1, Tx_send, strlen((char*)Tx_send),1000); + HAL_Delay(2000); + HAL_UART_Transmit(&huart1, data, strlen((char*)data),1000); + HAL_Delay(1000); + HAL_UART_Transmit(&huart2, data, strlen((char*)data),1000); + HAL_Delay(5000); +} +int ws_esp8266_checkOK(uint8_t *receiveData,int length){ + char *ret=""; + char *ret1=""; + HAL_UART_Transmit(&huart2, receiveData,length,1000); + ret = strstr((char*)receiveData,"OK"); + // ret = strstr((char*)receiveData,"change"); + // memset(receiveData,0,30); + if((ret[0]='O') && (ret[1]=='K')){ + //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); + return 1; + + } +// else if((ret1[0]='c') && (ret1[1]=='h')){ +// //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); +// return 1; +// +// } + else{ + return 0; + } + +} +int ws_esp8266_receivingMsg(uint8_t *receiveData,int length){ + char *ret=""; + HAL_UART_Transmit(&huart2, receiveData,length,1000); + ret = strstr((char*)receiveData,"+IPD"); + // memset(receiveData,0,30); + if((ret[0]='+') && (ret[1]=='I')){ + //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); + return 1; + + } + else{ + return 0; + } + +} +int ws_esp8266_unlink(uint8_t *receiveData,int length){ + char *ret=""; + HAL_UART_Transmit(&huart2, receiveData,length,1000); + ret = strstr((char*)receiveData,"UNLINK"); + // memset(receiveData,0,30); + if((ret[0]='U') && (ret[1]=='N')){ + //HAL_UART_Transmit(&huart2, (uint8_t*)ret, sizeof(ret), 100); + return 1; + + } + else{ + return 0; + } + +} + +void ws_esp8266_StartEsp(){ + + uint8_t Tx_AT[]="AT\r\n"; + uint8_t Rx_buffer[10]={0}; + for(int i=0;i<3;i++){ + // HAL_UART_Transmit(&huart2, hier,sizeof(hier),100); + HAL_UART_Transmit_IT(&huart1, Tx_AT,strlen((char*)Tx_AT)); + HAL_UART_Receive_IT(&huart1, Rx_buffer, 10); + + + HAL_UART_Transmit(&huart2, Rx_buffer,10,100); + HAL_Delay(5000); + //memset(Rx_buffer,0,sizeof(Rx_buffer)); + } + +} +void ws_esp8266_disconnect(){ + int ret; + uint8_t Tx_disconnect[]="AT+CWQAP\r\n";uint8_t buffer[17]={0}; + while(ret!=1){ + + HAL_UART_Transmit_IT(&huart1, Tx_disconnect,strlen((char*)Tx_disconnect)); + HAL_UART_Receive_IT(&huart1, buffer, 17); + HAL_Delay(2000); + + if(ws_esp8266_checkOK(buffer,17)==1){ + ret=1; + } + + } + + HAL_Delay(5000); +} +void ws_esp8266_mode(){ + int ret; + uint8_t buffer1[20]={0}; uint8_t Tx_mode[]="AT+CWMODE=1\r\n"; + + while(ret!=1){ + + HAL_UART_Transmit_IT(&huart1, Tx_mode,strlen((char*)Tx_mode)); + HAL_UART_Receive_IT(&huart1, buffer1, 20); + HAL_Delay(1000); + + if(ws_esp8266_checkOK(buffer1,20)==1){ + ret=1; + + } + + } + + HAL_Delay(1000); +} +void ws_esp8266_connect(){ + uint8_t Tx_network[]="AT+CWJAP=\"Test\",\"12345678\"\r\n"; + + + HAL_UART_Transmit(&huart1, Tx_network,strlen((char*)Tx_network),1000); + HAL_Delay(10000); +// HAL_UART_Transmit(&huart1, Tx_network,sizeof(Tx_network),1000); +// HAL_Delay(10000); + + + + + +} +void ws_esp8266_serveraan(){ + int ret; + uint8_t buffer1[30]={0}; uint8_t Tx_server[]="AT+CIPSERVER=1,80\r\n"; + + while(ret!=1){ + + HAL_UART_Transmit_IT(&huart1, Tx_server,strlen((char*)Tx_server)); + HAL_UART_Receive_IT(&huart1, buffer1, 30); + HAL_Delay(2000); + + if(ws_esp8266_checkOK(buffer1,30)==1){ + ret=1; + + } + + } + + HAL_Delay(1000); +} +void ws_esp8266_serveruit(){ + int ret; + uint8_t buffer1[27]={0}; uint8_t Tx_server[]="AT+CIPSERVER=0\r\n"; +// +// while(ret!=1){ + + HAL_UART_Transmit_IT(&huart1, Tx_server,strlen((char*)Tx_server)); +// HAL_UART_Receive_IT(&huart1, buffer1, 27); + HAL_Delay(3000); + +// if(unlink(buffer1,27)==1){ +// ret=1; +// +// } +// +// } + + HAL_Delay(1000); +} +void ws_esp8266_mux(){ + int ret; + uint8_t buffer2[20]={0}; uint8_t Tx_mux[]="AT+CIPMUX=1\r\n"; + + while(ret!=1){ + + HAL_UART_Transmit_IT(&huart1, Tx_mux,strlen((char*)Tx_mux)); + HAL_UART_Receive_IT(&huart1, buffer2, 20); + HAL_Delay(2000); + + if(ws_esp8266_checkOK(buffer2,20)==1){ + ret=1; + + } + + } + + HAL_Delay(5000); +} +void ws_esp8266_close(){ + + uint8_t Tx_close[]="AT+CIPCLOSE=0\r\n"; + + + HAL_UART_Transmit_IT(&huart1, Tx_close,strlen((char*)Tx_close)); + + HAL_Delay(3000); + +} + diff --git a/stm32f091/esp8266.h b/stm32f091/esp8266.h new file mode 100644 index 0000000..c09a557 --- /dev/null +++ b/stm32f091/esp8266.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +void ws_esp8266_ATsendCommand(uint8_t* data); +int ws_esp8266_checkOK(uint8_t *receiveData,int length); +int ws_esp8266_receivingMsg(uint8_t *receiveData,int length); +int ws_esp8266_unlink(uint8_t *receiveData,int length); +void ws_esp8266_StartEsp(); +void ws_esp8266_disconnect(); +void ws_esp8266_mode(); +void ws_esp8266_connect(); +void ws_esp8266_serveraan(); +void ws_esp8266_serveruit(); +void ws_esp8266_mux(); +void ws_esp8266_close(); diff --git a/stm32f091/server.c b/stm32f091/server.c new file mode 100644 index 0000000..e289245 --- /dev/null +++ b/stm32f091/server.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include "setup.h" +#include "server.h" +#include "esp8266.h" + +void ws_server_demo() { + uint8_t ok[]= "ok\r\n"; + uint8_t hier[]= "hier\r\n"; + //disconnect();//connect();// + + ws_esp8266_StartEsp(); + HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); + ws_esp8266_close(); + HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); + ws_esp8266_serveruit(); + HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); + ws_esp8266_mux(); + HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); + ws_esp8266_mode(); + HAL_UART_Transmit(&huart2, hier,sizeof(hier),1000); + + ws_esp8266_serveraan(); + HAL_UART_Transmit(&huart2, ok,sizeof(ok),1000); + uint8_t receive[24]={0}; + uint8_t sendToQTData[]="gelukt"; + uint8_t test[]="test"; + int ret; + //ATsendCommand(sendToQTData); + while (1) + { + + if(receive[0]=='\0') + { + HAL_UART_Receive_IT(&huart1, receive, 24); + } + else + { + HAL_UART_Transmit(&huart2, test,strlen((char*)test),1000); + HAL_Delay(5000); + + // if(receivingMsg(receive, 24)==1) + // { + // ret=1; + ws_esp8266_ATsendCommand(sendToQTData); + ws_esp8266_close(); + memset(receive,0,24); + //} + } + + + + } +} diff --git a/stm32f091/server.h b/stm32f091/server.h new file mode 100644 index 0000000..6a3501d --- /dev/null +++ b/stm32f091/server.h @@ -0,0 +1,6 @@ +#pragma once + +void ws_server_demo(); + +/** FreeRTOS task that listens for incoming requests from the esp */ +void ws_server_listen_task(); diff --git a/stm32f091/setup.c b/stm32f091/setup.c index ed4ee0b..fec2b7c 100644 --- a/stm32f091/setup.c +++ b/stm32f091/setup.c @@ -7,11 +7,47 @@ #include "setup.h" -I2C_HandleTypeDef hi2c1; -UART_HandleTypeDef huart2; +I2C_HandleTypeDef hi2c1 = { + .Instance = I2C1, + .Init.Timing = 0x2000090E, + .Init.OwnAddress1 = 0, + .Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT, + .Init.DualAddressMode = I2C_DUALADDRESS_DISABLE, + .Init.OwnAddress2 = 0, + .Init.OwnAddress2Masks = I2C_OA2_NOMASK, + .Init.GeneralCallMode = I2C_GENERALCALL_DISABLE, + .Init.NoStretchMode = I2C_NOSTRETCH_DISABLE, +}; + +UART_HandleTypeDef huart1 = { + .Instance = USART1, + .Init.BaudRate = 115200, + .Init.WordLength = UART_WORDLENGTH_8B, + .Init.StopBits = UART_STOPBITS_1, + .Init.Parity = UART_PARITY_NONE, + .Init.Mode = UART_MODE_TX_RX, + .Init.HwFlowCtl = UART_HWCONTROL_NONE, + .Init.OverSampling = UART_OVERSAMPLING_16, + .Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE, + .AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT, +}; + +UART_HandleTypeDef huart2 = { + .Instance = USART2, + .Init.BaudRate = 115200, + .Init.WordLength = UART_WORDLENGTH_8B, + .Init.StopBits = UART_STOPBITS_1, + .Init.Parity = UART_PARITY_NONE, + .Init.Mode = UART_MODE_TX_RX, + .Init.HwFlowCtl = UART_HWCONTROL_NONE, + .Init.OverSampling = UART_OVERSAMPLING_16, + .Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE, + .AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT, +}; static void ws_io_clock_setup(); static void ws_io_i2c_setup(); +static void ws_io_usart1_setup(); static void ws_io_usart2_setup(); static void ws_setup_error_handler(); @@ -20,67 +56,52 @@ void ws_io_setup() { ws_io_clock_setup(); ws_io_i2c_setup(); + ws_io_usart1_setup(); ws_io_usart2_setup(); } static void ws_io_clock_setup() { - 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_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; - RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) return ws_setup_error_handler(); - - /** Initializes the CPU, AHB and APB buses clocks */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) return ws_setup_error_handler(); - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_I2C1; - PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; - PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) return ws_setup_error_handler(); + if (HAL_OK != HAL_RCC_OscConfig(&(RCC_OscInitTypeDef){ + .OscillatorType = RCC_OSCILLATORTYPE_HSI, + .HSIState = RCC_HSI_ON, + .HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT, + .PLL.PLLState = RCC_PLL_ON, + .PLL.PLLSource = RCC_PLLSOURCE_HSI, + .PLL.PLLMUL = RCC_PLL_MUL12, + .PLL.PREDIV = RCC_PREDIV_DIV2, + })) return ws_setup_error_handler(); + + if (HAL_OK != HAL_RCC_ClockConfig(&(RCC_ClkInitTypeDef){ + .ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1, + .SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK, + .AHBCLKDivider = RCC_SYSCLK_DIV1, + .APB1CLKDivider = RCC_HCLK_DIV1, + }, FLASH_LATENCY_1)) return ws_setup_error_handler(); + + if (HAL_RCCEx_PeriphCLKConfig(&(RCC_PeriphCLKInitTypeDef){ + .PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_I2C1, + .Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1, + .I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI, + }) != HAL_OK) return ws_setup_error_handler(); } static void ws_io_i2c_setup() { - hi2c1.Instance = I2C1; - hi2c1.Init.Timing = 0x2000090E; - hi2c1.Init.OwnAddress1 = 0; - hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; - hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; - hi2c1.Init.OwnAddress2 = 0; - hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; - hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; - hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; - if (HAL_I2C_Init(&hi2c1) != HAL_OK) return ws_setup_error_handler(); - if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) return ws_setup_error_handler(); - if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) return ws_setup_error_handler(); + if (HAL_I2C_Init(&hi2c1) != HAL_OK) + return ws_setup_error_handler(); + if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) + return ws_setup_error_handler(); + if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) + return ws_setup_error_handler(); +} + +static void ws_io_usart1_setup() { + if (HAL_UART_Init(&huart1) != HAL_OK) + return ws_setup_error_handler(); } static void ws_io_usart2_setup() { - huart2.Instance = USART2; - huart2.Init.BaudRate = 115200; - huart2.Init.WordLength = UART_WORDLENGTH_8B; - huart2.Init.StopBits = UART_STOPBITS_1; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&huart2) != HAL_OK) return ws_setup_error_handler(); + if (HAL_UART_Init(&huart2) != HAL_OK) + return ws_setup_error_handler(); } void HAL_MspInit() { @@ -92,29 +113,43 @@ void HAL_MspInit() { void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) { if(hi2c->Instance != I2C1) return; - GPIO_InitTypeDef GPIO_InitStruct = {0}; __HAL_RCC_GPIOB_CLK_ENABLE(); - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; //TODO: use #defines in setup.h - GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF1_I2C1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &(GPIO_InitTypeDef) { + .Pin = GPIO_PIN_8|GPIO_PIN_9, //TODO: use #defines in setup.h + .Mode = GPIO_MODE_AF_OD, + .Pull = GPIO_NOPULL, + .Speed = GPIO_SPEED_FREQ_HIGH, + .Alternate = GPIO_AF1_I2C1, + }); __HAL_RCC_I2C1_CLK_ENABLE(); } void HAL_UART_MspInit(UART_HandleTypeDef *huart) { - if(huart->Instance != USART2) return; - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - __HAL_RCC_USART2_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - GPIO_InitStruct.Pin = WS_PINOUT_USART_TX_PIN | WS_PINOUT_USART_RX_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF1_USART2; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + if(huart->Instance == USART1) { + __HAL_RCC_USART1_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + HAL_GPIO_Init(GPIOA, &(GPIO_InitTypeDef){ + .Pin = WS_PINOUT_USART1_TX_PIN | WS_PINOUT_USART1_RX_PIN, + .Mode = GPIO_MODE_AF_PP, + .Pull = GPIO_NOPULL, + .Speed = GPIO_SPEED_FREQ_HIGH, + .Alternate = GPIO_AF1_USART1, + }); + + // USART1 interrupt Init + HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(USART1_IRQn); + } else if (huart->Instance == USART2) { + __HAL_RCC_USART2_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + HAL_GPIO_Init(GPIOA, &(GPIO_InitTypeDef) { + .Pin = WS_PINOUT_USART2_TX_PIN | WS_PINOUT_USART2_RX_PIN, + .Mode = GPIO_MODE_AF_PP, + .Pull = GPIO_NOPULL, + .Speed = GPIO_SPEED_FREQ_LOW, + .Alternate = GPIO_AF1_USART2, + }); + } } void SysTick_Handler() { diff --git a/stm32f091/setup.h b/stm32f091/setup.h index 713ed58..8ca3720 100644 --- a/stm32f091/setup.h +++ b/stm32f091/setup.h @@ -8,12 +8,19 @@ #define WS_PINOUT_I2C_SDA_PORT GPIOB #define WS_PINOUT_I2C_SCL_PIN GPIO_PIN_8 #define WS_PINOUT_I2C_SCL_PORT GPIOB -#define WS_PINOUT_USART_RX_PIN GPIO_PIN_3 -#define WS_PINOUT_USART_RX_PORT GPIOA -#define WS_PINOUT_USART_TX_PIN GPIO_PIN_2 -#define WS_PINOUT_USART_TX_PORT GPIOA + +#define WS_PINOUT_USART1_RX_PIN GPIO_PIN_10 +#define WS_PINOUT_USART1_RX_PORT GPIOA +#define WS_PINOUT_USART1_TX_PIN GPIO_PIN_9 +#define WS_PINOUT_USART1_TX_PORT GPIOA + +#define WS_PINOUT_USART2_RX_PIN GPIO_PIN_3 +#define WS_PINOUT_USART2_RX_PORT GPIOA +#define WS_PINOUT_USART2_TX_PIN GPIO_PIN_2 +#define WS_PINOUT_USART2_TX_PORT GPIOA extern I2C_HandleTypeDef hi2c1; +extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; void ws_io_setup(); -- cgit v1.2.3