├── .gitignore ├── Makefile ├── README.md ├── STM32F2_drivers ├── build │ └── Makefile ├── inc │ ├── misc.h │ ├── stm32f2xx_adc.h │ ├── stm32f2xx_can.h │ ├── stm32f2xx_crc.h │ ├── stm32f2xx_cryp.h │ ├── stm32f2xx_dac.h │ ├── stm32f2xx_dbgmcu.h │ ├── stm32f2xx_dcmi.h │ ├── stm32f2xx_dma.h │ ├── stm32f2xx_exti.h │ ├── stm32f2xx_flash.h │ ├── stm32f2xx_fsmc.h │ ├── stm32f2xx_gpio.h │ ├── stm32f2xx_hash.h │ ├── stm32f2xx_i2c.h │ ├── stm32f2xx_iwdg.h │ ├── stm32f2xx_pwr.h │ ├── stm32f2xx_rcc.h │ ├── stm32f2xx_rng.h │ ├── stm32f2xx_rtc.h │ ├── stm32f2xx_sdio.h │ ├── stm32f2xx_spi.h │ ├── stm32f2xx_syscfg.h │ ├── stm32f2xx_tim.h │ ├── stm32f2xx_usart.h │ └── stm32f2xx_wwdg.h └── src │ ├── misc.c │ ├── stm32f2xx_adc.c │ ├── stm32f2xx_can.c │ ├── stm32f2xx_crc.c │ ├── stm32f2xx_cryp.c │ ├── stm32f2xx_cryp_aes.c │ ├── stm32f2xx_cryp_des.c │ ├── stm32f2xx_cryp_tdes.c │ ├── stm32f2xx_dac.c │ ├── stm32f2xx_dbgmcu.c │ ├── stm32f2xx_dcmi.c │ ├── stm32f2xx_dma.c │ ├── stm32f2xx_exti.c │ ├── stm32f2xx_flash.c │ ├── stm32f2xx_fsmc.c │ ├── stm32f2xx_gpio.c │ ├── stm32f2xx_hash.c │ ├── stm32f2xx_hash_md5.c │ ├── stm32f2xx_hash_sha1.c │ ├── stm32f2xx_i2c.c │ ├── stm32f2xx_iwdg.c │ ├── stm32f2xx_pwr.c │ ├── stm32f2xx_rcc.c │ ├── stm32f2xx_rng.c │ ├── stm32f2xx_rtc.c │ ├── stm32f2xx_sdio.c │ ├── stm32f2xx_spi.c │ ├── stm32f2xx_syscfg.c │ ├── stm32f2xx_tim.c │ ├── stm32f2xx_usart.c │ └── stm32f2xx_wwdg.c ├── STM32F4_drivers ├── build │ └── Makefile ├── inc │ ├── misc.h │ ├── stm32f4xx_adc.h │ ├── stm32f4xx_can.h │ ├── stm32f4xx_crc.h │ ├── stm32f4xx_cryp.h │ ├── stm32f4xx_dac.h │ ├── stm32f4xx_dbgmcu.h │ ├── stm32f4xx_dcmi.h │ ├── stm32f4xx_dma.h │ ├── stm32f4xx_exti.h │ ├── stm32f4xx_flash.h │ ├── stm32f4xx_fsmc.h │ ├── stm32f4xx_gpio.h │ ├── stm32f4xx_hash.h │ ├── stm32f4xx_i2c.h │ ├── stm32f4xx_iwdg.h │ ├── stm32f4xx_pwr.h │ ├── stm32f4xx_rcc.h │ ├── stm32f4xx_rng.h │ ├── stm32f4xx_rtc.h │ ├── stm32f4xx_sdio.h │ ├── stm32f4xx_spi.h │ ├── stm32f4xx_syscfg.h │ ├── stm32f4xx_tim.h │ ├── stm32f4xx_usart.h │ └── stm32f4xx_wwdg.h └── src │ ├── misc.c │ ├── stm32f4xx_adc.c │ ├── stm32f4xx_can.c │ ├── stm32f4xx_crc.c │ ├── stm32f4xx_cryp.c │ ├── stm32f4xx_cryp_aes.c │ ├── stm32f4xx_cryp_des.c │ ├── stm32f4xx_cryp_tdes.c │ ├── stm32f4xx_dac.c │ ├── stm32f4xx_dbgmcu.c │ ├── stm32f4xx_dcmi.c │ ├── stm32f4xx_dma.c │ ├── stm32f4xx_exti.c │ ├── stm32f4xx_flash.c │ ├── stm32f4xx_fsmc.c │ ├── stm32f4xx_gpio.c │ ├── stm32f4xx_hash.c │ ├── stm32f4xx_hash_md5.c │ ├── stm32f4xx_hash_sha1.c │ ├── stm32f4xx_i2c.c │ ├── stm32f4xx_iwdg.c │ ├── stm32f4xx_pwr.c │ ├── stm32f4xx_rcc.c │ ├── stm32f4xx_rng.c │ ├── stm32f4xx_rtc.c │ ├── stm32f4xx_sdio.c │ ├── stm32f4xx_spi.c │ ├── stm32f4xx_syscfg.c │ ├── stm32f4xx_tim.c │ ├── stm32f4xx_usart.c │ └── stm32f4xx_wwdg.c ├── core ├── arm_math.h ├── core_cm3.h ├── core_cm4.h ├── core_cm4_simd.h ├── core_cmFunc.h ├── core_cmInstr.h ├── startup_stm32f2xx.s ├── startup_stm32f4xx.s ├── stm32f2xx.h ├── stm32f2xx_conf.h ├── stm32f2xx_flash.ld ├── stm32f4xx.h ├── stm32f4xx_conf.h ├── stm32f4xx_flash.ld ├── stm32fxxx_it.c ├── stm32fxxx_it.h ├── syscalls.c ├── system_stm32f2xx.c ├── system_stm32f4xx.c └── system_stm32fxxx.h ├── libs ├── delay.c ├── delay.h ├── hsv2rgb.c ├── hsv2rgb.h ├── irq.c ├── irq.h ├── math_emb.c ├── math_emb.h ├── spi.c └── spi.h ├── main.c ├── main.h ├── midi ├── midi.h ├── usb.c ├── usb.h ├── usb_midi.c └── usb_midi.h └── usb ├── usb_bsp.h ├── usb_conf.h ├── usb_core.c ├── usb_core.h ├── usb_dcd.c ├── usb_dcd.h ├── usb_dcd_int.c ├── usb_dcd_int.h ├── usb_defines.h ├── usb_otg.c ├── usb_otg.h ├── usb_regs.h ├── usbd_conf.h ├── usbd_core.c ├── usbd_core.h ├── usbd_def.h ├── usbd_desc.h ├── usbd_ioreq.c ├── usbd_ioreq.h ├── usbd_req.c └── usbd_req.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.bin 4 | *.elf 5 | *.lst 6 | 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJECT=template 2 | 3 | 4 | STM32F=4 5 | LSCRIPT=core/stm32f$(STM32F)xx_flash.ld 6 | 7 | OPTIMIZATION = -O2 8 | 9 | ifeq ($(STM32F),2) 10 | CORTEXM=3 11 | else 12 | CORTEXM=4 13 | endif 14 | 15 | 16 | SRC=$(wildcard *.c usb/*.c midi/*.c libs/*.c) \ 17 | core/syscalls.c \ 18 | core/stm32fxxx_it.c \ 19 | core/system_stm32f$(STM32F)xx.c 20 | 21 | ASRC=core/startup_stm32f$(STM32F)xx.s 22 | OBJECTS= $(SRC:.c=.o) $(ASRC:.s=.o) 23 | LSTFILES= $(SRC:.c=.lst) 24 | HEADERS=$(wildcard usb/*.h core/*.h *.h midi/*.h libs/*.h) 25 | 26 | # Compiler Options 27 | GCFLAGS = -DSTM32F=$(STM32F) -ffreestanding -std=gnu99 -mcpu=cortex-m$(CORTEXM) -mthumb $(OPTIMIZATION) -I. -Imidi -Icore -Iusb -DARM_MATH_CM$(CORTEXM) -DUSE_STDPERIPH_DRIVER 28 | ifeq ($(CORTEXM),4) 29 | GCFLAGS+= -mfpu=fpv4-sp-d16 -mfloat-abi=hard -falign-functions=16 30 | endif 31 | # Warnings 32 | GCFLAGS += -Wstrict-prototypes -Wundef -Wall -Wextra -Wunreachable-code -Wno-strict-aliasing 33 | # Optimizazions 34 | GCFLAGS += -fstrict-aliasing -fsingle-precision-constant -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-builtin -ffunction-sections -fno-common -fdata-sections 35 | # Debug stuff 36 | GCFLAGS += -Wa,-adhlns=$(<:.c=.lst),-gstabs -g 37 | 38 | GCFLAGS+= -ISTM32F$(STM32F)_drivers/inc 39 | 40 | 41 | LDFLAGS = -mcpu=cortex-m$(CORTEXM) -mthumb $(OPTIMIZATION) -T$(LSCRIPT) 42 | ifeq ($(CORTEXM),4) 43 | LDFLAGS+= -mfpu=fpv4-sp-d16 -mfloat-abi=hard -falign-functions=16 44 | endif 45 | LDFLAGS+= -LSTM32F$(STM32F)_drivers/build -lSTM32F$(STM32F)xx_drivers -lm -lnosys -lc --specs=nano.specs -Wl,--gc-section 46 | 47 | 48 | # Compiler/Assembler Paths 49 | GCC = arm-none-eabi-gcc 50 | AS = arm-none-eabi-as 51 | OBJCOPY = arm-none-eabi-objcopy 52 | REMOVE = rm -f 53 | SIZE = arm-none-eabi-size 54 | 55 | ######################################################################### 56 | 57 | all: STM32F$(STM32F)_drivers/build/libSTM32F$(STM32F)_drivers.a $(PROJECT).bin Makefile 58 | @$(SIZE) $(PROJECT).elf 59 | 60 | STM32F$(STM32F)_drivers/build/libSTM32F$(STM32F)_drivers.a: 61 | @make -C STM32F$(STM32F)_drivers/build 62 | 63 | $(PROJECT).bin: $(PROJECT).elf Makefile 64 | @echo "generating $(PROJECT).bin" 65 | @$(OBJCOPY) -R .stack -O binary $(PROJECT).elf $(PROJECT).bin 66 | 67 | $(PROJECT).elf: $(OBJECTS) Makefile $(LSCRIPT) 68 | @echo " LD $(PROJECT).elf" 69 | @$(GCC) $(OBJECTS) $(LDFLAGS) -o $(PROJECT).elf 70 | 71 | clean: 72 | $(REMOVE) $(OBJECTS) 73 | $(REMOVE) $(LSTFILES) 74 | $(REMOVE) $(PROJECT).bin 75 | $(REMOVE) $(PROJECT).elf 76 | # make -C STM32F$(STM32F)_drivers/build clean 77 | 78 | ######################################################################### 79 | 80 | %.o: %.c Makefile $(HEADERS) 81 | @echo " GCC $<" 82 | @$(GCC) $(GCFLAGS) -o $@ -c $< 83 | 84 | %.o: %.s Makefile 85 | @echo " AS $<" 86 | @$(AS) $(ASFLAGS) -o $@ $< 87 | 88 | ######################################################################### 89 | 90 | flash: all 91 | dfu-util -a 0 -s 0x08000000 -D $(PROJECT).bin -R 92 | 93 | .PHONY : clean all flash 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stm32-midi-demo 2 | 3 | use stm32f4 as (client) usb midi device 4 | -------------------------------------------------------------------------------- /STM32F2_drivers/build/Makefile: -------------------------------------------------------------------------------- 1 | LIB = libSTM32F2xx_drivers.a 2 | 3 | CC = arm-none-eabi-gcc 4 | AR = arm-none-eabi-ar 5 | RANLIB = arm-none-eabi-ranlib 6 | 7 | CFLAGS = -Wall -O2 -mthumb 8 | #CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=softfp 9 | CFLAGS += -mcpu=cortex-m3 -ffreestanding 10 | #CFLAGS += -mcpu=cortex-m4 -ffreestanding -nostdlib -Wl,--gc-sections -fsingle-precision-constant -funsigned-char -Wundef -Wsign-compare -Wunreachable-code -Wstrict-prototypes 11 | CFLAGS += -I../inc -I../../core -DARM_MATH_CM3 -DUSE_STDPERIPH_DRIVER 12 | 13 | SRCS = $(wildcard ../src/*.c) 14 | 15 | OBJS = $(SRCS:.c=.o) 16 | 17 | all: $(LIB) 18 | 19 | $(LIB): $(OBJS) 20 | @$(AR) -r $(LIB) $(OBJS) 21 | @$(RANLIB) $(LIB) 22 | 23 | %.o : %.c 24 | @echo " GCC $^" 25 | @$(CC) $(CFLAGS) -c -o $@ $^ 26 | 27 | clean: 28 | -rm -f $(OBJS) 29 | -rm -f $(LIB) 30 | 31 | .PHONY: all clean 32 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the miscellaneous 8 | * firmware library functions (add-on to CMSIS functions). 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 __MISC_H 31 | #define __MISC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup MISC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief NVIC Init Structure definition 52 | */ 53 | 54 | typedef struct 55 | { 56 | uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. 57 | This parameter can be an enumerator of @ref IRQn_Type 58 | enumeration (For the complete STM32 Devices IRQ Channels 59 | list, please refer to stm32f2xx.h file) */ 60 | 61 | uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel 62 | specified in NVIC_IRQChannel. This parameter can be a value 63 | between 0 and 15 as described in the table @ref MISC_NVIC_Priority_Table 64 | A lower priority value indicates a higher priority */ 65 | 66 | uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified 67 | in NVIC_IRQChannel. This parameter can be a value 68 | between 0 and 15 as described in the table @ref MISC_NVIC_Priority_Table 69 | A lower priority value indicates a higher priority */ 70 | 71 | FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel 72 | will be enabled or disabled. 73 | This parameter can be set either to ENABLE or DISABLE */ 74 | } NVIC_InitTypeDef; 75 | 76 | /* Exported constants --------------------------------------------------------*/ 77 | 78 | /** @defgroup MISC_Exported_Constants 79 | * @{ 80 | */ 81 | 82 | /** @defgroup MISC_Vector_Table_Base 83 | * @{ 84 | */ 85 | 86 | #define NVIC_VectTab_RAM ((uint32_t)0x20000000) 87 | #define NVIC_VectTab_FLASH ((uint32_t)0x08000000) 88 | #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \ 89 | ((VECTTAB) == NVIC_VectTab_FLASH)) 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup MISC_System_Low_Power 95 | * @{ 96 | */ 97 | 98 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10) 99 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04) 100 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02) 101 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \ 102 | ((LP) == NVIC_LP_SLEEPDEEP) || \ 103 | ((LP) == NVIC_LP_SLEEPONEXIT)) 104 | /** 105 | * @} 106 | */ 107 | 108 | /** @defgroup MISC_Preemption_Priority_Group 109 | * @{ 110 | */ 111 | 112 | #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 113 | 4 bits for subpriority */ 114 | #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 115 | 3 bits for subpriority */ 116 | #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 117 | 2 bits for subpriority */ 118 | #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 119 | 1 bits for subpriority */ 120 | #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 121 | 0 bits for subpriority */ 122 | 123 | #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \ 124 | ((GROUP) == NVIC_PriorityGroup_1) || \ 125 | ((GROUP) == NVIC_PriorityGroup_2) || \ 126 | ((GROUP) == NVIC_PriorityGroup_3) || \ 127 | ((GROUP) == NVIC_PriorityGroup_4)) 128 | 129 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 130 | 131 | #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 132 | 133 | #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF) 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** @defgroup MISC_SysTick_clock_source 140 | * @{ 141 | */ 142 | 143 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) 144 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) 145 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \ 146 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /* Exported macro ------------------------------------------------------------*/ 156 | /* Exported functions --------------------------------------------------------*/ 157 | 158 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); 159 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); 160 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset); 161 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); 162 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 163 | 164 | #ifdef __cplusplus 165 | } 166 | #endif 167 | 168 | #endif /* __MISC_H */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | /** 175 | * @} 176 | */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 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 __STM32F2xx_CRC_H 31 | #define __STM32F2xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F2xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the DBGMCU firmware 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F2xx_DBGMCU_H 30 | #define __STM32F2xx_DBGMCU_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f2xx.h" 38 | 39 | /** @addtogroup STM32F2xx_StdPeriph_Driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup DBGMCU 44 | * @{ 45 | */ 46 | 47 | /* Exported types ------------------------------------------------------------*/ 48 | /* Exported constants --------------------------------------------------------*/ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 54 | #define DBGMCU_STOP ((uint32_t)0x00000002) 55 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 56 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFFF8) == 0x00) && ((PERIPH) != 0x00)) 57 | 58 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000001) 59 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00000002) 60 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00000004) 61 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00000008) 62 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00000010) 63 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00000020) 64 | #define DBGMCU_TIM12_STOP ((uint32_t)0x00000040) 65 | #define DBGMCU_TIM13_STOP ((uint32_t)0x00000080) 66 | #define DBGMCU_TIM14_STOP ((uint32_t)0x00000100) 67 | #define DBGMCU_RTC_STOP ((uint32_t)0x00000400) 68 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000800) 69 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00001000) 70 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00200000) 71 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00400000) 72 | #define DBGMCU_I2C3_SMBUS_TIMEOUT ((uint32_t)0x00800000) 73 | #define DBGMCU_CAN1_STOP ((uint32_t)0x02000000) 74 | #define DBGMCU_CAN2_STOP ((uint32_t)0x04000000) 75 | #define IS_DBGMCU_APB1PERIPH(PERIPH) ((((PERIPH) & 0xF91FE200) == 0x00) && ((PERIPH) != 0x00)) 76 | 77 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000001) 78 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00000002) 79 | #define DBGMCU_TIM9_STOP ((uint32_t)0x00010000) 80 | #define DBGMCU_TIM10_STOP ((uint32_t)0x00020000) 81 | #define DBGMCU_TIM11_STOP ((uint32_t)0x00040000) 82 | #define IS_DBGMCU_APB2PERIPH(PERIPH) ((((PERIPH) & 0xFFF8FFFC) == 0x00) && ((PERIPH) != 0x00)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions --------------------------------------------------------*/ 89 | uint32_t DBGMCU_GetREVID(void); 90 | uint32_t DBGMCU_GetDEVID(void); 91 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 92 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 93 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* __STM32F2xx_DBGMCU_H */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_iwdg.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 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 __STM32F2xx_IWDG_H 31 | #define __STM32F2xx_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup IWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup IWDG_WriteAccess 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 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 70 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 71 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 72 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 73 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 74 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 75 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 76 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 77 | ((PRESCALER) == IWDG_Prescaler_8) || \ 78 | ((PRESCALER) == IWDG_Prescaler_16) || \ 79 | ((PRESCALER) == IWDG_Prescaler_32) || \ 80 | ((PRESCALER) == IWDG_Prescaler_64) || \ 81 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 82 | ((PRESCALER) == IWDG_Prescaler_256)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup IWDG_Flag 88 | * @{ 89 | */ 90 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 91 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 92 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 93 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /* Exported macro ------------------------------------------------------------*/ 103 | /* Exported functions --------------------------------------------------------*/ 104 | 105 | /* Prescaler and Counter configuration functions ******************************/ 106 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 107 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 108 | void IWDG_SetReload(uint16_t Reload); 109 | void IWDG_ReloadCounter(void); 110 | 111 | /* IWDG activation function ***************************************************/ 112 | void IWDG_Enable(void); 113 | 114 | /* Flag management function ***************************************************/ 115 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif /* __STM32F2xx_IWDG_H */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_pwr.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 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 __STM32F2xx_PWR_H 31 | #define __STM32F2xx_PWR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup PWR 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup PWR_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup PWR_PVD_detection_level 56 | * @{ 57 | */ 58 | 59 | #define PWR_PVDLevel_0 PWR_CR_PLS_LEV0 60 | #define PWR_PVDLevel_1 PWR_CR_PLS_LEV1 61 | #define PWR_PVDLevel_2 PWR_CR_PLS_LEV2 62 | #define PWR_PVDLevel_3 PWR_CR_PLS_LEV3 63 | #define PWR_PVDLevel_4 PWR_CR_PLS_LEV4 64 | #define PWR_PVDLevel_5 PWR_CR_PLS_LEV5 65 | #define PWR_PVDLevel_6 PWR_CR_PLS_LEV6 66 | #define PWR_PVDLevel_7 PWR_CR_PLS_LEV7 67 | 68 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \ 70 | ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \ 71 | ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7)) 72 | /** 73 | * @} 74 | */ 75 | 76 | 77 | /** @defgroup PWR_Regulator_state_in_STOP_mode 78 | * @{ 79 | */ 80 | 81 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 82 | #define PWR_Regulator_LowPower PWR_CR_LPDS 83 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 84 | ((REGULATOR) == PWR_Regulator_LowPower)) 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup PWR_STOP_mode_entry 90 | * @{ 91 | */ 92 | 93 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 94 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 95 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup PWR_Flag 102 | * @{ 103 | */ 104 | 105 | #define PWR_FLAG_WU PWR_CSR_WUF 106 | #define PWR_FLAG_SB PWR_CSR_SBF 107 | #define PWR_FLAG_PVDO PWR_CSR_PVDO 108 | #define PWR_FLAG_BRR PWR_CSR_BRR 109 | 110 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 111 | ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR)) 112 | 113 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /* Exported macro ------------------------------------------------------------*/ 123 | /* Exported functions --------------------------------------------------------*/ 124 | 125 | /* Function used to set the PWR configuration to the default reset state ******/ 126 | void PWR_DeInit(void); 127 | 128 | /* Backup Domain Access function **********************************************/ 129 | void PWR_BackupAccessCmd(FunctionalState NewState); 130 | 131 | /* PVD configuration functions ************************************************/ 132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 133 | void PWR_PVDCmd(FunctionalState NewState); 134 | 135 | /* WakeUp pins configuration functions ****************************************/ 136 | void PWR_WakeUpPinCmd(FunctionalState NewState); 137 | 138 | /* Backup Regulator configuration functions ***********************************/ 139 | void PWR_BackupRegulatorCmd(FunctionalState NewState); 140 | 141 | /* FLASH Power Down configuration functions ***********************************/ 142 | void PWR_FlashPowerDownCmd(FunctionalState NewState); 143 | 144 | /* Low Power modes configuration functions ************************************/ 145 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 146 | void PWR_EnterSTANDBYMode(void); 147 | 148 | /* Flags management functions *************************************************/ 149 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 150 | void PWR_ClearFlag(uint32_t PWR_FLAG); 151 | 152 | #ifdef __cplusplus 153 | } 154 | #endif 155 | 156 | #endif /* __STM32F2xx_PWR_H */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 167 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_rng.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_rng.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the Random 8 | * Number Generator(RNG) 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 __STM32F2xx_RNG_H 31 | #define __STM32F2xx_RNG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup RNG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup RNG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup RNG_flags_definition 56 | * @{ 57 | */ 58 | #define RNG_FLAG_DRDY ((uint8_t)0x0001) /*!< Data ready */ 59 | #define RNG_FLAG_CECS ((uint8_t)0x0002) /*!< Clock error current status */ 60 | #define RNG_FLAG_SECS ((uint8_t)0x0004) /*!< Seed error current status */ 61 | 62 | #define IS_RNG_GET_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_DRDY) || \ 63 | ((RNG_FLAG) == RNG_FLAG_CECS) || \ 64 | ((RNG_FLAG) == RNG_FLAG_SECS)) 65 | #define IS_RNG_CLEAR_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_CECS) || \ 66 | ((RNG_FLAG) == RNG_FLAG_SECS)) 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup RNG_interrupts_definition 72 | * @{ 73 | */ 74 | #define RNG_IT_CEI ((uint8_t)0x20) /*!< Clock error interrupt */ 75 | #define RNG_IT_SEI ((uint8_t)0x40) /*!< Seed error interrupt */ 76 | 77 | #define IS_RNG_IT(IT) ((((IT) & (uint8_t)0x9F) == 0x00) && ((IT) != 0x00)) 78 | #define IS_RNG_GET_IT(RNG_IT) (((RNG_IT) == RNG_IT_CEI) || ((RNG_IT) == RNG_IT_SEI)) 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions --------------------------------------------------------*/ 89 | 90 | /* Function used to set the RNG configuration to the default reset state *****/ 91 | void RNG_DeInit(void); 92 | 93 | /* Configuration function *****************************************************/ 94 | void RNG_Cmd(FunctionalState NewState); 95 | 96 | /* Get 32 bit Random number function ******************************************/ 97 | uint32_t RNG_GetRandomNumber(void); 98 | 99 | /* Interrupts and flags management functions **********************************/ 100 | void RNG_ITConfig(FunctionalState NewState); 101 | FlagStatus RNG_GetFlagStatus(uint8_t RNG_FLAG); 102 | void RNG_ClearFlag(uint8_t RNG_FLAG); 103 | ITStatus RNG_GetITStatus(uint8_t RNG_IT); 104 | void RNG_ClearITPendingBit(uint8_t RNG_IT); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /*__STM32F2xx_RNG_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 121 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_syscfg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_syscfg.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the SYSCFG 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 __STM32F2xx_SYSCFG_H 31 | #define __STM32F2xx_SYSCFG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup SYSCFG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup SYSCFG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup SYSCFG_EXTI_Port_Sources 56 | * @{ 57 | */ 58 | #define EXTI_PortSourceGPIOA ((uint8_t)0x00) 59 | #define EXTI_PortSourceGPIOB ((uint8_t)0x01) 60 | #define EXTI_PortSourceGPIOC ((uint8_t)0x02) 61 | #define EXTI_PortSourceGPIOD ((uint8_t)0x03) 62 | #define EXTI_PortSourceGPIOE ((uint8_t)0x04) 63 | #define EXTI_PortSourceGPIOF ((uint8_t)0x05) 64 | #define EXTI_PortSourceGPIOG ((uint8_t)0x06) 65 | #define EXTI_PortSourceGPIOH ((uint8_t)0x07) 66 | #define EXTI_PortSourceGPIOI ((uint8_t)0x08) 67 | 68 | #define IS_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == EXTI_PortSourceGPIOA) || \ 69 | ((PORTSOURCE) == EXTI_PortSourceGPIOB) || \ 70 | ((PORTSOURCE) == EXTI_PortSourceGPIOC) || \ 71 | ((PORTSOURCE) == EXTI_PortSourceGPIOD) || \ 72 | ((PORTSOURCE) == EXTI_PortSourceGPIOE) || \ 73 | ((PORTSOURCE) == EXTI_PortSourceGPIOF) || \ 74 | ((PORTSOURCE) == EXTI_PortSourceGPIOG) || \ 75 | ((PORTSOURCE) == EXTI_PortSourceGPIOH) || \ 76 | ((PORTSOURCE) == EXTI_PortSourceGPIOI)) 77 | /** 78 | * @} 79 | */ 80 | 81 | 82 | /** @defgroup SYSCFG_EXTI_Pin_Sources 83 | * @{ 84 | */ 85 | #define EXTI_PinSource0 ((uint8_t)0x00) 86 | #define EXTI_PinSource1 ((uint8_t)0x01) 87 | #define EXTI_PinSource2 ((uint8_t)0x02) 88 | #define EXTI_PinSource3 ((uint8_t)0x03) 89 | #define EXTI_PinSource4 ((uint8_t)0x04) 90 | #define EXTI_PinSource5 ((uint8_t)0x05) 91 | #define EXTI_PinSource6 ((uint8_t)0x06) 92 | #define EXTI_PinSource7 ((uint8_t)0x07) 93 | #define EXTI_PinSource8 ((uint8_t)0x08) 94 | #define EXTI_PinSource9 ((uint8_t)0x09) 95 | #define EXTI_PinSource10 ((uint8_t)0x0A) 96 | #define EXTI_PinSource11 ((uint8_t)0x0B) 97 | #define EXTI_PinSource12 ((uint8_t)0x0C) 98 | #define EXTI_PinSource13 ((uint8_t)0x0D) 99 | #define EXTI_PinSource14 ((uint8_t)0x0E) 100 | #define EXTI_PinSource15 ((uint8_t)0x0F) 101 | #define IS_EXTI_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == EXTI_PinSource0) || \ 102 | ((PINSOURCE) == EXTI_PinSource1) || \ 103 | ((PINSOURCE) == EXTI_PinSource2) || \ 104 | ((PINSOURCE) == EXTI_PinSource3) || \ 105 | ((PINSOURCE) == EXTI_PinSource4) || \ 106 | ((PINSOURCE) == EXTI_PinSource5) || \ 107 | ((PINSOURCE) == EXTI_PinSource6) || \ 108 | ((PINSOURCE) == EXTI_PinSource7) || \ 109 | ((PINSOURCE) == EXTI_PinSource8) || \ 110 | ((PINSOURCE) == EXTI_PinSource9) || \ 111 | ((PINSOURCE) == EXTI_PinSource10) || \ 112 | ((PINSOURCE) == EXTI_PinSource11) || \ 113 | ((PINSOURCE) == EXTI_PinSource12) || \ 114 | ((PINSOURCE) == EXTI_PinSource13) || \ 115 | ((PINSOURCE) == EXTI_PinSource14) || \ 116 | ((PINSOURCE) == EXTI_PinSource15)) 117 | /** 118 | * @} 119 | */ 120 | 121 | 122 | /** @defgroup SYSCFG_Memory_Remap_Config 123 | * @{ 124 | */ 125 | #define SYSCFG_MemoryRemap_Flash ((uint8_t)0x00) 126 | #define SYSCFG_MemoryRemap_SystemFlash ((uint8_t)0x01) 127 | #define SYSCFG_MemoryRemap_FSMC ((uint8_t)0x02) 128 | #define SYSCFG_MemoryRemap_SRAM ((uint8_t)0x03) 129 | 130 | #define IS_SYSCFG_MEMORY_REMAP_CONFING(REMAP) (((REMAP) == SYSCFG_MemoryRemap_Flash) || \ 131 | ((REMAP) == SYSCFG_MemoryRemap_SystemFlash) || \ 132 | ((REMAP) == SYSCFG_MemoryRemap_SRAM) || \ 133 | ((REMAP) == SYSCFG_MemoryRemap_FSMC)) 134 | /** 135 | * @} 136 | */ 137 | 138 | 139 | /** @defgroup SYSCFG_ETHERNET_Media_Interface 140 | * @{ 141 | */ 142 | #define SYSCFG_ETH_MediaInterface_MII ((uint32_t)0x00000000) 143 | #define SYSCFG_ETH_MediaInterface_RMII ((uint32_t)0x00000001) 144 | 145 | #define IS_SYSCFG_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == SYSCFG_ETH_MediaInterface_MII) || \ 146 | ((INTERFACE) == SYSCFG_ETH_MediaInterface_RMII)) 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /* Exported macro ------------------------------------------------------------*/ 156 | /* Exported functions --------------------------------------------------------*/ 157 | 158 | void SYSCFG_DeInit(void); 159 | void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap); 160 | void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex); 161 | void SYSCFG_ETH_MediaInterfaceConfig(uint32_t SYSCFG_ETH_MediaInterface); 162 | void SYSCFG_CompensationCellCmd(FunctionalState NewState); 163 | FlagStatus SYSCFG_GetCompensationCellStatus(void); 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /*__STM32F2xx_SYSCFG_H */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 180 | -------------------------------------------------------------------------------- /STM32F2_drivers/inc/stm32f2xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.1.2 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 __STM32F2xx_WWDG_H 31 | #define __STM32F2xx_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f2xx.h" 39 | 40 | /** @addtogroup STM32F2xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup WWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup WWDG_Prescaler 56 | * @{ 57 | */ 58 | 59 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 60 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 61 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 62 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 63 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 64 | ((PRESCALER) == WWDG_Prescaler_2) || \ 65 | ((PRESCALER) == WWDG_Prescaler_4) || \ 66 | ((PRESCALER) == WWDG_Prescaler_8)) 67 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 68 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* Exported functions --------------------------------------------------------*/ 80 | 81 | /* Function used to set the WWDG configuration to the default reset state ****/ 82 | void WWDG_DeInit(void); 83 | 84 | /* Prescaler, Refresh window and Counter configuration functions **************/ 85 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 86 | void WWDG_SetWindowValue(uint8_t WindowValue); 87 | void WWDG_EnableIT(void); 88 | void WWDG_SetCounter(uint8_t Counter); 89 | 90 | /* WWDG activation function ***************************************************/ 91 | void WWDG_Enable(uint8_t Counter); 92 | 93 | /* Interrupts and flags management functions **********************************/ 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F2xx_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /STM32F2_drivers/src/stm32f2xx_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_crc.c 4 | * @author MCD Application Team 5 | * @version V1.1.2 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 "stm32f2xx_crc.h" 30 | 31 | /** @addtogroup STM32F2xx_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup CRC 36 | * @brief CRC driver modules 37 | * @{ 38 | */ 39 | 40 | /* Private typedef -----------------------------------------------------------*/ 41 | /* Private define ------------------------------------------------------------*/ 42 | /* Private macro -------------------------------------------------------------*/ 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* Private function prototypes -----------------------------------------------*/ 45 | /* Private functions ---------------------------------------------------------*/ 46 | 47 | /** @defgroup CRC_Private_Functions 48 | * @{ 49 | */ 50 | 51 | /** 52 | * @brief Resets the CRC Data register (DR). 53 | * @param None 54 | * @retval None 55 | */ 56 | void CRC_ResetDR(void) 57 | { 58 | /* Reset CRC generator */ 59 | CRC->CR = CRC_CR_RESET; 60 | } 61 | 62 | /** 63 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 64 | * @param Data: data word(32-bit) to compute its CRC 65 | * @retval 32-bit CRC 66 | */ 67 | uint32_t CRC_CalcCRC(uint32_t Data) 68 | { 69 | CRC->DR = Data; 70 | 71 | return (CRC->DR); 72 | } 73 | 74 | /** 75 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 76 | * @param pBuffer: pointer to the buffer containing the data to be computed 77 | * @param BufferLength: length of the buffer to be computed 78 | * @retval 32-bit CRC 79 | */ 80 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 81 | { 82 | uint32_t index = 0; 83 | 84 | for(index = 0; index < BufferLength; index++) 85 | { 86 | CRC->DR = pBuffer[index]; 87 | } 88 | return (CRC->DR); 89 | } 90 | 91 | /** 92 | * @brief Returns the current CRC value. 93 | * @param None 94 | * @retval 32-bit CRC 95 | */ 96 | uint32_t CRC_GetCRC(void) 97 | { 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 103 | * @param IDValue: 8-bit value to be stored in the ID register 104 | * @retval None 105 | */ 106 | void CRC_SetIDRegister(uint8_t IDValue) 107 | { 108 | CRC->IDR = IDValue; 109 | } 110 | 111 | /** 112 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 113 | * @param None 114 | * @retval 8-bit value of the ID register 115 | */ 116 | uint8_t CRC_GetIDRegister(void) 117 | { 118 | return (CRC->IDR); 119 | } 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 134 | -------------------------------------------------------------------------------- /STM32F2_drivers/src/stm32f2xx_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f2xx_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V1.1.2 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 "stm32f2xx_dbgmcu.h" 30 | 31 | /** @addtogroup STM32F2xx_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup DBGMCU 36 | * @brief DBGMCU driver modules 37 | * @{ 38 | */ 39 | 40 | /* Private typedef -----------------------------------------------------------*/ 41 | /* Private define ------------------------------------------------------------*/ 42 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 43 | 44 | /* Private macro -------------------------------------------------------------*/ 45 | /* Private variables ---------------------------------------------------------*/ 46 | /* Private function prototypes -----------------------------------------------*/ 47 | /* Private functions ---------------------------------------------------------*/ 48 | 49 | /** @defgroup DBGMCU_Private_Functions 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @brief Returns the device revision identifier. 55 | * @param None 56 | * @retval Device revision identifier 57 | */ 58 | uint32_t DBGMCU_GetREVID(void) 59 | { 60 | return(DBGMCU->IDCODE >> 16); 61 | } 62 | 63 | /** 64 | * @brief Returns the device identifier. 65 | * @param None 66 | * @retval Device identifier 67 | */ 68 | uint32_t DBGMCU_GetDEVID(void) 69 | { 70 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 71 | } 72 | 73 | /** 74 | * @brief Configures low power mode behavior when the MCU is in Debug mode. 75 | * @param DBGMCU_Periph: specifies the low power mode. 76 | * This parameter can be any combination of the following values: 77 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 78 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 79 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 80 | * @param NewState: new state of the specified low power mode in Debug mode. 81 | * This parameter can be: ENABLE or DISABLE. 82 | * @retval None 83 | */ 84 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 85 | { 86 | /* Check the parameters */ 87 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 88 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 89 | if (NewState != DISABLE) 90 | { 91 | DBGMCU->CR |= DBGMCU_Periph; 92 | } 93 | else 94 | { 95 | DBGMCU->CR &= ~DBGMCU_Periph; 96 | } 97 | } 98 | 99 | /** 100 | * @brief Configures APB1 peripheral behavior when the MCU is in Debug mode. 101 | * @param DBGMCU_Periph: specifies the APB1 peripheral. 102 | * This parameter can be any combination of the following values: 103 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 104 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 105 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 106 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 107 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 108 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 109 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 112 | * @arg DBGMCU_RTC_STOP: RTC Wakeup counter stopped when Core is halted. 113 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 114 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 115 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 116 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 117 | * @arg DBGMCU_I2C3_SMBUS_TIMEOUT: I2C3 SMBUS timeout mode stopped when Core is halted 118 | * @arg DBGMCU_CAN2_STOP: Debug CAN1 stopped when Core is halted 119 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 120 | * This parameter can be: ENABLE or DISABLE. 121 | * @retval None 122 | */ 123 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState) 124 | { 125 | /* Check the parameters */ 126 | assert_param(IS_DBGMCU_APB1PERIPH(DBGMCU_Periph)); 127 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 128 | 129 | if (NewState != DISABLE) 130 | { 131 | DBGMCU->APB1FZ |= DBGMCU_Periph; 132 | } 133 | else 134 | { 135 | DBGMCU->APB1FZ &= ~DBGMCU_Periph; 136 | } 137 | } 138 | 139 | /** 140 | * @brief Configures APB2 peripheral behavior when the MCU is in Debug mode. 141 | * @param DBGMCU_Periph: specifies the APB2 peripheral. 142 | * This parameter can be any combination of the following values: 143 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 144 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 145 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 146 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 147 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 148 | * @param NewState: new state of the specified peripheral in Debug mode. 149 | * This parameter can be: ENABLE or DISABLE. 150 | * @retval None 151 | */ 152 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState) 153 | { 154 | /* Check the parameters */ 155 | assert_param(IS_DBGMCU_APB2PERIPH(DBGMCU_Periph)); 156 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 157 | 158 | if (NewState != DISABLE) 159 | { 160 | DBGMCU->APB2FZ |= DBGMCU_Periph; 161 | } 162 | else 163 | { 164 | DBGMCU->APB2FZ &= ~DBGMCU_Periph; 165 | } 166 | } 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 181 | -------------------------------------------------------------------------------- /STM32F4_drivers/build/Makefile: -------------------------------------------------------------------------------- 1 | LIB = libSTM32F4xx_drivers.a 2 | 3 | CC = arm-none-eabi-gcc 4 | AR = arm-none-eabi-ar 5 | RANLIB = arm-none-eabi-ranlib 6 | 7 | CFLAGS = -Wall -O2 -mthumb 8 | CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -falign-functions=16 9 | CFLAGS += -mcpu=cortex-m4 -fsingle-precision-constant -funsigned-char -Wundef -Wsign-compare -Wunreachable-code -Wstrict-prototypes 10 | CFLAGS += -I../inc -I../../core -DARM_MATH_CM4 -DUSE_STDPERIPH_DRIVER 11 | 12 | SRCS = \ 13 | ../src/misc.c \ 14 | ../src/stm32f4xx_adc.c \ 15 | ../src/stm32f4xx_can.c \ 16 | ../src/stm32f4xx_crc.c \ 17 | ../src/stm32f4xx_cryp.c \ 18 | ../src/stm32f4xx_cryp_aes.c \ 19 | ../src/stm32f4xx_cryp_des.c \ 20 | ../src/stm32f4xx_cryp_tdes.c \ 21 | ../src/stm32f4xx_dac.c \ 22 | ../src/stm32f4xx_dbgmcu.c \ 23 | ../src/stm32f4xx_dcmi.c \ 24 | ../src/stm32f4xx_dma.c \ 25 | ../src/stm32f4xx_exti.c \ 26 | ../src/stm32f4xx_flash.c \ 27 | ../src/stm32f4xx_fsmc.c \ 28 | ../src/stm32f4xx_gpio.c \ 29 | ../src/stm32f4xx_hash.c \ 30 | ../src/stm32f4xx_hash_md5.c \ 31 | ../src/stm32f4xx_hash_sha1.c \ 32 | ../src/stm32f4xx_i2c.c \ 33 | ../src/stm32f4xx_iwdg.c \ 34 | ../src/stm32f4xx_pwr.c \ 35 | ../src/stm32f4xx_rcc.c \ 36 | ../src/stm32f4xx_rng.c \ 37 | ../src/stm32f4xx_rtc.c \ 38 | ../src/stm32f4xx_sdio.c \ 39 | ../src/stm32f4xx_spi.c \ 40 | ../src/stm32f4xx_syscfg.c \ 41 | ../src/stm32f4xx_tim.c \ 42 | ../src/stm32f4xx_usart.c \ 43 | ../src/stm32f4xx_wwdg.c 44 | 45 | OBJS = $(SRCS:.c=.o) 46 | 47 | all: $(LIB) 48 | 49 | $(LIB): $(OBJS) 50 | @$(AR) -r $(LIB) $(OBJS) 51 | @$(RANLIB) $(LIB) 52 | 53 | %.o : %.c 54 | @echo " GCC $^" 55 | @$(CC) $(CFLAGS) -c -o $@ $^ 56 | 57 | clean: 58 | -rm -f $(OBJS) 59 | -rm -f $(LIB) 60 | 61 | .PHONY: all clean 62 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the miscellaneous 8 | * firmware library functions (add-on to CMSIS functions). 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 __MISC_H 31 | #define __MISC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup MISC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief NVIC Init Structure definition 52 | */ 53 | 54 | typedef struct 55 | { 56 | uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. 57 | This parameter can be an enumerator of @ref IRQn_Type 58 | enumeration (For the complete STM32 Devices IRQ Channels 59 | list, please refer to stm32f4xx.h file) */ 60 | 61 | uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel 62 | specified in NVIC_IRQChannel. This parameter can be a value 63 | between 0 and 15 as described in the table @ref MISC_NVIC_Priority_Table 64 | A lower priority value indicates a higher priority */ 65 | 66 | uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified 67 | in NVIC_IRQChannel. This parameter can be a value 68 | between 0 and 15 as described in the table @ref MISC_NVIC_Priority_Table 69 | A lower priority value indicates a higher priority */ 70 | 71 | FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel 72 | will be enabled or disabled. 73 | This parameter can be set either to ENABLE or DISABLE */ 74 | } NVIC_InitTypeDef; 75 | 76 | /* Exported constants --------------------------------------------------------*/ 77 | 78 | /** @defgroup MISC_Exported_Constants 79 | * @{ 80 | */ 81 | 82 | /** @defgroup MISC_Vector_Table_Base 83 | * @{ 84 | */ 85 | 86 | #define NVIC_VectTab_RAM ((uint32_t)0x20000000) 87 | #define NVIC_VectTab_FLASH ((uint32_t)0x08000000) 88 | #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \ 89 | ((VECTTAB) == NVIC_VectTab_FLASH)) 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup MISC_System_Low_Power 95 | * @{ 96 | */ 97 | 98 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10) 99 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04) 100 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02) 101 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \ 102 | ((LP) == NVIC_LP_SLEEPDEEP) || \ 103 | ((LP) == NVIC_LP_SLEEPONEXIT)) 104 | /** 105 | * @} 106 | */ 107 | 108 | /** @defgroup MISC_Preemption_Priority_Group 109 | * @{ 110 | */ 111 | 112 | #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 113 | 4 bits for subpriority */ 114 | #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 115 | 3 bits for subpriority */ 116 | #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 117 | 2 bits for subpriority */ 118 | #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 119 | 1 bits for subpriority */ 120 | #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 121 | 0 bits for subpriority */ 122 | 123 | #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \ 124 | ((GROUP) == NVIC_PriorityGroup_1) || \ 125 | ((GROUP) == NVIC_PriorityGroup_2) || \ 126 | ((GROUP) == NVIC_PriorityGroup_3) || \ 127 | ((GROUP) == NVIC_PriorityGroup_4)) 128 | 129 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 130 | 131 | #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 132 | 133 | #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF) 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** @defgroup MISC_SysTick_clock_source 140 | * @{ 141 | */ 142 | 143 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) 144 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) 145 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \ 146 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /* Exported macro ------------------------------------------------------------*/ 156 | /* Exported functions --------------------------------------------------------*/ 157 | 158 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); 159 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); 160 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset); 161 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); 162 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 163 | 164 | #ifdef __cplusplus 165 | } 166 | #endif 167 | 168 | #endif /* __MISC_H */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | /** 175 | * @} 176 | */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 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 __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the DBGMCU firmware 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_DBGMCU_H 30 | #define __STM32F4xx_DBGMCU_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /** @addtogroup STM32F4xx_StdPeriph_Driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup DBGMCU 44 | * @{ 45 | */ 46 | 47 | /* Exported types ------------------------------------------------------------*/ 48 | /* Exported constants --------------------------------------------------------*/ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 54 | #define DBGMCU_STOP ((uint32_t)0x00000002) 55 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 56 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFFF8) == 0x00) && ((PERIPH) != 0x00)) 57 | 58 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000001) 59 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00000002) 60 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00000004) 61 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00000008) 62 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00000010) 63 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00000020) 64 | #define DBGMCU_TIM12_STOP ((uint32_t)0x00000040) 65 | #define DBGMCU_TIM13_STOP ((uint32_t)0x00000080) 66 | #define DBGMCU_TIM14_STOP ((uint32_t)0x00000100) 67 | #define DBGMCU_RTC_STOP ((uint32_t)0x00000400) 68 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000800) 69 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00001000) 70 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00200000) 71 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00400000) 72 | #define DBGMCU_I2C3_SMBUS_TIMEOUT ((uint32_t)0x00800000) 73 | #define DBGMCU_CAN1_STOP ((uint32_t)0x02000000) 74 | #define DBGMCU_CAN2_STOP ((uint32_t)0x04000000) 75 | #define IS_DBGMCU_APB1PERIPH(PERIPH) ((((PERIPH) & 0xF91FE200) == 0x00) && ((PERIPH) != 0x00)) 76 | 77 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000001) 78 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00000002) 79 | #define DBGMCU_TIM9_STOP ((uint32_t)0x00010000) 80 | #define DBGMCU_TIM10_STOP ((uint32_t)0x00020000) 81 | #define DBGMCU_TIM11_STOP ((uint32_t)0x00040000) 82 | #define IS_DBGMCU_APB2PERIPH(PERIPH) ((((PERIPH) & 0xFFF8FFFC) == 0x00) && ((PERIPH) != 0x00)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions --------------------------------------------------------*/ 89 | uint32_t DBGMCU_GetREVID(void); 90 | uint32_t DBGMCU_GetDEVID(void); 91 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 92 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 93 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* __STM32F4xx_DBGMCU_H */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_exti.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the EXTI 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 __STM32F4xx_EXTI_H 31 | #define __STM32F4xx_EXTI_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup EXTI 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief EXTI mode enumeration 52 | */ 53 | 54 | typedef enum 55 | { 56 | EXTI_Mode_Interrupt = 0x00, 57 | EXTI_Mode_Event = 0x04 58 | }EXTIMode_TypeDef; 59 | 60 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 61 | 62 | /** 63 | * @brief EXTI Trigger enumeration 64 | */ 65 | 66 | typedef enum 67 | { 68 | EXTI_Trigger_Rising = 0x08, 69 | EXTI_Trigger_Falling = 0x0C, 70 | EXTI_Trigger_Rising_Falling = 0x10 71 | }EXTITrigger_TypeDef; 72 | 73 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 74 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 75 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 76 | /** 77 | * @brief EXTI Init Structure definition 78 | */ 79 | 80 | typedef struct 81 | { 82 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. 83 | This parameter can be any combination value of @ref EXTI_Lines */ 84 | 85 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. 86 | This parameter can be a value of @ref EXTIMode_TypeDef */ 87 | 88 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. 89 | This parameter can be a value of @ref EXTITrigger_TypeDef */ 90 | 91 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. 92 | This parameter can be set either to ENABLE or DISABLE */ 93 | }EXTI_InitTypeDef; 94 | 95 | /* Exported constants --------------------------------------------------------*/ 96 | 97 | /** @defgroup EXTI_Exported_Constants 98 | * @{ 99 | */ 100 | 101 | /** @defgroup EXTI_Lines 102 | * @{ 103 | */ 104 | 105 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */ 106 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */ 107 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */ 108 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */ 109 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */ 110 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */ 111 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */ 112 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */ 113 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */ 114 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */ 115 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */ 116 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */ 117 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */ 118 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */ 119 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */ 120 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */ 121 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */ 122 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 123 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB OTG FS Wakeup from suspend event */ 124 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */ 125 | #define EXTI_Line20 ((uint32_t)0x00100000) /*!< External interrupt line 20 Connected to the USB OTG HS (configured in FS) Wakeup event */ 126 | #define EXTI_Line21 ((uint32_t)0x00200000) /*!< External interrupt line 21 Connected to the RTC Tamper and Time Stamp events */ 127 | #define EXTI_Line22 ((uint32_t)0x00400000) /*!< External interrupt line 22 Connected to the RTC Wakeup event */ 128 | 129 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFF800000) == 0x00) && ((LINE) != (uint16_t)0x00)) 130 | 131 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 132 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 133 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 134 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 135 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 136 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 137 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 138 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 139 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 140 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19) || \ 141 | ((LINE) == EXTI_Line20) || ((LINE) == EXTI_Line21) ||\ 142 | ((LINE) == EXTI_Line22)) 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /* Exported macro ------------------------------------------------------------*/ 153 | /* Exported functions --------------------------------------------------------*/ 154 | 155 | /* Function used to set the EXTI configuration to the default reset state *****/ 156 | void EXTI_DeInit(void); 157 | 158 | /* Initialization and Configuration functions *********************************/ 159 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 160 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct); 161 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line); 162 | 163 | /* Interrupts and flags management functions **********************************/ 164 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 165 | void EXTI_ClearFlag(uint32_t EXTI_Line); 166 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 167 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 168 | 169 | #ifdef __cplusplus 170 | } 171 | #endif 172 | 173 | #endif /* __STM32F4xx_EXTI_H */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 184 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_iwdg.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 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 __STM32F4xx_IWDG_H 31 | #define __STM32F4xx_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup IWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup IWDG_WriteAccess 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 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 70 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 71 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 72 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 73 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 74 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 75 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 76 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 77 | ((PRESCALER) == IWDG_Prescaler_8) || \ 78 | ((PRESCALER) == IWDG_Prescaler_16) || \ 79 | ((PRESCALER) == IWDG_Prescaler_32) || \ 80 | ((PRESCALER) == IWDG_Prescaler_64) || \ 81 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 82 | ((PRESCALER) == IWDG_Prescaler_256)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup IWDG_Flag 88 | * @{ 89 | */ 90 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 91 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 92 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 93 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /* Exported macro ------------------------------------------------------------*/ 103 | /* Exported functions --------------------------------------------------------*/ 104 | 105 | /* Prescaler and Counter configuration functions ******************************/ 106 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 107 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 108 | void IWDG_SetReload(uint16_t Reload); 109 | void IWDG_ReloadCounter(void); 110 | 111 | /* IWDG activation function ***************************************************/ 112 | void IWDG_Enable(void); 113 | 114 | /* Flag management function ***************************************************/ 115 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif /* __STM32F4xx_IWDG_H */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_pwr.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 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 __STM32F4xx_PWR_H 31 | #define __STM32F4xx_PWR_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup PWR 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup PWR_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup PWR_PVD_detection_level 56 | * @{ 57 | */ 58 | 59 | #define PWR_PVDLevel_0 PWR_CR_PLS_LEV0 60 | #define PWR_PVDLevel_1 PWR_CR_PLS_LEV1 61 | #define PWR_PVDLevel_2 PWR_CR_PLS_LEV2 62 | #define PWR_PVDLevel_3 PWR_CR_PLS_LEV3 63 | #define PWR_PVDLevel_4 PWR_CR_PLS_LEV4 64 | #define PWR_PVDLevel_5 PWR_CR_PLS_LEV5 65 | #define PWR_PVDLevel_6 PWR_CR_PLS_LEV6 66 | #define PWR_PVDLevel_7 PWR_CR_PLS_LEV7 67 | 68 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_0) || ((LEVEL) == PWR_PVDLevel_1)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2) || ((LEVEL) == PWR_PVDLevel_3)|| \ 70 | ((LEVEL) == PWR_PVDLevel_4) || ((LEVEL) == PWR_PVDLevel_5)|| \ 71 | ((LEVEL) == PWR_PVDLevel_6) || ((LEVEL) == PWR_PVDLevel_7)) 72 | /** 73 | * @} 74 | */ 75 | 76 | 77 | /** @defgroup PWR_Regulator_state_in_STOP_mode 78 | * @{ 79 | */ 80 | 81 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 82 | #define PWR_Regulator_LowPower PWR_CR_LPDS 83 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 84 | ((REGULATOR) == PWR_Regulator_LowPower)) 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup PWR_STOP_mode_entry 90 | * @{ 91 | */ 92 | 93 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 94 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 95 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 96 | 97 | /** @defgroup PWR_Regulator_Voltage_Scale 98 | * @{ 99 | */ 100 | 101 | #define PWR_Regulator_Voltage_Scale1 ((uint32_t)0x00004000) 102 | #define PWR_Regulator_Voltage_Scale2 ((uint32_t)0x00000000) 103 | #define IS_PWR_REGULATOR_VOLTAGE(VOLTAGE) (((VOLTAGE) == PWR_Regulator_Voltage_Scale1) || ((VOLTAGE) == PWR_Regulator_Voltage_Scale2)) 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /** @defgroup PWR_Flag 110 | * @{ 111 | */ 112 | 113 | #define PWR_FLAG_WU PWR_CSR_WUF 114 | #define PWR_FLAG_SB PWR_CSR_SBF 115 | #define PWR_FLAG_PVDO PWR_CSR_PVDO 116 | #define PWR_FLAG_BRR PWR_CSR_BRR 117 | #define PWR_FLAG_VOSRDY PWR_CSR_VOSRDY 118 | 119 | /** @defgroup PWR_Flag_Legacy 120 | * @{ 121 | */ 122 | #define PWR_FLAG_REGRDY PWR_FLAG_VOSRDY 123 | /** 124 | * @} 125 | */ 126 | 127 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 128 | ((FLAG) == PWR_FLAG_PVDO) || ((FLAG) == PWR_FLAG_BRR) || \ 129 | ((FLAG) == PWR_FLAG_VOSRDY)) 130 | 131 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 132 | /** 133 | * @} 134 | */ 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /* Exported macro ------------------------------------------------------------*/ 141 | /* Exported functions --------------------------------------------------------*/ 142 | 143 | /* Function used to set the PWR configuration to the default reset state ******/ 144 | void PWR_DeInit(void); 145 | 146 | /* Backup Domain Access function **********************************************/ 147 | void PWR_BackupAccessCmd(FunctionalState NewState); 148 | 149 | /* PVD configuration functions ************************************************/ 150 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 151 | void PWR_PVDCmd(FunctionalState NewState); 152 | 153 | /* WakeUp pins configuration functions ****************************************/ 154 | void PWR_WakeUpPinCmd(FunctionalState NewState); 155 | 156 | /* Main and Backup Regulators configuration functions *************************/ 157 | void PWR_BackupRegulatorCmd(FunctionalState NewState); 158 | void PWR_MainRegulatorModeConfig(uint32_t PWR_Regulator_Voltage); 159 | 160 | /* FLASH Power Down configuration functions ***********************************/ 161 | void PWR_FlashPowerDownCmd(FunctionalState NewState); 162 | 163 | /* Low Power modes configuration functions ************************************/ 164 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 165 | void PWR_EnterSTANDBYMode(void); 166 | 167 | /* Flags management functions *************************************************/ 168 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 169 | void PWR_ClearFlag(uint32_t PWR_FLAG); 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif 174 | 175 | #endif /* __STM32F4xx_PWR_H */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | /** 182 | * @} 183 | */ 184 | 185 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 186 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_rng.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_rng.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the Random 8 | * Number Generator(RNG) 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 __STM32F4xx_RNG_H 31 | #define __STM32F4xx_RNG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup RNG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup RNG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup RNG_flags_definition 56 | * @{ 57 | */ 58 | #define RNG_FLAG_DRDY ((uint8_t)0x0001) /*!< Data ready */ 59 | #define RNG_FLAG_CECS ((uint8_t)0x0002) /*!< Clock error current status */ 60 | #define RNG_FLAG_SECS ((uint8_t)0x0004) /*!< Seed error current status */ 61 | 62 | #define IS_RNG_GET_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_DRDY) || \ 63 | ((RNG_FLAG) == RNG_FLAG_CECS) || \ 64 | ((RNG_FLAG) == RNG_FLAG_SECS)) 65 | #define IS_RNG_CLEAR_FLAG(RNG_FLAG) (((RNG_FLAG) == RNG_FLAG_CECS) || \ 66 | ((RNG_FLAG) == RNG_FLAG_SECS)) 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup RNG_interrupts_definition 72 | * @{ 73 | */ 74 | #define RNG_IT_CEI ((uint8_t)0x20) /*!< Clock error interrupt */ 75 | #define RNG_IT_SEI ((uint8_t)0x40) /*!< Seed error interrupt */ 76 | 77 | #define IS_RNG_IT(IT) ((((IT) & (uint8_t)0x9F) == 0x00) && ((IT) != 0x00)) 78 | #define IS_RNG_GET_IT(RNG_IT) (((RNG_IT) == RNG_IT_CEI) || ((RNG_IT) == RNG_IT_SEI)) 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions --------------------------------------------------------*/ 89 | 90 | /* Function used to set the RNG configuration to the default reset state *****/ 91 | void RNG_DeInit(void); 92 | 93 | /* Configuration function *****************************************************/ 94 | void RNG_Cmd(FunctionalState NewState); 95 | 96 | /* Get 32 bit Random number function ******************************************/ 97 | uint32_t RNG_GetRandomNumber(void); 98 | 99 | /* Interrupts and flags management functions **********************************/ 100 | void RNG_ITConfig(FunctionalState NewState); 101 | FlagStatus RNG_GetFlagStatus(uint8_t RNG_FLAG); 102 | void RNG_ClearFlag(uint8_t RNG_FLAG); 103 | ITStatus RNG_GetITStatus(uint8_t RNG_IT); 104 | void RNG_ClearITPendingBit(uint8_t RNG_IT); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /*__STM32F4xx_RNG_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 121 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_syscfg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_syscfg.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the SYSCFG 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 __STM32F4xx_SYSCFG_H 31 | #define __STM32F4xx_SYSCFG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup SYSCFG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup SYSCFG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup SYSCFG_EXTI_Port_Sources 56 | * @{ 57 | */ 58 | #define EXTI_PortSourceGPIOA ((uint8_t)0x00) 59 | #define EXTI_PortSourceGPIOB ((uint8_t)0x01) 60 | #define EXTI_PortSourceGPIOC ((uint8_t)0x02) 61 | #define EXTI_PortSourceGPIOD ((uint8_t)0x03) 62 | #define EXTI_PortSourceGPIOE ((uint8_t)0x04) 63 | #define EXTI_PortSourceGPIOF ((uint8_t)0x05) 64 | #define EXTI_PortSourceGPIOG ((uint8_t)0x06) 65 | #define EXTI_PortSourceGPIOH ((uint8_t)0x07) 66 | #define EXTI_PortSourceGPIOI ((uint8_t)0x08) 67 | 68 | #define IS_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == EXTI_PortSourceGPIOA) || \ 69 | ((PORTSOURCE) == EXTI_PortSourceGPIOB) || \ 70 | ((PORTSOURCE) == EXTI_PortSourceGPIOC) || \ 71 | ((PORTSOURCE) == EXTI_PortSourceGPIOD) || \ 72 | ((PORTSOURCE) == EXTI_PortSourceGPIOE) || \ 73 | ((PORTSOURCE) == EXTI_PortSourceGPIOF) || \ 74 | ((PORTSOURCE) == EXTI_PortSourceGPIOG) || \ 75 | ((PORTSOURCE) == EXTI_PortSourceGPIOH) || \ 76 | ((PORTSOURCE) == EXTI_PortSourceGPIOI)) 77 | /** 78 | * @} 79 | */ 80 | 81 | 82 | /** @defgroup SYSCFG_EXTI_Pin_Sources 83 | * @{ 84 | */ 85 | #define EXTI_PinSource0 ((uint8_t)0x00) 86 | #define EXTI_PinSource1 ((uint8_t)0x01) 87 | #define EXTI_PinSource2 ((uint8_t)0x02) 88 | #define EXTI_PinSource3 ((uint8_t)0x03) 89 | #define EXTI_PinSource4 ((uint8_t)0x04) 90 | #define EXTI_PinSource5 ((uint8_t)0x05) 91 | #define EXTI_PinSource6 ((uint8_t)0x06) 92 | #define EXTI_PinSource7 ((uint8_t)0x07) 93 | #define EXTI_PinSource8 ((uint8_t)0x08) 94 | #define EXTI_PinSource9 ((uint8_t)0x09) 95 | #define EXTI_PinSource10 ((uint8_t)0x0A) 96 | #define EXTI_PinSource11 ((uint8_t)0x0B) 97 | #define EXTI_PinSource12 ((uint8_t)0x0C) 98 | #define EXTI_PinSource13 ((uint8_t)0x0D) 99 | #define EXTI_PinSource14 ((uint8_t)0x0E) 100 | #define EXTI_PinSource15 ((uint8_t)0x0F) 101 | #define IS_EXTI_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == EXTI_PinSource0) || \ 102 | ((PINSOURCE) == EXTI_PinSource1) || \ 103 | ((PINSOURCE) == EXTI_PinSource2) || \ 104 | ((PINSOURCE) == EXTI_PinSource3) || \ 105 | ((PINSOURCE) == EXTI_PinSource4) || \ 106 | ((PINSOURCE) == EXTI_PinSource5) || \ 107 | ((PINSOURCE) == EXTI_PinSource6) || \ 108 | ((PINSOURCE) == EXTI_PinSource7) || \ 109 | ((PINSOURCE) == EXTI_PinSource8) || \ 110 | ((PINSOURCE) == EXTI_PinSource9) || \ 111 | ((PINSOURCE) == EXTI_PinSource10) || \ 112 | ((PINSOURCE) == EXTI_PinSource11) || \ 113 | ((PINSOURCE) == EXTI_PinSource12) || \ 114 | ((PINSOURCE) == EXTI_PinSource13) || \ 115 | ((PINSOURCE) == EXTI_PinSource14) || \ 116 | ((PINSOURCE) == EXTI_PinSource15)) 117 | /** 118 | * @} 119 | */ 120 | 121 | 122 | /** @defgroup SYSCFG_Memory_Remap_Config 123 | * @{ 124 | */ 125 | #define SYSCFG_MemoryRemap_Flash ((uint8_t)0x00) 126 | #define SYSCFG_MemoryRemap_SystemFlash ((uint8_t)0x01) 127 | #define SYSCFG_MemoryRemap_FSMC ((uint8_t)0x02) 128 | #define SYSCFG_MemoryRemap_SRAM ((uint8_t)0x03) 129 | 130 | #define IS_SYSCFG_MEMORY_REMAP_CONFING(REMAP) (((REMAP) == SYSCFG_MemoryRemap_Flash) || \ 131 | ((REMAP) == SYSCFG_MemoryRemap_SystemFlash) || \ 132 | ((REMAP) == SYSCFG_MemoryRemap_SRAM) || \ 133 | ((REMAP) == SYSCFG_MemoryRemap_FSMC)) 134 | /** 135 | * @} 136 | */ 137 | 138 | 139 | /** @defgroup SYSCFG_ETHERNET_Media_Interface 140 | * @{ 141 | */ 142 | #define SYSCFG_ETH_MediaInterface_MII ((uint32_t)0x00000000) 143 | #define SYSCFG_ETH_MediaInterface_RMII ((uint32_t)0x00000001) 144 | 145 | #define IS_SYSCFG_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == SYSCFG_ETH_MediaInterface_MII) || \ 146 | ((INTERFACE) == SYSCFG_ETH_MediaInterface_RMII)) 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /* Exported macro ------------------------------------------------------------*/ 156 | /* Exported functions --------------------------------------------------------*/ 157 | 158 | void SYSCFG_DeInit(void); 159 | void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap); 160 | void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex); 161 | void SYSCFG_ETH_MediaInterfaceConfig(uint32_t SYSCFG_ETH_MediaInterface); 162 | void SYSCFG_CompensationCellCmd(FunctionalState NewState); 163 | FlagStatus SYSCFG_GetCompensationCellStatus(void); 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /*__STM32F4xx_SYSCFG_H */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 180 | -------------------------------------------------------------------------------- /STM32F4_drivers/inc/stm32f4xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 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 __STM32F4xx_WWDG_H 31 | #define __STM32F4xx_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup WWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup WWDG_Prescaler 56 | * @{ 57 | */ 58 | 59 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 60 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 61 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 62 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 63 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 64 | ((PRESCALER) == WWDG_Prescaler_2) || \ 65 | ((PRESCALER) == WWDG_Prescaler_4) || \ 66 | ((PRESCALER) == WWDG_Prescaler_8)) 67 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 68 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* Exported functions --------------------------------------------------------*/ 80 | 81 | /* Function used to set the WWDG configuration to the default reset state ****/ 82 | void WWDG_DeInit(void); 83 | 84 | /* Prescaler, Refresh window and Counter configuration functions **************/ 85 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 86 | void WWDG_SetWindowValue(uint8_t WindowValue); 87 | void WWDG_EnableIT(void); 88 | void WWDG_SetCounter(uint8_t Counter); 89 | 90 | /* WWDG activation function ***************************************************/ 91 | void WWDG_Enable(uint8_t Counter); 92 | 93 | /* Interrupts and flags management functions **********************************/ 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F4xx_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /STM32F4_drivers/src/stm32f4xx_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.c 4 | * @author MCD Application Team 5 | * @version V1.0.2 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 "stm32f4xx_crc.h" 30 | 31 | /** @addtogroup STM32F4xx_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup CRC 36 | * @brief CRC driver modules 37 | * @{ 38 | */ 39 | 40 | /* Private typedef -----------------------------------------------------------*/ 41 | /* Private define ------------------------------------------------------------*/ 42 | /* Private macro -------------------------------------------------------------*/ 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* Private function prototypes -----------------------------------------------*/ 45 | /* Private functions ---------------------------------------------------------*/ 46 | 47 | /** @defgroup CRC_Private_Functions 48 | * @{ 49 | */ 50 | 51 | /** 52 | * @brief Resets the CRC Data register (DR). 53 | * @param None 54 | * @retval None 55 | */ 56 | void CRC_ResetDR(void) 57 | { 58 | /* Reset CRC generator */ 59 | CRC->CR = CRC_CR_RESET; 60 | } 61 | 62 | /** 63 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 64 | * @param Data: data word(32-bit) to compute its CRC 65 | * @retval 32-bit CRC 66 | */ 67 | uint32_t CRC_CalcCRC(uint32_t Data) 68 | { 69 | CRC->DR = Data; 70 | 71 | return (CRC->DR); 72 | } 73 | 74 | /** 75 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 76 | * @param pBuffer: pointer to the buffer containing the data to be computed 77 | * @param BufferLength: length of the buffer to be computed 78 | * @retval 32-bit CRC 79 | */ 80 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 81 | { 82 | uint32_t index = 0; 83 | 84 | for(index = 0; index < BufferLength; index++) 85 | { 86 | CRC->DR = pBuffer[index]; 87 | } 88 | return (CRC->DR); 89 | } 90 | 91 | /** 92 | * @brief Returns the current CRC value. 93 | * @param None 94 | * @retval 32-bit CRC 95 | */ 96 | uint32_t CRC_GetCRC(void) 97 | { 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 103 | * @param IDValue: 8-bit value to be stored in the ID register 104 | * @retval None 105 | */ 106 | void CRC_SetIDRegister(uint8_t IDValue) 107 | { 108 | CRC->IDR = IDValue; 109 | } 110 | 111 | /** 112 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 113 | * @param None 114 | * @retval 8-bit value of the ID register 115 | */ 116 | uint8_t CRC_GetIDRegister(void) 117 | { 118 | return (CRC->IDR); 119 | } 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 134 | -------------------------------------------------------------------------------- /STM32F4_drivers/src/stm32f4xx_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V1.0.2 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 "stm32f4xx_dbgmcu.h" 30 | 31 | /** @addtogroup STM32F4xx_StdPeriph_Driver 32 | * @{ 33 | */ 34 | 35 | /** @defgroup DBGMCU 36 | * @brief DBGMCU driver modules 37 | * @{ 38 | */ 39 | 40 | /* Private typedef -----------------------------------------------------------*/ 41 | /* Private define ------------------------------------------------------------*/ 42 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 43 | 44 | /* Private macro -------------------------------------------------------------*/ 45 | /* Private variables ---------------------------------------------------------*/ 46 | /* Private function prototypes -----------------------------------------------*/ 47 | /* Private functions ---------------------------------------------------------*/ 48 | 49 | /** @defgroup DBGMCU_Private_Functions 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @brief Returns the device revision identifier. 55 | * @param None 56 | * @retval Device revision identifier 57 | */ 58 | uint32_t DBGMCU_GetREVID(void) 59 | { 60 | return(DBGMCU->IDCODE >> 16); 61 | } 62 | 63 | /** 64 | * @brief Returns the device identifier. 65 | * @param None 66 | * @retval Device identifier 67 | */ 68 | uint32_t DBGMCU_GetDEVID(void) 69 | { 70 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 71 | } 72 | 73 | /** 74 | * @brief Configures low power mode behavior when the MCU is in Debug mode. 75 | * @param DBGMCU_Periph: specifies the low power mode. 76 | * This parameter can be any combination of the following values: 77 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 78 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 79 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 80 | * @param NewState: new state of the specified low power mode in Debug mode. 81 | * This parameter can be: ENABLE or DISABLE. 82 | * @retval None 83 | */ 84 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 85 | { 86 | /* Check the parameters */ 87 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 88 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 89 | if (NewState != DISABLE) 90 | { 91 | DBGMCU->CR |= DBGMCU_Periph; 92 | } 93 | else 94 | { 95 | DBGMCU->CR &= ~DBGMCU_Periph; 96 | } 97 | } 98 | 99 | /** 100 | * @brief Configures APB1 peripheral behavior when the MCU is in Debug mode. 101 | * @param DBGMCU_Periph: specifies the APB1 peripheral. 102 | * This parameter can be any combination of the following values: 103 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 104 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 105 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 106 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 107 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 108 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 109 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 112 | * @arg DBGMCU_RTC_STOP: RTC Calendar and Wakeup counter stopped when Core is halted. 113 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 114 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 115 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 116 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 117 | * @arg DBGMCU_I2C3_SMBUS_TIMEOUT: I2C3 SMBUS timeout mode stopped when Core is halted 118 | * @arg DBGMCU_CAN2_STOP: Debug CAN1 stopped when Core is halted 119 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 120 | * This parameter can be: ENABLE or DISABLE. 121 | * @retval None 122 | */ 123 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState) 124 | { 125 | /* Check the parameters */ 126 | assert_param(IS_DBGMCU_APB1PERIPH(DBGMCU_Periph)); 127 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 128 | 129 | if (NewState != DISABLE) 130 | { 131 | DBGMCU->APB1FZ |= DBGMCU_Periph; 132 | } 133 | else 134 | { 135 | DBGMCU->APB1FZ &= ~DBGMCU_Periph; 136 | } 137 | } 138 | 139 | /** 140 | * @brief Configures APB2 peripheral behavior when the MCU is in Debug mode. 141 | * @param DBGMCU_Periph: specifies the APB2 peripheral. 142 | * This parameter can be any combination of the following values: 143 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 144 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 145 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 146 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 147 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 148 | * @param NewState: new state of the specified peripheral in Debug mode. 149 | * This parameter can be: ENABLE or DISABLE. 150 | * @retval None 151 | */ 152 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState) 153 | { 154 | /* Check the parameters */ 155 | assert_param(IS_DBGMCU_APB2PERIPH(DBGMCU_Periph)); 156 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 157 | 158 | if (NewState != DISABLE) 159 | { 160 | DBGMCU->APB2FZ |= DBGMCU_Periph; 161 | } 162 | else 163 | { 164 | DBGMCU->APB2FZ &= ~DBGMCU_Periph; 165 | } 166 | } 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 181 | -------------------------------------------------------------------------------- /STM32F4_drivers/src/stm32f4xx_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebseb7/stm32-midi-demo/46cdf5577039d7c1e8640fbf1538c8a84f87b2c3/STM32F4_drivers/src/stm32f4xx_flash.c -------------------------------------------------------------------------------- /STM32F4_drivers/src/stm32f4xx_rcc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebseb7/stm32-midi-demo/46cdf5577039d7c1e8640fbf1538c8a84f87b2c3/STM32F4_drivers/src/stm32f4xx_rcc.c -------------------------------------------------------------------------------- /STM32F4_drivers/src/stm32f4xx_syscfg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_syscfg.c 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file provides firmware functions to manage the SYSCFG peripheral. 8 | * 9 | * @verbatim 10 | * 11 | * =================================================================== 12 | * How to use this driver 13 | * =================================================================== 14 | * 15 | * This driver provides functions for: 16 | * 17 | * 1. Remapping the memory accessible in the code area using SYSCFG_MemoryRemapConfig() 18 | * 19 | * 2. Manage the EXTI lines connection to the GPIOs using SYSCFG_EXTILineConfig() 20 | * 21 | * 3. Select the ETHERNET media interface (RMII/RII) using SYSCFG_ETH_MediaInterfaceConfig() 22 | * 23 | * @note SYSCFG APB clock must be enabled to get write access to SYSCFG registers, 24 | * using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 25 | * 26 | * @endverbatim 27 | * 28 | ****************************************************************************** 29 | * @attention 30 | * 31 | *

© COPYRIGHT 2012 STMicroelectronics

32 | * 33 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 34 | * You may not use this file except in compliance with the License. 35 | * You may obtain a copy of the License at: 36 | * 37 | * http://www.st.com/software_license_agreement_liberty_v2 38 | * 39 | * Unless required by applicable law or agreed to in writing, software 40 | * distributed under the License is distributed on an "AS IS" BASIS, 41 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 42 | * See the License for the specific language governing permissions and 43 | * limitations under the License. 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32f4xx_syscfg.h" 50 | #include "stm32f4xx_rcc.h" 51 | 52 | /** @addtogroup STM32F4xx_StdPeriph_Driver 53 | * @{ 54 | */ 55 | 56 | /** @defgroup SYSCFG 57 | * @brief SYSCFG driver modules 58 | * @{ 59 | */ 60 | 61 | /* Private typedef -----------------------------------------------------------*/ 62 | /* Private define ------------------------------------------------------------*/ 63 | /* ------------ RCC registers bit address in the alias region ----------- */ 64 | #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE) 65 | /* --- PMC Register ---*/ 66 | /* Alias word address of MII_RMII_SEL bit */ 67 | #define PMC_OFFSET (SYSCFG_OFFSET + 0x04) 68 | #define MII_RMII_SEL_BitNumber ((uint8_t)0x17) 69 | #define PMC_MII_RMII_SEL_BB (PERIPH_BB_BASE + (PMC_OFFSET * 32) + (MII_RMII_SEL_BitNumber * 4)) 70 | 71 | /* --- CMPCR Register ---*/ 72 | /* Alias word address of CMP_PD bit */ 73 | #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20) 74 | #define CMP_PD_BitNumber ((uint8_t)0x00) 75 | #define CMPCR_CMP_PD_BB (PERIPH_BB_BASE + (CMPCR_OFFSET * 32) + (CMP_PD_BitNumber * 4)) 76 | 77 | /* Private macro -------------------------------------------------------------*/ 78 | /* Private variables ---------------------------------------------------------*/ 79 | /* Private function prototypes -----------------------------------------------*/ 80 | /* Private functions ---------------------------------------------------------*/ 81 | 82 | /** @defgroup SYSCFG_Private_Functions 83 | * @{ 84 | */ 85 | 86 | /** 87 | * @brief Deinitializes the Alternate Functions (remap and EXTI configuration) 88 | * registers to their default reset values. 89 | * @param None 90 | * @retval None 91 | */ 92 | void SYSCFG_DeInit(void) 93 | { 94 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE); 95 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, DISABLE); 96 | } 97 | 98 | /** 99 | * @brief Changes the mapping of the specified pin. 100 | * @param SYSCFG_Memory: selects the memory remapping. 101 | * This parameter can be one of the following values: 102 | * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000 103 | * @arg SYSCFG_MemoryRemap_SystemFlash: System Flash memory mapped at 0x00000000 104 | * @arg SYSCFG_MemoryRemap_FSMC: FSMC (Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000 105 | * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM (112kB) mapped at 0x00000000 106 | * @retval None 107 | */ 108 | void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap) 109 | { 110 | /* Check the parameters */ 111 | assert_param(IS_SYSCFG_MEMORY_REMAP_CONFING(SYSCFG_MemoryRemap)); 112 | 113 | SYSCFG->MEMRMP = SYSCFG_MemoryRemap; 114 | } 115 | 116 | /** 117 | * @brief Selects the GPIO pin used as EXTI Line. 118 | * @param EXTI_PortSourceGPIOx : selects the GPIO port to be used as source for 119 | * EXTI lines where x can be (A..I). 120 | * @param EXTI_PinSourcex: specifies the EXTI line to be configured. 121 | * This parameter can be EXTI_PinSourcex where x can be (0..15, except 122 | * for EXTI_PortSourceGPIOI x can be (0..11). 123 | * @retval None 124 | */ 125 | void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex) 126 | { 127 | uint32_t tmp = 0x00; 128 | 129 | /* Check the parameters */ 130 | assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx)); 131 | assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex)); 132 | 133 | tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)); 134 | SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp; 135 | SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03))); 136 | } 137 | 138 | /** 139 | * @brief Selects the ETHERNET media interface 140 | * @param SYSCFG_ETH_MediaInterface: specifies the Media Interface mode. 141 | * This parameter can be one of the following values: 142 | * @arg SYSCFG_ETH_MediaInterface_MII: MII mode selected 143 | * @arg SYSCFG_ETH_MediaInterface_RMII: RMII mode selected 144 | * @retval None 145 | */ 146 | void SYSCFG_ETH_MediaInterfaceConfig(uint32_t SYSCFG_ETH_MediaInterface) 147 | { 148 | assert_param(IS_SYSCFG_ETH_MEDIA_INTERFACE(SYSCFG_ETH_MediaInterface)); 149 | /* Configure MII_RMII selection bit */ 150 | *(__IO uint32_t *) PMC_MII_RMII_SEL_BB = SYSCFG_ETH_MediaInterface; 151 | } 152 | 153 | /** 154 | * @brief Enables or disables the I/O Compensation Cell. 155 | * @note The I/O compensation cell can be used only when the device supply 156 | * voltage ranges from 2.4 to 3.6 V. 157 | * @param NewState: new state of the I/O Compensation Cell. 158 | * This parameter can be one of the following values: 159 | * @arg ENABLE: I/O compensation cell enabled 160 | * @arg DISABLE: I/O compensation cell power-down mode 161 | * @retval None 162 | */ 163 | void SYSCFG_CompensationCellCmd(FunctionalState NewState) 164 | { 165 | /* Check the parameters */ 166 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 167 | 168 | *(__IO uint32_t *) CMPCR_CMP_PD_BB = (uint32_t)NewState; 169 | } 170 | 171 | /** 172 | * @brief Checks whether the I/O Compensation Cell ready flag is set or not. 173 | * @param None 174 | * @retval The new state of the I/O Compensation Cell ready flag (SET or RESET) 175 | */ 176 | FlagStatus SYSCFG_GetCompensationCellStatus(void) 177 | { 178 | FlagStatus bitstatus = RESET; 179 | 180 | if ((SYSCFG->CMPCR & SYSCFG_CMPCR_READY ) != (uint32_t)RESET) 181 | { 182 | bitstatus = SET; 183 | } 184 | else 185 | { 186 | bitstatus = RESET; 187 | } 188 | return bitstatus; 189 | } 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | /** 196 | * @} 197 | */ 198 | 199 | /** 200 | * @} 201 | */ 202 | 203 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 204 | -------------------------------------------------------------------------------- /core/stm32f2xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebseb7/stm32-midi-demo/46cdf5577039d7c1e8640fbf1538c8a84f87b2c3/core/stm32f2xx.h -------------------------------------------------------------------------------- /core/stm32f2xx_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F2xx_StdPeriph_Template/stm32f2xx_conf.h 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 13-April-2012 7 | * @brief Library configuration file. 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 __STM32F2xx_CONF_H 30 | #define __STM32F2xx_CONF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Uncomment the line below to enable peripheral header file inclusion */ 34 | #include "stm32f2xx_adc.h" 35 | #include "stm32f2xx_can.h" 36 | #include "stm32f2xx_crc.h" 37 | #include "stm32f2xx_cryp.h" 38 | #include "stm32f2xx_dac.h" 39 | #include "stm32f2xx_dbgmcu.h" 40 | #include "stm32f2xx_dcmi.h" 41 | #include "stm32f2xx_dma.h" 42 | #include "stm32f2xx_exti.h" 43 | #include "stm32f2xx_flash.h" 44 | #include "stm32f2xx_fsmc.h" 45 | #include "stm32f2xx_hash.h" 46 | #include "stm32f2xx_gpio.h" 47 | #include "stm32f2xx_i2c.h" 48 | #include "stm32f2xx_iwdg.h" 49 | #include "stm32f2xx_pwr.h" 50 | #include "stm32f2xx_rcc.h" 51 | #include "stm32f2xx_rng.h" 52 | #include "stm32f2xx_rtc.h" 53 | #include "stm32f2xx_sdio.h" 54 | #include "stm32f2xx_spi.h" 55 | #include "stm32f2xx_syscfg.h" 56 | #include "stm32f2xx_tim.h" 57 | #include "stm32f2xx_usart.h" 58 | #include "stm32f2xx_wwdg.h" 59 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 60 | 61 | /* Exported types ------------------------------------------------------------*/ 62 | /* Exported constants --------------------------------------------------------*/ 63 | 64 | /* If an external clock source is used, then the value of the following define 65 | should be set to the value of the external clock source, else, if no external 66 | clock is used, keep this define commented */ 67 | /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ 68 | 69 | 70 | /* Uncomment the line below to expanse the "assert_param" macro in the 71 | Standard Peripheral Library drivers code */ 72 | /* #define USE_FULL_ASSERT 1 */ 73 | 74 | /* Exported macro ------------------------------------------------------------*/ 75 | #ifdef USE_FULL_ASSERT 76 | 77 | /** 78 | * @brief The assert_param macro is used for function's parameters check. 79 | * @param expr: If expr is false, it calls assert_failed function 80 | * which reports the name of the source file and the source 81 | * line number of the call that failed. 82 | * If expr is true, it returns no value. 83 | * @retval None 84 | */ 85 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 86 | /* Exported functions ------------------------------------------------------- */ 87 | void assert_failed(uint8_t* file, uint32_t line); 88 | #else 89 | #define assert_param(expr) ((void)0) 90 | #endif /* USE_FULL_ASSERT */ 91 | 92 | #endif /* __STM32F2xx_CONF_H */ 93 | 94 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /core/stm32f2xx_flash.ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebseb7/stm32-midi-demo/46cdf5577039d7c1e8640fbf1538c8a84f87b2c3/core/stm32f2xx_flash.ld -------------------------------------------------------------------------------- /core/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebseb7/stm32-midi-demo/46cdf5577039d7c1e8640fbf1538c8a84f87b2c3/core/stm32f4xx.h -------------------------------------------------------------------------------- /core/stm32f4xx_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_conf.h 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 13-April-2012 7 | * @brief Library configuration file. 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 __STM32F4xx_CONF_H 30 | #define __STM32F4xx_CONF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Uncomment the line below to enable peripheral header file inclusion */ 34 | #include "stm32f4xx_adc.h" 35 | #include "stm32f4xx_can.h" 36 | #include "stm32f4xx_crc.h" 37 | #include "stm32f4xx_cryp.h" 38 | #include "stm32f4xx_dac.h" 39 | #include "stm32f4xx_dbgmcu.h" 40 | #include "stm32f4xx_dcmi.h" 41 | #include "stm32f4xx_dma.h" 42 | #include "stm32f4xx_exti.h" 43 | #include "stm32f4xx_flash.h" 44 | #include "stm32f4xx_fsmc.h" 45 | #include "stm32f4xx_hash.h" 46 | #include "stm32f4xx_gpio.h" 47 | #include "stm32f4xx_i2c.h" 48 | #include "stm32f4xx_iwdg.h" 49 | #include "stm32f4xx_pwr.h" 50 | #include "stm32f4xx_rcc.h" 51 | #include "stm32f4xx_rng.h" 52 | #include "stm32f4xx_rtc.h" 53 | #include "stm32f4xx_sdio.h" 54 | #include "stm32f4xx_spi.h" 55 | #include "stm32f4xx_syscfg.h" 56 | #include "stm32f4xx_tim.h" 57 | #include "stm32f4xx_usart.h" 58 | #include "stm32f4xx_wwdg.h" 59 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 60 | 61 | /* Exported types ------------------------------------------------------------*/ 62 | /* Exported constants --------------------------------------------------------*/ 63 | 64 | /* If an external clock source is used, then the value of the following define 65 | should be set to the value of the external clock source, else, if no external 66 | clock is used, keep this define commented */ 67 | /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ 68 | 69 | 70 | /* Uncomment the line below to expanse the "assert_param" macro in the 71 | Standard Peripheral Library drivers code */ 72 | /* #define USE_FULL_ASSERT 1 */ 73 | 74 | /* Exported macro ------------------------------------------------------------*/ 75 | #ifdef USE_FULL_ASSERT 76 | 77 | /** 78 | * @brief The assert_param macro is used for function's parameters check. 79 | * @param expr: If expr is false, it calls assert_failed function 80 | * which reports the name of the source file and the source 81 | * line number of the call that failed. 82 | * If expr is true, it returns no value. 83 | * @retval None 84 | */ 85 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 86 | /* Exported functions ------------------------------------------------------- */ 87 | void assert_failed(uint8_t* file, uint32_t line); 88 | #else 89 | #define assert_param(expr) ((void)0) 90 | #endif /* USE_FULL_ASSERT */ 91 | 92 | #endif /* __STM32F4xx_CONF_H */ 93 | 94 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /core/stm32f4xx_flash.ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebseb7/stm32-midi-demo/46cdf5577039d7c1e8640fbf1538c8a84f87b2c3/core/stm32f4xx_flash.ld -------------------------------------------------------------------------------- /core/stm32fxxx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32fxxx_it.c 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides all exceptions handler and peripherals interrupt 9 | * service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© COPYRIGHT 2012 STMicroelectronics

14 | * 15 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 16 | * You may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at: 18 | * 19 | * http://www.st.com/software_license_agreement_liberty_v2 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | * 27 | ****************************************************************************** 28 | */ 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32fxxx_it.h" 32 | #include "main.h" 33 | 34 | 35 | 36 | //#ifdef USE_USB_OTG_FS 37 | #include "usb_core.h" 38 | #include "usbd_core.h" 39 | //#include "usbd_cdc_core.h" 40 | 41 | /* Private typedef -----------------------------------------------------------*/ 42 | /* Private define ------------------------------------------------------------*/ 43 | /* Private macro -------------------------------------------------------------*/ 44 | /* Private variables ---------------------------------------------------------*/ 45 | /* Private function prototypes -----------------------------------------------*/ 46 | extern USB_OTG_CORE_HANDLE USB_OTG_dev; 47 | extern uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); 48 | 49 | //#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED 50 | //extern uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); 51 | //extern uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); 52 | //#endif 53 | //#endif 54 | 55 | /******************************************************************************/ 56 | /* Cortex-M Processor Exceptions Handlers */ 57 | /******************************************************************************/ 58 | 59 | /** 60 | * @brief This function handles NMI exception. 61 | * @param None 62 | * @retval None 63 | */ 64 | void NMI_Handler(void) 65 | { 66 | } 67 | 68 | /** 69 | * @brief This function handles Hard Fault exception. 70 | * @param None 71 | * @retval None 72 | */ 73 | void HardFault_Handler(void) 74 | { 75 | /* Go to infinite loop when Hard Fault exception occurs */ 76 | while (1) 77 | { 78 | } 79 | } 80 | 81 | /** 82 | * @brief This function handles Memory Manage exception. 83 | * @param None 84 | * @retval None 85 | */ 86 | void MemManage_Handler(void) 87 | { 88 | /* Go to infinite loop when Memory Manage exception occurs */ 89 | while (1) 90 | { 91 | } 92 | } 93 | 94 | /** 95 | * @brief This function handles Bus Fault exception. 96 | * @param None 97 | * @retval None 98 | */ 99 | void BusFault_Handler(void) 100 | { 101 | /* Go to infinite loop when Bus Fault exception occurs */ 102 | while (1) 103 | { 104 | } 105 | } 106 | 107 | /** 108 | * @brief This function handles Usage Fault exception. 109 | * @param None 110 | * @retval None 111 | */ 112 | void UsageFault_Handler(void) 113 | { 114 | /* Go to infinite loop when Usage Fault exception occurs */ 115 | while (1) 116 | { 117 | } 118 | } 119 | 120 | /** 121 | * @brief This function handles SVCall exception. 122 | * @param None 123 | * @retval None 124 | */ 125 | void SVC_Handler(void) 126 | { 127 | } 128 | 129 | /** 130 | * @brief This function handles Debug Monitor exception. 131 | * @param None 132 | * @retval None 133 | */ 134 | void DebugMon_Handler(void) 135 | { 136 | } 137 | 138 | /** 139 | * @brief This function handles PendSVC exception. 140 | * @param None 141 | * @retval None 142 | */ 143 | void PendSV_Handler(void) 144 | { 145 | } 146 | 147 | /** 148 | * @brief This function handles SysTick Handler. 149 | * @param None 150 | * @retval None 151 | */ 152 | 153 | /* 154 | * 155 | * moved to main.c : 156 | * void SysTick_Handler(void) 157 | * { 158 | * 159 | * } 160 | * 161 | */ 162 | 163 | 164 | 165 | /** 166 | * @brief This function handles EXTI15_10_IRQ Handler. 167 | * @param None 168 | * @retval None 169 | */ 170 | //#ifdef USE_USB_OTG_FS 171 | void OTG_FS_WKUP_IRQHandler(void) 172 | { 173 | if(USB_OTG_dev.cfg.low_power) 174 | { 175 | *(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ; 176 | SystemInit(); 177 | USB_OTG_UngateClock(&USB_OTG_dev); 178 | } 179 | EXTI_ClearITPendingBit(EXTI_Line18); 180 | } 181 | //#endif 182 | 183 | /** 184 | * @brief This function handles EXTI15_10_IRQ Handler. 185 | * @param None 186 | * @retval None 187 | */ 188 | #ifdef USE_USB_OTG_HS 189 | void OTG_HS_WKUP_IRQHandler(void) 190 | { 191 | if(USB_OTG_dev.cfg.low_power) 192 | { 193 | *(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ; 194 | SystemInit(); 195 | USB_OTG_UngateClock(&USB_OTG_dev); 196 | } 197 | EXTI_ClearITPendingBit(EXTI_Line20); 198 | } 199 | #endif 200 | 201 | /** 202 | * @brief This function handles OTG_HS Handler. 203 | * @param None 204 | * @retval None 205 | */ 206 | #ifdef USE_USB_OTG_HS 207 | void OTG_HS_IRQHandler(void) 208 | { 209 | USBD_OTG_ISR_Handler (&USB_OTG_dev); 210 | } 211 | #endif 212 | //#ifdef USE_USB_OTG_FS 213 | void OTG_FS_IRQHandler(void) 214 | { 215 | USBD_OTG_ISR_Handler (&USB_OTG_dev); 216 | } 217 | //#endif 218 | 219 | #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED 220 | /** 221 | * @brief This function handles EP1_IN Handler. 222 | * @param None 223 | * @retval None 224 | */ 225 | void OTG_HS_EP1_IN_IRQHandler(void) 226 | { 227 | USBD_OTG_EP1IN_ISR_Handler (&USB_OTG_dev); 228 | } 229 | 230 | /** 231 | * @brief This function handles EP1_OUT Handler. 232 | * @param None 233 | * @retval None 234 | */ 235 | void OTG_HS_EP1_OUT_IRQHandler(void) 236 | { 237 | USBD_OTG_EP1OUT_ISR_Handler (&USB_OTG_dev); 238 | } 239 | #endif 240 | 241 | 242 | /******************************************************************************/ 243 | /* STM32Fxxx Peripherals Interrupt Handlers */ 244 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 245 | /* available peripheral interrupt handler's name please refer to the startup */ 246 | /* file (startup_stm32fxxx.s). */ 247 | /******************************************************************************/ 248 | 249 | /** 250 | * @brief This function handles PPP interrupt request. 251 | * @param None 252 | * @retval None 253 | */ 254 | /*void PPP_IRQHandler(void) 255 | { 256 | }*/ 257 | 258 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 259 | -------------------------------------------------------------------------------- /core/stm32fxxx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32fxxx_it.h 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief This file contains the headers of the interrupt handlers. 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 __STM32Fxxx_IT_H 30 | #define __STM32Fxxx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | //#ifdef USE_USB_OTG_FS 38 | #include "usb_conf.h" 39 | //#endif 40 | /* Exported types ------------------------------------------------------------*/ 41 | /* Exported constants --------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions ------------------------------------------------------- */ 44 | 45 | void NMI_Handler(void); 46 | void HardFault_Handler(void); 47 | void MemManage_Handler(void); 48 | void BusFault_Handler(void); 49 | void UsageFault_Handler(void); 50 | void SVC_Handler(void); 51 | void DebugMon_Handler(void); 52 | void PendSV_Handler(void); 53 | void SysTick_Handler(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* __STM32Fxxx_IT_H */ 60 | 61 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 62 | -------------------------------------------------------------------------------- /core/syscalls.c: -------------------------------------------------------------------------------- 1 | // from newlib_stubs.c 2 | 3 | #if STM32F == 2 4 | #include "stm32f2xx.h" 5 | #endif 6 | #if STM32F == 4 7 | #include "stm32f4xx.h" 8 | #endif 9 | #include 10 | #include 11 | 12 | caddr_t _sbrk(int incr) { 13 | 14 | extern char _ebss; // Defined by the linker 15 | static char *heap_end; 16 | char *prev_heap_end; 17 | 18 | if (heap_end == 0) { 19 | heap_end = &_ebss; 20 | } 21 | prev_heap_end = heap_end; 22 | 23 | char * stack = (char*) __get_MSP(); 24 | if (heap_end + incr > stack) 25 | { 26 | //_write (STDERR_FILENO, "Heap and stack collision\n", 25); 27 | errno = ENOMEM; 28 | return (caddr_t) -1; 29 | //abort (); 30 | } 31 | 32 | heap_end += incr; 33 | return (caddr_t) prev_heap_end; 34 | 35 | } 36 | 37 | void _exit(void) { 38 | while(1) { 39 | // Loop until reset 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /core/system_stm32fxxx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32fxxx.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32Fxxx devices. 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 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32fxxx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32FXXX_H 40 | #define __SYSTEM_STM32FXXX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32Fxxx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32Fxxx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32Fxxx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32Fxxx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32Fxxx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | extern unsigned char GetHSEOK(void); 89 | /** 90 | * @} 91 | */ 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /*__SYSTEM_STM32FXXX_H */ 98 | 99 | /** 100 | * @} 101 | */ 102 | 103 | /** 104 | * @} 105 | */ 106 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 107 | -------------------------------------------------------------------------------- /libs/delay.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DELAY_TIMER TIM1 4 | 5 | #define DELAY_TIMER_RCC RCC_APB2Periph_TIM1 6 | 7 | 8 | void DELAY_Init(void) 9 | { 10 | 11 | // enable timer clock 12 | if( DELAY_TIMER == TIM1 || DELAY_TIMER == TIM8 ) 13 | RCC_APB2PeriphClockCmd(DELAY_TIMER_RCC, ENABLE); 14 | else 15 | RCC_APB1PeriphClockCmd(DELAY_TIMER_RCC, ENABLE); 16 | 17 | 18 | RCC_ClocksTypeDef RCC_Clocks; 19 | RCC_GetClocksFreq(&RCC_Clocks); 20 | 21 | // time base configuration 22 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 23 | TIM_TimeBaseStructure.TIM_Period = 65535; // maximum value 24 | TIM_TimeBaseStructure.TIM_Prescaler = (RCC_Clocks.SYSCLK_Frequency/1000000)-1; // for 1 uS accuracy 25 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; 26 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 27 | TIM_TimeBaseInit(DELAY_TIMER, &TIM_TimeBaseStructure); 28 | 29 | // enable counter 30 | TIM_Cmd(DELAY_TIMER, ENABLE); 31 | 32 | } 33 | 34 | void DELAY_Wait_uS(uint16_t uS) 35 | { 36 | uint16_t start = DELAY_TIMER->CNT; 37 | 38 | // note that this even works on 16bit counter wrap-arounds 39 | while( (uint16_t)(DELAY_TIMER->CNT - start) <= uS ); 40 | 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /libs/delay.h: -------------------------------------------------------------------------------- 1 | #ifndef _DELAY_H 2 | #define _DELAY_H 3 | 4 | #include "main.h" 5 | 6 | void DELAY_Init(void); 7 | void DELAY_Wait_uS(uint16_t uS); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /libs/hsv2rgb.c: -------------------------------------------------------------------------------- 1 | /* hsv2rgb.c 2 | * Convert Hue Saturation Value to Red Green Blue 3 | * 4 | * P.J. 08-Aug-98 5 | * 6 | * Reference: 7 | * D. F. Rogers 8 | * Procedural Elements for Computer Graphics 9 | * McGraw Hill 1985 10 | */ 11 | 12 | #include "hsv2rgb.h" 13 | 14 | int hsv2rgb( struct hsv_colour *hsv, struct rgb_colour *rgb ) { 15 | /* 16 | * Purpose: 17 | * Convert HSV values to RGB values 18 | * All values are in the range [0.0 .. 1.0] 19 | */ 20 | float S, H, V, F, M, N, K; 21 | int I; 22 | 23 | S = hsv->s; /* Saturation */ 24 | H = hsv->h; /* Hue */ 25 | V = hsv->v; /* value or brightness */ 26 | 27 | if ( S == 0.0 ) { 28 | /* 29 | * Achromatic case, set level of grey 30 | */ 31 | rgb->r = V; 32 | rgb->g = V; 33 | rgb->b = V; 34 | } else { 35 | /* 36 | * Determine levels of primary colours. 37 | */ 38 | if (H >= 1.0) { 39 | H = 0.0; 40 | } else { 41 | H = H * 6; 42 | } /* end if */ 43 | I = (int) H; /* should be in the range 0..5 */ 44 | F = H - I; /* fractional part */ 45 | 46 | M = V * (1 - S); 47 | N = V * (1 - S * F); 48 | K = V * (1 - S * (1 - F)); 49 | 50 | if (I == 0) { rgb->r = V; rgb->g = K; rgb->b = M; } 51 | if (I == 1) { rgb->r = N; rgb->g = V; rgb->b = M; } 52 | if (I == 2) { rgb->r = M; rgb->g = V; rgb->b = K; } 53 | if (I == 3) { rgb->r = M; rgb->g = N; rgb->b = V; } 54 | if (I == 4) { rgb->r = K; rgb->g = M; rgb->b = V; } 55 | if (I == 5) { rgb->r = V; rgb->g = M; rgb->b = N; } 56 | } /* end if */ 57 | 58 | return 0; 59 | } /* end function hsv2rgb */ 60 | -------------------------------------------------------------------------------- /libs/hsv2rgb.h: -------------------------------------------------------------------------------- 1 | #ifndef _HSV2RGB_H 2 | #define _HSV2RGB_H 3 | 4 | /* hsv2rgb.h */ 5 | 6 | struct hsv_colour { 7 | float h; 8 | float s; 9 | float v; 10 | }; /* end struct */ 11 | 12 | struct rgb_colour { 13 | float r; 14 | float g; 15 | float b; 16 | }; /* end struct */ 17 | 18 | int hsv2rgb( struct hsv_colour *hsv, struct rgb_colour *rgb ); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libs/irq.c: -------------------------------------------------------------------------------- 1 | #include "libs/irq.h" 2 | 3 | static uint32_t nested_ctr; 4 | 5 | // stored priority level before IRQ has been disabled (important for co-existence with vPortEnterCritical) 6 | static uint32_t prev_primask; 7 | 8 | 9 | void IRQ_Disable(void) 10 | { 11 | // get current priority if nested level == 0 12 | if( !nested_ctr ) { 13 | __asm volatile ( \ 14 | " mrs %0, primask\n" \ 15 | : "=r" (prev_primask) \ 16 | ); 17 | } 18 | 19 | // disable interrupts 20 | __asm volatile ( \ 21 | " mov r0, #1 \n" \ 22 | " msr primask, r0\n" \ 23 | :::"r0" \ 24 | ); 25 | 26 | ++nested_ctr; 27 | 28 | } 29 | 30 | int32_t IRQ_Enable(void) 31 | { 32 | // check for nesting error 33 | if( nested_ctr == 0 ) 34 | return -1; // nesting error 35 | 36 | // decrease nesting level 37 | --nested_ctr; 38 | 39 | // set back previous priority once nested level reached 0 again 40 | if( nested_ctr == 0 ) { 41 | __asm volatile ( \ 42 | " msr primask, %0\n" \ 43 | :: "r" (prev_primask) \ 44 | ); 45 | } 46 | 47 | return 0; // no error 48 | } 49 | 50 | int32_t IRQ_Install(uint8_t IRQn, uint8_t priority) 51 | { 52 | // no check for IRQn as it's device dependent 53 | 54 | if( priority >= 16 ) 55 | return -1; // invalid priority 56 | 57 | u32 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700)) >> 8; 58 | u32 tmppre = (4 - tmppriority); 59 | tmppriority = priority << tmppre; 60 | tmppriority = tmppriority << 4; 61 | NVIC->IP[IRQn] = tmppriority; 62 | 63 | NVIC_EnableIRQ(IRQn); 64 | 65 | return 0; // no error 66 | } 67 | 68 | 69 | void IRQ_DeInstall(uint8_t IRQn) 70 | { 71 | NVIC_DisableIRQ(IRQn); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /libs/irq.h: -------------------------------------------------------------------------------- 1 | #ifndef _IRQ_H 2 | #define _IRQ_H 3 | 4 | #include "main.h" 5 | 6 | #define IRQ_USB_PRIORITY 8 7 | 8 | 9 | void IRQ_Disable(void); 10 | int32_t IRQ_Enable(void); 11 | 12 | int32_t IRQ_Install(uint8_t IRQn, uint8_t priority); 13 | void IRQ_DeInstall(uint8_t IRQn); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /libs/math_emb.h: -------------------------------------------------------------------------------- 1 | #ifndef _MATH_EMB_H 2 | #define _MATH_EMB_H 3 | 4 | #include 5 | 6 | uint16_t sini(uint16_t x); 7 | double pythagoras( double side1, double side2 ); 8 | float pythagorasf( float side1, float side2 ); 9 | uint16_t randr(uint16_t start,uint16_t end); 10 | float _sinf(float theta); 11 | float _cosf(float theta); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libs/spi.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if STM32F == 2 4 | #include "stm32f2xx.h" 5 | #endif 6 | #if STM32F == 4 7 | #include "stm32f4xx.h" 8 | #endif 9 | 10 | #include "spi.h" 11 | #include "main.h" 12 | 13 | #define SPIx_SD SPI1 14 | #define SPIx_SD_CLK RCC_APB2Periph_SPI1 15 | #define SPIx_SD_CLK_INIT RCC_APB2PeriphClockCmd 16 | #define SPIx_SD_IRQn SPI1_IRQn 17 | #define SPIx_SD_IRQHANDLER SPI1_IRQHandler 18 | 19 | #define SPIx_SD_SCK_PIN GPIO_Pin_5 20 | #define SPIx_SD_SCK_GPIO_PORT GPIOA 21 | #define SPIx_SD_SCK_GPIO_CLK RCC_AHB1Periph_GPIOA 22 | #define SPIx_SD_SCK_SOURCE GPIO_PinSource5 23 | #define SPIx_SD_SCK_AF GPIO_AF_SPI1 24 | 25 | #define SPIx_SD_MOSI_PIN GPIO_Pin_7 26 | #define SPIx_SD_MOSI_GPIO_PORT GPIOA 27 | #define SPIx_SD_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOA 28 | #define SPIx_SD_MOSI_SOURCE GPIO_PinSource7 29 | #define SPIx_SD_MOSI_AF GPIO_AF_SPI1 30 | 31 | 32 | #define SPIx_SD_BAUDRATE_SLOW SPI_BaudRatePrescaler_4 33 | //#define SPIx_SD_BAUDRATE_FAST SPI_BaudRatePrescaler_8 34 | 35 | 36 | 37 | /*#define SPI_SD SPI2 38 | #define GPIO_CS GPIOC 39 | #define RCC_APB2Periph_GPIO_CS RCC_AHB1Periph_GPIOB 40 | #define GPIO_Pin_CS GPIO_Pin_7 41 | #define DMA_Channel_SPI_SD_RX DMA1_Channel2 42 | #define DMA_Channel_SPI_SD_TX DMA1_Channel3 43 | #define DMA_FLAG_SPI_SD_TC_RX DMA1_FLAG_TC2 44 | #define DMA_FLAG_SPI_SD_TC_TX DMA1_FLAG_TC3 45 | #define GPIO_SPI_SD GPIOB 46 | #define GPIO_Pin_SPI_SD_SCK GPIO_Pin_10 47 | #define GPIO_Pin_SPI_SD_MISO GPIO_Pin_14 48 | A 49 | #define GPIO_Pin_SPI_SD_MOSI GPIO_Pin_15 50 | #define RCC_APBPeriphClockCmd_SPI_SD RCC_APB1PeriphClockCmd 51 | #define RCC_APBPeriph_SPI_SD RCC_APB1Periph_SPI2 52 | */ 53 | 54 | /* - for SPI1 and full-speed APB2: 72MHz/4 */ 55 | //#define SPI_BaudRatePrescaler_SPI_SD SPI_BaudRatePrescaler_4 56 | 57 | void spi_send( uint8_t out ) 58 | { 59 | while (SPI_I2S_GetFlagStatus(SPIx_SD, SPI_I2S_FLAG_TXE) == RESET) { ; } 60 | SPI_I2S_SendData(SPIx_SD, out); 61 | } 62 | 63 | void init_spi(void) 64 | { 65 | SPI_InitTypeDef SPI_InitStructure; 66 | GPIO_InitTypeDef GPIO_InitStructure; 67 | 68 | /* Enable GPIO clocks */ 69 | RCC_AHB1PeriphClockCmd(SPIx_SD_SCK_GPIO_CLK | SPIx_SD_MOSI_GPIO_CLK, ENABLE); 70 | 71 | /* Enable the SPI clock */ 72 | SPIx_SD_CLK_INIT(SPIx_SD_CLK, ENABLE); 73 | 74 | 75 | /* SPI GPIO Configuration --------------------------------------------------*/ 76 | 77 | /* Connect SPI pins to AF5 */ 78 | GPIO_PinAFConfig(SPIx_SD_SCK_GPIO_PORT, SPIx_SD_SCK_SOURCE, SPIx_SD_SCK_AF); 79 | GPIO_PinAFConfig(SPIx_SD_MOSI_GPIO_PORT, SPIx_SD_MOSI_SOURCE, SPIx_SD_MOSI_AF); 80 | 81 | /* SPI SCK pin configuration */ 82 | GPIO_InitStructure.GPIO_Pin = SPIx_SD_SCK_PIN; 83 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 84 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 85 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 86 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; 87 | GPIO_Init(SPIx_SD_SCK_GPIO_PORT, &GPIO_InitStructure); 88 | 89 | /* SPI MOSI pin configuration */ 90 | GPIO_InitStructure.GPIO_Pin = SPIx_SD_MOSI_PIN; 91 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 92 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 93 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 94 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; 95 | GPIO_Init(SPIx_SD_MOSI_GPIO_PORT, &GPIO_InitStructure); 96 | 97 | /* SPI configuration */ 98 | SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; 99 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 100 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 101 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; 102 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; 103 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; 104 | SPI_InitStructure.SPI_BaudRatePrescaler = SPIx_SD_BAUDRATE_SLOW; // 42000kHz/128=328kHz < 400kHz 105 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 106 | SPI_InitStructure.SPI_CRCPolynomial = 7; 107 | 108 | SPI_Init(SPI1, &SPI_InitStructure); 109 | SPI_CalculateCRC(SPI1, DISABLE); 110 | SPI_Cmd(SPI1, ENABLE); 111 | 112 | } 113 | 114 | 115 | -------------------------------------------------------------------------------- /libs/spi.h: -------------------------------------------------------------------------------- 1 | #ifndef SPI_H_ 2 | #define SPI_H_ 3 | 4 | void init_spi (void); 5 | void spi_send( uint8_t out ); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "libs/math_emb.h" 3 | 4 | #include "libs/spi.h" 5 | 6 | #include "usb.h" 7 | //#include "midi.h" 8 | #include "libs/delay.h" 9 | #include "usb_midi.h" 10 | 11 | 12 | /* 13 | * boot loader: http://www.st.com/stonline/stappl/st/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00167594.pdf (page 31) 14 | * data sheet : http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00277537.pdf 15 | * 16 | */ 17 | 18 | static uint16_t key_state; 19 | static uint16_t key_press; 20 | static uint32_t buttonsInitialized = 0; 21 | 22 | void SysTick_Handler(void) 23 | { 24 | static uint16_t ct0, ct1; 25 | static uint16_t button_event = 3; 26 | uint16_t i; 27 | 28 | USB_MIDI_Periodic_mS(); 29 | 30 | if(buttonsInitialized) 31 | { 32 | button_event--; 33 | if(button_event == 0) 34 | { 35 | uint16_t key_curr = ((GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4)<<1)| 36 | GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_6)); 37 | 38 | i = key_state ^ ~key_curr; 39 | ct0 = ~( ct0 & i ); 40 | ct1 = ct0 ^ (ct1 & i); 41 | i &= ct0 & ct1; 42 | key_state ^= i; 43 | key_press |= key_state & i; 44 | button_event=3; 45 | } 46 | } 47 | } 48 | uint16_t get_key_press( uint16_t key_mask ) 49 | { 50 | key_mask &= key_press; // read key(s) 51 | key_press ^= key_mask; // clear key(s) 52 | return key_mask; 53 | } 54 | 55 | uint16_t get_key_state( uint16_t key_mask ) 56 | { 57 | return key_mask & key_press; 58 | } 59 | 60 | 61 | int main(void) 62 | { 63 | RCC_ClocksTypeDef RCC_Clocks; 64 | RCC_GetClocksFreq(&RCC_Clocks); 65 | /* SysTick event each 1ms */ 66 | SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); 67 | 68 | DELAY_Init(); 69 | USB_Init(0); 70 | 71 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); 72 | 73 | GPIO_InitTypeDef GPIO_InitStructure; 74 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; 75 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; 76 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 77 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 78 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; 79 | GPIO_Init(GPIOB, &GPIO_InitStructure); 80 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; 81 | GPIO_Init(GPIOB, &GPIO_InitStructure); 82 | 83 | //buttons 84 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); 85 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; 86 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 87 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; 88 | GPIO_Init(GPIOC, &GPIO_InitStructure); 89 | 90 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 91 | GPIO_Init(GPIOC, &GPIO_InitStructure); 92 | buttonsInitialized=1; 93 | 94 | int loopcount = 0; 95 | while(1) 96 | { 97 | midi_package_t rpack; 98 | 99 | int recv = USB_MIDI_PackageReceive(&rpack); 100 | 101 | if(recv != -1) 102 | { 103 | if(rpack.velocity > 50) 104 | { 105 | GPIOB->ODR |= 1<<13; 106 | } 107 | else 108 | { 109 | GPIOB->ODR &= ~(1<<13); 110 | } 111 | } 112 | 113 | loopcount++; 114 | if((loopcount == 50)||(loopcount == 150)) 115 | { 116 | if(USB_MIDI_CheckAvailable(0)) 117 | { 118 | GPIOB->ODR &= ~(1<<12); 119 | } 120 | } 121 | if((loopcount == 100)||(loopcount == 200)) 122 | { 123 | if(USB_MIDI_CheckAvailable(0)) 124 | { 125 | GPIOB->ODR |= 1<<12; 126 | } 127 | 128 | if(loopcount==200) 129 | loopcount = 0; 130 | 131 | } 132 | 133 | if(get_key_press(KEY_A)) 134 | { 135 | 136 | midi_package_t package; 137 | 138 | package.type = CC; 139 | package.event = CC; 140 | package.note = 7; 141 | package.velocity = 100; 142 | 143 | 144 | USB_MIDI_PackageSend_NonBlocking(package); 145 | } 146 | 147 | if(get_key_press(KEY_B)) 148 | { 149 | 150 | midi_package_t package; 151 | 152 | package.type = CC; 153 | package.event = CC; 154 | package.note = 7; 155 | package.velocity = 50; 156 | 157 | 158 | USB_MIDI_PackageSend_NonBlocking(package); 159 | } 160 | 161 | DELAY_Wait_uS(1000); 162 | } 163 | 164 | 165 | } 166 | 167 | -------------------------------------------------------------------------------- /main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H_ 2 | #define MAIN_H_ 3 | 4 | #if STM32F == 2 5 | #include "stm32f2xx.h" 6 | #endif 7 | #if STM32F == 4 8 | #include "stm32f4xx.h" 9 | #endif 10 | 11 | #define KEY_A (1<<0) 12 | #define KEY_B (1<<1) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /midi/midi.h: -------------------------------------------------------------------------------- 1 | #ifndef _MIDI_H 2 | #define _MIDI_H 3 | 4 | typedef enum { 5 | NoteOff = 0x8, 6 | NoteOn = 0x9, 7 | PolyPressure = 0xa, 8 | CC = 0xb, 9 | ProgramChange = 0xc, 10 | Aftertouch = 0xd, 11 | PitchBend = 0xe 12 | } midi_event_t; 13 | 14 | 15 | typedef union { 16 | struct { 17 | u32 ALL; 18 | }; 19 | struct { 20 | u8 cin_cable; 21 | u8 evnt0; 22 | u8 evnt1; 23 | u8 evnt2; 24 | }; 25 | struct { 26 | u8 type:4; 27 | u8 cable:4; 28 | u8 chn:4; 29 | u8 event:4; 30 | u8 value1; 31 | u8 value2; 32 | }; 33 | struct { 34 | u8 cin:4; 35 | u8 dummy1_cable:4; 36 | u8 dummy1_chn:4; 37 | u8 dummy1_event:4; 38 | u8 note:8; 39 | u8 velocity:8; 40 | }; 41 | struct { 42 | u8 dummy2_cin:4; 43 | u8 dummy2_cable:4; 44 | u8 dummy2_chn:4; 45 | u8 dummy2_event:4; 46 | u8 cc_number:8; 47 | u8 value:8; 48 | }; 49 | } midi_package_t; 50 | 51 | #endif /* _MIOS32_MIDI_H */ 52 | 53 | -------------------------------------------------------------------------------- /midi/usb.h: -------------------------------------------------------------------------------- 1 | // $Id: usb.h 1715 2013-03-17 11:14:14Z tk $ 2 | /* 3 | * Header file for USB Driver 4 | * 5 | * ========================================================================== 6 | * 7 | * Copyright (C) 2008 Thorsten Klose (tk@midibox.org) 8 | * Licensed for personal non-commercial use only. 9 | * All other rights reserved. 10 | * 11 | * ========================================================================== 12 | */ 13 | 14 | #ifndef _USB_H 15 | #define _USB_H 16 | 17 | #include "main.h" 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | // Global definitions 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 23 | 24 | // Following settings allow to customize the USB device descriptor 25 | #ifndef USB_VENDOR_ID 26 | #define USB_VENDOR_ID 0x16c0 // sponsored by voti.nl! see http://www.voti.nl/pids 27 | #endif 28 | #ifndef USB_VENDOR_STR 29 | #define USB_VENDOR_STR "seb" // you will see this in the USB device description 30 | #endif 31 | #ifndef USB_PRODUCT_STR 32 | #define USB_PRODUCT_STR "midi_ctrl" // you will see this in the MIDI device list 33 | #endif 34 | #ifndef USB_PRODUCT_ID 35 | #define USB_PRODUCT_ID 0x03e8 // ==1022; 1020-1029 reserved for T.Klose, 1000 - 1009 free for lab use 36 | // note: Vendor ID 1022 is required if the GM5 driver should be used! 37 | #endif 38 | #ifndef USB_VERSION_ID 39 | #define USB_VERSION_ID 0x0100 // v1.00 40 | #endif 41 | 42 | #define USB_MIDI_NUM_PORTS 1 43 | 44 | // internal defines which are used by MIOS32 USB MIDI/COM (don't touch) 45 | #define USB_EP_NUM 5 46 | 47 | // buffer table base address 48 | #define USB_BTABLE_ADDRESS 0x000 49 | 50 | // EP0 rx/tx buffer base address 51 | #define USB_ENDP0_RXADDR 0x040 52 | #define USB_ENDP0_TXADDR 0x080 53 | 54 | // EP1 Rx/Tx buffer base address for MIDI driver 55 | #define USB_ENDP1_TXADDR 0x0c0 56 | #define USB_ENDP2_RXADDR 0x100 57 | 58 | // EP3/4/5 buffer base addresses for COM driver 59 | #define USB_ENDP3_RXADDR 0x140 60 | #define USB_ENDP4_TXADDR 0x180 61 | #define USB_ENDP5_TXADDR 0x1c0 62 | 63 | 64 | 65 | ///////////////////////////////////////////////////////////////////////////// 66 | // Prototypes 67 | ///////////////////////////////////////////////////////////////////////////// 68 | 69 | extern s32 USB_Init(u32 mode); 70 | extern s32 USB_IsInitialized(void); 71 | extern s32 USB_ForceSingleUSB(void); 72 | 73 | 74 | ///////////////////////////////////////////////////////////////////////////// 75 | // Export global variables 76 | ///////////////////////////////////////////////////////////////////////////// 77 | 78 | extern void (*pEpInt_IN[7])(void); 79 | extern void (*pEpInt_OUT[7])(void); 80 | 81 | #endif /* _USB_H */ 82 | -------------------------------------------------------------------------------- /midi/usb_midi.h: -------------------------------------------------------------------------------- 1 | // $Id: usb_midi.h 1800 2013-06-02 22:09:03Z tk $ 2 | /* 3 | * Header file for USB MIDI Driver 4 | * 5 | * ========================================================================== 6 | * 7 | * Copyright (C) 2008 Thorsten Klose (tk@midibox.org) 8 | * Licensed for personal non-commercial use only. 9 | * All other rights reserved. 10 | * 11 | * ========================================================================== 12 | */ 13 | 14 | #ifndef _USB_MIDI_H 15 | #define _USB_MIDI_H 16 | 17 | #include "midi.h" 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | // Global definitions 21 | ///////////////////////////////////////////////////////////////////////////// 22 | 23 | // 1 to stay compatible to USB MIDI spec, 0 as workaround for some windows versions... 24 | #ifndef USB_MIDI_USE_AC_INTERFACE 25 | #define USB_MIDI_USE_AC_INTERFACE 0 26 | #endif 27 | 28 | // allowed numbers: 1..8 29 | #ifndef USB_MIDI_NUM_PORTS 30 | #define USB_MIDI_NUM_PORTS 1 31 | #endif 32 | 33 | // buffer size (should be at least >= USB_MIDI_DESC_DATA_*_SIZE/4) 34 | #ifndef USB_MIDI_RX_BUFFER_SIZE 35 | #define USB_MIDI_RX_BUFFER_SIZE 64 // packages 36 | #endif 37 | 38 | #ifndef USB_MIDI_TX_BUFFER_SIZE 39 | #define USB_MIDI_TX_BUFFER_SIZE 64 // packages 40 | #endif 41 | 42 | 43 | // size of IN/OUT pipe 44 | #ifndef USB_MIDI_DATA_IN_SIZE 45 | #define USB_MIDI_DATA_IN_SIZE 64 46 | #endif 47 | #ifndef USB_MIDI_DATA_OUT_SIZE 48 | #define USB_MIDI_DATA_OUT_SIZE 64 49 | #endif 50 | 51 | 52 | // endpoint assignments (don't change!) 53 | #define USB_MIDI_DATA_OUT_EP 0x02 54 | #define USB_MIDI_DATA_IN_EP 0x81 55 | 56 | 57 | ///////////////////////////////////////////////////////////////////////////// 58 | // Prototypes 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | extern s32 USB_MIDI_Init(u32 mode); 62 | 63 | extern s32 USB_MIDI_ChangeConnectionState(u8 connected); 64 | extern void USB_MIDI_EP1_IN_Callback(u8 bEP, u8 bEPStatus); 65 | extern void USB_MIDI_EP2_OUT_Callback(u8 bEP, u8 bEPStatus); 66 | 67 | extern s32 USB_MIDI_CheckAvailable(u8 cable); 68 | 69 | extern s32 USB_MIDI_PackageSend_NonBlocking(midi_package_t package); 70 | extern s32 USB_MIDI_PackageSend(midi_package_t package); 71 | extern s32 USB_MIDI_PackageReceive(midi_package_t *package); 72 | 73 | extern s32 USB_MIDI_Periodic_mS(void); 74 | 75 | 76 | ///////////////////////////////////////////////////////////////////////////// 77 | // Export global variables 78 | ///////////////////////////////////////////////////////////////////////////// 79 | 80 | 81 | #endif /* _USB_MIDI_H */ 82 | -------------------------------------------------------------------------------- /usb/usb_bsp.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_bsp.h 4 | * @author MCD Application Team 5 | * @version V2.1.0 6 | * @date 19-March-2012 7 | * @brief Specific api's relative to the used hardware platform 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_BSP__H__ 30 | #define __USB_BSP__H__ 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "usb_core.h" 34 | #include "usb_conf.h" 35 | 36 | /** @addtogroup USB_OTG_DRIVER 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USB_BSP 41 | * @brief This file is the 42 | * @{ 43 | */ 44 | 45 | 46 | /** @defgroup USB_BSP_Exported_Defines 47 | * @{ 48 | */ 49 | /** 50 | * @} 51 | */ 52 | 53 | 54 | /** @defgroup USB_BSP_Exported_Types 55 | * @{ 56 | */ 57 | /** 58 | * @} 59 | */ 60 | 61 | 62 | /** @defgroup USB_BSP_Exported_Macros 63 | * @{ 64 | */ 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup USB_BSP_Exported_Variables 70 | * @{ 71 | */ 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USB_BSP_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | void BSP_Init(void); 80 | 81 | void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev); 82 | void USB_OTG_BSP_uDelay (const uint32_t usec); 83 | void USB_OTG_BSP_mDelay (const uint32_t msec); 84 | void USB_OTG_BSP_EnableInterrupt (USB_OTG_CORE_HANDLE *pdev); 85 | #ifdef USE_HOST_MODE 86 | void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev); 87 | void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state); 88 | #endif 89 | /** 90 | * @} 91 | */ 92 | 93 | #endif //__USB_BSP__H__ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** 100 | * @} 101 | */ 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /usb/usb_dcd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_dcd.h 4 | * @author MCD Application Team 5 | * @version V2.1.0 6 | * @date 19-March-2012 7 | * @brief Peripheral Driver Header file 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 __DCD_H__ 30 | #define __DCD_H__ 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "usb_core.h" 34 | 35 | 36 | /** @addtogroup USB_OTG_DRIVER 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USB_DCD 41 | * @brief This file is the 42 | * @{ 43 | */ 44 | 45 | 46 | /** @defgroup USB_DCD_Exported_Defines 47 | * @{ 48 | */ 49 | #define USB_OTG_EP_CONTROL 0 50 | #define USB_OTG_EP_ISOC 1 51 | #define USB_OTG_EP_BULK 2 52 | #define USB_OTG_EP_INT 3 53 | #define USB_OTG_EP_MASK 3 54 | 55 | /* Device Status */ 56 | #define USB_OTG_DEFAULT 1 57 | #define USB_OTG_ADDRESSED 2 58 | #define USB_OTG_CONFIGURED 3 59 | #define USB_OTG_SUSPENDED 4 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USB_DCD_Exported_Types 67 | * @{ 68 | */ 69 | /******************************************************************************** 70 | Data structure type 71 | ********************************************************************************/ 72 | typedef struct 73 | { 74 | uint8_t bLength; 75 | uint8_t bDescriptorType; 76 | uint8_t bEndpointAddress; 77 | uint8_t bmAttributes; 78 | uint16_t wMaxPacketSize; 79 | uint8_t bInterval; 80 | } 81 | EP_DESCRIPTOR , *PEP_DESCRIPTOR; 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | 88 | /** @defgroup USB_DCD_Exported_Macros 89 | * @{ 90 | */ 91 | /** 92 | * @} 93 | */ 94 | 95 | /** @defgroup USB_DCD_Exported_Variables 96 | * @{ 97 | */ 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USB_DCD_Exported_FunctionsPrototype 103 | * @{ 104 | */ 105 | /******************************************************************************** 106 | EXPORTED FUNCTION FROM THE USB-OTG LAYER 107 | ********************************************************************************/ 108 | void DCD_Init(USB_OTG_CORE_HANDLE *pdev , 109 | USB_OTG_CORE_ID_TypeDef coreID); 110 | 111 | void DCD_DevConnect (USB_OTG_CORE_HANDLE *pdev); 112 | void DCD_DevDisconnect (USB_OTG_CORE_HANDLE *pdev); 113 | void DCD_EP_SetAddress (USB_OTG_CORE_HANDLE *pdev, 114 | uint8_t address); 115 | uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev , 116 | uint8_t ep_addr, 117 | uint16_t ep_mps, 118 | uint8_t ep_type); 119 | 120 | uint32_t DCD_EP_Close (USB_OTG_CORE_HANDLE *pdev, 121 | uint8_t ep_addr); 122 | 123 | 124 | uint32_t DCD_EP_PrepareRx ( USB_OTG_CORE_HANDLE *pdev, 125 | uint8_t ep_addr, 126 | uint8_t *pbuf, 127 | uint16_t buf_len); 128 | 129 | uint32_t DCD_EP_Tx (USB_OTG_CORE_HANDLE *pdev, 130 | uint8_t ep_addr, 131 | uint8_t *pbuf, 132 | uint32_t buf_len); 133 | uint32_t DCD_EP_Stall (USB_OTG_CORE_HANDLE *pdev, 134 | uint8_t epnum); 135 | uint32_t DCD_EP_ClrStall (USB_OTG_CORE_HANDLE *pdev, 136 | uint8_t epnum); 137 | uint32_t DCD_EP_Flush (USB_OTG_CORE_HANDLE *pdev, 138 | uint8_t epnum); 139 | uint32_t DCD_Handle_ISR(USB_OTG_CORE_HANDLE *pdev); 140 | 141 | uint32_t DCD_GetEPStatus(USB_OTG_CORE_HANDLE *pdev , 142 | uint8_t epnum); 143 | 144 | void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , 145 | uint8_t epnum , 146 | uint32_t Status); 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | 153 | #endif //__DCD_H__ 154 | 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 164 | 165 | -------------------------------------------------------------------------------- /usb/usb_dcd_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_dcd_int.h 4 | * @author MCD Application Team 5 | * @version V2.1.0 6 | * @date 19-March-2012 7 | * @brief Peripheral Device Interface Layer 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_DCD_INT_H__ 30 | #define USB_DCD_INT_H__ 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "usb_dcd.h" 34 | 35 | 36 | 37 | /** @addtogroup USB_OTG_DRIVER 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USB_DCD_INT 42 | * @brief This file is the 43 | * @{ 44 | */ 45 | 46 | 47 | /** @defgroup USB_DCD_INT_Exported_Defines 48 | * @{ 49 | */ 50 | 51 | typedef struct _USBD_DCD_INT 52 | { 53 | uint8_t (* DataOutStage) (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); 54 | uint8_t (* DataInStage) (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum); 55 | uint8_t (* SetupStage) (USB_OTG_CORE_HANDLE *pdev); 56 | uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev); 57 | uint8_t (* Reset) (USB_OTG_CORE_HANDLE *pdev); 58 | uint8_t (* Suspend) (USB_OTG_CORE_HANDLE *pdev); 59 | uint8_t (* Resume) (USB_OTG_CORE_HANDLE *pdev); 60 | uint8_t (* IsoINIncomplete) (USB_OTG_CORE_HANDLE *pdev); 61 | uint8_t (* IsoOUTIncomplete) (USB_OTG_CORE_HANDLE *pdev); 62 | }USBD_DCD_INT_cb_TypeDef; 63 | 64 | extern USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops; 65 | /** 66 | * @} 67 | */ 68 | 69 | 70 | /** @defgroup USB_DCD_INT_Exported_Types 71 | * @{ 72 | */ 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup USB_DCD_INT_Exported_Macros 78 | * @{ 79 | */ 80 | 81 | #define CLEAR_IN_EP_INTR(epnum,intr) \ 82 | diepint.d32=0; \ 83 | diepint.b.intr = 1; \ 84 | USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[epnum]->DIEPINT,diepint.d32); 85 | 86 | #define CLEAR_OUT_EP_INTR(epnum,intr) \ 87 | doepint.d32=0; \ 88 | doepint.b.intr = 1; \ 89 | USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[epnum]->DOEPINT,doepint.d32); 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** @defgroup USB_DCD_INT_Exported_Variables 96 | * @{ 97 | */ 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USB_DCD_INT_Exported_FunctionsPrototype 103 | * @{ 104 | */ 105 | 106 | uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | 113 | #endif // USB_DCD_INT_H__ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | 124 | -------------------------------------------------------------------------------- /usb/usb_defines.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_defines.h 4 | * @author MCD Application Team 5 | * @version V2.1.0 6 | * @date 19-March-2012 7 | * @brief Header of the Core Layer 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 | #include "usb_conf.h" 34 | 35 | /** @addtogroup USB_OTG_DRIVER 36 | * @{ 37 | */ 38 | 39 | /** @defgroup USB_DEFINES 40 | * @brief This file is the 41 | * @{ 42 | */ 43 | 44 | 45 | /** @defgroup USB_DEFINES_Exported_Defines 46 | * @{ 47 | */ 48 | /** 49 | * @} 50 | */ 51 | 52 | 53 | /** @defgroup _CORE_DEFINES_ 54 | * @{ 55 | */ 56 | 57 | #define USB_OTG_SPEED_PARAM_HIGH 0 58 | #define USB_OTG_SPEED_PARAM_HIGH_IN_FULL 1 59 | #define USB_OTG_SPEED_PARAM_FULL 3 60 | 61 | #define USB_OTG_SPEED_HIGH 0 62 | #define USB_OTG_SPEED_FULL 1 63 | 64 | #define USB_OTG_ULPI_PHY 1 65 | #define USB_OTG_EMBEDDED_PHY 2 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | 72 | /** @defgroup _GLOBAL_DEFINES_ 73 | * @{ 74 | */ 75 | #define GAHBCFG_TXFEMPTYLVL_EMPTY 1 76 | #define GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0 77 | #define GAHBCFG_GLBINT_ENABLE 1 78 | #define GAHBCFG_INT_DMA_BURST_SINGLE 0 79 | #define GAHBCFG_INT_DMA_BURST_INCR 1 80 | #define GAHBCFG_INT_DMA_BURST_INCR4 3 81 | #define GAHBCFG_INT_DMA_BURST_INCR8 5 82 | #define GAHBCFG_INT_DMA_BURST_INCR16 7 83 | #define GAHBCFG_DMAENABLE 1 84 | #define GAHBCFG_TXFEMPTYLVL_EMPTY 1 85 | #define GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0 86 | #define GRXSTS_PKTSTS_IN 2 87 | #define GRXSTS_PKTSTS_IN_XFER_COMP 3 88 | #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5 89 | #define GRXSTS_PKTSTS_CH_HALTED 7 90 | /** 91 | * @} 92 | */ 93 | 94 | 95 | /** @defgroup _OnTheGo_DEFINES_ 96 | * @{ 97 | */ 98 | #define MODE_HNP_SRP_CAPABLE 0 99 | #define MODE_SRP_ONLY_CAPABLE 1 100 | #define MODE_NO_HNP_SRP_CAPABLE 2 101 | #define MODE_SRP_CAPABLE_DEVICE 3 102 | #define MODE_NO_SRP_CAPABLE_DEVICE 4 103 | #define MODE_SRP_CAPABLE_HOST 5 104 | #define MODE_NO_SRP_CAPABLE_HOST 6 105 | #define A_HOST 1 106 | #define A_SUSPEND 2 107 | #define A_PERIPHERAL 3 108 | #define B_PERIPHERAL 4 109 | #define B_HOST 5 110 | #define DEVICE_MODE 0 111 | #define HOST_MODE 1 112 | #define OTG_MODE 2 113 | /** 114 | * @} 115 | */ 116 | 117 | 118 | /** @defgroup __DEVICE_DEFINES_ 119 | * @{ 120 | */ 121 | #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0 122 | #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1 123 | #define DSTS_ENUMSPD_LS_PHY_6MHZ 2 124 | #define DSTS_ENUMSPD_FS_PHY_48MHZ 3 125 | 126 | #define DCFG_FRAME_INTERVAL_80 0 127 | #define DCFG_FRAME_INTERVAL_85 1 128 | #define DCFG_FRAME_INTERVAL_90 2 129 | #define DCFG_FRAME_INTERVAL_95 3 130 | 131 | #define DEP0CTL_MPS_64 0 132 | #define DEP0CTL_MPS_32 1 133 | #define DEP0CTL_MPS_16 2 134 | #define DEP0CTL_MPS_8 3 135 | 136 | #define EP_SPEED_LOW 0 137 | #define EP_SPEED_FULL 1 138 | #define EP_SPEED_HIGH 2 139 | 140 | #define EP_TYPE_CTRL 0 141 | #define EP_TYPE_ISOC 1 142 | #define EP_TYPE_BULK 2 143 | #define EP_TYPE_INTR 3 144 | #define EP_TYPE_MSK 3 145 | 146 | #define STS_GOUT_NAK 1 147 | #define STS_DATA_UPDT 2 148 | #define STS_XFER_COMP 3 149 | #define STS_SETUP_COMP 4 150 | #define STS_SETUP_UPDT 6 151 | /** 152 | * @} 153 | */ 154 | 155 | 156 | /** @defgroup __HOST_DEFINES_ 157 | * @{ 158 | */ 159 | #define HC_PID_DATA0 0 160 | #define HC_PID_DATA2 1 161 | #define HC_PID_DATA1 2 162 | #define HC_PID_SETUP 3 163 | 164 | #define HPRT0_PRTSPD_HIGH_SPEED 0 165 | #define HPRT0_PRTSPD_FULL_SPEED 1 166 | #define HPRT0_PRTSPD_LOW_SPEED 2 167 | 168 | #define HCFG_30_60_MHZ 0 169 | #define HCFG_48_MHZ 1 170 | #define HCFG_6_MHZ 2 171 | 172 | #define HCCHAR_CTRL 0 173 | #define HCCHAR_ISOC 1 174 | #define HCCHAR_BULK 2 175 | #define HCCHAR_INTR 3 176 | 177 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | 184 | /** @defgroup USB_DEFINES_Exported_Types 185 | * @{ 186 | */ 187 | 188 | typedef enum 189 | { 190 | USB_OTG_HS_CORE_ID = 0, 191 | USB_OTG_FS_CORE_ID = 1 192 | }USB_OTG_CORE_ID_TypeDef; 193 | /** 194 | * @} 195 | */ 196 | 197 | 198 | /** @defgroup USB_DEFINES_Exported_Macros 199 | * @{ 200 | */ 201 | /** 202 | * @} 203 | */ 204 | 205 | /** @defgroup USB_DEFINES_Exported_Variables 206 | * @{ 207 | */ 208 | /** 209 | * @} 210 | */ 211 | 212 | /** @defgroup USB_DEFINES_Exported_FunctionsPrototype 213 | * @{ 214 | */ 215 | /** 216 | * @} 217 | */ 218 | 219 | 220 | /** @defgroup Internal_Macro's 221 | * @{ 222 | */ 223 | #define USB_OTG_READ_REG32(reg) (*(__IO uint32_t *)reg) 224 | #define USB_OTG_WRITE_REG32(reg,value) (*(__IO uint32_t *)reg = value) 225 | #define USB_OTG_MODIFY_REG32(reg,clear_mask,set_mask) \ 226 | USB_OTG_WRITE_REG32(reg, (((USB_OTG_READ_REG32(reg)) & ~clear_mask) | set_mask ) ) 227 | 228 | /******************************************************************************** 229 | ENUMERATION TYPE 230 | ********************************************************************************/ 231 | enum USB_OTG_SPEED { 232 | USB_SPEED_UNKNOWN = 0, 233 | USB_SPEED_LOW, 234 | USB_SPEED_FULL, 235 | USB_SPEED_HIGH 236 | }; 237 | 238 | #endif //__USB_DEFINES__H__ 239 | 240 | 241 | /** 242 | * @} 243 | */ 244 | 245 | /** 246 | * @} 247 | */ 248 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 249 | 250 | -------------------------------------------------------------------------------- /usb/usb_otg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_otg.h 4 | * @author MCD Application Team 5 | * @version V2.1.0 6 | * @date 19-March-2012 7 | * @brief OTG Core Header 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_OTG__ 30 | #define __USB_OTG__ 31 | 32 | 33 | /** @addtogroup USB_OTG_DRIVER 34 | * @{ 35 | */ 36 | 37 | /** @defgroup USB_OTG 38 | * @brief This file is the 39 | * @{ 40 | */ 41 | 42 | 43 | /** @defgroup USB_OTG_Exported_Defines 44 | * @{ 45 | */ 46 | 47 | 48 | uint32_t STM32_USBO_OTG_ISR_Handler(USB_OTG_CORE_HANDLE *pdev); 49 | void USB_OTG_InitiateSRP(USB_OTG_CORE_HANDLE *pdev); 50 | void USB_OTG_InitiateHNP(USB_OTG_CORE_HANDLE *pdev, uint8_t state , uint8_t mode); 51 | //void USB_OTG_Switchback (USB_OTG_CORE_DEVICE *pdev); 52 | //uint32_t USB_OTG_GetCurrentState (USB_OTG_CORE_DEVICE *pdev); 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | /** @defgroup USB_OTG_Exported_Types 60 | * @{ 61 | */ 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USB_OTG_Exported_Macros 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USB_OTG_Exported_Variables 75 | * @{ 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup USB_OTG_Exported_FunctionsPrototype 82 | * @{ 83 | */ 84 | /** 85 | * @} 86 | */ 87 | 88 | 89 | #endif //__USB_OTG__ 90 | 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 100 | 101 | -------------------------------------------------------------------------------- /usb/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_conf_template.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 22-July-2011 7 | * @brief usb device configuration template 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 __USBD_CONF__H__ 24 | #define __USBD_CONF__H__ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f4xx.h" 28 | 29 | //#define USE_USB_OTG_HS 30 | #define USE_USB_OTG_FS 31 | 32 | #define USBD_CFG_MAX_NUM 1 33 | #define USBD_ITF_MAX_NUM 1 34 | 35 | // created in STM32_USB_Device_Library/Core/src/usbd_req.c 36 | // used in usb.c as temporary string buffer 37 | #define USB_MAX_STR_DESC_SIZ 100 38 | extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ]; 39 | 40 | #define USB_SUPPORT_USER_STRING_DESC 41 | 42 | #endif //__USBD_CONF__H__ 43 | 44 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 45 | 46 | -------------------------------------------------------------------------------- /usb/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief Header file for usbd_core.c 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 __USBD_CORE_H 30 | #define __USBD_CORE_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "usb_dcd.h" 34 | #include "usbd_def.h" 35 | #include "usbd_conf.h" 36 | 37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_CORE 42 | * @brief This file is the Header file for usbd_core.c file 43 | * @{ 44 | */ 45 | 46 | 47 | /** @defgroup USBD_CORE_Exported_Defines 48 | * @{ 49 | */ 50 | 51 | typedef enum { 52 | USBD_OK = 0, 53 | USBD_BUSY, 54 | USBD_FAIL, 55 | }USBD_Status; 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | 71 | 72 | /** @defgroup USBD_CORE_Exported_Macros 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_CORE_Exported_Variables 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 89 | * @{ 90 | */ 91 | void USBD_Init(USB_OTG_CORE_HANDLE *pdev, 92 | USB_OTG_CORE_ID_TypeDef coreID, 93 | USBD_DEVICE *pDevice, 94 | USBD_Class_cb_TypeDef *class_cb, 95 | USBD_Usr_cb_TypeDef *usr_cb); 96 | 97 | USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev); 98 | 99 | USBD_Status USBD_ClrCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx); 100 | 101 | USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx); 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | #endif /* __USBD_CORE_H */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /usb/usbd_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_def.h 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief general defines for the usb device 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | 30 | #ifndef __USBD_DEF_H 31 | #define __USBD_DEF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usbd_conf.h" 35 | 36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USB_DEF 41 | * @brief general defines for the usb device library file 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USB_DEF_Exported_Defines 46 | * @{ 47 | */ 48 | 49 | #ifndef NULL 50 | #define NULL 0 51 | #endif 52 | 53 | #define USB_LEN_DEV_QUALIFIER_DESC 0x0A 54 | #define USB_LEN_DEV_DESC 0x12 55 | #define USB_LEN_CFG_DESC 0x09 56 | #define USB_LEN_IF_DESC 0x09 57 | #define USB_LEN_EP_DESC 0x07 58 | #define USB_LEN_OTG_DESC 0x03 59 | 60 | #define USBD_IDX_LANGID_STR 0x00 61 | #define USBD_IDX_MFC_STR 0x01 62 | #define USBD_IDX_PRODUCT_STR 0x02 63 | #define USBD_IDX_SERIAL_STR 0x03 64 | #define USBD_IDX_CONFIG_STR 0x04 65 | #define USBD_IDX_INTERFACE_STR 0x05 66 | 67 | #define USB_REQ_TYPE_STANDARD 0x00 68 | #define USB_REQ_TYPE_CLASS 0x20 69 | #define USB_REQ_TYPE_VENDOR 0x40 70 | #define USB_REQ_TYPE_MASK 0x60 71 | 72 | #define USB_REQ_RECIPIENT_DEVICE 0x00 73 | #define USB_REQ_RECIPIENT_INTERFACE 0x01 74 | #define USB_REQ_RECIPIENT_ENDPOINT 0x02 75 | #define USB_REQ_RECIPIENT_MASK 0x03 76 | 77 | #define USB_REQ_GET_STATUS 0x00 78 | #define USB_REQ_CLEAR_FEATURE 0x01 79 | #define USB_REQ_SET_FEATURE 0x03 80 | #define USB_REQ_SET_ADDRESS 0x05 81 | #define USB_REQ_GET_DESCRIPTOR 0x06 82 | #define USB_REQ_SET_DESCRIPTOR 0x07 83 | #define USB_REQ_GET_CONFIGURATION 0x08 84 | #define USB_REQ_SET_CONFIGURATION 0x09 85 | #define USB_REQ_GET_INTERFACE 0x0A 86 | #define USB_REQ_SET_INTERFACE 0x0B 87 | #define USB_REQ_SYNCH_FRAME 0x0C 88 | 89 | #define USB_DESC_TYPE_DEVICE 1 90 | #define USB_DESC_TYPE_CONFIGURATION 2 91 | #define USB_DESC_TYPE_STRING 3 92 | #define USB_DESC_TYPE_INTERFACE 4 93 | #define USB_DESC_TYPE_ENDPOINT 5 94 | #define USB_DESC_TYPE_DEVICE_QUALIFIER 6 95 | #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 96 | 97 | 98 | #define USB_CONFIG_REMOTE_WAKEUP 2 99 | #define USB_CONFIG_SELF_POWERED 1 100 | 101 | #define USB_FEATURE_EP_HALT 0 102 | #define USB_FEATURE_REMOTE_WAKEUP 1 103 | #define USB_FEATURE_TEST_MODE 2 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | 110 | /** @defgroup USBD_DEF_Exported_TypesDefinitions 111 | * @{ 112 | */ 113 | /** 114 | * @} 115 | */ 116 | 117 | 118 | 119 | /** @defgroup USBD_DEF_Exported_Macros 120 | * @{ 121 | */ 122 | #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ 123 | (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) 124 | 125 | #define LOBYTE(x) ((uint8_t)(x & 0x00FF)) 126 | #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) 127 | /** 128 | * @} 129 | */ 130 | 131 | /** @defgroup USBD_DEF_Exported_Variables 132 | * @{ 133 | */ 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** @defgroup USBD_DEF_Exported_FunctionsPrototype 140 | * @{ 141 | */ 142 | 143 | /** 144 | * @} 145 | */ 146 | 147 | #endif /* __USBD_DEF_H */ 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** 154 | * @} 155 | */ 156 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /usb/usbd_desc.h: -------------------------------------------------------------------------------- 1 | // $Id: usbd_desc.h 1800 2013-06-02 22:09:03Z tk $ 2 | 3 | // Dummy file which only exists, since it's referenced in the STM32 device library (usbd_req.c) 4 | 5 | #ifndef __USB_DESC_H 6 | #define __USB_DESC_H 7 | 8 | #endif /* __USB_DESC_H */ 9 | -------------------------------------------------------------------------------- /usb/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief This file provides the IO requests APIs for control endpoints. 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 "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief control I/O requests module 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USBD_IOREQ_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 76 | * @{ 77 | */ 78 | /** 79 | * @} 80 | */ 81 | 82 | 83 | /** @defgroup USBD_IOREQ_Private_Functions 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief USBD_CtlSendData 89 | * send data on the ctl pipe 90 | * @param pdev: device instance 91 | * @param buff: pointer to data buffer 92 | * @param len: length of data to be sent 93 | * @retval status 94 | */ 95 | USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, 96 | uint8_t *pbuf, 97 | uint16_t len) 98 | { 99 | USBD_Status ret = USBD_OK; 100 | 101 | pdev->dev.in_ep[0].total_data_len = len; 102 | pdev->dev.in_ep[0].rem_data_len = len; 103 | pdev->dev.device_state = USB_OTG_EP0_DATA_IN; 104 | 105 | DCD_EP_Tx (pdev, 0, pbuf, len); 106 | 107 | return ret; 108 | } 109 | 110 | /** 111 | * @brief USBD_CtlContinueSendData 112 | * continue sending data on the ctl pipe 113 | * @param pdev: device instance 114 | * @param buff: pointer to data buffer 115 | * @param len: length of data to be sent 116 | * @retval status 117 | */ 118 | USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, 119 | uint8_t *pbuf, 120 | uint16_t len) 121 | { 122 | USBD_Status ret = USBD_OK; 123 | 124 | DCD_EP_Tx (pdev, 0, pbuf, len); 125 | 126 | 127 | return ret; 128 | } 129 | 130 | /** 131 | * @brief USBD_CtlPrepareRx 132 | * receive data on the ctl pipe 133 | * @param pdev: USB OTG device instance 134 | * @param buff: pointer to data buffer 135 | * @param len: length of data to be received 136 | * @retval status 137 | */ 138 | USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, 139 | uint8_t *pbuf, 140 | uint16_t len) 141 | { 142 | USBD_Status ret = USBD_OK; 143 | 144 | pdev->dev.out_ep[0].total_data_len = len; 145 | pdev->dev.out_ep[0].rem_data_len = len; 146 | pdev->dev.device_state = USB_OTG_EP0_DATA_OUT; 147 | 148 | DCD_EP_PrepareRx (pdev, 149 | 0, 150 | pbuf, 151 | len); 152 | 153 | 154 | return ret; 155 | } 156 | 157 | /** 158 | * @brief USBD_CtlContinueRx 159 | * continue receive data on the ctl pipe 160 | * @param pdev: USB OTG device instance 161 | * @param buff: pointer to data buffer 162 | * @param len: length of data to be received 163 | * @retval status 164 | */ 165 | USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, 166 | uint8_t *pbuf, 167 | uint16_t len) 168 | { 169 | USBD_Status ret = USBD_OK; 170 | 171 | DCD_EP_PrepareRx (pdev, 172 | 0, 173 | pbuf, 174 | len); 175 | return ret; 176 | } 177 | /** 178 | * @brief USBD_CtlSendStatus 179 | * send zero lzngth packet on the ctl pipe 180 | * @param pdev: USB OTG device instance 181 | * @retval status 182 | */ 183 | USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev) 184 | { 185 | USBD_Status ret = USBD_OK; 186 | pdev->dev.device_state = USB_OTG_EP0_STATUS_IN; 187 | DCD_EP_Tx (pdev, 188 | 0, 189 | NULL, 190 | 0); 191 | 192 | USB_OTG_EP0_OutStart(pdev); 193 | 194 | return ret; 195 | } 196 | 197 | /** 198 | * @brief USBD_CtlReceiveStatus 199 | * receive zero lzngth packet on the ctl pipe 200 | * @param pdev: USB OTG device instance 201 | * @retval status 202 | */ 203 | USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev) 204 | { 205 | USBD_Status ret = USBD_OK; 206 | pdev->dev.device_state = USB_OTG_EP0_STATUS_OUT; 207 | DCD_EP_PrepareRx ( pdev, 208 | 0, 209 | NULL, 210 | 0); 211 | 212 | USB_OTG_EP0_OutStart(pdev); 213 | 214 | return ret; 215 | } 216 | 217 | 218 | /** 219 | * @brief USBD_GetRxCount 220 | * returns the received data length 221 | * @param pdev: USB OTG device instance 222 | * epnum: endpoint index 223 | * @retval Rx Data blength 224 | */ 225 | uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum) 226 | { 227 | return pdev->dev.out_ep[epnum].xfer_count; 228 | } 229 | 230 | /** 231 | * @} 232 | */ 233 | 234 | 235 | /** 236 | * @} 237 | */ 238 | 239 | 240 | /** 241 | * @} 242 | */ 243 | 244 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 245 | -------------------------------------------------------------------------------- /usb/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief header file for the usbd_ioreq.c file 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 | 30 | #ifndef __USBD_IOREQ_H_ 31 | #define __USBD_IOREQ_H_ 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usbd_def.h" 35 | #include "usbd_core.h" 36 | 37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ 42 | * @brief header file for the usbd_ioreq.c file 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_IOREQ_Exported_Defines 47 | * @{ 48 | */ 49 | /** 50 | * @} 51 | */ 52 | 53 | 54 | /** @defgroup USBD_IOREQ_Exported_Types 55 | * @{ 56 | */ 57 | 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | 64 | 65 | /** @defgroup USBD_IOREQ_Exported_Macros 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_IOREQ_Exported_Variables 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 82 | * @{ 83 | */ 84 | 85 | USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, 86 | uint8_t *buf, 87 | uint16_t len); 88 | 89 | USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, 90 | uint8_t *pbuf, 91 | uint16_t len); 92 | 93 | USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev, 94 | uint8_t *pbuf, 95 | uint16_t len); 96 | 97 | USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev, 98 | uint8_t *pbuf, 99 | uint16_t len); 100 | 101 | USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev); 102 | 103 | USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev); 104 | 105 | uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev , 106 | uint8_t epnum); 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | #endif /* __USBD_IOREQ_H_ */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /usb/usbd_req.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @version V1.1.0 6 | * @date 19-March-2012 7 | * @brief header file for the usbd_req.c file 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 | 30 | #ifndef __USB_REQUEST_H_ 31 | #define __USB_REQUEST_H_ 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usbd_def.h" 35 | #include "usbd_core.h" 36 | #include "usbd_conf.h" 37 | 38 | 39 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_REQ 44 | * @brief header file for the usbd_ioreq.c file 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_REQ_Exported_Defines 49 | * @{ 50 | */ 51 | /** 52 | * @} 53 | */ 54 | 55 | 56 | /** @defgroup USBD_REQ_Exported_Types 57 | * @{ 58 | */ 59 | /** 60 | * @} 61 | */ 62 | 63 | 64 | 65 | /** @defgroup USBD_REQ_Exported_Macros 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_Variables 73 | * @{ 74 | */ 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 80 | * @{ 81 | */ 82 | 83 | USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); 84 | USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); 85 | USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req); 86 | void USBD_ParseSetupRequest( USB_OTG_CORE_HANDLE *pdev, 87 | USB_SETUP_REQ *req); 88 | 89 | void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev, 90 | USB_SETUP_REQ *req); 91 | 92 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 93 | /** 94 | * @} 95 | */ 96 | 97 | #endif /* __USB_REQUEST_H_ */ 98 | 99 | /** 100 | * @} 101 | */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | 108 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 109 | --------------------------------------------------------------------------------