diff --git a/EPROMEmu.ioc b/EPROMEmu.ioc index 42a0354..56d3611 100644 --- a/EPROMEmu.ioc +++ b/EPROMEmu.ioc @@ -54,6 +54,8 @@ NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true +NVIC.TIM6_IRQn=true\:2\:0\:true\:false\:true\:true\:true +NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true PA0.GPIOParameters=GPIO_Label PA0.GPIO_Label=D0 PA0.Locked=true diff --git a/Inc/adc.h b/Inc/adc.h index 5693bb1..75d73ca 100644 --- a/Inc/adc.h +++ b/Inc/adc.h @@ -1,58 +1,7 @@ -/** - ****************************************************************************** - * File Name : ADC.h - * Description : This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __adc_H -#define __adc_H -#ifdef __cplusplus - extern "C" { +#ifndef ADC_H +#define ADC_H + +#include "stm32f0xx_system.h" + + #endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern ADC_HandleTypeDef hadc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ adc_H */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Inc/gpio.h b/Inc/gpio.h index 1e2e3a2..135c73d 100644 --- a/Inc/gpio.h +++ b/Inc/gpio.h @@ -1,57 +1,8 @@ -/** - ****************************************************************************** - * File Name : gpio.h - * Description : This file contains all the functions prototypes for - * the gpio - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ +#ifndef GPIO_H +#define GPIO_H + +#include "stm32f0xx_system.h" + +void initialise_gpio(void); -/* 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****/ diff --git a/Inc/main.h b/Inc/main.h deleted file mode 100644 index 2df159a..0000000 --- a/Inc/main.h +++ /dev/null @@ -1,119 +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) 2019 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 - * - ****************************************************************************** - */ -/* 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 -----------------------------------------------------------*/ -#define BOARD_RESET_Pin GPIO_PIN_13 -#define BOARD_RESET_GPIO_Port GPIOC -#define BOARD_POWER_Pin GPIO_PIN_14 -#define BOARD_POWER_GPIO_Port GPIOC -#define BOARD_RUN_Pin GPIO_PIN_15 -#define BOARD_RUN_GPIO_Port GPIOC -#define ROM_ACTIVE_Pin GPIO_PIN_0 -#define ROM_ACTIVE_GPIO_Port GPIOC -#define D0_Pin GPIO_PIN_0 -#define D0_GPIO_Port GPIOA -#define D1_Pin GPIO_PIN_1 -#define D1_GPIO_Port GPIOA -#define D2_Pin GPIO_PIN_2 -#define D2_GPIO_Port GPIOA -#define D3_Pin GPIO_PIN_3 -#define D3_GPIO_Port GPIOA -#define D4_Pin GPIO_PIN_4 -#define D4_GPIO_Port GPIOA -#define D5_Pin GPIO_PIN_5 -#define D5_GPIO_Port GPIOA -#define D6_Pin GPIO_PIN_6 -#define D6_GPIO_Port GPIOA -#define D7_Pin GPIO_PIN_7 -#define D7_GPIO_Port GPIOA -#define SR_DATAIN_Pin GPIO_PIN_4 -#define SR_DATAIN_GPIO_Port GPIOC -#define TARGET_VOLTAGE_Pin GPIO_PIN_0 -#define TARGET_VOLTAGE_GPIO_Port GPIOB -#define ROM_WE_Pin GPIO_PIN_11 -#define ROM_WE_GPIO_Port GPIOB -#define ROM_OE_Pin GPIO_PIN_12 -#define ROM_OE_GPIO_Port GPIOB -#define ROM_CE_Pin GPIO_PIN_13 -#define ROM_CE_GPIO_Port GPIOB -#define DATA_ROM_CE_Pin GPIO_PIN_14 -#define DATA_ROM_CE_GPIO_Port GPIOB -#define DATA_DIR_Pin GPIO_PIN_15 -#define DATA_DIR_GPIO_Port GPIOB -#define SR_OE_Pin GPIO_PIN_6 -#define SR_OE_GPIO_Port GPIOC -#define SR_RST_Pin GPIO_PIN_7 -#define SR_RST_GPIO_Port GPIOC -#define SR_STRB_Pin GPIO_PIN_8 -#define SR_STRB_GPIO_Port GPIOC -#define SR_DATA_Pin GPIO_PIN_9 -#define SR_DATA_GPIO_Port GPIOC -#define SR_CLK_Pin GPIO_PIN_8 -#define SR_CLK_GPIO_Port GPIOA -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Inc/port_definitions.h b/Inc/port_definitions.h new file mode 100644 index 0000000..3c7e1a8 --- /dev/null +++ b/Inc/port_definitions.h @@ -0,0 +1,60 @@ +#ifndef PORT_DEFINITIONS_H +#define PORT_DEFINITIONS_H + +#include "stm32f0xx_hal.h" + +#define BOARD_RESET_Pin GPIO_PIN_13 +#define BOARD_RESET_GPIO_Port GPIOC +#define BOARD_POWER_Pin GPIO_PIN_14 +#define BOARD_POWER_GPIO_Port GPIOC +#define BOARD_RUN_Pin GPIO_PIN_15 +#define BOARD_RUN_GPIO_Port GPIOC + +#define D0_Pin GPIO_PIN_0 +#define D0_GPIO_Port GPIOA +#define D1_Pin GPIO_PIN_1 +#define D1_GPIO_Port GPIOA +#define D2_Pin GPIO_PIN_2 +#define D2_GPIO_Port GPIOA +#define D3_Pin GPIO_PIN_3 +#define D3_GPIO_Port GPIOA +#define D4_Pin GPIO_PIN_4 +#define D4_GPIO_Port GPIOA +#define D5_Pin GPIO_PIN_5 +#define D5_GPIO_Port GPIOA +#define D6_Pin GPIO_PIN_6 +#define D6_GPIO_Port GPIOA +#define D7_Pin GPIO_PIN_7 +#define D7_GPIO_Port GPIOA + +#define TARGET_VOLTAGE_Pin GPIO_PIN_0 +#define TARGET_VOLTAGE_GPIO_Port GPIOB + +#define ROM_ACTIVE_Pin GPIO_PIN_0 +#define ROM_ACTIVE_GPIO_Port GPIOC +#define ROM_WE_Pin GPIO_PIN_11 +#define ROM_WE_GPIO_Port GPIOB +#define ROM_OE_Pin GPIO_PIN_12 +#define ROM_OE_GPIO_Port GPIOB +#define ROM_CE_Pin GPIO_PIN_13 +#define ROM_CE_GPIO_Port GPIOB + +#define DATA_ROM_CE_Pin GPIO_PIN_14 +#define DATA_ROM_CE_GPIO_Port GPIOB +#define DATA_DIR_Pin GPIO_PIN_15 +#define DATA_DIR_GPIO_Port GPIOB + +#define SR_DATAIN_Pin GPIO_PIN_4 +#define SR_DATAIN_GPIO_Port GPIOC +#define SR_OE_Pin GPIO_PIN_6 +#define SR_OE_GPIO_Port GPIOC +#define SR_RST_Pin GPIO_PIN_7 +#define SR_RST_GPIO_Port GPIOC +#define SR_STRB_Pin GPIO_PIN_8 +#define SR_STRB_GPIO_Port GPIOC +#define SR_DATA_Pin GPIO_PIN_9 +#define SR_DATA_GPIO_Port GPIOC +#define SR_CLK_Pin GPIO_PIN_8 +#define SR_CLK_GPIO_Port GPIOA + +#endif diff --git a/Inc/stm32f0xx_it.h b/Inc/stm32f0xx_it.h deleted file mode 100644 index 689f9ce..0000000 --- a/Inc/stm32f0xx_it.h +++ /dev/null @@ -1,65 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ -/* 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); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F0xx_IT_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Inc/stm32f0xx_system.h b/Inc/stm32f0xx_system.h new file mode 100644 index 0000000..0290c22 --- /dev/null +++ b/Inc/stm32f0xx_system.h @@ -0,0 +1,24 @@ +#ifndef STM32F0xx_SYSTEM_H +#define STM32F0xx_SYSTEM_H + +#include "stm32f0xx_hal.h" +#include "port_definitions.h" + +extern ADC_HandleTypeDef hadc; +extern TIM_HandleTypeDef htim6; +extern UART_HandleTypeDef huart1; + +void NMI_Handler(void); +void HardFault_Handler(void); +void SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void SystemClock_Config(void); +void Error_Handler(); + +void MX_ADC_Init(void); +void MX_GPIO_Init(void); +void MX_TIM6_Init(void); +void MX_USART1_UART_Init(void); + +#endif diff --git a/Inc/tim.h b/Inc/tim.h deleted file mode 100644 index 68dce53..0000000 --- a/Inc/tim.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - ****************************************************************************** - * File Name : TIM.h - * Description : This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __tim_H -#define __tim_H -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern TIM_HandleTypeDef htim6; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM6_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ tim_H */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Inc/timers.h b/Inc/timers.h new file mode 100644 index 0000000..c43d657 --- /dev/null +++ b/Inc/timers.h @@ -0,0 +1,7 @@ +#ifndef TIMERS_H +#define TIMERS_H + +#include "stm32f0xx_system.h" + + +#endif diff --git a/Inc/usart.h b/Inc/usart.h index 0a8a5e9..dbb632a 100644 --- a/Inc/usart.h +++ b/Inc/usart.h @@ -1,58 +1,6 @@ -/** - ****************************************************************************** - * File Name : USART.h - * Description : This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __usart_H -#define __usart_H -#ifdef __cplusplus - extern "C" { +#ifndef USART_H +#define USART_H + +#include "stm32f0xx_system.h" + #endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern UART_HandleTypeDef huart1; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ usart_H */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Src/adc.c b/Src/adc.c index 774574f..b984cec 100644 --- a/Src/adc.c +++ b/Src/adc.c @@ -1,119 +1,2 @@ -/** - ****************************************************************************** - * File Name : ADC.c - * Description : This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ #include "adc.h" -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -ADC_HandleTypeDef hadc; - -/* ADC init function */ -void MX_ADC_Init(void) -{ - ADC_ChannelConfTypeDef sConfig = {0}; - - /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) - */ - hadc.Instance = ADC1; - hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; - hadc.Init.Resolution = ADC_RESOLUTION_12B; - hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; - hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV; - hadc.Init.LowPowerAutoWait = DISABLE; - hadc.Init.LowPowerAutoPowerOff = DISABLE; - hadc.Init.ContinuousConvMode = DISABLE; - hadc.Init.DiscontinuousConvMode = DISABLE; - hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - hadc.Init.DMAContinuousRequests = DISABLE; - hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; - if (HAL_ADC_Init(&hadc) != HAL_OK) - { - Error_Handler(); - } - /** Configure for the selected ADC regular channel to be converted. - */ - sConfig.Channel = ADC_CHANNEL_8; - sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; - sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; - if (HAL_ADC_ConfigChannel(&hadc, &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_GPIOB_CLK_ENABLE(); - /**ADC GPIO Configuration - PB0 ------> ADC_IN8 - */ - GPIO_InitStruct.Pin = TARGET_VOLTAGE_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(TARGET_VOLTAGE_GPIO_Port, &GPIO_InitStruct); - - /* 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(); - - /**ADC GPIO Configuration - PB0 ------> ADC_IN8 - */ - HAL_GPIO_DeInit(TARGET_VOLTAGE_GPIO_Port, TARGET_VOLTAGE_Pin); - - /* 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****/ diff --git a/Src/gpio.c b/Src/gpio.c index 8d7f940..7249b3a 100644 --- a/Src/gpio.c +++ b/Src/gpio.c @@ -1,118 +1,9 @@ -/** - ****************************************************************************** - * File Name : gpio.c - * Description : This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ - -/* 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) +void initialise_gpio(void) { - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, BOARD_RESET_Pin|BOARD_RUN_Pin|SR_OE_Pin|SR_RST_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, ROM_ACTIVE_Pin|SR_STRB_Pin|SR_DATA_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, D0_Pin|D1_Pin|D2_Pin|D3_Pin - |D4_Pin|D5_Pin|D6_Pin|D7_Pin - |SR_CLK_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, ROM_WE_Pin|ROM_OE_Pin|ROM_CE_Pin|DATA_ROM_CE_Pin - |DATA_DIR_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pins : PCPin PCPin PCPin */ - GPIO_InitStruct.Pin = BOARD_RESET_Pin|BOARD_RUN_Pin|ROM_ACTIVE_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = BOARD_POWER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(BOARD_POWER_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PAPin PAPin PAPin PAPin - PAPin PAPin PAPin PAPin - PAPin */ - GPIO_InitStruct.Pin = D0_Pin|D1_Pin|D2_Pin|D3_Pin - |D4_Pin|D5_Pin|D6_Pin|D7_Pin - |SR_CLK_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 = SR_DATAIN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(SR_DATAIN_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin PBPin PBPin - PBPin */ - GPIO_InitStruct.Pin = ROM_WE_Pin|ROM_OE_Pin|ROM_CE_Pin|DATA_ROM_CE_Pin - |DATA_DIR_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 : PCPin PCPin PCPin PCPin */ - GPIO_InitStruct.Pin = SR_OE_Pin|SR_RST_Pin|SR_STRB_Pin|SR_DATA_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - + MX_GPIO_Init(); + MX_ADC_Init(); + MX_USART1_UART_Init(); + MX_TIM6_Init(); } - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Src/main.c b/Src/main.c index 221be50..7f71873 100644 --- a/Src/main.c +++ b/Src/main.c @@ -1,189 +1,21 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +#include "stm32f0xx_system.h" +#include "timers.h" #include "adc.h" -#include "tim.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 */ + // Reset of all peripherals, Initializes the Flash interface and the Systick. + HAL_Init(); - /* USER CODE END 1 */ - + // Configure the system clock + SystemClock_Config(); - /* MCU Configuration--------------------------------------------------------*/ + // Initialize all configured peripherals */ + initialise_gpio(); - /* 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_ADC_Init(); - MX_TIM6_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 */ + while (1) + { + } } - -/** - * @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 CPU, AHB and APB busses clocks - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.HSI14State = RCC_HSI14_ON; - RCC_OscInitStruct.HSI14CalibrationValue = 16; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; - RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - /** Initializes the CPU, AHB and APB busses 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) - { - Error_Handler(); - } - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; - PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; - 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(char *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****/ diff --git a/Src/stm32f0xx_hal_msp.c b/Src/stm32f0xx_hal_msp.c index 5995979..9d575ec 100644 --- a/Src/stm32f0xx_hal_msp.c +++ b/Src/stm32f0xx_hal_msp.c @@ -20,7 +20,7 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" +#include /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ diff --git a/Src/stm32f0xx_it.c b/Src/stm32f0xx_it.c deleted file mode 100644 index 46191bd..0000000 --- a/Src/stm32f0xx_it.c +++ /dev/null @@ -1,145 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f0xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ -/* 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 --------------------------------------------------------*/ - -/* 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 */ - - /* 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). */ -/******************************************************************************/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Src/stm32f0xx_system.c b/Src/stm32f0xx_system.c new file mode 100644 index 0000000..5ab8968 --- /dev/null +++ b/Src/stm32f0xx_system.c @@ -0,0 +1,296 @@ +#include "stm32f0xx_system.h" + +ADC_HandleTypeDef hadc; +TIM_HandleTypeDef htim6; +UART_HandleTypeDef huart1; + + +void NMI_Handler(void) +{ +} + + +void HardFault_Handler(void) +{ + while (1) + {} +} + +void SVC_Handler(void) +{ +} + +void PendSV_Handler(void) +{ +} + +void SysTick_Handler(void) +{ + HAL_IncTick(); + HAL_SYSTICK_IRQHandler(); +} + +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + + // Initializes the CPU, AHB and APB busses clocks + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14 | RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSI14State = RCC_HSI14_ON; + RCC_OscInitStruct.HSI14CalibrationValue = 16; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; + RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; + + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + // Initializes the CPU, AHB and APB busses 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) + { + Error_Handler(); + } + + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; + PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; + + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } +} + +void Error_Handler(void) +{ +} + + +void MX_ADC_Init(void) +{ + ADC_ChannelConfTypeDef sConfig = {0}; + + // Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) + hadc.Instance = ADC1; + hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; + hadc.Init.Resolution = ADC_RESOLUTION_12B; + hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; + hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc.Init.LowPowerAutoWait = DISABLE; + hadc.Init.LowPowerAutoPowerOff = DISABLE; + hadc.Init.ContinuousConvMode = DISABLE; + hadc.Init.DiscontinuousConvMode = DISABLE; + hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc.Init.DMAContinuousRequests = DISABLE; + hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; + + if (HAL_ADC_Init(&hadc) != HAL_OK) + { + Error_Handler(); + } + + // Configure for the selected ADC regular channel to be converted. + sConfig.Channel = ADC_CHANNEL_8; + sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; + sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; + + if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) + { + Error_Handler(); + } + +} + +void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (adcHandle->Instance==ADC1) + { + __HAL_RCC_ADC1_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + + // ADC GPIO Configuration + // PB0 ------> ADC_IN8 + GPIO_InitStruct.Pin = TARGET_VOLTAGE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(TARGET_VOLTAGE_GPIO_Port, &GPIO_InitStruct); + } +} + +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) +{ + if (adcHandle->Instance==ADC1) + { + __HAL_RCC_ADC1_CLK_DISABLE(); + + HAL_GPIO_DeInit(TARGET_VOLTAGE_GPIO_Port, TARGET_VOLTAGE_Pin); + } +} + +void MX_GPIO_Init(void) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + // GPIO Ports Clock Enable + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + + // Configure GPIO pin Output Level + HAL_GPIO_WritePin(GPIOC, BOARD_RESET_Pin | BOARD_RUN_Pin | SR_OE_Pin | SR_RST_Pin, GPIO_PIN_SET); + + // Configure GPIO pin Output Level + HAL_GPIO_WritePin(GPIOC, ROM_ACTIVE_Pin | SR_STRB_Pin | SR_DATA_Pin, GPIO_PIN_RESET); + + // Configure GPIO pin Output Level + HAL_GPIO_WritePin(GPIOA, D0_Pin | D1_Pin | D2_Pin | D3_Pin | D4_Pin | D5_Pin | D6_Pin | D7_Pin | SR_CLK_Pin, GPIO_PIN_RESET); + + // Configure GPIO pin Output Level + HAL_GPIO_WritePin(GPIOB, ROM_WE_Pin | ROM_OE_Pin | ROM_CE_Pin | DATA_ROM_CE_Pin | DATA_DIR_Pin, GPIO_PIN_RESET); + + // Configure GPIO pins : PCPin PCPin PCPin + GPIO_InitStruct.Pin = BOARD_RESET_Pin | BOARD_RUN_Pin | ROM_ACTIVE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + // Configure GPIO pin : PtPin + GPIO_InitStruct.Pin = BOARD_POWER_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(BOARD_POWER_GPIO_Port, &GPIO_InitStruct); + + // Configure GPIO pins : PAPin PAPin PAPin PAPin PAPin PAPin PAPin PAPin PAPin + GPIO_InitStruct.Pin = D0_Pin | D1_Pin | D2_Pin | D3_Pin | D4_Pin | D5_Pin | D6_Pin | D7_Pin | SR_CLK_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 = SR_DATAIN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(SR_DATAIN_GPIO_Port, &GPIO_InitStruct); + + // Configure GPIO pins : PBPin PBPin PBPin PBPin PBPin + GPIO_InitStruct.Pin = ROM_WE_Pin | ROM_OE_Pin | ROM_CE_Pin | DATA_ROM_CE_Pin | DATA_DIR_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 : PCPin PCPin PCPin PCPin + GPIO_InitStruct.Pin = SR_OE_Pin | SR_RST_Pin | SR_STRB_Pin | SR_DATA_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); +} + + +void MX_TIM6_Init(void) +{ + htim6.Instance = TIM6; + htim6.Init.Prescaler = 47999; + htim6.Init.CounterMode = TIM_COUNTERMODE_UP; + htim6.Init.Period = 100; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; + + if (HAL_TIM_Base_Init(&htim6) != HAL_OK) + { + Error_Handler(); + } +} + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if (tim_baseHandle->Instance==TIM6) + { + __HAL_RCC_TIM6_CLK_ENABLE(); + // TIM6 interrupt Init + HAL_NVIC_SetPriority(TIM6_IRQn, 2, 0); + HAL_NVIC_EnableIRQ(TIM6_IRQn); + } +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if (tim_baseHandle->Instance==TIM6) + { + __HAL_RCC_TIM6_CLK_DISABLE(); + // TIM6 interrupt Deinit + HAL_NVIC_DisableIRQ(TIM6_IRQn); + } +} + +void MX_USART1_UART_Init(void) +{ + 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(); + } +} + +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance==USART1) + { + __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); + } +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +{ + if (uartHandle->Instance==USART1) + { + __HAL_RCC_USART1_CLK_DISABLE(); + + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9 | GPIO_PIN_10); + HAL_NVIC_DisableIRQ(USART1_IRQn); + } +} diff --git a/Src/tim.c b/Src/tim.c deleted file mode 100644 index 17d54f2..0000000 --- a/Src/tim.c +++ /dev/null @@ -1,81 +0,0 @@ -/** - ****************************************************************************** - * File Name : TIM.c - * Description : This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -TIM_HandleTypeDef htim6; - -/* TIM6 init function */ -void MX_TIM6_Init(void) -{ - - htim6.Instance = TIM6; - htim6.Init.Prescaler = 47999; - htim6.Init.CounterMode = TIM_COUNTERMODE_UP; - htim6.Init.Period = 100; - htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; - if (HAL_TIM_Base_Init(&htim6) != HAL_OK) - { - Error_Handler(); - } - -} - -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) -{ - - if(tim_baseHandle->Instance==TIM6) - { - /* USER CODE BEGIN TIM6_MspInit 0 */ - - /* USER CODE END TIM6_MspInit 0 */ - /* TIM6 clock enable */ - __HAL_RCC_TIM6_CLK_ENABLE(); - /* USER CODE BEGIN TIM6_MspInit 1 */ - - /* USER CODE END TIM6_MspInit 1 */ - } -} - -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) -{ - - if(tim_baseHandle->Instance==TIM6) - { - /* USER CODE BEGIN TIM6_MspDeInit 0 */ - - /* USER CODE END TIM6_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM6_CLK_DISABLE(); - /* USER CODE BEGIN TIM6_MspDeInit 1 */ - - /* USER CODE END TIM6_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Src/timers.c b/Src/timers.c new file mode 100644 index 0000000..58aa4e0 --- /dev/null +++ b/Src/timers.c @@ -0,0 +1,6 @@ +#include "timers.h" + +void TIM6_IRQHandler(void) +{ + HAL_TIM_IRQHandler(&htim6); +} diff --git a/Src/usart.c b/Src/usart.c index 258af6a..d79066c 100644 --- a/Src/usart.c +++ b/Src/usart.c @@ -1,108 +1,6 @@ -/** - ****************************************************************************** - * File Name : USART.c - * Description : This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 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 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ #include "usart.h" -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -UART_HandleTypeDef huart1; - -/* USART1 init function */ - -void MX_USART1_UART_Init(void) +void USART1_IRQHandler(void) { - - 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(); - } - + HAL_UART_IRQHandler(&huart1); } - -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspInit 0 */ - - /* USER CODE END USART1_MspInit 0 */ - /* USART1 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); - - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ - } -} - -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) -{ - - if(uartHandle->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); - - /* USER CODE BEGIN USART1_MspDeInit 1 */ - - /* USER CODE END USART1_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/