├── CMSIS ├── core_cm3.c ├── core_cm3.h ├── startup │ ├── startup_stm32f10x_cl.s │ ├── startup_stm32f10x_hd.s │ ├── startup_stm32f10x_hd_vl.s │ ├── startup_stm32f10x_ld.s │ ├── startup_stm32f10x_ld_vl.s │ ├── startup_stm32f10x_md.s │ ├── startup_stm32f10x_md_vl.s │ └── startup_stm32f10x_xl.s ├── stm32f10x.h ├── system_stm32f10x.c └── system_stm32f10x.h ├── FWlib ├── inc │ ├── misc.h │ ├── stm32f10x_adc.h │ ├── stm32f10x_bkp.h │ ├── stm32f10x_can.h │ ├── stm32f10x_cec.h │ ├── stm32f10x_crc.h │ ├── stm32f10x_dac.h │ ├── stm32f10x_dbgmcu.h │ ├── stm32f10x_dma.h │ ├── stm32f10x_exti.h │ ├── stm32f10x_flash.h │ ├── stm32f10x_fsmc.h │ ├── stm32f10x_gpio.h │ ├── stm32f10x_i2c.h │ ├── stm32f10x_iwdg.h │ ├── stm32f10x_pwr.h │ ├── stm32f10x_rcc.h │ ├── stm32f10x_rtc.h │ ├── stm32f10x_sdio.h │ ├── stm32f10x_spi.h │ ├── stm32f10x_tim.h │ ├── stm32f10x_usart.h │ └── stm32f10x_wwdg.h └── src │ ├── misc.c │ ├── stm32f10x_adc.c │ ├── stm32f10x_bkp.c │ ├── stm32f10x_can.c │ ├── stm32f10x_cec.c │ ├── stm32f10x_crc.c │ ├── stm32f10x_dac.c │ ├── stm32f10x_dbgmcu.c │ ├── stm32f10x_dma.c │ ├── stm32f10x_exti.c │ ├── stm32f10x_flash.c │ ├── stm32f10x_fsmc.c │ ├── stm32f10x_gpio.c │ ├── stm32f10x_i2c.c │ ├── stm32f10x_iwdg.c │ ├── stm32f10x_pwr.c │ ├── stm32f10x_rcc.c │ ├── stm32f10x_rtc.c │ ├── stm32f10x_sdio.c │ ├── stm32f10x_spi.c │ ├── stm32f10x_tim.c │ ├── stm32f10x_usart.c │ └── stm32f10x_wwdg.c ├── Libraries ├── STM32F10x_StdPeriph_Driver │ ├── inc │ │ ├── misc.h │ │ ├── stm32f10x_adc.h │ │ ├── stm32f10x_bkp.h │ │ ├── stm32f10x_can.h │ │ ├── stm32f10x_cec.h │ │ ├── stm32f10x_crc.h │ │ ├── stm32f10x_dac.h │ │ ├── stm32f10x_dbgmcu.h │ │ ├── stm32f10x_dma.h │ │ ├── stm32f10x_exti.h │ │ ├── stm32f10x_flash.h │ │ ├── stm32f10x_fsmc.h │ │ ├── stm32f10x_gpio.h │ │ ├── stm32f10x_i2c.h │ │ ├── stm32f10x_iwdg.h │ │ ├── stm32f10x_pwr.h │ │ ├── stm32f10x_rcc.h │ │ ├── stm32f10x_rtc.h │ │ ├── stm32f10x_sdio.h │ │ ├── stm32f10x_spi.h │ │ ├── stm32f10x_tim.h │ │ ├── stm32f10x_usart.h │ │ └── stm32f10x_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f10x_adc.c │ │ ├── stm32f10x_bkp.c │ │ ├── stm32f10x_can.c │ │ ├── stm32f10x_cec.c │ │ ├── stm32f10x_crc.c │ │ ├── stm32f10x_dac.c │ │ ├── stm32f10x_dbgmcu.c │ │ ├── stm32f10x_dma.c │ │ ├── stm32f10x_exti.c │ │ ├── stm32f10x_flash.c │ │ ├── stm32f10x_fsmc.c │ │ ├── stm32f10x_gpio.c │ │ ├── stm32f10x_i2c.c │ │ ├── stm32f10x_iwdg.c │ │ ├── stm32f10x_pwr.c │ │ ├── stm32f10x_rcc.c │ │ ├── stm32f10x_rtc.c │ │ ├── stm32f10x_sdio.c │ │ ├── stm32f10x_spi.c │ │ ├── stm32f10x_tim.c │ │ ├── stm32f10x_usart.c │ │ └── stm32f10x_wwdg.c └── STM32_USB-FS-Device_Driver │ ├── inc │ ├── usb_core.h │ ├── usb_def.h │ ├── usb_init.h │ ├── usb_int.h │ ├── usb_lib.h │ ├── usb_mem.h │ ├── usb_regs.h │ ├── usb_sil.h │ └── usb_type.h │ └── src │ ├── usb_core.c │ ├── usb_init.c │ ├── usb_int.c │ ├── usb_mem.c │ ├── usb_regs.c │ └── usb_sil.c ├── Output └── STM32-DEMO.hex ├── README.md ├── SRC ├── MargAHRS.c ├── MargAHRS.h ├── bgc32.h ├── board.h ├── calibration │ ├── magCalibration.c │ ├── magCalibration.h │ ├── mpu6050Calibration.c │ └── mpu6050Calibration.h ├── cli │ ├── cli.c │ ├── cli.h │ └── cliSensor.c ├── computeMotorCommands.c ├── computeMotorCommands.h ├── config.c ├── config.h ├── drv │ ├── drv_cli.c │ ├── drv_cli.h │ ├── drv_gpio.c │ ├── drv_gpio.h │ ├── drv_i2c.c │ ├── drv_i2c.h │ ├── drv_irq.c │ ├── drv_irq.h │ ├── drv_pwmMotors.c │ ├── drv_pwmMotors.h │ ├── drv_rc.c │ ├── drv_rc.h │ ├── drv_system.c │ ├── drv_system.h │ ├── drv_timingFunctions.c │ ├── drv_timingFunctions.h │ ├── drv_usart.c │ ├── drv_usart.h │ ├── ringbuffer.c │ └── ringbuffer.h ├── evvgcCF.c ├── evvgcCF.h ├── fastTrig.c ├── fastTrig.h ├── firstOrderFilter.c ├── firstOrderFilter.h ├── pid.c ├── pid.h ├── pointingCommands.c ├── pointingCommands.h ├── sensors │ ├── hmc5883.c │ ├── hmc5883.h │ ├── mpu6050.c │ └── mpu6050.h ├── stm32_it.c ├── stm32_it.h ├── utilities.c ├── utilities.h └── vcp │ ├── hw_config.c │ ├── hw_config.h │ ├── platform_config.h │ ├── usb_conf.h │ ├── usb_desc.c │ ├── usb_desc.h │ ├── usb_endp.c │ ├── usb_istr.c │ ├── usb_istr.h │ ├── usb_prop.c │ ├── usb_prop.h │ ├── usb_pwr.c │ └── usb_pwr.h ├── USER ├── DebugConfig │ └── USART1-DEMO_STM32F103VE.dbgconf ├── JLink Regs CM3.txt ├── JLinkSettings.ini ├── RTE │ └── _USART1-DEMO │ │ └── RTE_Components.h ├── STM32-DEMO.uvgui.Administrator ├── STM32-DEMO.uvgui.flyleaf ├── STM32-DEMO.uvguix.zhaojiahai ├── STM32-DEMO.uvopt ├── STM32-DEMO.uvoptx ├── STM32-DEMO.uvproj.saved_uv4 ├── STM32-DEMO.uvprojx ├── main.c ├── stm32f10x_conf.h ├── stm32f10x_it.c ├── stm32f10x_it.h ├── usart1.c └── usart1.h └── keilkill.bat /CMSIS/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/CMSIS/stm32f10x.h -------------------------------------------------------------------------------- /CMSIS/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CRC_H 25 | #define __STM32F10x_CRC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CRC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup CRC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | void CRC_ResetDR(void); 71 | uint32_t CRC_CalcCRC(uint32_t Data); 72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 73 | uint32_t CRC_GetCRC(void); 74 | void CRC_SetIDRegister(uint8_t IDValue); 75 | uint8_t CRC_GetIDRegister(void); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F10x_CRC_H */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_DBGMCU_H 25 | #define __STM32F10x_DBGMCU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup DBGMCU 39 | * @{ 40 | */ 41 | 42 | /** @defgroup DBGMCU_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 55 | #define DBGMCU_STOP ((uint32_t)0x00000002) 56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 80 | 81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup DBGMCU_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup DBGMCU_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | uint32_t DBGMCU_GetREVID(void); 99 | uint32_t DBGMCU_GetDEVID(void); 100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __STM32F10x_DBGMCU_H */ 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_IWDG_H 25 | #define __STM32F10x_IWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup IWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup IWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup IWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup IWDG_WriteAccess 55 | * @{ 56 | */ 57 | 58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 61 | ((ACCESS) == IWDG_WriteAccess_Disable)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup IWDG_prescaler 67 | * @{ 68 | */ 69 | 70 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 71 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 72 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 73 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 74 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 75 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 76 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 77 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 78 | ((PRESCALER) == IWDG_Prescaler_8) || \ 79 | ((PRESCALER) == IWDG_Prescaler_16) || \ 80 | ((PRESCALER) == IWDG_Prescaler_32) || \ 81 | ((PRESCALER) == IWDG_Prescaler_64) || \ 82 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 83 | ((PRESCALER) == IWDG_Prescaler_256)) 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup IWDG_Flag 89 | * @{ 90 | */ 91 | 92 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 93 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 94 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 95 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @defgroup IWDG_Exported_Macros 105 | * @{ 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** @defgroup IWDG_Exported_Functions 113 | * @{ 114 | */ 115 | 116 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 117 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 118 | void IWDG_SetReload(uint16_t Reload); 119 | void IWDG_ReloadCounter(void); 120 | void IWDG_Enable(void); 121 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __STM32F10x_IWDG_H */ 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 141 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_PWR_H 25 | #define __STM32F10x_PWR_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup PWR 39 | * @{ 40 | */ 41 | 42 | /** @defgroup PWR_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup PWR_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup PVD_detection_level 55 | * @{ 56 | */ 57 | 58 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 59 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 60 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 61 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 62 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 63 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 64 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 65 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 66 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 67 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 68 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup Regulator_state_is_STOP_mode 75 | * @{ 76 | */ 77 | 78 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 79 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 80 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 81 | ((REGULATOR) == PWR_Regulator_LowPower)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup STOP_mode_entry 87 | * @{ 88 | */ 89 | 90 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 91 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 92 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup PWR_Flag 99 | * @{ 100 | */ 101 | 102 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 103 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 104 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 105 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 106 | ((FLAG) == PWR_FLAG_PVDO)) 107 | 108 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup PWR_Exported_Macros 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup PWR_Exported_Functions 126 | * @{ 127 | */ 128 | 129 | void PWR_DeInit(void); 130 | void PWR_BackupAccessCmd(FunctionalState NewState); 131 | void PWR_PVDCmd(FunctionalState NewState); 132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 133 | void PWR_WakeUpPinCmd(FunctionalState NewState); 134 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 135 | void PWR_EnterSTANDBYMode(void); 136 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 137 | void PWR_ClearFlag(uint32_t PWR_FLAG); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __STM32F10x_PWR_H */ 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_RTC_H 25 | #define __STM32F10x_RTC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RTC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup RTC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup RTC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup RTC_interrupts_define 55 | * @{ 56 | */ 57 | 58 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 59 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 60 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 61 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 62 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 63 | ((IT) == RTC_IT_SEC)) 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup RTC_interrupts_flags 69 | * @{ 70 | */ 71 | 72 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 73 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 74 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 75 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 76 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 77 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 78 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 79 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 80 | ((FLAG) == RTC_FLAG_SEC)) 81 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @defgroup RTC_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup RTC_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 104 | void RTC_EnterConfigMode(void); 105 | void RTC_ExitConfigMode(void); 106 | uint32_t RTC_GetCounter(void); 107 | void RTC_SetCounter(uint32_t CounterValue); 108 | void RTC_SetPrescaler(uint32_t PrescalerValue); 109 | void RTC_SetAlarm(uint32_t AlarmValue); 110 | uint32_t RTC_GetDivider(void); 111 | void RTC_WaitForLastTask(void); 112 | void RTC_WaitForSynchro(void); 113 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 114 | void RTC_ClearFlag(uint16_t RTC_FLAG); 115 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 116 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* __STM32F10x_RTC_H */ 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 136 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_WWDG_H 25 | #define __STM32F10x_WWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup WWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup WWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Exported_Macros 78 | * @{ 79 | */ 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | void WWDG_DeInit(void); 89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 90 | void WWDG_SetWindowValue(uint8_t WindowValue); 91 | void WWDG_EnableIT(void); 92 | void WWDG_SetCounter(uint8_t Counter); 93 | void WWDG_Enable(uint8_t Counter); 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F10x_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_crc.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup CRC 30 | * @brief CRC driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup CRC_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup CRC_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup CRC_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Resets the CRC Data register (DR). 80 | * @param None 81 | * @retval None 82 | */ 83 | void CRC_ResetDR(void) 84 | { 85 | /* Reset CRC generator */ 86 | CRC->CR = CRC_CR_RESET; 87 | } 88 | 89 | /** 90 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 91 | * @param Data: data word(32-bit) to compute its CRC 92 | * @retval 32-bit CRC 93 | */ 94 | uint32_t CRC_CalcCRC(uint32_t Data) 95 | { 96 | CRC->DR = Data; 97 | 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 103 | * @param pBuffer: pointer to the buffer containing the data to be computed 104 | * @param BufferLength: length of the buffer to be computed 105 | * @retval 32-bit CRC 106 | */ 107 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 108 | { 109 | uint32_t index = 0; 110 | 111 | for(index = 0; index < BufferLength; index++) 112 | { 113 | CRC->DR = pBuffer[index]; 114 | } 115 | 116 | return (CRC->DR); 117 | } 118 | 119 | /** 120 | * @brief Returns the current CRC value. 121 | * @param None 122 | * @retval 32-bit CRC 123 | */ 124 | uint32_t CRC_GetCRC(void) 125 | { 126 | return (CRC->DR); 127 | } 128 | 129 | /** 130 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 131 | * @param IDValue: 8-bit value to be stored in the ID register 132 | * @retval None 133 | */ 134 | void CRC_SetIDRegister(uint8_t IDValue) 135 | { 136 | CRC->IDR = IDValue; 137 | } 138 | 139 | /** 140 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 141 | * @param None 142 | * @retval 8-bit value of the ID register 143 | */ 144 | uint8_t CRC_GetIDRegister(void) 145 | { 146 | return (CRC->IDR); 147 | } 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** 154 | * @} 155 | */ 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 162 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the DBGMCU firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_dbgmcu.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup DBGMCU 30 | * @brief DBGMCU driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup DBGMCU_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup DBGMCU_Private_Defines 43 | * @{ 44 | */ 45 | 46 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 47 | /** 48 | * @} 49 | */ 50 | 51 | /** @defgroup DBGMCU_Private_Macros 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup DBGMCU_Private_Variables 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @defgroup DBGMCU_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup DBGMCU_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief Returns the device revision identifier. 81 | * @param None 82 | * @retval Device revision identifier 83 | */ 84 | uint32_t DBGMCU_GetREVID(void) 85 | { 86 | return(DBGMCU->IDCODE >> 16); 87 | } 88 | 89 | /** 90 | * @brief Returns the device identifier. 91 | * @param None 92 | * @retval Device identifier 93 | */ 94 | uint32_t DBGMCU_GetDEVID(void) 95 | { 96 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 97 | } 98 | 99 | /** 100 | * @brief Configures the specified peripheral and low power mode behavior 101 | * when the MCU under Debug mode. 102 | * @param DBGMCU_Periph: specifies the peripheral and low power mode. 103 | * This parameter can be any combination of the following values: 104 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 105 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 106 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 107 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 108 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 109 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 112 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 113 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 114 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 115 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 116 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 117 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 118 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 119 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 120 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted 121 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted 122 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted 123 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted 124 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 125 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 126 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 127 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 128 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 129 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 130 | * @param NewState: new state of the specified peripheral in Debug mode. 131 | * This parameter can be: ENABLE or DISABLE. 132 | * @retval None 133 | */ 134 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 135 | { 136 | /* Check the parameters */ 137 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 138 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 139 | 140 | if (NewState != DISABLE) 141 | { 142 | DBGMCU->CR |= DBGMCU_Periph; 143 | } 144 | 145 | else 146 | { 147 | DBGMCU->CR &= ~DBGMCU_Periph; 148 | } 149 | } 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 164 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/FWlib/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/FWlib/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the IWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_iwdg.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup IWDG 30 | * @brief IWDG driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup IWDG_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup IWDG_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /* ---------------------- IWDG registers bit mask ----------------------------*/ 47 | 48 | /* KR register bit mask */ 49 | #define KR_KEY_Reload ((uint16_t)0xAAAA) 50 | #define KR_KEY_Enable ((uint16_t)0xCCCC) 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup IWDG_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup IWDG_Private_Variables 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup IWDG_Private_FunctionPrototypes 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup IWDG_Private_Functions 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers. 86 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers. 87 | * This parameter can be one of the following values: 88 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers 89 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers 90 | * @retval None 91 | */ 92 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 93 | { 94 | /* Check the parameters */ 95 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 96 | IWDG->KR = IWDG_WriteAccess; 97 | } 98 | 99 | /** 100 | * @brief Sets IWDG Prescaler value. 101 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 102 | * This parameter can be one of the following values: 103 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 104 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 105 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 106 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 107 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 108 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 109 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 110 | * @retval None 111 | */ 112 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 113 | { 114 | /* Check the parameters */ 115 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 116 | IWDG->PR = IWDG_Prescaler; 117 | } 118 | 119 | /** 120 | * @brief Sets IWDG Reload value. 121 | * @param Reload: specifies the IWDG Reload value. 122 | * This parameter must be a number between 0 and 0x0FFF. 123 | * @retval None 124 | */ 125 | void IWDG_SetReload(uint16_t Reload) 126 | { 127 | /* Check the parameters */ 128 | assert_param(IS_IWDG_RELOAD(Reload)); 129 | IWDG->RLR = Reload; 130 | } 131 | 132 | /** 133 | * @brief Reloads IWDG counter with value defined in the reload register 134 | * (write access to IWDG_PR and IWDG_RLR registers disabled). 135 | * @param None 136 | * @retval None 137 | */ 138 | void IWDG_ReloadCounter(void) 139 | { 140 | IWDG->KR = KR_KEY_Reload; 141 | } 142 | 143 | /** 144 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled). 145 | * @param None 146 | * @retval None 147 | */ 148 | void IWDG_Enable(void) 149 | { 150 | IWDG->KR = KR_KEY_Enable; 151 | } 152 | 153 | /** 154 | * @brief Checks whether the specified IWDG flag is set or not. 155 | * @param IWDG_FLAG: specifies the flag to check. 156 | * This parameter can be one of the following values: 157 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 158 | * @arg IWDG_FLAG_RVU: Reload Value Update on going 159 | * @retval The new state of IWDG_FLAG (SET or RESET). 160 | */ 161 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 162 | { 163 | FlagStatus bitstatus = RESET; 164 | /* Check the parameters */ 165 | assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 166 | 167 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 168 | { 169 | bitstatus = SET; 170 | } 171 | 172 | else 173 | { 174 | bitstatus = RESET; 175 | } 176 | 177 | /* Return the flag status */ 178 | return bitstatus; 179 | } 180 | 181 | /** 182 | * @} 183 | */ 184 | 185 | /** 186 | * @} 187 | */ 188 | 189 | /** 190 | * @} 191 | */ 192 | 193 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 194 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/FWlib/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_CRC_H 31 | #define __STM32F10x_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /** @defgroup CRC_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup CRC_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup CRC_Exported_Macros 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup CRC_Exported_Functions 73 | * @{ 74 | */ 75 | 76 | void CRC_ResetDR(void); 77 | uint32_t CRC_CalcCRC(uint32_t Data); 78 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 79 | uint32_t CRC_GetCRC(void); 80 | void CRC_SetIDRegister(uint8_t IDValue); 81 | uint8_t CRC_GetIDRegister(void); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* __STM32F10x_CRC_H */ 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 101 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_DBGMCU_H 31 | #define __STM32F10x_DBGMCU_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup DBGMCU 45 | * @{ 46 | */ 47 | 48 | /** @defgroup DBGMCU_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup DBGMCU_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 61 | #define DBGMCU_STOP ((uint32_t)0x00000002) 62 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 63 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 64 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 65 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 66 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 67 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 68 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 69 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 70 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 71 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 72 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 73 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 74 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 75 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 76 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 77 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 78 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 79 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 80 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 81 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 82 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 83 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 84 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 85 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 86 | 87 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup DBGMCU_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @defgroup DBGMCU_Exported_Functions 101 | * @{ 102 | */ 103 | 104 | uint32_t DBGMCU_GetREVID(void); 105 | uint32_t DBGMCU_GetDEVID(void); 106 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* __STM32F10x_DBGMCU_H */ 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 126 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_IWDG_H 31 | #define __STM32F10x_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /** @defgroup IWDG_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup IWDG_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup IWDG_WriteAccess 61 | * @{ 62 | */ 63 | 64 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 65 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 66 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 67 | ((ACCESS) == IWDG_WriteAccess_Disable)) 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup IWDG_prescaler 73 | * @{ 74 | */ 75 | 76 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 77 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 78 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 79 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 80 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 81 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 82 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 83 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 84 | ((PRESCALER) == IWDG_Prescaler_8) || \ 85 | ((PRESCALER) == IWDG_Prescaler_16) || \ 86 | ((PRESCALER) == IWDG_Prescaler_32) || \ 87 | ((PRESCALER) == IWDG_Prescaler_64) || \ 88 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 89 | ((PRESCALER) == IWDG_Prescaler_256)) 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup IWDG_Flag 95 | * @{ 96 | */ 97 | 98 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 99 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 100 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 101 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 102 | /** 103 | * @} 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** @defgroup IWDG_Exported_Macros 111 | * @{ 112 | */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** @defgroup IWDG_Exported_Functions 119 | * @{ 120 | */ 121 | 122 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 123 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 124 | void IWDG_SetReload(uint16_t Reload); 125 | void IWDG_ReloadCounter(void); 126 | void IWDG_Enable(void); 127 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __STM32F10x_IWDG_H */ 134 | /** 135 | * @} 136 | */ 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 147 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_PWR_H 31 | #define __STM32F10x_PWR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup PWR 45 | * @{ 46 | */ 47 | 48 | /** @defgroup PWR_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup PWR_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup PVD_detection_level 61 | * @{ 62 | */ 63 | 64 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 65 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 66 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 67 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 68 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 69 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 70 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 71 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 72 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 73 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 74 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 75 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup Regulator_state_is_STOP_mode 81 | * @{ 82 | */ 83 | 84 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 85 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 86 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 87 | ((REGULATOR) == PWR_Regulator_LowPower)) 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup STOP_mode_entry 93 | * @{ 94 | */ 95 | 96 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 97 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 98 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @defgroup PWR_Flag 105 | * @{ 106 | */ 107 | 108 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 109 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 110 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 111 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 112 | ((FLAG) == PWR_FLAG_PVDO)) 113 | 114 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | /** @defgroup PWR_Exported_Macros 124 | * @{ 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** @defgroup PWR_Exported_Functions 132 | * @{ 133 | */ 134 | 135 | void PWR_DeInit(void); 136 | void PWR_BackupAccessCmd(FunctionalState NewState); 137 | void PWR_PVDCmd(FunctionalState NewState); 138 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 139 | void PWR_WakeUpPinCmd(FunctionalState NewState); 140 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 141 | void PWR_EnterSTANDBYMode(void); 142 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 143 | void PWR_ClearFlag(uint32_t PWR_FLAG); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* __STM32F10x_PWR_H */ 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 163 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_RTC_H 31 | #define __STM32F10x_RTC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup RTC 45 | * @{ 46 | */ 47 | 48 | /** @defgroup RTC_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup RTC_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup RTC_interrupts_define 61 | * @{ 62 | */ 63 | 64 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 65 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 66 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 67 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 68 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 69 | ((IT) == RTC_IT_SEC)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup RTC_interrupts_flags 75 | * @{ 76 | */ 77 | 78 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 79 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 80 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 81 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 82 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 83 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 84 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 85 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 86 | ((FLAG) == RTC_FLAG_SEC)) 87 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @defgroup RTC_Exported_Macros 98 | * @{ 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** @defgroup RTC_Exported_Functions 106 | * @{ 107 | */ 108 | 109 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 110 | void RTC_EnterConfigMode(void); 111 | void RTC_ExitConfigMode(void); 112 | uint32_t RTC_GetCounter(void); 113 | void RTC_SetCounter(uint32_t CounterValue); 114 | void RTC_SetPrescaler(uint32_t PrescalerValue); 115 | void RTC_SetAlarm(uint32_t AlarmValue); 116 | uint32_t RTC_GetDivider(void); 117 | void RTC_WaitForLastTask(void); 118 | void RTC_WaitForSynchro(void); 119 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 120 | void RTC_ClearFlag(uint16_t RTC_FLAG); 121 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 122 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* __STM32F10x_RTC_H */ 129 | /** 130 | * @} 131 | */ 132 | 133 | /** 134 | * @} 135 | */ 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 142 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F10x_WWDG_H 31 | #define __STM32F10x_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f10x.h" 39 | 40 | /** @addtogroup STM32F10x_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /** @defgroup WWDG_Exported_Types 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup WWDG_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** @defgroup WWDG_Prescaler 61 | * @{ 62 | */ 63 | 64 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 65 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 66 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 67 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 68 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 69 | ((PRESCALER) == WWDG_Prescaler_2) || \ 70 | ((PRESCALER) == WWDG_Prescaler_4) || \ 71 | ((PRESCALER) == WWDG_Prescaler_8)) 72 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 73 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup WWDG_Exported_Macros 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** @defgroup WWDG_Exported_Functions 91 | * @{ 92 | */ 93 | 94 | void WWDG_DeInit(void); 95 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 96 | void WWDG_SetWindowValue(uint8_t WindowValue); 97 | void WWDG_EnableIT(void); 98 | void WWDG_SetCounter(uint8_t Counter); 99 | void WWDG_Enable(uint8_t Counter); 100 | FlagStatus WWDG_GetFlagStatus(void); 101 | void WWDG_ClearFlag(void); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __STM32F10x_WWDG_H */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_crc.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup CRC 36 | * @brief CRC driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup CRC_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup CRC_Private_Defines 49 | * @{ 50 | */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup CRC_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup CRC_Private_Variables 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup CRC_Private_FunctionPrototypes 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup CRC_Private_Functions 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @brief Resets the CRC Data register (DR). 86 | * @param None 87 | * @retval None 88 | */ 89 | void CRC_ResetDR(void) 90 | { 91 | /* Reset CRC generator */ 92 | CRC->CR = CRC_CR_RESET; 93 | } 94 | 95 | /** 96 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 97 | * @param Data: data word(32-bit) to compute its CRC 98 | * @retval 32-bit CRC 99 | */ 100 | uint32_t CRC_CalcCRC(uint32_t Data) 101 | { 102 | CRC->DR = Data; 103 | 104 | return (CRC->DR); 105 | } 106 | 107 | /** 108 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 109 | * @param pBuffer: pointer to the buffer containing the data to be computed 110 | * @param BufferLength: length of the buffer to be computed 111 | * @retval 32-bit CRC 112 | */ 113 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 114 | { 115 | uint32_t index = 0; 116 | 117 | for(index = 0; index < BufferLength; index++) 118 | { 119 | CRC->DR = pBuffer[index]; 120 | } 121 | 122 | return (CRC->DR); 123 | } 124 | 125 | /** 126 | * @brief Returns the current CRC value. 127 | * @param None 128 | * @retval 32-bit CRC 129 | */ 130 | uint32_t CRC_GetCRC(void) 131 | { 132 | return (CRC->DR); 133 | } 134 | 135 | /** 136 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 137 | * @param IDValue: 8-bit value to be stored in the ID register 138 | * @retval None 139 | */ 140 | void CRC_SetIDRegister(uint8_t IDValue) 141 | { 142 | CRC->IDR = IDValue; 143 | } 144 | 145 | /** 146 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 147 | * @param None 148 | * @retval 8-bit value of the ID register 149 | */ 150 | uint8_t CRC_GetIDRegister(void) 151 | { 152 | return (CRC->IDR); 153 | } 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 168 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the DBGMCU firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_dbgmcu.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup DBGMCU 36 | * @brief DBGMCU driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup DBGMCU_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup DBGMCU_Private_Defines 49 | * @{ 50 | */ 51 | 52 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 53 | /** 54 | * @} 55 | */ 56 | 57 | /** @defgroup DBGMCU_Private_Macros 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup DBGMCU_Private_Variables 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup DBGMCU_Private_FunctionPrototypes 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup DBGMCU_Private_Functions 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @brief Returns the device revision identifier. 87 | * @param None 88 | * @retval Device revision identifier 89 | */ 90 | uint32_t DBGMCU_GetREVID(void) 91 | { 92 | return(DBGMCU->IDCODE >> 16); 93 | } 94 | 95 | /** 96 | * @brief Returns the device identifier. 97 | * @param None 98 | * @retval Device identifier 99 | */ 100 | uint32_t DBGMCU_GetDEVID(void) 101 | { 102 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 103 | } 104 | 105 | /** 106 | * @brief Configures the specified peripheral and low power mode behavior 107 | * when the MCU under Debug mode. 108 | * @param DBGMCU_Periph: specifies the peripheral and low power mode. 109 | * This parameter can be any combination of the following values: 110 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 111 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 112 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 113 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 114 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 115 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 116 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 117 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 118 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 119 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 120 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 121 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 122 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 123 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 124 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 125 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 126 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted 127 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted 128 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted 129 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted 130 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 131 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 132 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 133 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 134 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 135 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 136 | * @param NewState: new state of the specified peripheral in Debug mode. 137 | * This parameter can be: ENABLE or DISABLE. 138 | * @retval None 139 | */ 140 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 141 | { 142 | /* Check the parameters */ 143 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 144 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 145 | 146 | if (NewState != DISABLE) 147 | { 148 | DBGMCU->CR |= DBGMCU_Periph; 149 | } 150 | 151 | else 152 | { 153 | DBGMCU->CR &= ~DBGMCU_Periph; 154 | } 155 | } 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 170 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.c 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file provides all the IWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f10x_iwdg.h" 30 | 31 | /** @addtogroup STM32F10x_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup IWDG 36 | * @brief IWDG driver modules 37 | * @{ 38 | */ 39 | 40 | /** @defgroup IWDG_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | /** @defgroup IWDG_Private_Defines 49 | * @{ 50 | */ 51 | 52 | /* ---------------------- IWDG registers bit mask ----------------------------*/ 53 | 54 | /* KR register bit mask */ 55 | #define KR_KEY_Reload ((uint16_t)0xAAAA) 56 | #define KR_KEY_Enable ((uint16_t)0xCCCC) 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup IWDG_Private_Macros 63 | * @{ 64 | */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @defgroup IWDG_Private_Variables 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup IWDG_Private_FunctionPrototypes 79 | * @{ 80 | */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup IWDG_Private_Functions 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers. 92 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers. 93 | * This parameter can be one of the following values: 94 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers 95 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers 96 | * @retval None 97 | */ 98 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 99 | { 100 | /* Check the parameters */ 101 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 102 | IWDG->KR = IWDG_WriteAccess; 103 | } 104 | 105 | /** 106 | * @brief Sets IWDG Prescaler value. 107 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 108 | * This parameter can be one of the following values: 109 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 110 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 111 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 112 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 113 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 114 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 115 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 116 | * @retval None 117 | */ 118 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 119 | { 120 | /* Check the parameters */ 121 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 122 | IWDG->PR = IWDG_Prescaler; 123 | } 124 | 125 | /** 126 | * @brief Sets IWDG Reload value. 127 | * @param Reload: specifies the IWDG Reload value. 128 | * This parameter must be a number between 0 and 0x0FFF. 129 | * @retval None 130 | */ 131 | void IWDG_SetReload(uint16_t Reload) 132 | { 133 | /* Check the parameters */ 134 | assert_param(IS_IWDG_RELOAD(Reload)); 135 | IWDG->RLR = Reload; 136 | } 137 | 138 | /** 139 | * @brief Reloads IWDG counter with value defined in the reload register 140 | * (write access to IWDG_PR and IWDG_RLR registers disabled). 141 | * @param None 142 | * @retval None 143 | */ 144 | void IWDG_ReloadCounter(void) 145 | { 146 | IWDG->KR = KR_KEY_Reload; 147 | } 148 | 149 | /** 150 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled). 151 | * @param None 152 | * @retval None 153 | */ 154 | void IWDG_Enable(void) 155 | { 156 | IWDG->KR = KR_KEY_Enable; 157 | } 158 | 159 | /** 160 | * @brief Checks whether the specified IWDG flag is set or not. 161 | * @param IWDG_FLAG: specifies the flag to check. 162 | * This parameter can be one of the following values: 163 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 164 | * @arg IWDG_FLAG_RVU: Reload Value Update on going 165 | * @retval The new state of IWDG_FLAG (SET or RESET). 166 | */ 167 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 168 | { 169 | FlagStatus bitstatus = RESET; 170 | /* Check the parameters */ 171 | assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 172 | 173 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 174 | { 175 | bitstatus = SET; 176 | } 177 | 178 | else 179 | { 180 | bitstatus = RESET; 181 | } 182 | 183 | /* Return the flag status */ 184 | return bitstatus; 185 | } 186 | 187 | /** 188 | * @} 189 | */ 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | /** 196 | * @} 197 | */ 198 | 199 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 200 | -------------------------------------------------------------------------------- /Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_def.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Definitions related to USB Core 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_DEF_H 30 | #define __USB_DEF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported types ------------------------------------------------------------*/ 34 | typedef enum _RECIPIENT_TYPE 35 | { 36 | DEVICE_RECIPIENT, /* Recipient device */ 37 | INTERFACE_RECIPIENT, /* Recipient interface */ 38 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 39 | OTHER_RECIPIENT 40 | } RECIPIENT_TYPE; 41 | 42 | 43 | typedef enum _STANDARD_REQUESTS 44 | { 45 | GET_STATUS = 0, 46 | CLEAR_FEATURE, 47 | RESERVED1, 48 | SET_FEATURE, 49 | RESERVED2, 50 | SET_ADDRESS, 51 | GET_DESCRIPTOR, 52 | SET_DESCRIPTOR, 53 | GET_CONFIGURATION, 54 | SET_CONFIGURATION, 55 | GET_INTERFACE, 56 | SET_INTERFACE, 57 | TOTAL_sREQUEST, /* Total number of Standard request */ 58 | SYNCH_FRAME = 12 59 | } STANDARD_REQUESTS; 60 | 61 | /* Definition of "USBwValue" */ 62 | typedef enum _DESCRIPTOR_TYPE 63 | { 64 | DEVICE_DESCRIPTOR = 1, 65 | CONFIG_DESCRIPTOR, 66 | STRING_DESCRIPTOR, 67 | INTERFACE_DESCRIPTOR, 68 | ENDPOINT_DESCRIPTOR 69 | } DESCRIPTOR_TYPE; 70 | 71 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 72 | typedef enum _FEATURE_SELECTOR 73 | { 74 | ENDPOINT_STALL, 75 | DEVICE_REMOTE_WAKEUP 76 | } FEATURE_SELECTOR; 77 | 78 | /* Exported constants --------------------------------------------------------*/ 79 | /* Definition of "USBbmRequestType" */ 80 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 81 | #define STANDARD_REQUEST 0x00 /* Standard request */ 82 | #define CLASS_REQUEST 0x20 /* Class request */ 83 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 84 | 85 | #define RECIPIENT 0x1F /* Mask to get recipient */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions ------------------------------------------------------- */ 89 | 90 | #endif /* __USB_DEF_H */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INIT_H 31 | #define __USB_INIT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void USB_Init(void); 39 | 40 | /* External variables --------------------------------------------------------*/ 41 | /* The number of current endpoint, it will be used to specify an endpoint */ 42 | extern uint8_t EPindex; 43 | /* The number of current device, it is an index to the Device_Table */ 44 | /*extern uint8_t Device_no; */ 45 | /* Points to the DEVICE_INFO structure of current device */ 46 | /* The purpose of this register is to speed up the execution */ 47 | extern DEVICE_INFO *pInformation; 48 | /* Points to the DEVICE_PROP structure of current device */ 49 | /* The purpose of this register is to speed up the execution */ 50 | extern DEVICE_PROP *pProperty; 51 | /* Temporary save the state of Rx & Tx status. */ 52 | /* Whenever the Rx or Tx state is changed, its value is saved */ 53 | /* in this variable first and will be set to the EPRB or EPRA */ 54 | /* at the end of interrupt process */ 55 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 56 | 57 | extern uint16_t SaveState ; 58 | extern uint16_t wInterrupt_Mask; 59 | 60 | #endif /* __USB_INIT_H */ 61 | 62 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 63 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INT_H 31 | #define __USB_INT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void CTR_LP(void); 39 | void CTR_HP(void); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /* __USB_INT_H */ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_lib.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief USB library include files 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_LIB_H 31 | #define __USB_LIB_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "hw_config.h" 35 | #include "usb_type.h" 36 | #include "usb_regs.h" 37 | #include "usb_def.h" 38 | #include "usb_core.h" 39 | #include "usb_init.h" 40 | #include "usb_sil.h" 41 | #include "usb_mem.h" 42 | #include "usb_int.h" 43 | 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | /* Exported macro ------------------------------------------------------------*/ 47 | /* Exported functions ------------------------------------------------------- */ 48 | /* External variables --------------------------------------------------------*/ 49 | 50 | #endif /* __USB_LIB_H */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility prototypes functions for memory/PMA transfers 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_MEM_H 31 | #define __USB_MEM_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 39 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /*__USB_MEM_H*/ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer function prototypes. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_SIL_H 31 | #define __USB_SIL_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | 39 | uint32_t USB_SIL_Init(void); 40 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t *pBufferPointer, uint32_t wBufferSize); 41 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t *pBufferPointer); 42 | 43 | /* External variables --------------------------------------------------------*/ 44 | 45 | #endif /* __USB_SIL_H */ 46 | 47 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 48 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_type.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Type definitions used by the USB Library 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_TYPE_H 31 | #define __USB_TYPE_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usb_conf.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | #ifndef NULL 39 | #define NULL ((void *)0) 40 | #endif 41 | 42 | typedef enum 43 | { 44 | FALSE = 0, TRUE = !FALSE 45 | } 46 | boolean; // HJI bool; 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* Exported functions ------------------------------------------------------- */ 50 | /* External variables --------------------------------------------------------*/ 51 | 52 | #endif /* __USB_TYPE_H */ 53 | 54 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* Private define ------------------------------------------------------------*/ 34 | /* Private macro -------------------------------------------------------------*/ 35 | /* Private variables ---------------------------------------------------------*/ 36 | /* The number of current endpoint, it will be used to specify an endpoint */ 37 | uint8_t EPindex; 38 | /* The number of current device, it is an index to the Device_Table */ 39 | /* uint8_t Device_no; */ 40 | /* Points to the DEVICE_INFO structure of current device */ 41 | /* The purpose of this register is to speed up the execution */ 42 | DEVICE_INFO *pInformation; 43 | /* Points to the DEVICE_PROP structure of current device */ 44 | /* The purpose of this register is to speed up the execution */ 45 | DEVICE_PROP *pProperty; 46 | /* Temporary save the state of Rx & Tx status. */ 47 | /* Whenever the Rx or Tx state is changed, its value is saved */ 48 | /* in this variable first and will be set to the EPRB or EPRA */ 49 | /* at the end of interrupt process */ 50 | uint16_t SaveState ; 51 | uint16_t wInterrupt_Mask; 52 | DEVICE_INFO Device_Info; 53 | USER_STANDARD_REQUESTS *pUser_Standard_Requests; 54 | 55 | /* Extern variables ----------------------------------------------------------*/ 56 | /* Private function prototypes -----------------------------------------------*/ 57 | /* Private functions ---------------------------------------------------------*/ 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_Init 61 | * Description : USB system initialization 62 | * Input : None. 63 | * Output : None. 64 | * Return : None. 65 | *******************************************************************************/ 66 | void USB_Init(void) 67 | { 68 | pInformation = &Device_Info; 69 | pInformation->ControlState = 2; 70 | pProperty = &Device_Property; 71 | pUser_Standard_Requests = &User_Standard_Requests; 72 | /* Initialize devices one by one */ 73 | pProperty->Init(); 74 | } 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_mem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility functions for memory transfers to/from PMA 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Extern variables ----------------------------------------------------------*/ 36 | /* Private function prototypes -----------------------------------------------*/ 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /******************************************************************************* 40 | * Function Name : UserToPMABufferCopy 41 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 42 | * Input : - pbUsrBuf: pointer to user memory area. 43 | * - wPMABufAddr: address into PMA. 44 | * - wNBytes: no. of bytes to be copied. 45 | * Output : None. 46 | * Return : None . 47 | *******************************************************************************/ 48 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 49 | { 50 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 51 | uint32_t i, temp1, temp2; 52 | uint16_t *pdwVal; 53 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 54 | 55 | for (i = n; i != 0; i--) 56 | { 57 | temp1 = (uint16_t) * pbUsrBuf; 58 | pbUsrBuf++; 59 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; 60 | *pdwVal++ = temp2; 61 | pdwVal++; 62 | pbUsrBuf++; 63 | } 64 | } 65 | 66 | /******************************************************************************* 67 | * Function Name : PMAToUserBufferCopy 68 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 69 | * Input : - pbUsrBuf = pointer to user memory area. 70 | * - wPMABufAddr = address into PMA. 71 | * - wNBytes = no. of bytes to be copied. 72 | * Output : None. 73 | * Return : None. 74 | *******************************************************************************/ 75 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 76 | { 77 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 78 | uint32_t i; 79 | uint32_t *pdwVal; 80 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 81 | 82 | for (i = n; i != 0; i--) 83 | { 84 | *(uint16_t *)pbUsrBuf++ = *pdwVal++; 85 | pbUsrBuf++; 86 | } 87 | } 88 | 89 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 90 | -------------------------------------------------------------------------------- /Libraries/STM32_USB-FS-Device_Driver/src/usb_sil.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer for Global Initialization and Endpoint 8 | * Rea/Write operations. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usb_lib.h" 32 | 33 | /* Private typedef -----------------------------------------------------------*/ 34 | /* Private define ------------------------------------------------------------*/ 35 | /* Private macro -------------------------------------------------------------*/ 36 | /* Private variables ---------------------------------------------------------*/ 37 | /* Extern variables ----------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /******************************************************************************* 42 | * Function Name : USB_SIL_Init 43 | * Description : Initialize the USB Device IP and the Endpoint 0. 44 | * Input : None. 45 | * Output : None. 46 | * Return : Status. 47 | *******************************************************************************/ 48 | uint32_t USB_SIL_Init(void) 49 | { 50 | /* USB interrupts initialization */ 51 | /* clear pending interrupts */ 52 | _SetISTR(0); 53 | wInterrupt_Mask = IMR_MSK; 54 | /* set interrupts mask */ 55 | _SetCNTR(wInterrupt_Mask); 56 | return 0; 57 | } 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_SIL_Write 61 | * Description : Write a buffer of data to a selected endpoint. 62 | * Input : - bEpAddr: The address of the non control endpoint. 63 | * - pBufferPointer: The pointer to the buffer of data to be written 64 | * to the endpoint. 65 | * - wBufferSize: Number of data to be written (in bytes). 66 | * Output : None. 67 | * Return : Status. 68 | *******************************************************************************/ 69 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t *pBufferPointer, uint32_t wBufferSize) 70 | { 71 | /* Use the memory interface function to write to the selected endpoint */ 72 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); 73 | 74 | /* Update the data length in the control register */ 75 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize); 76 | 77 | return 0; 78 | } 79 | 80 | /******************************************************************************* 81 | * Function Name : USB_SIL_Read 82 | * Description : Write a buffer of data to a selected endpoint. 83 | * Input : - bEpAddr: The address of the non control endpoint. 84 | * - pBufferPointer: The pointer to which will be saved the 85 | * received data buffer. 86 | * Output : None. 87 | * Return : Number of received data (in Bytes). 88 | *******************************************************************************/ 89 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t *pBufferPointer) 90 | { 91 | uint32_t DataLength = 0; 92 | 93 | /* Get the number of received data on the selected Endpoint */ 94 | DataLength = GetEPRxCount(bEpAddr & 0x7F); 95 | 96 | /* Use the memory interface function to write to the selected endpoint */ 97 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); 98 | 99 | /* Return the number of received data */ 100 | return DataLength; 101 | } 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # - SimpleBGC 开源三轴无刷云台算法完全解说。 2 | - An interpreter:康朝阳 3 | - Email:547336083@qq.com 4 | - date:2016/09/19 # 5 | -------------------------------------------------------------------------------- /SRC/MargAHRS.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/MargAHRS.c -------------------------------------------------------------------------------- /SRC/MargAHRS.h: -------------------------------------------------------------------------------- 1 | //===================================================================================================== 2 | // AHRS.h 3 | // S.O.H. Madgwick 4 | // 25th August 2010 5 | // 6 | // 1 June 2012 Modified by J. Ihlein 7 | // 27 Aug 2012 Extensively modified to include G.K. Egan's accel confidence calculations and 8 | // calculation efficiency updates 9 | //===================================================================================================== 10 | // 11 | // See AHRS.c file for description. 12 | // 13 | //===================================================================================================== 14 | 15 | #pragma once 16 | 17 | //---------------------------------------------------------------------------------------------------- 18 | // Variable declaration 19 | 20 | extern float accConfidenceDecay; 21 | 22 | extern float q0, q1, q2, q3; // quaternion elements representing the estimated orientation 23 | 24 | // auxiliary variables to reduce number of repeated operations 25 | extern float q0q0, q0q1, q0q2, q0q3; 26 | extern float q1q1, q1q2, q1q3; 27 | extern float q2q2, q2q3; 28 | extern float q3q3; 29 | 30 | //--------------------------------------------------------------------------------------------------- 31 | // Function declaration 32 | 33 | void MargAHRSupdate(float gx, float gy, float gz, 34 | float ax, float ay, float az, 35 | float mx, float my, float mz, 36 | uint8_t magDataUpdate, float dt); 37 | 38 | //===================================================================================================== 39 | // End of file 40 | //===================================================================================================== 41 | -------------------------------------------------------------------------------- /SRC/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #include "stm32f10x.h" 52 | #include "stm32f10x_conf.h" 53 | 54 | #include "hw_config.h" 55 | #include "usb_lib.h" 56 | #include "usb_desc.h" 57 | #include "usb_pwr.h" 58 | 59 | /////////////////////////////////////// 60 | 61 | #include "pid.h" 62 | 63 | #include "bgc32.h" 64 | 65 | #include "drv_cli.h" 66 | #include "drv_gpio.h" 67 | #include "drv_i2c.h" 68 | #include "drv_irq.h" 69 | #include "drv_pwmMotors.h" 70 | #include "drv_rc.h" 71 | #include "drv_system.h" 72 | #include "drv_timingFunctions.h" 73 | #include "drv_usart.h" 74 | #include "ringbuffer.h" 75 | 76 | #include "hmc5883.h" 77 | #include "mpu6050.h" 78 | 79 | #include "cli.h" 80 | #include "computeMotorCommands.h" 81 | #include "config.h" 82 | #include "evvgcCF.h" 83 | #include "fastTrig.h" 84 | #include "firstOrderFilter.h" 85 | #include "magCalibration.h" 86 | #include "MargAHRS.h" 87 | #include "mpu6050Calibration.h" 88 | #include "pointingCommands.h" 89 | #include "utilities.h" 90 | #define M_TWOPI 6.28318531f 91 | 92 | //#define M_TWOPI (2.0f*3.141592653f) 93 | /////////////////////////////////////////////////////////////////////////////// 94 | -------------------------------------------------------------------------------- /SRC/calibration/magCalibration.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "board.h" 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | uint8_t magCalibrating = false; 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | // Mag Calibration 45 | /////////////////////////////////////////////////////////////////////////////// 46 | 47 | void magCalibration(void) 48 | { 49 | uint16_t calibrationCounter = 0; 50 | uint16_t population[2][3]; 51 | 52 | float d[600][3]; // 600 Samples = 60 seconds of data at 10 Hz 53 | float sphereOrigin[3]; 54 | float sphereRadius; 55 | 56 | magCalibrating = true; 57 | 58 | cliPrintF("\nMagnetometer Calibration:\n\n"); 59 | 60 | cliPrintF("Rotate magnetometer around all axes multiple times\n"); 61 | cliPrintF("Must complete within 60 seconds....\n\n"); 62 | cliPrintF(" Send a character when ready to begin and another when complete\n\n"); 63 | 64 | while (cliAvailable() == false); 65 | 66 | cliPrintF(" Start rotations.....\n"); 67 | 68 | getChar(); 69 | 70 | while ((cliAvailable() == false) && (calibrationCounter < 600)) 71 | { 72 | if (readMag() == true) 73 | { 74 | d[calibrationCounter][XAXIS] = (float)rawMag[XAXIS].value * magScaleFactor[XAXIS]; 75 | d[calibrationCounter][YAXIS] = (float)rawMag[YAXIS].value * magScaleFactor[YAXIS]; 76 | d[calibrationCounter][ZAXIS] = (float)rawMag[ZAXIS].value * magScaleFactor[ZAXIS]; 77 | 78 | calibrationCounter++; 79 | } 80 | 81 | delay(100); 82 | } 83 | 84 | cliPrintF("\n\nMagnetometer Bias Calculation, %3ld samples collected out of 600 max)\n", calibrationCounter); 85 | 86 | sphereFit(d, calibrationCounter, 100, 0.0f, population, sphereOrigin, &sphereRadius); 87 | 88 | eepromConfig.magBias[XAXIS] = sphereOrigin[XAXIS]; 89 | eepromConfig.magBias[YAXIS] = sphereOrigin[YAXIS]; 90 | eepromConfig.magBias[ZAXIS] = sphereOrigin[ZAXIS]; 91 | 92 | magCalibrating = false; 93 | } 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | -------------------------------------------------------------------------------- /SRC/calibration/magCalibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | extern uint8_t magCalibrating; 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | void magCalibration(void); 46 | 47 | /////////////////////////////////////////////////////////////////////////////// 48 | -------------------------------------------------------------------------------- /SRC/calibration/mpu6050Calibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // MPU6050 Calibration 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | void mpu6050Calibration(void); 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | -------------------------------------------------------------------------------- /SRC/cli/cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | extern uint8_t cliBusy; 42 | 43 | extern uint8_t highSpeedTelem1Enabled; 44 | extern uint8_t highSpeedTelem2Enabled; 45 | extern uint8_t highSpeedTelem3Enabled; 46 | extern uint8_t highSpeedTelem4Enabled; 47 | extern uint8_t highSpeedTelem5Enabled; 48 | extern uint8_t highSpeedTelem6Enabled; 49 | extern uint8_t highSpeedTelem7Enabled; 50 | extern uint8_t highSpeedTelem8Enabled; 51 | extern uint8_t highSpeedTelem9Enabled; 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | // High Speed Telem Disable 55 | /////////////////////////////////////////////////////////////////////////////// 56 | 57 | void highSpeedTelemDisable(void); 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | // Read Float from CLI 61 | /////////////////////////////////////////////////////////////////////////////// 62 | 63 | float readFloatCLI(void); 64 | 65 | /////////////////////////////////////////////////////////////////////////////// 66 | // Read Character String from CLI 67 | /////////////////////////////////////////////////////////////////////////////// 68 | 69 | uint8_t *readStringCLI(uint8_t *data, uint8_t length); 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | // CLI Communication 73 | /////////////////////////////////////////////////////////////////////////////// 74 | 75 | void cliCom(void); 76 | 77 | /////////////////////////////////////////////////////////////////////////////// 78 | // Mixer CLI 79 | /////////////////////////////////////////////////////////////////////////////// 80 | 81 | void mixerCLI(void); 82 | 83 | /////////////////////////////////////////////////////////////////////////////// 84 | // Receiver CLI 85 | /////////////////////////////////////////////////////////////////////////////// 86 | 87 | void receiverCLI(void); 88 | 89 | /////////////////////////////////////////////////////////////////////////////// 90 | // Sensor CLI 91 | /////////////////////////////////////////////////////////////////////////////// 92 | 93 | void sensorCLI(void); 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | -------------------------------------------------------------------------------- /SRC/computeMotorCommands.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/computeMotorCommands.c -------------------------------------------------------------------------------- /SRC/computeMotorCommands.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | extern float mechanical2electricalDegrees[3]; 42 | extern float electrical2mechanicalDegrees[3]; 43 | 44 | extern float pidCmd[3]; 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | // Compute Motor Commands 48 | /////////////////////////////////////////////////////////////////////////////// 49 | 50 | void computeMotorCommands(float dt); 51 | 52 | /////////////////////////////////////////////////////////////////////////////// 53 | -------------------------------------------------------------------------------- /SRC/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | void readEEPROM(void); 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | void writeEEPROM(void); 46 | 47 | /////////////////////////////////////////////////////////////////////////////// 48 | 49 | void checkFirstTime(bool eepromReset); 50 | 51 | /////////////////////////////////////////////////////////////////////////////// 52 | -------------------------------------------------------------------------------- /SRC/drv/drv_cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // CLI Init 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | void cliInit(void); 46 | 47 | /////////////////////////////////////////////////////////////////////////////// 48 | // CLI Available 49 | /////////////////////////////////////////////////////////////////////////////// 50 | 51 | uint32_t cliAvailable(void); 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | // CLI Read 55 | /////////////////////////////////////////////////////////////////////////////// 56 | 57 | //uint8_t cliRead(void); 58 | 59 | uint32_t cliRead(uint8_t *recvBuf, uint32_t len); 60 | 61 | int getChar(void); 62 | 63 | /////////////////////////////////////////////////////////////////////////////// 64 | // CLI Print 65 | /////////////////////////////////////////////////////////////////////////////// 66 | 67 | uint32_t cliPrint(const uint8_t *str, uint32_t len); 68 | 69 | /////////////////////////////////////////////////////////////////////////////// 70 | // CLI Print Formatted - Print formatted string to USB VCP 71 | // From Ala42 72 | /////////////////////////////////////////////////////////////////////////////// 73 | 74 | void cliPrintF(const char *fmt, ...); 75 | 76 | /////////////////////////////////////////////////////////////////////////////// 77 | 78 | void printUSART(const char *fmt, ...); 79 | 80 | /////////////////////////////////////////////////////////////////////////////// 81 | 82 | void printDirect(const char *fmt, ...); 83 | 84 | /////////////////////////////////////////////////////////////////////////////// 85 | -------------------------------------------------------------------------------- /SRC/drv/drv_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "board.h" 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // Initialize GPIO 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | void gpioInit(void) 44 | { 45 | GPIO_InitTypeDef GPIO_InitStructure; 46 | 47 | GPIO_InitStructure.GPIO_Pin = LED1_PIN; 48 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 49 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 50 | 51 | GPIO_Init(LED1_GPIO, &GPIO_InitStructure); 52 | 53 | GPIO_InitStructure.GPIO_Pin = LED2_PIN; 54 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 55 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 56 | 57 | GPIO_Init(LED2_GPIO, &GPIO_InitStructure); 58 | 59 | LED1_OFF; 60 | LED2_OFF; 61 | } 62 | 63 | /////////////////////////////////////////////////////////////////////////////// 64 | -------------------------------------------------------------------------------- /SRC/drv/drv_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // LED Defines 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | #define LED1_GPIO GPIOB 44 | #define LED1_PIN GPIO_Pin_12 45 | 46 | #define LED2_GPIO GPIOA 47 | #define LED2_PIN GPIO_Pin_3 48 | 49 | /////////////////////////////////////// 50 | 51 | #define LED1_ON GPIO_SetBits(LED1_GPIO, LED1_PIN); 52 | #define LED1_OFF GPIO_ResetBits(LED1_GPIO, LED1_PIN); 53 | #define LED1_TOGGLE GPIO_ToggleBits(LED1_GPIO, LED1_PIN); 54 | 55 | #define LED2_ON GPIO_SetBits(LED2_GPIO, LED2_PIN); 56 | #define LED2_OFF GPIO_ResetBits(LED2_GPIO, LED2_PIN); 57 | #define LED2_TOGGLE GPIO_ToggleBits(LED2_GPIO, LED2_PIN); 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | // Initialize GPIO 61 | /////////////////////////////////////////////////////////////////////////////// 62 | 63 | void gpioInit(void); 64 | 65 | /////////////////////////////////////////////////////////////////////////////// 66 | -------------------------------------------------------------------------------- /SRC/drv/drv_i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | June 2012 3 | 4 | BaseFlightPlus Rev - 5 | 6 | An Open Source STM32 Based Multicopter 7 | 8 | Includes code and/or ideas from: 9 | 10 | 1)AeroQuad 11 | 2)BaseFlight 12 | 3)CH Robotics 13 | 4)MultiWii 14 | 5)S.O.H. Madgwick 15 | 16 | Designed to run on Naze32 Flight Control Board 17 | 18 | This program is free software: you can redistribute it and/or modify 19 | it under the terms of the GNU General Public License as published by 20 | the Free Software Foundation, either version 3 of the License, or 21 | (at your option) any later version. 22 | 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU General Public License for more details. 27 | 28 | You should have received a copy of the GNU General Public License 29 | along with this program. If not, see . 30 | */ 31 | 32 | #pragma once 33 | 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | void i2cInit(I2C_TypeDef *I2Cx); 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | 40 | bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data); 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | 44 | bool i2cWrite(uint8_t addr_, uint8_t reg, uint8_t data); 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | 48 | bool i2cRead(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t *buf); 49 | 50 | /////////////////////////////////////////////////////////////////////////////// 51 | 52 | uint16_t i2cGetErrorCounter(void); 53 | 54 | /////////////////////////////////////////////////////////////////////////////// 55 | -------------------------------------------------------------------------------- /SRC/drv/drv_irq.c: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | 3 | volatile int __irq_nesting_counter; 4 | 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | -------------------------------------------------------------------------------- /SRC/drv/drv_irq.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | 3 | //#pragma once 4 | 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | extern volatile int __irq_nesting_counter; 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | __attribute__((always_inline)) /*__STATIC_INLINE*/ void __disable_irq_nested(void) 12 | { 13 | __disable_irq(); 14 | __irq_nesting_counter++; 15 | } 16 | 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | __attribute__((always_inline)) /*__STATIC_INLINE */void __enable_irq_nested(void) 20 | { 21 | if (--__irq_nesting_counter == 0) 22 | { 23 | __enable_irq(); 24 | } 25 | } 26 | 27 | /////////////////////////////////////////////////////////////////////////////// 28 | 29 | -------------------------------------------------------------------------------- /SRC/drv/drv_pwmMotors.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/drv/drv_pwmMotors.c -------------------------------------------------------------------------------- /SRC/drv/drv_pwmMotors.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | extern int maxCnt[NUMAXIS]; 42 | extern int minCnt[NUMAXIS]; 43 | extern int irqCnt[NUMAXIS]; 44 | 45 | extern int timer4timer5deadTimeDelay; 46 | 47 | /////////////////////////////////////////////////////////////////////////////// 48 | // Initialize PWM Motor Drivers 49 | /////////////////////////////////////////////////////////////////////////////// 50 | 51 | void pwmMotorDriverInit(void); 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | // Set Roll Axis PWM 55 | /////////////////////////////////////////////////////////////////////////////// 56 | 57 | void setRollMotor(float phi, int power); 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | // Set Pitch Axis PWM 61 | /////////////////////////////////////////////////////////////////////////////// 62 | 63 | void setPitchMotor(float theta, int power); 64 | 65 | /////////////////////////////////////////////////////////////////////////////// 66 | // Set Yaw Axis PWM 67 | /////////////////////////////////////////////////////////////////////////////// 68 | 69 | void setYawMotor(float psi, int power); 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | -------------------------------------------------------------------------------- /SRC/drv/drv_rc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/drv/drv_rc.c -------------------------------------------------------------------------------- /SRC/drv/drv_rc.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | 3 | //#pragma once 4 | #include "stm32f10x.h" 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | extern uint8_t rcActive; 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | void rcInit(void); 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | 15 | uint16_t rxRead(uint8_t channel); 16 | 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /SRC/drv/drv_system.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/drv/drv_system.c -------------------------------------------------------------------------------- /SRC/drv/drv_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // Frame Timing Defines and Variables 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | /////////////////////////////////////// 44 | // Frame Timing Defines 45 | /////////////////////////////////////// 46 | 47 | #define FRAME_COUNT 1000 48 | 49 | #define COUNT_500HZ 2 // Number of 1000 Hz frames for 500 Hz Loop 50 | #define COUNT_100HZ 10 // Number of 1000 Hz frames for 100 Hz Loop 51 | #define COUNT_50HZ 20 // Number of 1000 Hz frames for 50 Hz Loop 52 | #define COUNT_10HZ 100 // Number of 1000 Hz frames for 10 Hz Loop 53 | #define COUNT_5HZ 200 // Number of 1000 Hz frames for 5 Hz Loop 54 | #define COUNT_1HZ 1000 // Number of 1000 Hz frames for 1 Hz Loop 55 | 56 | /////////////////////////////////////// 57 | // Frame Timing Variables 58 | /////////////////////////////////////// 59 | 60 | extern uint16_t frameCounter; 61 | 62 | extern semaphore_t frame_500Hz; 63 | extern semaphore_t frame_100Hz; 64 | extern semaphore_t frame_50Hz; 65 | extern semaphore_t frame_10Hz; 66 | extern semaphore_t frame_5Hz; 67 | extern semaphore_t frame_1Hz; 68 | 69 | extern uint32_t deltaTime1000Hz, executionTime1000Hz, previous1000HzTime; 70 | extern uint32_t deltaTime500Hz, executionTime500Hz, previous500HzTime; 71 | extern uint32_t deltaTime100Hz, executionTime100Hz, previous100HzTime; 72 | extern uint32_t deltaTime50Hz, executionTime50Hz, previous50HzTime; 73 | extern uint32_t deltaTime10Hz, executionTime10Hz, previous10HzTime; 74 | extern uint32_t deltaTime5Hz, executionTime5Hz, previous5HzTime; 75 | extern uint32_t deltaTime1Hz, executionTime1Hz, previous1HzTime; 76 | 77 | extern float dt500Hz; 78 | 79 | extern uint8_t systemReady; 80 | 81 | /////////////////////////////////////////////////////////////////////////////// 82 | 83 | #ifdef _DTIMING 84 | void timingSetup(void); 85 | #endif 86 | 87 | /////////////////////////////////////////////////////////////////////////////// 88 | 89 | void systemInit(void); 90 | 91 | /////////////////////////////////////////////////////////////////////////////// 92 | 93 | void delayMicroseconds(uint32_t us); 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | 97 | void delay(uint32_t ms); 98 | 99 | /////////////////////////////////////////////////////////////////////////////// 100 | 101 | uint32_t micros(void); 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | 105 | uint32_t millis(void); 106 | 107 | /////////////////////////////////////////////////////////////////////////////// 108 | 109 | void BKPInit(void); 110 | 111 | /////////////////////////////////////////////////////////////////////////////// 112 | 113 | unsigned long BKPRead(void); 114 | 115 | /////////////////////////////////////////////////////////////////////////////// 116 | 117 | void BKPWrite(unsigned long val); 118 | 119 | /////////////////////////////////////////////////////////////////////////////// 120 | 121 | void reboot(void); 122 | 123 | /////////////////////////////////////////////////////////////////////////////// 124 | 125 | void bootloader(void); 126 | 127 | /////////////////////////////////////////////////////////////////////////////// 128 | -------------------------------------------------------------------------------- /SRC/drv/drv_timingFunctions.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "board.h" 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // Timing Functions Initialization 41 | /////////////////////////////////////////////////////////////////////////////// 42 | #include "stm32f10x.h" 43 | void timingFunctionsInit(void) 44 | { 45 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 46 | 47 | // Output timers 48 | 49 | TIM_TimeBaseStructure.TIM_Period = 0xFFFF; // Just roll over counter at max value 50 | TIM_TimeBaseStructure.TIM_Prescaler = 36 - 1; // 72 MHz / 36 = 2 MHz = 0.5 uSec Tick 51 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; 52 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 53 | TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000; 54 | 55 | TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); 56 | 57 | TIM_SetCounter(TIM6, 4000); // First pass value 58 | } 59 | 60 | /////////////////////////////////////////////////////////////////////////////// 61 | -------------------------------------------------------------------------------- /SRC/drv/drv_timingFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | #pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // Timing Functions Initialization 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | void timingFunctionsInit(void); 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | -------------------------------------------------------------------------------- /SRC/drv/drv_usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usart.h 3 | * 4 | * Created on: Jun 26, 2013 5 | * Author: Denis aka caat 6 | */ 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | #pragma once 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | extern unsigned int IrqCntUart4; 14 | 15 | /////////////////////////////////////////////////////////////////////////////// 16 | 17 | void Usart4Init(void); 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | void USART_PutChar(uint8_t ch); 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | 25 | void USART_PutString(uint8_t *str); 26 | 27 | /////////////////////////////////////////////////////////////////////////////// 28 | 29 | void USART_PutCharDirect(uint8_t ch); 30 | 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | void USART_PutStringDirect(uint8_t *str); 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | void USART_Flush(void); 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | int USART_GetChar(void); 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | int USART_PeekChar(void); 46 | 47 | /////////////////////////////////////////////////////////////////////////////// 48 | 49 | int USART_Available(void); 50 | 51 | /////////////////////////////////////////////////////////////////////////////// 52 | 53 | void InitUart4Buffer(void); 54 | 55 | /////////////////////////////////////////////////////////////////////////////// 56 | 57 | void TestUart4Buffer(void); 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | 61 | void UART4_IRQHandler(void); 62 | 63 | /////////////////////////////////////////////////////////////////////////////// 64 | -------------------------------------------------------------------------------- /SRC/drv/ringbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ringbuffer.c 3 | * 4 | * Created on: Aug 1, 2013 5 | * Author: ala42 6 | */ 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | #include "board.h" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | void RingBufferInit(tRingBuffer *rb, void (*callback)(void)) 14 | { 15 | rb->Read = 0; 16 | rb->Write = 0; 17 | rb->Overrun = 0; 18 | rb->CallBack = callback; 19 | } 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | 23 | int RingBufferSize(tRingBuffer *rb) 24 | { 25 | return sizeof(rb->Buffer); 26 | } 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | 30 | int RingBufferFillLevel(tRingBuffer *rb) 31 | { 32 | return (rb->Write - rb->Read + RingBufferSize(rb)) % RingBufferSize(rb); 33 | } 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | void RingBufferPut(tRingBuffer *rb, unsigned char c, int block) 38 | { 39 | if (block) 40 | { 41 | while (RingBufferFillLevel(rb) + 1 == RingBufferSize(rb)) 42 | { 43 | // wait 44 | } 45 | } 46 | else 47 | { 48 | if (RingBufferFillLevel(rb) + 1 == RingBufferSize(rb)) 49 | { 50 | rb->Overrun++; 51 | return; 52 | } 53 | } 54 | 55 | rb->Buffer[rb->Write] = c; 56 | 57 | if (rb->Write + 1 == RingBufferSize(rb)) 58 | { 59 | rb->Write = 0; 60 | } 61 | 62 | else 63 | { 64 | rb->Write++; 65 | } 66 | 67 | if (rb->CallBack) 68 | { 69 | rb->CallBack(); 70 | } 71 | } 72 | 73 | /////////////////////////////////////////////////////////////////////////////// 74 | 75 | void RingBufferPutBlock(tRingBuffer *rb, unsigned char *data, int dataLen, int block) 76 | { 77 | 78 | int free1; 79 | 80 | 81 | if (block) 82 | { 83 | while (RingBufferFillLevel(rb) + dataLen >= RingBufferSize(rb)) 84 | { 85 | // wait 86 | } 87 | } 88 | else 89 | { 90 | if (RingBufferFillLevel(rb) + dataLen >= RingBufferSize(rb)) 91 | { 92 | rb->Overrun += dataLen; 93 | 94 | if (rb->CallBack) 95 | { 96 | rb->CallBack(); 97 | } 98 | 99 | return; 100 | } 101 | } 102 | 103 | free1 = RingBufferSize(rb) - rb->Write; 104 | 105 | if (dataLen <= free1) 106 | { 107 | memcpy(rb->Buffer + rb->Write, data, dataLen); 108 | 109 | if (rb->Write + dataLen == RingBufferSize(rb)) 110 | { 111 | rb->Write = 0; 112 | } 113 | 114 | else 115 | { 116 | rb->Write += dataLen; 117 | } 118 | } 119 | 120 | else 121 | { 122 | 123 | int len2; 124 | memcpy(rb->Buffer + rb->Write, data, free1); 125 | len2 = dataLen - free1; 126 | memcpy(rb->Buffer, data + free1, len2); 127 | rb->Write = len2; 128 | } 129 | 130 | if (rb->CallBack) 131 | { 132 | rb->CallBack(); 133 | } 134 | } 135 | 136 | /////////////////////////////////////////////////////////////////////////////// 137 | 138 | int RingBufferGet(tRingBuffer *rb) 139 | { 140 | if (rb->Read == rb->Write) 141 | { 142 | return -1; 143 | } 144 | 145 | else 146 | { 147 | int c = rb->Buffer[rb->Read]; 148 | 149 | if (rb->Read + 1 == RingBufferSize(rb)) 150 | { 151 | rb->Read = 0; 152 | } 153 | 154 | else 155 | { 156 | rb->Read++; 157 | } 158 | 159 | return c; 160 | } 161 | } 162 | 163 | /////////////////////////////////////////////////////////////////////////////// 164 | 165 | int RingBufferPeek(tRingBuffer *rb) 166 | { 167 | if (rb->Read == rb->Write) 168 | { 169 | return -1; 170 | } 171 | 172 | else 173 | { 174 | int c = rb->Buffer[rb->Read]; 175 | 176 | return c; 177 | } 178 | } 179 | 180 | /////////////////////////////////////////////////////////////////////////////// 181 | 182 | -------------------------------------------------------------------------------- /SRC/drv/ringbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ringbuffer.h 3 | * 4 | * Created on: Aug 1, 2013 5 | * Author: ala42 6 | */ 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | 10 | #pragma once 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | typedef struct 15 | { 16 | volatile int Read, Write, Overrun; 17 | unsigned char Buffer[1024]; 18 | void (*CallBack)(void); 19 | 20 | } tRingBuffer; 21 | 22 | /////////////////////////////////////////////////////////////////////////////// 23 | 24 | void RingBufferInit(tRingBuffer *rb, void (*callback)(void)); 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | 28 | int RingBufferSize(tRingBuffer *rb); 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | int RingBufferFillLevel(tRingBuffer *rb); 33 | 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | void RingBufferPut(tRingBuffer *rb, unsigned char c, int block); 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | 40 | void RingBufferPutBlock(tRingBuffer *rb, unsigned char *data, int dataLen, int block); 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | 44 | int RingBufferGet(tRingBuffer *rb); 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | 48 | int RingBufferPeek(tRingBuffer *rb); 49 | 50 | /////////////////////////////////////////////////////////////////////////////// 51 | -------------------------------------------------------------------------------- /SRC/evvgcCF.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/evvgcCF.c -------------------------------------------------------------------------------- /SRC/evvgcCF.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | 3 | #pragma once 4 | 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | extern float accAngleSmooth[3]; 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | void initOrientation(void); 12 | void getOrientation(float *smoothAcc, float *orient, float *accData, float *gyroData, float dt); 13 | 14 | /////////////////////////////////////////////////////////////////////////////// 15 | -------------------------------------------------------------------------------- /SRC/fastTrig.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | /* 37 | * fasttrig.c 38 | * 39 | * Created on: Aug 10, 2013 40 | * Author: ala42 41 | */ 42 | #include "board.h" 43 | 44 | 45 | short int sinDataI16[SINARRAYSIZE]; 46 | 47 | void initSinArray(void) 48 | { 49 | int i; 50 | 51 | for (i = 0; i < SINARRAYSIZE; i++) 52 | { 53 | float x = i * M_TWOPI / SINARRAYSIZE; 54 | sinDataI16[i] = (short int)round(sinf(x) * SINARRAYSCALE); 55 | } 56 | } 57 | 58 | float fastSin(float x) 59 | { 60 | if (x >= 0) 61 | { 62 | int ix = ((int)(x / M_TWOPI * (float)SINARRAYSIZE)) % SINARRAYSIZE; 63 | return sinDataI16[ix] / (float)SINARRAYSCALE; 64 | } 65 | 66 | else 67 | { 68 | int ix = ((int)(-x / M_TWOPI * (float)SINARRAYSIZE)) % SINARRAYSIZE; 69 | return -sinDataI16[ix] / (float)SINARRAYSCALE; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /SRC/fastTrig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | /* 37 | * fasttrig.h 38 | * 39 | * Created on: Aug 10, 2013 40 | * Author: ala42 41 | */ 42 | 43 | #ifndef FASTTRIG_H_ 44 | #define FASTTRIG_H_ 45 | 46 | //#include 47 | #define SINARRAYSIZE 1024 48 | #define SINARRAYSCALE 32767 49 | 50 | extern short int sinDataI16[]; 51 | void initSinArray(void); 52 | float fastSin(float x); 53 | 54 | #endif /* FASTTRIG_H_ */ 55 | -------------------------------------------------------------------------------- /SRC/firstOrderFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | #ifndef __FIRSTORDERFILTER_H_ 41 | 42 | #define __FIRSTORDERFILTER_H_ 43 | 44 | 45 | 46 | 47 | #define NUMBER_OF_FIRST_ORDER_FILTERS 9 48 | 49 | #define ACCEL_X_500HZ_LOWPASS 0 50 | #define ACCEL_Y_500HZ_LOWPASS 1 51 | #define ACCEL_Z_500HZ_LOWPASS 2 52 | 53 | #define ROLL_RATE_POINTING_50HZ_LOWPASS 3 54 | #define PITCH_RATE_POINTING_50HZ_LOWPASS 4 55 | #define YAW_RATE_POINTING_50HZ_LOWPASS 5 56 | 57 | #define ROLL_ATT_POINTING_50HZ_LOWPASS 6 58 | #define PITCH_ATT_POINTING_50HZ_LOWPASS 7 59 | #define YAW_ATT_POINTING_50HZ_LOWPASS 8 60 | 61 | /////////////////////////////////////////////////////////////////////////////// 62 | 63 | typedef struct firstOrderFilterData 64 | { 65 | float gx1; 66 | float gx2; 67 | float gx3; 68 | float previousInput; 69 | float previousOutput; 70 | } firstOrderFilterData_t; 71 | 72 | extern firstOrderFilterData_t firstOrderFilters[NUMBER_OF_FIRST_ORDER_FILTERS]; 73 | 74 | /////////////////////////////////////////////////////////////////////////////// 75 | 76 | void initFirstOrderFilter(void); 77 | 78 | /////////////////////////////////////////////////////////////////////////////// 79 | 80 | float firstOrderFilter(float input, struct firstOrderFilterData *filterParameters); 81 | 82 | /////////////////////////////////////////////////////////////////////////////// 83 | #endif 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /SRC/pid.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/pid.c -------------------------------------------------------------------------------- /SRC/pid.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | #include "stm32f10x.h" 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | #define OTHER false 42 | #define ANGULAR true 43 | 44 | #define D_ERROR true 45 | #define D_STATE false 46 | 47 | // PID Variables 48 | typedef struct PIDdata 49 | { 50 | float B, P, I, D; 51 | float iTerm; 52 | float windupGuard; 53 | float lastDcalcValue; 54 | float lastDterm; 55 | float lastLastDterm; 56 | uint8_t dErrorCalc; 57 | uint8_t type; 58 | } PIDdata_t; 59 | 60 | extern uint8_t holdIntegrators; 61 | 62 | /////////////////////////////////////////////////////////////////////////////// 63 | 64 | void initPID(void); 65 | 66 | /////////////////////////////////////////////////////////////////////////////// 67 | 68 | float updatePID(float command, float state, float deltaT, uint8_t iHold, struct PIDdata *PIDparameters); 69 | 70 | /////////////////////////////////////////////////////////////////////////////// 71 | 72 | void setPIDintegralError(uint8_t IDPid, float value); 73 | 74 | /////////////////////////////////////////////////////////////////////////////// 75 | 76 | void zeroPIDintegralError(void); 77 | 78 | /////////////////////////////////////////////////////////////////////////////// 79 | 80 | void setPIDstates(uint8_t IDPid, float value); 81 | 82 | /////////////////////////////////////////////////////////////////////////////// 83 | 84 | void zeroPIDstates(void); 85 | 86 | /////////////////////////////////////////////////////////////////////////////// 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /SRC/pointingCommands.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/pointingCommands.c -------------------------------------------------------------------------------- /SRC/pointingCommands.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | // Process Pilot Commands Defines and Variables 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | #define DEADBAND 24 44 | #define DEADBAND_SLOPE (1000/(1000-DEADBAND)) 45 | 46 | extern float pointingCmd[3]; 47 | 48 | extern float rxCommand[3]; 49 | 50 | /////////////////////////////////////////////////////////////////////////////// 51 | // Process Pointing Commands 52 | /////////////////////////////////////////////////////////////////////////////// 53 | 54 | void processPointingCommands(void); 55 | 56 | /////////////////////////////////////////////////////////////////////////////// 57 | -------------------------------------------------------------------------------- /SRC/sensors/hmc5883.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | #include "stm32f10x.h" 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | 42 | 43 | extern float magScaleFactor[3]; 44 | 45 | extern uint8_t magDataUpdate; 46 | 47 | extern uint8_t newMagData; 48 | 49 | extern int16andUint8_t rawMag[3]; 50 | 51 | /////////////////////////////////////////////////////////////////////////////// 52 | 53 | uint8_t readMag(void); 54 | 55 | /////////////////////////////////////////////////////////////////////////////// 56 | 57 | void initMag(void); 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | -------------------------------------------------------------------------------- /SRC/sensors/mpu6050.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/SRC/sensors/mpu6050.c -------------------------------------------------------------------------------- /SRC/sensors/mpu6050.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | //#pragma once 38 | #include "stm32f10x.h" 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | #define MPU6050_ADDRESS 0x68 42 | 43 | #define MPU6050_CONFIG 0x1A 44 | 45 | #define BITS_DLPF_CFG_256HZ 0x00 46 | #define BITS_DLPF_CFG_188HZ 0x01 47 | #define BITS_DLPF_CFG_98HZ 0x02 48 | #define BITS_DLPF_CFG_42HZ 0x03 49 | 50 | #define ACCEL_SCALE_FACTOR 0.00119708f // (1/8192) * 9.8065 (8192 LSB = 1 G) 51 | #define GYRO_SCALE_FACTOR 0.00026646f // (1/65.5) * pi/180 (65.5 LSB = 1 DPS) 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | // MPU6050 Variables 55 | /////////////////////////////////////////////////////////////////////////////// 56 | 57 | extern float accelOneG; 58 | 59 | extern float accelTCBias[3]; 60 | 61 | extern int16_t accelData500Hz[3]; 62 | 63 | extern int16andUint8_t rawAccel[3]; 64 | 65 | /////////////////////////////////////// 66 | 67 | extern float gyroRTBias[3]; 68 | 69 | extern float gyroTCBias[3]; 70 | 71 | extern int16_t gyroData500Hz[3]; 72 | 73 | extern int16andUint8_t rawGyro[3]; 74 | 75 | /////////////////////////////////////// 76 | 77 | extern uint8_t mpu6050Calibrating; 78 | 79 | extern float mpu6050Temperature; 80 | 81 | extern int16andUint8_t rawMPU6050Temperature; 82 | 83 | /////////////////////////////////////////////////////////////////////////////// 84 | // MPU6050 Initialization 85 | /////////////////////////////////////////////////////////////////////////////// 86 | 87 | void initMPU6050(void); 88 | 89 | /////////////////////////////////////////////////////////////////////////////// 90 | // Read MPU6050 91 | /////////////////////////////////////////////////////////////////////////////// 92 | 93 | void readMPU6050(void); 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | // Compute MPU6050 Runtime Data 97 | /////////////////////////////////////////////////////////////////////////////// 98 | 99 | void computeMPU6050RTData(void); 100 | 101 | /////////////////////////////////////////////////////////////////////////////// 102 | // Compute MPU6050 Temperature Compensation Bias 103 | /////////////////////////////////////////////////////////////////////////////// 104 | 105 | void computeMPU6050TCBias(void); 106 | 107 | /////////////////////////////////////////////////////////////////////////////// 108 | // Orient IMU 109 | /////////////////////////////////////////////////////////////////////////////// 110 | 111 | void orientIMU(void); 112 | 113 | /////////////////////////////////////////////////////////////////////////////// 114 | -------------------------------------------------------------------------------- /SRC/stm32_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_it.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32_IT_H 31 | #define __STM32_IT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "platform_config.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | /* Exported macro ------------------------------------------------------------*/ 39 | /* Exported functions ------------------------------------------------------- */ 40 | 41 | void NMI_Handler(void); 42 | void HardFault_Handler(void); 43 | void MemManage_Handler(void); 44 | void BusFault_Handler(void); 45 | void UsageFault_Handler(void); 46 | void SVC_Handler(void); 47 | void DebugMon_Handler(void); 48 | void PendSV_Handler(void); 49 | void SysTick_Handler(void); 50 | //void USBWakeUp_IRQHandler(void); 51 | //void USB_FS_WKUP_IRQHandler(void); 52 | 53 | #endif /* __STM32_IT_H */ 54 | 55 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 56 | -------------------------------------------------------------------------------- /SRC/utilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | Sept 2013 3 | 4 | bgc32 Rev - 5 | 6 | Copyright (c) 2013 John Ihlein. All rights reserved. 7 | 8 | Open Source STM32 Based Brushless Gimbal Controller Software 9 | 10 | Includes code and/or ideas from: 11 | 12 | 1)AeroQuad 13 | 2)BaseFlight 14 | 3)CH Robotics 15 | 4)MultiWii 16 | 5)S.O.H. Madgwick 17 | 6)UAVX 18 | 19 | Designed to run on the EvvGC Brushless Gimbal Controller Board 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | */ 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | #include "stm32f10x.h" 37 | //#pragma once 38 | 39 | #ifdef _DTIMING 40 | #define LA2_ENABLE GPIO_SetBits(GPIOC, GPIO_Pin_2) 41 | #define LA2_DISABLE GPIO_ResetBits(GPIOC, GPIO_Pin_2) 42 | #define LA1_ENABLE GPIO_SetBits(GPIOC, GPIO_Pin_3) 43 | #define LA1_DISABLE GPIO_ResetBits(GPIOC, GPIO_Pin_3) 44 | #endif 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | // Constrain 48 | /////////////////////////////////////////////////////////////////////////////// 49 | 50 | float constrain(float input, float minValue, float maxValue); 51 | 52 | //////////////////////////////////////////////////////////////////////////////// 53 | // Matrix Multiply 54 | // Multiply matrix A times matrix B, matrix A dimension m x n, matrix B dimension n x p 55 | // Result placed in matrix C, dimension m x p 56 | // 57 | // Call as: matrixMultiply(m, n, p, C, A, B) 58 | //////////////////////////////////////////////////////////////////////////////// 59 | 60 | void matrixMultiply(uint8_t aRows, uint8_t aCols_bRows, uint8_t bCols, int16_t matrixC[], int16_t matrixA[], int16_t matrixB[]); 61 | 62 | /////////////////////////////////////////////////////////////////////////////// 63 | // Round 64 | /////////////////////////////////////////////////////////////////////////////// 65 | 66 | float Round(float x); 67 | 68 | /////////////////////////////////////////////////////////////////////////////// 69 | // Least Squares Fit a Sphere to 3D Data 70 | //////////////////////////////////////////////////////////////////////////////// 71 | 72 | // Least squares fit a sphere to 3D data, ImaginaryZ's blog, 73 | // Miscellaneous banter, Useful mathematics, game programming 74 | // tools and the occasional kink or two. 75 | // 22 April 2011. 76 | // http: imaginaryz.blogspot.com.au/2011/04/least-squares-fit-sphere-to-3d-data.html 77 | 78 | // Substantially rewritten for UAVXArm by Prof. G.K. Egan (C) 2012. 79 | 80 | // Incorporated into AQ32Plus by J. Ihlein (C) 2012. 81 | 82 | uint16_t sphereFit(float d[][3], 83 | uint16_t N, 84 | uint16_t MaxIterations, 85 | float Err, 86 | uint16_t Population[][3], 87 | float SphereOrigin[], 88 | float *SphereRadius); 89 | 90 | /////////////////////////////////////////////////////////////////////////////// 91 | // _sbrk 92 | /////////////////////////////////////////////////////////////////////////////// 93 | 94 | /* 95 | * newlib_stubs.c 96 | * 97 | * Created on: 2 Nov 2010 98 | * Author: nanoage.co.uk 99 | */ 100 | 101 | /* 102 | sbrk 103 | Increase program data space. 104 | Malloc and related functions depend on this 105 | */ 106 | 107 | /*caddr_t*/int _sbrk(int incr); 108 | 109 | /////////////////////////////////////////////////////////////////////////////// 110 | // Standard Radian Format Limiter 111 | //////////////////////////////////////////////////////////////////////////////// 112 | 113 | float standardRadianFormat(float angle); 114 | 115 | //////////////////////////////////////////////////////////////////////////////// 116 | // String to Float Conversion 117 | //////////////////////////////////////////////////////////////////////////////// 118 | 119 | float stringToFloat(const uint8_t *p); 120 | -------------------------------------------------------------------------------- /SRC/vcp/hw_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hw_config.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Hardware Configuration & Setup 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __HW_CONFIG_H 31 | #define __HW_CONFIG_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "platform_config.h" 35 | #include "usb_type.h" 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* Exported macro ------------------------------------------------------------*/ 40 | /* Exported define -----------------------------------------------------------*/ 41 | #define MASS_MEMORY_START 0x04002000 42 | #define BULK_MAX_PACKET_SIZE 0x00000040 43 | 44 | /* Exported functions ------------------------------------------------------- */ 45 | void Set_System(void); 46 | void Set_USBClock(void); 47 | void Enter_LowPowerMode(void); 48 | void Leave_LowPowerMode(void); 49 | void USB_Interrupts_Config(void); 50 | //void USB_Cable_Config(FunctionalState NewState); 51 | void Get_SerialNum(void); 52 | uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, int sendLength); // HJI 53 | uint32_t CDC_Receive_DATA(uint8_t *recvBuf, uint32_t len); // HJI 54 | uint8_t usbIsConfigured(void); // HJI 55 | uint8_t usbIsConnected(void); // HJI 56 | 57 | typedef enum 58 | { 59 | eVCPConnectReset, 60 | eVCPConnectData, 61 | eVCPConnectNoData 62 | } tVCPConnectMode; 63 | 64 | void SetVCPConnectMode(tVCPConnectMode mode); 65 | 66 | tVCPConnectMode GetVCPConnectMode(void); 67 | 68 | /* External variables --------------------------------------------------------*/ 69 | 70 | extern __IO uint32_t receiveLength; // HJI 71 | extern __IO uint32_t packetSent; // HJI 72 | 73 | #endif /*__HW_CONFIG_H*/ 74 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 75 | -------------------------------------------------------------------------------- /SRC/vcp/platform_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file platform_config.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Evaluation board specific configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __PLATFORM_CONFIG_H 31 | #define __PLATFORM_CONFIG_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #if defined (STM32F10X_MD) || defined (STM32F10X_HD) 35 | #include "stm32f10x.h" 36 | #elif defined (STM32F30X) 37 | #include "stm32f30x.h" 38 | #endif 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | /* Exported constants --------------------------------------------------------*/ 42 | 43 | /*Unique Devices IDs register set*/ 44 | 45 | #if defined (STM32F37X) || defined(STM32F30X) 46 | 47 | #define ID1 (0x1FFFF7AC) 48 | #define ID2 (0x1FFFF7B0) 49 | #define ID3 (0x1FFFF7B4) 50 | 51 | #else /*STM32F1x*/ 52 | 53 | #define ID1 (0x1FFFF7E8) 54 | #define ID2 (0x1FFFF7EC) 55 | #define ID3 (0x1FFFF7F0) 56 | 57 | #endif 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions ------------------------------------------------------- */ 61 | 62 | #endif /* __PLATFORM_CONFIG_H */ 63 | 64 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 65 | -------------------------------------------------------------------------------- /SRC/vcp/usb_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_conf.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Virtual COM Port Demo configuration header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_CONF_H 31 | #define __USB_CONF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | /* External variables --------------------------------------------------------*/ 39 | 40 | /*-------------------------------------------------------------*/ 41 | /* EP_NUM */ 42 | /* defines how many endpoints are used by the device */ 43 | /*-------------------------------------------------------------*/ 44 | 45 | #define EP_NUM (4) 46 | 47 | /*-------------------------------------------------------------*/ 48 | /* -------------- Buffer Description Table -----------------*/ 49 | /*-------------------------------------------------------------*/ 50 | /* buffer table base address */ 51 | /* buffer table base address */ 52 | #define BTABLE_ADDRESS (0x00) 53 | 54 | /* EP0 */ 55 | /* rx/tx buffer base address */ 56 | #define ENDP0_RXADDR (0x40) 57 | #define ENDP0_TXADDR (0x80) 58 | 59 | /* EP1 */ 60 | /* tx buffer base address */ 61 | #define ENDP1_TXADDR (0xC0) 62 | #define ENDP2_TXADDR (0x100) 63 | #define ENDP3_RXADDR (0x110) 64 | 65 | 66 | /*-------------------------------------------------------------*/ 67 | /* ------------------- ISTR events -------------------------*/ 68 | /*-------------------------------------------------------------*/ 69 | /* IMR_MSK */ 70 | /* mask defining which events has to be handled */ 71 | /* by the device application software */ 72 | // HJI #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM | CNTR_ESOFM | CNTR_RESETM ) 73 | 74 | // Disable Suspend/Resume response completely // HJI 75 | #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_ERRM | CNTR_SOFM | CNTR_RESETM ) // HJI 76 | 77 | /*#define CTR_CALLBACK*/ 78 | /*#define DOVR_CALLBACK*/ 79 | #define ERR_CALLBACK 80 | /*#define WKUP_CALLBACK*/ 81 | /*#define SUSP_CALLBACK*/ 82 | /*#define RESET_CALLBACK*/ 83 | /*#define SOF_CALLBACK*/ 84 | /*#define ESOF_CALLBACK*/ 85 | /* CTR service routines */ 86 | /* associated to defined endpoints */ 87 | /*#define EP1_IN_Callback NOP_Process*/ 88 | #define EP2_IN_Callback NOP_Process 89 | #define EP3_IN_Callback NOP_Process 90 | #define EP4_IN_Callback NOP_Process 91 | #define EP5_IN_Callback NOP_Process 92 | #define EP6_IN_Callback NOP_Process 93 | #define EP7_IN_Callback NOP_Process 94 | 95 | #define EP1_OUT_Callback NOP_Process 96 | #define EP2_OUT_Callback NOP_Process 97 | /*#define EP3_OUT_Callback NOP_Process*/ 98 | #define EP4_OUT_Callback NOP_Process 99 | #define EP5_OUT_Callback NOP_Process 100 | #define EP6_OUT_Callback NOP_Process 101 | #define EP7_OUT_Callback NOP_Process 102 | 103 | #endif /* __USB_CONF_H */ 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /SRC/vcp/usb_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Descriptor Header for Virtual COM Port Device 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_DESC_H 31 | #define __USB_DESC_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported define -----------------------------------------------------------*/ 38 | #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 39 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 40 | #define USB_STRING_DESCRIPTOR_TYPE 0x03 41 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 42 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 43 | 44 | #define VIRTUAL_COM_PORT_DATA_SIZE 64 45 | #define VIRTUAL_COM_PORT_INT_SIZE 8 46 | 47 | #define VIRTUAL_COM_PORT_SIZ_DEVICE_DESC 18 48 | #define VIRTUAL_COM_PORT_SIZ_CONFIG_DESC 67 49 | #define VIRTUAL_COM_PORT_SIZ_STRING_LANGID 4 50 | #define VIRTUAL_COM_PORT_SIZ_STRING_VENDOR 38 51 | #define VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT 50 52 | #define VIRTUAL_COM_PORT_SIZ_STRING_SERIAL 26 53 | 54 | #define STANDARD_ENDPOINT_DESC_SIZE 0x09 55 | 56 | /* Exported functions ------------------------------------------------------- */ 57 | extern const uint8_t Virtual_Com_Port_DeviceDescriptor[VIRTUAL_COM_PORT_SIZ_DEVICE_DESC]; 58 | extern const uint8_t Virtual_Com_Port_ConfigDescriptor[VIRTUAL_COM_PORT_SIZ_CONFIG_DESC]; 59 | 60 | extern const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID]; 61 | extern const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR]; 62 | extern const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT]; 63 | extern uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL]; 64 | 65 | #endif /* __USB_DESC_H */ 66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 67 | -------------------------------------------------------------------------------- /SRC/vcp/usb_endp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_endp.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Endpoint routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_desc.h" 32 | #include "usb_mem.h" 33 | #include "hw_config.h" 34 | #include "usb_istr.h" 35 | #include "usb_pwr.h" 36 | 37 | /* Private typedef -----------------------------------------------------------*/ 38 | /* Private define ------------------------------------------------------------*/ 39 | 40 | /* Interval between sending IN packets in frame number (1 frame = 1ms) */ 41 | #define VCOMPORT_IN_FRAME_INTERVAL 5 42 | /* Private macro -------------------------------------------------------------*/ 43 | /* Private variables ---------------------------------------------------------*/ 44 | extern __IO uint32_t packetSent; // HJI 45 | extern __IO uint8_t receiveBuffer[64]; // HJI 46 | __IO uint32_t receiveLength; // HJI 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* Private functions ---------------------------------------------------------*/ 49 | 50 | /******************************************************************************* 51 | * Function Name : EP1_IN_Callback 52 | * Description : 53 | * Input : None. 54 | * Output : None. 55 | * Return : None. 56 | *******************************************************************************/ 57 | void EP1_IN_Callback(void) __attribute__((weak)); //ala42 58 | void EP1_IN_Callback(void) 59 | { 60 | packetSent = 0; // HJI 61 | } 62 | 63 | /******************************************************************************* 64 | * Function Name : EP3_OUT_Callback 65 | * Description : 66 | * Input : None. 67 | * Output : None. 68 | * Return : None. 69 | *******************************************************************************/ 70 | void EP3_OUT_Callback(void) 71 | { 72 | receiveLength = GetEPRxCount(ENDP3); // HJI 73 | PMAToUserBufferCopy((unsigned char *)receiveBuffer, ENDP3_RXADDR, receiveLength); // HJI 74 | } 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /SRC/vcp/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_ISTR_H 31 | #define __USB_ISTR_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usb_conf.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* Exported constants --------------------------------------------------------*/ 38 | /* Exported macro ------------------------------------------------------------*/ 39 | /* Exported functions ------------------------------------------------------- */ 40 | 41 | void USB_Istr(void); 42 | 43 | /* function prototypes Automatically built defining related macros */ 44 | 45 | void EP1_IN_Callback(void); 46 | void EP2_IN_Callback(void); 47 | void EP3_IN_Callback(void); 48 | void EP4_IN_Callback(void); 49 | void EP5_IN_Callback(void); 50 | void EP6_IN_Callback(void); 51 | void EP7_IN_Callback(void); 52 | 53 | void EP1_OUT_Callback(void); 54 | void EP2_OUT_Callback(void); 55 | void EP3_OUT_Callback(void); 56 | void EP4_OUT_Callback(void); 57 | void EP5_OUT_Callback(void); 58 | void EP6_OUT_Callback(void); 59 | void EP7_OUT_Callback(void); 60 | 61 | #ifdef CTR_CALLBACK 62 | void CTR_Callback(void); 63 | #endif 64 | 65 | #ifdef DOVR_CALLBACK 66 | void DOVR_Callback(void); 67 | #endif 68 | 69 | #ifdef ERR_CALLBACK 70 | void ERR_Callback(void); 71 | #endif 72 | 73 | #ifdef WKUP_CALLBACK 74 | void WKUP_Callback(void); 75 | #endif 76 | 77 | #ifdef SUSP_CALLBACK 78 | void SUSP_Callback(void); 79 | #endif 80 | 81 | #ifdef RESET_CALLBACK 82 | void RESET_Callback(void); 83 | #endif 84 | 85 | #ifdef SOF_CALLBACK 86 | void SOF_Callback(void); 87 | #endif 88 | 89 | #ifdef ESOF_CALLBACK 90 | void ESOF_Callback(void); 91 | #endif 92 | #endif /*__USB_ISTR_H*/ 93 | 94 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /SRC/vcp/usb_prop.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_prop.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief All processing related to Virtual COM Port Demo (Endpoint 0) 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __usb_prop_H 31 | #define __usb_prop_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | typedef struct 36 | { 37 | uint32_t bitrate; 38 | uint8_t format; 39 | uint8_t paritytype; 40 | uint8_t datatype; 41 | } LINE_CODING; 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* Exported define -----------------------------------------------------------*/ 46 | 47 | #define Virtual_Com_Port_GetConfiguration NOP_Process 48 | //#define Virtual_Com_Port_SetConfiguration NOP_Process 49 | #define Virtual_Com_Port_GetInterface NOP_Process 50 | #define Virtual_Com_Port_SetInterface NOP_Process 51 | #define Virtual_Com_Port_GetStatus NOP_Process 52 | #define Virtual_Com_Port_ClearFeature NOP_Process 53 | #define Virtual_Com_Port_SetEndPointFeature NOP_Process 54 | #define Virtual_Com_Port_SetDeviceFeature NOP_Process 55 | //#define Virtual_Com_Port_SetDeviceAddress NOP_Process 56 | 57 | #define SEND_ENCAPSULATED_COMMAND 0x00 58 | #define GET_ENCAPSULATED_RESPONSE 0x01 59 | #define SET_COMM_FEATURE 0x02 60 | #define GET_COMM_FEATURE 0x03 61 | #define CLEAR_COMM_FEATURE 0x04 62 | #define SET_LINE_CODING 0x20 63 | #define GET_LINE_CODING 0x21 64 | #define SET_CONTROL_LINE_STATE 0x22 65 | #define SEND_BREAK 0x23 66 | 67 | /* Exported functions ------------------------------------------------------- */ 68 | void Virtual_Com_Port_init(void); 69 | void Virtual_Com_Port_Reset(void); 70 | void Virtual_Com_Port_SetConfiguration(void); 71 | void Virtual_Com_Port_SetDeviceAddress(void); 72 | void Virtual_Com_Port_Status_In(void); 73 | void Virtual_Com_Port_Status_Out(void); 74 | RESULT Virtual_Com_Port_Data_Setup(uint8_t); 75 | RESULT Virtual_Com_Port_NoData_Setup(uint8_t); 76 | RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting); 77 | uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t); 78 | uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t); 79 | uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t); 80 | 81 | uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length); 82 | uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length); 83 | 84 | #endif /* __usb_prop_H */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | 88 | -------------------------------------------------------------------------------- /SRC/vcp/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_PWR_H 31 | #define __USB_PWR_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | typedef enum _RESUME_STATE 36 | { 37 | RESUME_EXTERNAL, 38 | RESUME_INTERNAL, 39 | RESUME_LATER, 40 | RESUME_WAIT, 41 | RESUME_START, 42 | RESUME_ON, 43 | RESUME_OFF, 44 | RESUME_ESOF 45 | } RESUME_STATE; 46 | 47 | typedef enum _DEVICE_STATE 48 | { 49 | UNCONNECTED, 50 | ATTACHED, 51 | POWERED, 52 | SUSPENDED, 53 | ADDRESSED, 54 | CONFIGURED 55 | } DEVICE_STATE; 56 | 57 | /* Exported constants --------------------------------------------------------*/ 58 | /* Exported macro ------------------------------------------------------------*/ 59 | /* Exported functions ------------------------------------------------------- */ 60 | void Suspend(void); 61 | void Resume_Init(void); 62 | void Resume(RESUME_STATE eResumeSetVal); 63 | RESULT PowerOn(void); 64 | RESULT PowerOff(void); 65 | 66 | /* External variables --------------------------------------------------------*/ 67 | extern __IO uint32_t bDeviceState; /* USB device status */ 68 | extern __IO boolean fSuspendEnabled; /* true when suspend is possible */ // HJI 69 | 70 | #endif /*__USB_PWR_H*/ 71 | 72 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 73 | -------------------------------------------------------------------------------- /USER/JLink Regs CM3.txt: -------------------------------------------------------------------------------- 1 | 0: R0: 0x00 2 | 1: R1: 0x01 3 | 2: R2: 0x02 4 | 3: R3: 0x03 5 | 4: R4: 0x04 6 | 5: R5: 0x05 7 | 6: R6: 0x06 8 | 7: R7: 0x07 9 | 8: R8: 0x08 10 | 9: R9: 0x09 11 | 10: R10: 0x0a 12 | 11: R11: 0x0b 13 | 12: R12: 0x0c 14 | 13: R13: 0x0d 15 | 14: R14: 0x0e 16 | 15: R15: 0x0f 17 | 16: XPSR: 0x10 18 | 17: MSP: 0x11 19 | 18: PSP: 0x12 20 | 19: RAZ: 0x13 21 | 20: CFBP: 0x14 22 | 21: APSR: 0x15 23 | 22: EPSR: 0x16 24 | 23: IPSR: 0x17 25 | 24: PRIMASK: 0x18 26 | 25: BASEPRI: 0x19 27 | 26: FAULTMASK: 0x1a 28 | 27: CONTROL: 0x1b 29 | 28: BASEPRI_MAX: 0x1c 30 | 29: IAPSR: 0x1d 31 | 30: EAPSR: 0x1e 32 | 31: IEPSR: 0x1f 33 | -------------------------------------------------------------------------------- /USER/JLinkSettings.ini: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ShowInfoWin = 1 3 | EnableFlashBP = 2 4 | BPDuringExecution = 0 5 | [CFI] 6 | CFISize = 0x00 7 | CFIAddr = 0x00 8 | [CPU] 9 | OverrideMemMap = 0 10 | AllowSimulation = 1 11 | ScriptFile="" 12 | [FLASH] 13 | SkipProgOnCRCMatch = 1 14 | VerifyDownload = 1 15 | AllowCaching = 1 16 | EnableFlashDL = 2 17 | Override = 0 18 | Device="ADUC7020X62" 19 | [GENERAL] 20 | WorkRAMSize = 0x00 21 | WorkRAMAddr = 0x00 22 | [SWO] 23 | SWOLogFile="" 24 | -------------------------------------------------------------------------------- /USER/RTE/_USART1-DEMO/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'STM32-DEMO' 7 | * Target: 'USART1-DEMO' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | 20 | #endif /* RTE_COMPONENTS_H */ 21 | -------------------------------------------------------------------------------- /USER/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/USER/main.c -------------------------------------------------------------------------------- /USER/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CONF_H 24 | #define __STM32F10x_CONF_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ 28 | #include "stm32f10x_adc.h" 29 | #include "stm32f10x_bkp.h" 30 | #include "stm32f10x_can.h" 31 | #include "stm32f10x_cec.h" 32 | #include "stm32f10x_crc.h" 33 | #include "stm32f10x_dac.h" 34 | #include "stm32f10x_dbgmcu.h" 35 | #include "stm32f10x_dma.h" 36 | #include "stm32f10x_exti.h" 37 | #include "stm32f10x_flash.h" 38 | #include "stm32f10x_fsmc.h" 39 | #include "stm32f10x_gpio.h" 40 | #include "stm32f10x_i2c.h" 41 | #include "stm32f10x_iwdg.h" 42 | #include "stm32f10x_pwr.h" 43 | #include "stm32f10x_rcc.h" 44 | #include "stm32f10x_rtc.h" 45 | #include "stm32f10x_sdio.h" 46 | #include "stm32f10x_spi.h" 47 | #include "stm32f10x_tim.h" 48 | #include "stm32f10x_usart.h" 49 | #include "stm32f10x_wwdg.h" 50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Uncomment the line below to expanse the "assert_param" macro in the 55 | Standard Peripheral Library drivers code */ 56 | /* #define USE_FULL_ASSERT 1 */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #ifdef USE_FULL_ASSERT 60 | 61 | /** 62 | * @brief The assert_param macro is used for function's parameters check. 63 | * @param expr: If expr is false, it calls assert_failed function which reports 64 | * the name of the source file and the source line number of the call 65 | * that failed. If expr is true, it returns no value. 66 | * @retval None 67 | */ 68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 69 | /* Exported functions ------------------------------------------------------- */ 70 | void assert_failed(uint8_t *file, uint32_t line); 71 | #else 72 | #define assert_param(expr) ((void)0) 73 | #endif /* USE_FULL_ASSERT */ 74 | 75 | #endif /* __STM32F10x_CONF_H */ 76 | 77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /USER/stm32f10x_it.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/USER/stm32f10x_it.c -------------------------------------------------------------------------------- /USER/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_IT_H 24 | #define __STM32F10x_IT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | 38 | void NMI_Handler(void); 39 | void HardFault_Handler(void); 40 | void MemManage_Handler(void); 41 | void BusFault_Handler(void); 42 | void UsageFault_Handler(void); 43 | void SVC_Handler(void); 44 | void DebugMon_Handler(void); 45 | void PendSV_Handler(void); 46 | void SysTick_Handler(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __STM32F10x_IT_H */ 53 | 54 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /USER/usart1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/USER/usart1.c -------------------------------------------------------------------------------- /USER/usart1.h: -------------------------------------------------------------------------------- 1 | #ifndef __USART1_H 2 | #define __USART1_H 3 | 4 | #include "stm32f10x.h" 5 | #include 6 | 7 | #define MY_PRINTF 8 | 9 | 10 | void USART1_Config(void); 11 | void NVIC_Configuration(void); 12 | int fputc(int ch, FILE *f); 13 | void myPrintf(const char *fmt, ...); 14 | #endif /* __USART1_H */ 15 | -------------------------------------------------------------------------------- /keilkill.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaojiahai/simpleBGC32/5bcd92be3e7033c8d6a110bd980622777ab585b4/keilkill.bat --------------------------------------------------------------------------------