You've already forked M5Unit-ExtEncoder-Internal-FW
mirror of
https://github.com/m5stack/M5Unit-ExtEncoder-Internal-FW.git
synced 2026-05-20 10:48:34 -07:00
init
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/MDK-ARM/Unit_ExtEncoder
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : gpio.h
|
||||
* Description : This file contains all the functions prototypes for
|
||||
* the gpio
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __encoder_H
|
||||
#define __encoder_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
#define gpio_low() GPIOA->BRR = GPIO_PIN_0
|
||||
#define gpio_high() GPIOA->BSRR = GPIO_PIN_0
|
||||
#define delay_150ns() __asm("NOP"); __asm("NOP"); __asm("NOP"); __asm("NOP"); __asm("NOP"); __asm("NOP")
|
||||
#define delay_300ns() delay_150ns(); __asm("NOP"); __asm("NOP"); __asm("NOP"); __asm("NOP"); __asm("NOP"); __asm("NOP")
|
||||
#define delay_600ns() delay_300ns(); delay_300ns()
|
||||
#define delay_900ns() delay_600ns(); delay_300ns()
|
||||
|
||||
#define out_bit_low() \
|
||||
gpio_high(); \
|
||||
delay_300ns(); \
|
||||
gpio_low(); \
|
||||
delay_600ns();
|
||||
|
||||
#define out_bit_high() \
|
||||
gpio_high(); \
|
||||
delay_900ns(); \
|
||||
gpio_low(); \
|
||||
delay_150ns();
|
||||
|
||||
#define Button_Pin GPIO_PIN_5
|
||||
#define Button_GPIO_Port GPIOA
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
extern __IO int8_t cDirCnt;
|
||||
extern uint16_t usLastCnt;
|
||||
|
||||
extern __IO int32_t encoder_countAB;
|
||||
extern __IO int32_t encoder_counter;
|
||||
extern __IO int32_t increment_countAB;
|
||||
extern __IO uint16_t encoder_countPulse;
|
||||
extern __IO int8_t count_mode;
|
||||
|
||||
void encode_update(void);
|
||||
|
||||
void pulseCounterInit(void);
|
||||
void pulseCounterDeinit(void);
|
||||
void EncodeABModeInit(void);
|
||||
void EncoderABModeDeinit(void);
|
||||
void advanceModeInit(uint8_t mode);
|
||||
void advanceModeDeinit(uint8_t mode);
|
||||
|
||||
void restart(void);
|
||||
void GPIO_init(void);
|
||||
void sk6812_init(uint8_t num);
|
||||
void neopixel_set_color(uint8_t num, uint32_t color);
|
||||
void neopixel_set_all_color(uint32_t color);
|
||||
void neopixel_show(void);
|
||||
void color_set_single(uint32_t color);
|
||||
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ pinoutConfig_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef __FLASH_H
|
||||
#define __FLASH_H
|
||||
|
||||
#include "stm32f0xx.h"
|
||||
#include <stdbool.h>
|
||||
#include "stm32f0xx_hal_flash_ex.h"
|
||||
|
||||
//Message head
|
||||
#define EEPPROM_PACKAGEHEAD 0xAA55//
|
||||
|
||||
//Flash page head
|
||||
#define STM32F0xx_PAGE_SIZE 0x400
|
||||
#define STM32F0xx_FLASH_PAGE0_STARTADDR 0x8000000
|
||||
#define STM32F0xx_FLASH_PAGE1_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE2_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+2*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE3_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+3*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE4_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+4*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE5_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+5*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE6_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+6*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE7_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+7*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE8_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+8*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE9_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+9*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE10_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+10*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE11_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+11*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE12_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+12*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE13_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+13*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE14_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+14*STM32F0xx_PAGE_SIZE)
|
||||
#define STM32F0xx_FLASH_PAGE15_STARTADDR (STM32F0xx_FLASH_PAGE0_STARTADDR+15*STM32F0xx_PAGE_SIZE)
|
||||
|
||||
|
||||
#define MIN(A,B) (A<B?A:B)
|
||||
|
||||
|
||||
// void flashReadWriteTest( void ) ;
|
||||
bool writeMessageToFlash( uint8_t *buff , uint16_t length);
|
||||
uint16_t readPackedMessageFromFlash( uint8_t *buff , uint16_t length);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : I2C.h
|
||||
* Description : This file provides code for the configuration
|
||||
* of the I2C instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __i2c_ex_H
|
||||
#define __i2c_ex_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
extern void i2c1_it_enable(void);
|
||||
extern void i2c1_it_disable(void);
|
||||
extern void i2c1_set_send_data(uint8_t *tx_ptr, uint16_t len);
|
||||
extern void set_i2c_slave_address(uint8_t addr);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ i2c_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,84 @@
|
||||
/* 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) 2023 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"
|
||||
#include "stm32f0xx_ll_i2c.h"
|
||||
#include "stm32f0xx_ll_crs.h"
|
||||
#include "stm32f0xx_ll_rcc.h"
|
||||
#include "stm32f0xx_ll_bus.h"
|
||||
#include "stm32f0xx_ll_system.h"
|
||||
#include "stm32f0xx_ll_exti.h"
|
||||
#include "stm32f0xx_ll_cortex.h"
|
||||
#include "stm32f0xx_ll_utils.h"
|
||||
#include "stm32f0xx_ll_pwr.h"
|
||||
#include "stm32f0xx_ll_dma.h"
|
||||
#include "stm32f0xx_ll_gpio.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 */
|
||||
#define High 1
|
||||
#define Low 0
|
||||
#define TIM_ENCODE_DEFAULT 0x8000
|
||||
extern __IO float meter;
|
||||
extern __IO int32_t perimeter;
|
||||
extern __IO int32_t pulse;
|
||||
/* 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 */
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef __MODECFG__H_
|
||||
#define __MODECFG__H_
|
||||
|
||||
#include "main.h"
|
||||
extern void inputModeInit(uint8_t num);
|
||||
extern void inputModeDeinit(uint8_t num);
|
||||
extern void pulseModeInit(uint8_t num);
|
||||
extern void pulseModeDeinit(uint8_t num);
|
||||
extern void encodeABModeInit(void);
|
||||
extern void encodeABModeDeInit(void);
|
||||
extern void encodePulseModeInit(void);
|
||||
extern void encodePulseModeDeinit(void);
|
||||
extern void modeDeinit(uint8_t num, uint8_t mode);
|
||||
extern void modeInit(uint8_t num, uint8_t mode);
|
||||
extern void modeConfig(uint8_t currMode,uint8_t lastMode);
|
||||
extern void advanceModeInit(uint8_t mode);
|
||||
extern void advanceModeDeinit(uint8_t mode);
|
||||
extern GPIO_TypeDef *GPIOx_List[4];
|
||||
extern const uint16_t GPIO_Pin_list[4];
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32_assert.h
|
||||
* @brief STM32 assert file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2018 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 __STM32_ASSERT_H
|
||||
#define __STM32_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* 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 /* __STM32_ASSERT_H */
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
/* 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 */
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f0xx_it.h
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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 EXTI4_15_IRQHandler(void);
|
||||
void TIM3_IRQHandler(void);
|
||||
void I2C1_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F0xx_IT_H */
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : TIM.h
|
||||
* Description : This file provides code for the configuration
|
||||
* of the TIM instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __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 htim3;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_TIM3_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ tim_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : encoder.c
|
||||
* Description : This file provides code for the configuration
|
||||
* of all used GPIO pins.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "encoder.h"
|
||||
#include "tim.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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
|
||||
*/
|
||||
// encoder
|
||||
uint16_t usNowCnt;
|
||||
uint16_t usLastCnt = TIM_ENCODE_DEFAULT;
|
||||
__IO int8_t cDirCnt = 1;
|
||||
__IO int32_t encoder_countAB;
|
||||
__IO int32_t encoder_counter;
|
||||
__IO int32_t increment_countAB;
|
||||
__IO uint16_t encoder_countPulse;
|
||||
__IO uint8_t ucPressState = 0;
|
||||
__IO int8_t count_mode = 0;
|
||||
|
||||
uint8_t led_num;
|
||||
uint32_t *color_buf = NULL;
|
||||
void color_set_single(uint32_t color);
|
||||
|
||||
void restart(void) {
|
||||
for (uint8_t i = 0; i < 113; i++) {
|
||||
delay_600ns();
|
||||
}
|
||||
}
|
||||
|
||||
void GPIO_init(void) {
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_InitTypeDef GPIO_InitStruct = { 0 };
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void sk6812_init(uint8_t num) {
|
||||
GPIO_init();
|
||||
color_buf = (uint32_t *)calloc(num, sizeof(uint32_t));
|
||||
led_num = num;
|
||||
}
|
||||
|
||||
void neopixel_set_color(uint8_t num, uint32_t color) {
|
||||
uint8_t rled = (color >> 16) & 0xff;
|
||||
uint8_t gled = (color >> 8) & 0xff;
|
||||
uint8_t bled = color & 0xff;
|
||||
color_buf[num] = gled << 16 | rled << 8 | bled;
|
||||
}
|
||||
|
||||
void neopixel_set_all_color(uint32_t color) {
|
||||
for (uint8_t i = 0; i < led_num; i++) {
|
||||
uint8_t rled = (color >> 16) & 0xff;
|
||||
uint8_t gled = (color >> 8) & 0xff;
|
||||
uint8_t bled = color & 0xff;
|
||||
color_buf[i] = gled << 16 | rled << 8 | bled;
|
||||
}
|
||||
}
|
||||
|
||||
void neopixel_show(void) {
|
||||
__disable_irq();
|
||||
for (uint8_t i = 0; i < led_num; i++) {
|
||||
color_set_single(color_buf[i]);
|
||||
}
|
||||
__enable_irq();
|
||||
restart();
|
||||
}
|
||||
|
||||
void color_set_single(uint32_t color) {
|
||||
for (uint8_t i = 0; i < 24; i++) {
|
||||
if (color & (1 << (23 - i))) {
|
||||
out_bit_high();
|
||||
}
|
||||
else {
|
||||
out_bit_low();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EncoderABModeInit(void)
|
||||
{
|
||||
// this is internal encoder timer3 CH1 & CH2 initial
|
||||
cDirCnt = 1;
|
||||
usLastCnt = TIM_ENCODE_DEFAULT;
|
||||
MX_TIM3_Init();
|
||||
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
|
||||
__HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);
|
||||
__HAL_TIM_SET_COUNTER(&htim3, TIM_ENCODE_DEFAULT);
|
||||
}
|
||||
|
||||
void EncoderABModeDeinit(void)
|
||||
{
|
||||
__HAL_TIM_DISABLE_IT(&htim3, TIM_IT_UPDATE);
|
||||
HAL_TIM_Encoder_Stop(&htim3, TIM_CHANNEL_ALL);
|
||||
HAL_TIM_Encoder_DeInit(&htim3);
|
||||
}
|
||||
|
||||
void pulseCounterInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitTypeDef));
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
|
||||
}
|
||||
|
||||
void pulseCounterDeinit(void)
|
||||
{
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
|
||||
HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
|
||||
}
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
if (htim->Instance == TIM3) {
|
||||
cDirCnt = (TIM3->CNT > 60535) ? cDirCnt + 1 : cDirCnt - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/** GPIO中断回调
|
||||
* @brief EXTI line detection callbacks.
|
||||
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
encoder_counter++;
|
||||
}
|
||||
|
||||
void advanceModeInit(uint8_t mode)
|
||||
{
|
||||
if(mode == 0)
|
||||
{
|
||||
EncoderABModeInit();
|
||||
}
|
||||
else if(mode == 1)
|
||||
{
|
||||
pulseCounterInit();
|
||||
}
|
||||
}
|
||||
|
||||
void advanceModeDeinit(uint8_t mode)
|
||||
{
|
||||
if(mode == 0)
|
||||
{
|
||||
EncoderABModeDeinit();
|
||||
}
|
||||
else if(mode == 1)
|
||||
{
|
||||
pulseCounterDeinit();
|
||||
}
|
||||
}
|
||||
|
||||
// Encoder AB
|
||||
void encode_update(void) {
|
||||
if(count_mode == 0)
|
||||
{
|
||||
usNowCnt = __HAL_TIM_GET_COUNTER(&htim3);
|
||||
if (cDirCnt < 0) {
|
||||
encoder_countAB += 65536 + usNowCnt - usLastCnt;
|
||||
increment_countAB += 65536 + usNowCnt - usLastCnt;
|
||||
} else if(cDirCnt > 0){
|
||||
encoder_countAB += -65536 + usNowCnt - usLastCnt;
|
||||
increment_countAB += -65536 + usNowCnt - usLastCnt;
|
||||
} else {
|
||||
encoder_countAB += usNowCnt - usLastCnt;
|
||||
increment_countAB += usNowCnt - usLastCnt;
|
||||
}
|
||||
usLastCnt = usNowCnt;
|
||||
cDirCnt = 0;
|
||||
meter = ((double)encoder_countAB / (double)pulse) * ((double)perimeter / 100.0);
|
||||
}
|
||||
ucPressState = HAL_GPIO_ReadPin(Button_GPIO_Port, Button_Pin);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,186 @@
|
||||
#include "flash.h"
|
||||
/*******************************************************************************
|
||||
* Function Name : doseFlashHasPackedMessage
|
||||
* Description : Does flash has packed messages
|
||||
* Input : None
|
||||
* Output :
|
||||
* Return : ture/false
|
||||
*******************************************************************************/
|
||||
bool doseFlashHasPackedMessage(void)
|
||||
{
|
||||
uint16_t length;
|
||||
uint16_t getHead;
|
||||
|
||||
/*Is head matched*/
|
||||
getHead = (uint16_t)(*(uint16_t*)(STM32F0xx_FLASH_PAGE15_STARTADDR ));
|
||||
if( EEPPROM_PACKAGEHEAD != getHead )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Is length zero*/
|
||||
length = (*(uint16_t*)(STM32F0xx_FLASH_PAGE15_STARTADDR+2));
|
||||
if( 0 == length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : getValuablePackedMessageLengthofFlash
|
||||
* Description : Get valuable packed message length of flash
|
||||
* Input : None
|
||||
* Output :
|
||||
* Return : valuable length
|
||||
*******************************************************************************/
|
||||
uint16_t getValuablePackedMessageLengthofFlash( void )
|
||||
{
|
||||
uint16_t length;
|
||||
|
||||
/*Is head matched*/
|
||||
if( EEPPROM_PACKAGEHEAD != (*(uint16_t*)(STM32F0xx_FLASH_PAGE15_STARTADDR )) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*Get length*/
|
||||
length = (uint16_t)(*(uint16_t*)(STM32F0xx_FLASH_PAGE15_STARTADDR+2));
|
||||
|
||||
return length;
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : readPackedMessageFromFlash
|
||||
* Description : Read packed message form flash
|
||||
* Input : buff:point to first location of received buffer.length:Maxmum length of reception
|
||||
* Output :
|
||||
* Return : reception length
|
||||
*******************************************************************************/
|
||||
uint16_t readPackedMessageFromFlash( uint8_t *buff , uint16_t length)
|
||||
{
|
||||
int i;
|
||||
uint16_t getLength;
|
||||
|
||||
if( !doseFlashHasPackedMessage() )
|
||||
return 0;
|
||||
|
||||
/*Get valuable length*/
|
||||
getLength = getValuablePackedMessageLengthofFlash();
|
||||
|
||||
/*Read out message*/
|
||||
for(i=0;i<MIN(getLength,length);i++)
|
||||
{
|
||||
buff[i]= *(uint8_t*)(STM32F0xx_FLASH_PAGE15_STARTADDR+4+i);
|
||||
}
|
||||
|
||||
return MIN(getLength,length);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : isItOddNumber
|
||||
* Description : is input data an odd number?
|
||||
* Input : number:input data
|
||||
* Output :
|
||||
* Return : true/false
|
||||
*******************************************************************************/
|
||||
bool isItOddNumber(uint16_t number)
|
||||
{
|
||||
if(0 != number%2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_eeprom_WriteWithPacked
|
||||
* Description : Write a group of datas to flash.
|
||||
* Input : buff:pointer of first data, length: write length
|
||||
* Output :
|
||||
* Return : true/false
|
||||
*******************************************************************************/
|
||||
bool writeMessageToFlash( uint8_t *buff , uint16_t length)
|
||||
{
|
||||
uint16_t temp;
|
||||
int i;
|
||||
FLASH_EraseInitTypeDef My_Flash;
|
||||
|
||||
/*Protection*/
|
||||
if( (length+4) > STM32F0xx_PAGE_SIZE )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
My_Flash.TypeErase = FLASH_TYPEERASE_PAGES; //标明Flash执行页面只做擦除操作
|
||||
My_Flash.PageAddress = STM32F0xx_FLASH_PAGE15_STARTADDR; //声明要擦除的地址
|
||||
My_Flash.NbPages = 1; //说明要擦除的页数,此参数必须是Min_Data = 1和Max_Data =(最大页数-初始页的值)之间的值
|
||||
|
||||
uint32_t PageError = 0; //设置PageError,如果出现错误这个变量会被设置为出错的FLASH地址
|
||||
HAL_FLASHEx_Erase(&My_Flash, &PageError); //调用擦除函数擦除
|
||||
|
||||
//对Flash进行烧写,FLASH_TYPEPROGRAM_HALFWORD 声明操作的Flash地址的16位的,此外还有32位跟64位的操作,自行翻查HAL库的定义即可
|
||||
|
||||
/*Write head*/
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, STM32F0xx_FLASH_PAGE15_STARTADDR, EEPPROM_PACKAGEHEAD);
|
||||
/*Write length*/
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, STM32F0xx_FLASH_PAGE15_STARTADDR+2, length);
|
||||
|
||||
|
||||
/*Write datas*/
|
||||
for(i=0 ;i<length/2 ;i++)
|
||||
{
|
||||
temp = buff[2*i]|(uint16_t)buff[2*i+1]<<8;
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, STM32F0xx_FLASH_PAGE15_STARTADDR+4+2*i, temp);
|
||||
}
|
||||
if( isItOddNumber(length) )//Write one more if length is odd number.
|
||||
{
|
||||
temp = (uint16_t)buff[length-1];
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, STM32F0xx_FLASH_PAGE15_STARTADDR+4+(length-1), temp);
|
||||
}
|
||||
|
||||
|
||||
/*Read out and check*/
|
||||
for(i=0 ;i<length ;i++)
|
||||
{
|
||||
if( *(uint8_t*)(STM32F0xx_FLASH_PAGE15_STARTADDR+4+i) != buff[i] )
|
||||
{
|
||||
HAL_FLASH_Lock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
HAL_FLASH_Lock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : flashReadWriteTest
|
||||
* Description : Flash read write test.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
//void flashReadWriteTest( void )
|
||||
//{
|
||||
// #define testReadWriteNumber 200
|
||||
// uint8_t buff_write[testReadWriteNumber]={0};
|
||||
// uint8_t buff_read[testReadWriteNumber]={0};
|
||||
// uint16_t length;
|
||||
// int i;
|
||||
//
|
||||
// for( i=0;i<testReadWriteNumber;i++)
|
||||
// {
|
||||
// buff_write[i]=i;
|
||||
// }
|
||||
//
|
||||
// writeMessageToFlash( buff_write , testReadWriteNumber);
|
||||
// length = readPackedMessageFromFlash( buff_read , testReadWriteNumber);
|
||||
// printf("length=%d\r\n",length);
|
||||
// for(i=0;i<length;i++)
|
||||
// {
|
||||
// printf("read[%d]=%d\r\n",i,buff_read[i]);
|
||||
// }
|
||||
//
|
||||
// while(1);
|
||||
//}
|
||||
@@ -0,0 +1,190 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "i2c_ex.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */
|
||||
|
||||
#define I2C_RECEIVE_BUFFER_LEN 50
|
||||
|
||||
__IO uint8_t aReceiveBuffer[I2C_RECEIVE_BUFFER_LEN];
|
||||
__IO uint8_t tx_buffer[I2C_RECEIVE_BUFFER_LEN];
|
||||
__IO uint16_t ubReceiveIndex = 0;
|
||||
uint8_t* pSlaveTransmitBuffer = 0;
|
||||
volatile uint8_t i2c_addr = 0;
|
||||
|
||||
void set_i2c_slave_address(uint8_t addr)
|
||||
{
|
||||
i2c_addr = (addr << 1);
|
||||
}
|
||||
|
||||
__weak void Slave_Complete_Callback(uint8_t *rx_data, uint16_t len)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(rx_data);
|
||||
UNUSED(len);
|
||||
}
|
||||
|
||||
void i2c1_it_enable(void)
|
||||
{
|
||||
LL_I2C_Enable(I2C1);
|
||||
|
||||
/* (6) Enable I2C1 address match/error interrupts:
|
||||
* - Enable Address Match Interrupt
|
||||
* - Enable Not acknowledge received interrupt
|
||||
* - Enable Error interrupts
|
||||
* - Enable Stop interrupt
|
||||
*/
|
||||
LL_I2C_EnableIT_ADDR(I2C1);
|
||||
LL_I2C_EnableIT_NACK(I2C1);
|
||||
LL_I2C_EnableIT_ERR(I2C1);
|
||||
LL_I2C_EnableIT_STOP(I2C1);
|
||||
}
|
||||
|
||||
void i2c1_it_disable(void)
|
||||
{
|
||||
LL_I2C_DisableIT_ADDR(I2C1);
|
||||
LL_I2C_DisableIT_TX(I2C1);
|
||||
LL_I2C_DisableIT_RX(I2C1);
|
||||
LL_I2C_DisableIT_NACK(I2C1);
|
||||
LL_I2C_DisableIT_ERR(I2C1);
|
||||
LL_I2C_DisableIT_STOP(I2C1);
|
||||
}
|
||||
|
||||
void Error_Callback(void)
|
||||
{
|
||||
i2c1_it_enable();
|
||||
LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK);
|
||||
}
|
||||
|
||||
void i2c1_set_send_data(uint8_t *tx_ptr, uint16_t len) {
|
||||
if (len > I2C_RECEIVE_BUFFER_LEN) {
|
||||
len = I2C_RECEIVE_BUFFER_LEN;
|
||||
}
|
||||
|
||||
if (len == 0 || tx_ptr == NULL) {
|
||||
return;
|
||||
}
|
||||
memcpy((void *)tx_buffer, tx_ptr, len);
|
||||
pSlaveTransmitBuffer = (uint8_t*)tx_buffer;
|
||||
}
|
||||
|
||||
void Slave_Reception_Callback(void)
|
||||
{
|
||||
/* Read character in Receive Data register.
|
||||
RXNE flag is cleared by reading data in RXDR register */
|
||||
aReceiveBuffer[ubReceiveIndex++] = LL_I2C_ReceiveData8(I2C1);
|
||||
}
|
||||
|
||||
void Slave_Ready_To_Transmit_Callback(void)
|
||||
{
|
||||
/* Send the Byte requested by the Master */
|
||||
LL_I2C_TransmitData8(I2C1, (uint8_t)(*pSlaveTransmitBuffer++));
|
||||
}
|
||||
|
||||
void I2C1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_IRQn 0 */
|
||||
/* Check ADDR flag value in ISR register */
|
||||
if(LL_I2C_IsActiveFlag_ADDR(I2C1))
|
||||
{
|
||||
/* Verify the Address Match with the OWN Slave address */
|
||||
if(LL_I2C_GetAddressMatchCode(I2C1) == i2c_addr)
|
||||
{
|
||||
if (ubReceiveIndex) {
|
||||
i2c1_it_disable();
|
||||
Slave_Complete_Callback((uint8_t *)aReceiveBuffer, ubReceiveIndex);
|
||||
ubReceiveIndex = 0;
|
||||
i2c1_it_enable();
|
||||
}
|
||||
/* Verify the transfer direction, a write direction, Slave enters receiver mode */
|
||||
if(LL_I2C_GetTransferDirection(I2C1) == LL_I2C_DIRECTION_WRITE)
|
||||
{
|
||||
/* Clear ADDR flag value in ISR register */
|
||||
LL_I2C_ClearFlag_ADDR(I2C1);
|
||||
|
||||
/* Enable Receive Interrupt */
|
||||
LL_I2C_EnableIT_RX(I2C1);
|
||||
}
|
||||
/* Verify the transfer direction, a read direction, Slave enters transmitter mode */
|
||||
else if(LL_I2C_GetTransferDirection(I2C1) == LL_I2C_DIRECTION_READ)
|
||||
{
|
||||
/* Clear ADDR flag value in ISR register */
|
||||
LL_I2C_ClearFlag_ADDR(I2C1);
|
||||
|
||||
/* Enable Transmit Interrupt */
|
||||
LL_I2C_EnableIT_TX(I2C1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear ADDR flag value in ISR register */
|
||||
LL_I2C_ClearFlag_ADDR(I2C1);
|
||||
|
||||
/* Call Error function */
|
||||
Error_Callback();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear ADDR flag value in ISR register */
|
||||
LL_I2C_ClearFlag_ADDR(I2C1);
|
||||
|
||||
/* Call Error function */
|
||||
Error_Callback();
|
||||
}
|
||||
}
|
||||
/* Check NACK flag value in ISR register */
|
||||
else if(LL_I2C_IsActiveFlag_NACK(I2C1))
|
||||
{
|
||||
/* End of Transfer */
|
||||
LL_I2C_ClearFlag_NACK(I2C1);
|
||||
}
|
||||
/* Check TXIS flag value in ISR register */
|
||||
else if(LL_I2C_IsActiveFlag_TXIS(I2C1))
|
||||
{
|
||||
/* Call function Slave Ready to Transmit Callback */
|
||||
Slave_Ready_To_Transmit_Callback();
|
||||
}
|
||||
/* Check RXNE flag value in ISR register */
|
||||
else if(LL_I2C_IsActiveFlag_RXNE(I2C1))
|
||||
{
|
||||
/* Call function Slave Reception Callback */
|
||||
Slave_Reception_Callback();
|
||||
}
|
||||
/* Check STOP flag value in ISR register */
|
||||
else if(LL_I2C_IsActiveFlag_STOP(I2C1))
|
||||
{
|
||||
/* End of Transfer */
|
||||
LL_I2C_ClearFlag_STOP(I2C1);
|
||||
|
||||
/* Check TXE flag value in ISR register */
|
||||
if(!LL_I2C_IsActiveFlag_TXE(I2C1))
|
||||
{
|
||||
/* Flush the TXDR register */
|
||||
LL_I2C_ClearFlag_TXE(I2C1);
|
||||
}
|
||||
|
||||
i2c1_it_disable();
|
||||
/* Call function Slave Complete Callback */
|
||||
Slave_Complete_Callback((uint8_t *)aReceiveBuffer, ubReceiveIndex);
|
||||
ubReceiveIndex = 0;
|
||||
i2c1_it_enable();
|
||||
}
|
||||
/* Check TXE flag value in ISR register */
|
||||
else if(!LL_I2C_IsActiveFlag_TXE(I2C1))
|
||||
{
|
||||
/* Do nothing */
|
||||
/* This Flag will be set by hardware when the TXDR register is empty */
|
||||
/* If needed, use LL_I2C_ClearFlag_TXE() interface to flush the TXDR register */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call Error function */
|
||||
Error_Callback();
|
||||
}
|
||||
/* USER CODE END I2C1_IRQn 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C1_IRQn 1 */
|
||||
|
||||
/* USER CODE END I2C1_IRQn 1 */
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,151 @@
|
||||
/* 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) 2023 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 TIM_Encoder MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param htim_encoder: TIM_Encoder handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* htim_encoder)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(htim_encoder->Instance==TIM3)
|
||||
{
|
||||
/* USER CODE BEGIN TIM3_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM3_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM3 GPIO Configuration
|
||||
PA6 ------> TIM3_CH1
|
||||
PA7 ------> TIM3_CH2
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF1_TIM3;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* TIM3 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM3_IRQn, 1, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||
/* USER CODE BEGIN TIM3_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM3_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM_Encoder MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param htim_encoder: TIM_Encoder handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* htim_encoder)
|
||||
{
|
||||
if(htim_encoder->Instance==TIM3)
|
||||
{
|
||||
/* USER CODE BEGIN TIM3_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM3_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM3_CLK_DISABLE();
|
||||
|
||||
/**TIM3 GPIO Configuration
|
||||
PA6 ------> TIM3_CH1
|
||||
PA7 ------> TIM3_CH2
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
/* TIM3 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(TIM3_IRQn);
|
||||
/* USER CODE BEGIN TIM3_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM3_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
@@ -0,0 +1,187 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f0xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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 TIM_HandleTypeDef htim3;
|
||||
/* 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 EXTI line 4 to 15 interrupts.
|
||||
*/
|
||||
void EXTI4_15_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI4_15_IRQn 0 */
|
||||
|
||||
/* USER CODE END EXTI4_15_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
|
||||
/* USER CODE BEGIN EXTI4_15_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI4_15_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM3 global interrupt.
|
||||
*/
|
||||
void TIM3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM3_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM3_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim3);
|
||||
/* USER CODE BEGIN TIM3_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM3_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles I2C1 global interrupt.
|
||||
*/
|
||||
__weak void I2C1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_IRQn 0 */
|
||||
|
||||
/* USER CODE END I2C1_IRQn 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C1_IRQn 1 */
|
||||
|
||||
/* USER CODE END I2C1_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @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****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user