├── src ├── USER │ ├── main.c │ ├── stm32f10x.h │ ├── JLinkSettings.ini │ ├── stm32f10x_it.h │ ├── system_stm32f10x.h │ ├── stm32f10x_it.c │ ├── serprog.h │ └── stm32f10x_conf.h ├── keilkilll.bat ├── SYSTEM │ ├── sys │ │ ├── sys.c │ │ └── sys.h │ ├── delay │ │ ├── delay.c │ │ └── delay.h │ └── usart │ │ ├── usart.c │ │ └── usart.h ├── HARDWARE │ ├── LED │ │ ├── led.c │ │ └── led.h │ └── SPI │ │ ├── spi.c │ │ └── spi.h ├── USB │ ├── CONFIG │ │ ├── hw_config.c │ │ ├── hw_config.h │ │ ├── usb_endp.c │ │ ├── usb_prop.c │ │ ├── platform_config.h │ │ ├── usb_pwr.h │ │ ├── usb_istr.h │ │ ├── usb_desc.h │ │ ├── usb_prop.h │ │ ├── usb_conf.h │ │ ├── usb_istr.c │ │ ├── usb_desc.c │ │ └── usb_pwr.c │ └── STM32_USB-FS-Device_Driver │ │ ├── inc │ │ ├── usb_int.h │ │ ├── usb_type.h │ │ ├── usb_mem.h │ │ ├── usb_sil.h │ │ ├── usb_lib.h │ │ ├── usb_init.h │ │ └── usb_def.h │ │ └── src │ │ ├── usb_init.c │ │ ├── usb_mem.c │ │ ├── usb_sil.c │ │ └── usb_int.c └── STM32F10x_FWLib │ ├── src │ ├── stm32f10x_flash.c │ ├── stm32f10x_i2c.c │ ├── stm32f10x_usart.c │ ├── stm32f10x_crc.c │ ├── stm32f10x_iwdg.c │ ├── stm32f10x_dbgmcu.c │ ├── stm32f10x_wwdg.c │ ├── misc.c │ └── stm32f10x_exti.c │ └── inc │ ├── stm32f10x_crc.h │ ├── stm32f10x_wwdg.h │ ├── stm32f10x_dbgmcu.h │ ├── stm32f10x_iwdg.h │ ├── stm32f10x_rtc.h │ ├── stm32f10x_pwr.h │ ├── stm32f10x_cec.h │ ├── stm32f10x_exti.h │ └── stm32f10x_bkp.h ├── desktop.ini ├── flashrom0.961 ├── VERSION ├── runme.bat ├── start.bat ├── flashrom.exe ├── libftdi.dll ├── FlashTool.exe ├── libusb0_x86.dll ├── FlashTool.exe.config └── 操作指令.txt ├── README.md └── example ├── io_spi.h ├── io_usb.h ├── config.h ├── io_usb.c ├── serprog.h ├── interrupts.h ├── startup.c ├── serprog-protocol.txt ├── serprog.c └── io_spi.c /src/USER/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USER/main.c -------------------------------------------------------------------------------- /desktop.ini: -------------------------------------------------------------------------------- 1 | [LocalizedFileNames] 2 | Command Prompt.lnk=@%SystemRoot%\system32\shell32.dll,-22022 3 | -------------------------------------------------------------------------------- /flashrom0.961/VERSION: -------------------------------------------------------------------------------- 1 | flashrom-0.9.6.1-r1705 2 | libusb-win32-bin-1.2.4.0 3 | libftdi_0.20git_win32 4 | -------------------------------------------------------------------------------- /src/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/keilkilll.bat -------------------------------------------------------------------------------- /src/SYSTEM/sys/sys.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/SYSTEM/sys/sys.c -------------------------------------------------------------------------------- /src/SYSTEM/sys/sys.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/SYSTEM/sys/sys.h -------------------------------------------------------------------------------- /src/USER/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USER/stm32f10x.h -------------------------------------------------------------------------------- /flashrom0.961/runme.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/flashrom0.961/runme.bat -------------------------------------------------------------------------------- /flashrom0.961/start.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/flashrom0.961/start.bat -------------------------------------------------------------------------------- /src/HARDWARE/LED/led.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/HARDWARE/LED/led.c -------------------------------------------------------------------------------- /src/HARDWARE/LED/led.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/HARDWARE/LED/led.h -------------------------------------------------------------------------------- /src/HARDWARE/SPI/spi.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/HARDWARE/SPI/spi.c -------------------------------------------------------------------------------- /src/HARDWARE/SPI/spi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/HARDWARE/SPI/spi.h -------------------------------------------------------------------------------- /flashrom0.961/flashrom.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/flashrom0.961/flashrom.exe -------------------------------------------------------------------------------- /flashrom0.961/libftdi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/flashrom0.961/libftdi.dll -------------------------------------------------------------------------------- /src/SYSTEM/delay/delay.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/SYSTEM/delay/delay.c -------------------------------------------------------------------------------- /src/SYSTEM/delay/delay.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/SYSTEM/delay/delay.h -------------------------------------------------------------------------------- /src/SYSTEM/usart/usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/SYSTEM/usart/usart.c -------------------------------------------------------------------------------- /src/SYSTEM/usart/usart.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/SYSTEM/usart/usart.h -------------------------------------------------------------------------------- /src/USB/CONFIG/hw_config.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USB/CONFIG/hw_config.c -------------------------------------------------------------------------------- /src/USB/CONFIG/hw_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USB/CONFIG/hw_config.h -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_endp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USB/CONFIG/usb_endp.c -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_prop.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USB/CONFIG/usb_prop.c -------------------------------------------------------------------------------- /flashrom0.961/FlashTool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/flashrom0.961/FlashTool.exe -------------------------------------------------------------------------------- /flashrom0.961/libusb0_x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/flashrom0.961/libusb0_x86.dll -------------------------------------------------------------------------------- /src/USB/CONFIG/platform_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/USB/CONFIG/platform_config.h -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/STM32F10x_FWLib/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/STM32F10x_FWLib/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/posystorage/serprog-stm32-gd32/HEAD/src/STM32F10x_FWLib/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /flashrom0.961/FlashTool.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # serprog-stm32-gd32 2 | stm32/gd32 spi-flash vcp 3 | 目前支持SPI1和SPI2,在SPI.h头文件中切换 4 | 详细使用介绍见: 5 | https://www.flashrom.org/ 6 | https://github.com/dword1511/serprog-stm32vcp 7 | 8 | 在flashrom0.961文件夹下有runme.bat批处理文件,减轻运行麻烦程度 9 | -------------------------------------------------------------------------------- /example/io_spi.h: -------------------------------------------------------------------------------- 1 | #ifndef __IO_SPI_H__ 2 | #define __IO_SPI_H__ 3 | 4 | extern uint32_t spi_conf(uint32_t speed_hz); 5 | extern void spi_bulk_write(uint32_t size); 6 | extern void spi_bulk_read(uint32_t size); 7 | 8 | #endif /* __IO_SPI_H__ */ 9 | -------------------------------------------------------------------------------- /example/io_usb.h: -------------------------------------------------------------------------------- 1 | #ifndef __IO_USB_H__ 2 | #define __IO_USB_H__ 3 | 4 | extern void usb_putc(char data); 5 | extern char usb_getc(void); 6 | extern uint32_t usb_getu24(void); 7 | extern uint32_t usb_getu32(void); 8 | extern void usb_putu32(uint32_t ww); 9 | extern void usb_sync(void); 10 | 11 | #endif /* __IO_USB_H__ */ 12 | -------------------------------------------------------------------------------- /flashrom0.961/操作指令.txt: -------------------------------------------------------------------------------- 1 | f: 2 | cd F:\github\serprog-stm32-gd32\flashrom0.961 3 | flashrom -p serprog:dev=\\.\com28:115200 4 | flashrom -p serprog:dev=\\.\com28:115200 -c MX25L3206E -r f:\save1.bin 5 | flashrom -p serprog:dev=\\.\com28:115200 -c MX25L3206E -E 6 | flashrom -p serprog:dev=\\.\com28:115200 -c MX25L3206E -w f:\save1.bin 7 | flashrom -p serprog:dev=\\.\com28:115200 -c MX25L3206E -v f:\save1.bin -------------------------------------------------------------------------------- /src/USER/JLinkSettings.ini: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ShowInfoWin = 1 3 | EnableFlashBP = 2 4 | BPDuringExecution = 0 5 | [CFI] 6 | CFISize = 0x00 7 | CFIAddr = 0x00 8 | [CPU] 9 | OverrideMemMap = 0 10 | AllowSimulation = 1 11 | ScriptFile="" 12 | [FLASH] 13 | MinNumBytesFlashDL = 0 14 | SkipProgOnCRCMatch = 1 15 | VerifyDownload = 1 16 | AllowCaching = 1 17 | EnableFlashDL = 2 18 | Override = 0 19 | Device="UNSPECIFIED" 20 | [GENERAL] 21 | WorkRAMSize = 0x00 22 | WorkRAMAddr = 0x00 23 | [SWO] 24 | SWOLogFile="" 25 | [MEM] 26 | RdOverrideOrMask = 0x00 27 | RdOverrideAndMask = 0xFFFFFFFF 28 | RdOverrideAddr = 0xFFFFFFFF 29 | WrOverrideOrMask = 0x00 30 | WrOverrideAndMask = 0xFFFFFFFF 31 | WrOverrideAddr = 0xFFFFFFFF 32 | -------------------------------------------------------------------------------- /src/USB/STM32_USB-FS-Device_Driver/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INT_H 31 | #define __USB_INT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void CTR_LP(void); 39 | void CTR_HP(void); 40 | 41 | /* External variables --------------------------------------------------------*/ 42 | 43 | #endif /* __USB_INT_H */ 44 | 45 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /src/USER/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_it.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_IT_H 24 | #define __STM32F10x_IT_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /* Exported types ------------------------------------------------------------*/ 30 | /* Exported constants --------------------------------------------------------*/ 31 | /* Exported macro ------------------------------------------------------------*/ 32 | /* Exported functions ------------------------------------------------------- */ 33 | 34 | void NMI_Handler(void); 35 | void HardFault_Handler(void); 36 | void MemManage_Handler(void); 37 | void BusFault_Handler(void); 38 | void UsageFault_Handler(void); 39 | void SVC_Handler(void); 40 | void DebugMon_Handler(void); 41 | void PendSV_Handler(void); 42 | void SysTick_Handler(void); 43 | 44 | #endif /* __STM32F10x_IT_H */ 45 | 46 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 47 | -------------------------------------------------------------------------------- /src/USB/STM32_USB-FS-Device_Driver/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_type.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Type definitions used by the USB Library 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

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

© COPYRIGHT 2012 STMicroelectronics

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

© COPYRIGHT 2012 STMicroelectronics

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

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_LIB_H 31 | #define __USB_LIB_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "hw_config.h" 35 | #include "usb_type.h" 36 | #include "usb_regs.h" 37 | #include "usb_def.h" 38 | #include "usb_core.h" 39 | #include "usb_init.h" 40 | #include "usb_sil.h" 41 | #include "usb_mem.h" 42 | #include "usb_int.h" 43 | 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | /* Exported macro ------------------------------------------------------------*/ 47 | /* Exported functions ------------------------------------------------------- */ 48 | /* External variables --------------------------------------------------------*/ 49 | 50 | #endif /* __USB_LIB_H */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /example/config.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONFIG_H__ 2 | #define __CONFIG_H__ 3 | 4 | /* Wirings */ 5 | #define PORT_LED GPIOA 6 | #define PIN_LED GPIO_Pin_0 7 | #define PORT_SS GPIOA /* Software SS, assign as you like */ 8 | #define PIN_SS GPIO_Pin_4 9 | 10 | /* USB */ 11 | #define MASS_MEMORY_START 0x04002000 12 | #define BULK_MAX_PACKET_SIZE 0x00000040 /* Max packet size for FullSpeed bulk transfer */ 13 | #define VCP_DATA_SIZE 0x40 /* Should be the same as BULK_MAX_PACKET_SIZE */ 14 | #define ENDP0_RXADDR 0x40 /* EP0 RX buffer base address */ 15 | #define ENDP0_TXADDR 0x80 /* EP0 TX buffer base address */ 16 | #define ENDP1_TXADDR 0xC0 /* EP1 TX buffer base address */ 17 | #define ENDP2_TXADDR 0x100 /* EP2 TX buffer base address */ 18 | #define ENDP3_RXADDR 0x110 /* EP3 RX buffer base address */ 19 | 20 | /* SPI */ 21 | #define SPI_BUS_USED SPI1 22 | #define SPI_ENGINE_RCC RCC_APB2Periph_SPI1 23 | #define SPI_DEFAULT_SPEED 9000000 /* Default SPI clock = 9MHz to support most chips.*/ 24 | #define SPI_DR_Base (&(SPI_BUS_USED->DR)) 25 | #define SPI_TX_DMA_CH DMA1_Channel3 /* SPI1 TX is only available on DMA1 CH3 */ 26 | #define SPI_TX_DMA_FLAG DMA1_FLAG_TC3 27 | #define SPI_RX_DMA_CH DMA1_Channel2 /* SPI1 RX is only available on DMA1 CH2 */ 28 | #define SPI_RX_DMA_FLAG DMA1_FLAG_TC2 29 | 30 | /* serprog */ 31 | #define S_PGM_NAME "serprog-STM32VCP" /* The program's name, must < 16 bytes */ 32 | #define S_SUPPORTED_BUS BUS_SPI 33 | #define S_CMD_MAP ( \ 34 | (1 << S_CMD_NOP) | \ 35 | (1 << S_CMD_Q_IFACE) | \ 36 | (1 << S_CMD_Q_CMDMAP) | \ 37 | (1 << S_CMD_Q_PGMNAME) | \ 38 | (1 << S_CMD_Q_SERBUF) | \ 39 | (1 << S_CMD_Q_BUSTYPE) | \ 40 | (1 << S_CMD_SYNCNOP) | \ 41 | (1 << S_CMD_O_SPIOP) | \ 42 | (1 << S_CMD_S_BUSTYPE) | \ 43 | (1 << S_CMD_S_SPI_FREQ) \ 44 | ) 45 | 46 | /* GPIO macros */ 47 | #define select_chip() GPIO_ResetBits( PORT_SS, PIN_SS) 48 | #define unselect_chip() GPIO_SetBits( PORT_SS, PIN_SS) 49 | #define led_off() GPIO_ResetBits(PORT_LED, PIN_LED) 50 | #define led_on() GPIO_SetBits(PORT_LED, PIN_LED) 51 | 52 | #endif /* __CONFIG_H__ */ -------------------------------------------------------------------------------- /src/USER/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /example/io_usb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "config.h" 3 | #include "io_usb.h" 4 | 5 | /* Do not place const in front of declarations. * 6 | * const variables are stored in flash that needs a 2-cycle wait */ 7 | uint8_t USB_Tx_Buf[VCP_DATA_SIZE]; 8 | uint16_t USB_Tx_ptr_in = 0; 9 | 10 | uint8_t USB_Rx_Buf[VCP_DATA_SIZE]; 11 | uint16_t USB_Rx_ptr_out = 0; 12 | uint8_t USB_Rx_len = 0; 13 | 14 | uint32_t val; 15 | 16 | void usb_putp(void) { 17 | /* Previous transmission complete? */ 18 | while(GetEPTxStatus(ENDP1) != EP_TX_NAK); 19 | /* Send buffer contents */ 20 | UserToPMABufferCopy(USB_Tx_Buf, ENDP1_TXADDR, USB_Tx_ptr_in); 21 | SetEPTxCount(ENDP1, USB_Tx_ptr_in); 22 | SetEPTxValid(ENDP1); 23 | /* Reset buffer pointer */ 24 | USB_Tx_ptr_in = 0; 25 | } 26 | 27 | void usb_getp(void) { 28 | /* Anything new? */ 29 | while(GetEPRxStatus(ENDP3) != EP_RX_NAK); 30 | /* Get the length */ 31 | USB_Rx_len = GetEPRxCount(ENDP3); 32 | if(USB_Rx_len > VCP_DATA_SIZE) USB_Rx_len = VCP_DATA_SIZE; 33 | /* Fetch data and fill buffer */ 34 | PMAToUserBufferCopy(USB_Rx_Buf, ENDP3_RXADDR, VCP_DATA_SIZE); 35 | /* We are good, next? */ 36 | SetEPRxValid(ENDP3); 37 | USB_Rx_ptr_out = 0; 38 | } 39 | 40 | void usb_putc(char data) { 41 | /* Feed new data */ 42 | USB_Tx_Buf[USB_Tx_ptr_in] = data; 43 | USB_Tx_ptr_in ++; 44 | /* End of the buffer, send packet now */ 45 | if(USB_Tx_ptr_in == VCP_DATA_SIZE) usb_putp(); 46 | } 47 | 48 | char usb_getc(void) { 49 | /* End of the buffer, wait for new packet */ 50 | if(USB_Rx_ptr_out == USB_Rx_len) usb_getp(); 51 | /* Get data from the packet */ 52 | USB_Rx_ptr_out ++; 53 | return USB_Rx_Buf[USB_Rx_ptr_out - 1]; 54 | } 55 | 56 | uint32_t usb_getu24(void) { 57 | val = 0; 58 | 59 | val = (uint32_t)usb_getc() << 0; 60 | val |= (uint32_t)usb_getc() << 8; 61 | val |= (uint32_t)usb_getc() << 16; 62 | 63 | return val; 64 | } 65 | 66 | uint32_t usb_getu32(void) { 67 | val = 0; 68 | 69 | val = (uint32_t)usb_getc() << 0; 70 | val |= (uint32_t)usb_getc() << 8; 71 | val |= (uint32_t)usb_getc() << 16; 72 | val |= (uint32_t)usb_getc() << 24; 73 | 74 | return val; 75 | } 76 | 77 | void usb_putu32(uint32_t ww) { 78 | usb_putc(ww >> 0 & 0x000000ff); 79 | usb_putc(ww >> 8 & 0x000000ff); 80 | usb_putc(ww >> 16 & 0x000000ff); 81 | usb_putc(ww >> 24 & 0x000000ff); 82 | } 83 | 84 | void usb_sync(void) { 85 | if(USB_Tx_ptr_in != 0) usb_putp(); 86 | } 87 | -------------------------------------------------------------------------------- /example/serprog.h: -------------------------------------------------------------------------------- 1 | #ifndef __SERPROG_H__ 2 | #define __SERPROG_H__ 3 | 4 | #define S_IFACE_VERSION 0x01 /* Version of the protocol */ 5 | 6 | /* According to Serial Flasher Protocol Specification - version 1 */ 7 | #define S_ACK 0x06 8 | #define S_NAK 0x15 9 | #define S_CMD_NOP 0x00 /* No operation */ 10 | #define S_CMD_Q_IFACE 0x01 /* Query interface version */ 11 | #define S_CMD_Q_CMDMAP 0x02 /* Query supported commands bitmap */ 12 | #define S_CMD_Q_PGMNAME 0x03 /* Query programmer name */ 13 | #define S_CMD_Q_SERBUF 0x04 /* Query Serial Buffer Size */ 14 | #define S_CMD_Q_BUSTYPE 0x05 /* Query supported bustypes */ 15 | #define S_CMD_Q_CHIPSIZE 0x06 /* Query supported chipsize (2^n format) */ 16 | #define S_CMD_Q_OPBUF 0x07 /* Query operation buffer size */ 17 | #define S_CMD_Q_WRNMAXLEN 0x08 /* Query Write to opbuf: Write-N maximum length */ 18 | #define S_CMD_R_BYTE 0x09 /* Read a single byte */ 19 | #define S_CMD_R_NBYTES 0x0A /* Read n bytes */ 20 | #define S_CMD_O_INIT 0x0B /* Initialize operation buffer */ 21 | #define S_CMD_O_WRITEB 0x0C /* Write opbuf: Write byte with address */ 22 | #define S_CMD_O_WRITEN 0x0D /* Write to opbuf: Write-N */ 23 | #define S_CMD_O_DELAY 0x0E /* Write opbuf: udelay */ 24 | #define S_CMD_O_EXEC 0x0F /* Execute operation buffer */ 25 | #define S_CMD_SYNCNOP 0x10 /* Special no-operation that returns NAK+ACK */ 26 | #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ 27 | #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s) */ 28 | #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation */ 29 | #define S_CMD_S_SPI_FREQ 0x14 /* Set SPI clock frequency */ 30 | #define S_CMD_S_PIN_STATE 0x15 /* Enable/disable output drivers */ 31 | 32 | /* flashrom bus types */ 33 | #define BUS_NONE 0x00 34 | #define BUS_PARALLEL 0x01 35 | #define BUS_LPC 0x02 36 | #define BUS_FWH 0x04 37 | #define BUS_SPI 0x08 38 | #define BUS_PROG 0x10 39 | #define BUS_NONSPI (BUS_PARALLEL | BUS_LPC | BUS_FWH) 40 | 41 | #endif /* __SERPROG_H__ */ 42 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CRC_H 25 | #define __STM32F10x_CRC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CRC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup CRC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | void CRC_ResetDR(void); 71 | uint32_t CRC_CalcCRC(uint32_t Data); 72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 73 | uint32_t CRC_GetCRC(void); 74 | void CRC_SetIDRegister(uint8_t IDValue); 75 | uint8_t CRC_GetIDRegister(void); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F10x_CRC_H */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_PWR_H 31 | #define __USB_PWR_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | typedef enum _RESUME_STATE 36 | { 37 | RESUME_EXTERNAL, 38 | RESUME_INTERNAL, 39 | RESUME_LATER, 40 | RESUME_WAIT, 41 | RESUME_START, 42 | RESUME_ON, 43 | RESUME_OFF, 44 | RESUME_ESOF 45 | } RESUME_STATE; 46 | 47 | typedef enum _DEVICE_STATE 48 | { 49 | UNCONNECTED, 50 | ATTACHED, 51 | POWERED, 52 | SUSPENDED, 53 | ADDRESSED, 54 | CONFIGURED 55 | } DEVICE_STATE; 56 | 57 | /* Exported constants --------------------------------------------------------*/ 58 | /* Exported macro ------------------------------------------------------------*/ 59 | /* Exported functions ------------------------------------------------------- */ 60 | void Suspend(void); 61 | void Resume_Init(void); 62 | void Resume(RESUME_STATE eResumeSetVal); 63 | RESULT PowerOn(void); 64 | RESULT PowerOff(void); 65 | 66 | /* External variables --------------------------------------------------------*/ 67 | extern __IO uint32_t bDeviceState; /* USB device status */ 68 | extern __IO bool fSuspendEnabled; /* true when suspend is possible */ 69 | 70 | #endif /*__USB_PWR_H*/ 71 | 72 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 73 | -------------------------------------------------------------------------------- /src/USER/stm32f10x_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_it.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and peripherals 9 | * interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 14 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 15 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 16 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 17 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 18 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 19 | * 20 | *

© COPYRIGHT 2011 STMicroelectronics

21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include "stm32f10x_it.h" 26 | 27 | 28 | 29 | void NMI_Handler(void) 30 | { 31 | } 32 | 33 | void HardFault_Handler(void) 34 | { 35 | /* Go to infinite loop when Hard Fault exception occurs */ 36 | while (1) 37 | { 38 | } 39 | } 40 | 41 | void MemManage_Handler(void) 42 | { 43 | /* Go to infinite loop when Memory Manage exception occurs */ 44 | while (1) 45 | { 46 | } 47 | } 48 | 49 | 50 | void BusFault_Handler(void) 51 | { 52 | /* Go to infinite loop when Bus Fault exception occurs */ 53 | while (1) 54 | { 55 | } 56 | } 57 | 58 | void UsageFault_Handler(void) 59 | { 60 | /* Go to infinite loop when Usage Fault exception occurs */ 61 | while (1) 62 | { 63 | } 64 | } 65 | 66 | void SVC_Handler(void) 67 | { 68 | } 69 | 70 | void DebugMon_Handler(void) 71 | { 72 | } 73 | 74 | void PendSV_Handler(void) 75 | { 76 | } 77 | 78 | void SysTick_Handler(void) 79 | { 80 | } 81 | 82 | /******************************************************************************/ 83 | /* STM32F10x Peripherals Interrupt Handlers */ 84 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 85 | /* available peripheral interrupt handler's name please refer to the startup */ 86 | /* file (startup_stm32f10x_xx.s). */ 87 | /******************************************************************************/ 88 | -------------------------------------------------------------------------------- /src/USB/STM32_USB-FS-Device_Driver/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_INIT_H 31 | #define __USB_INIT_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | void USB_Init(void); 39 | 40 | /* External variables --------------------------------------------------------*/ 41 | /* The number of current endpoint, it will be used to specify an endpoint */ 42 | extern uint8_t EPindex; 43 | /* The number of current device, it is an index to the Device_Table */ 44 | /*extern uint8_t Device_no; */ 45 | /* Points to the DEVICE_INFO structure of current device */ 46 | /* The purpose of this register is to speed up the execution */ 47 | extern DEVICE_INFO* pInformation; 48 | /* Points to the DEVICE_PROP structure of current device */ 49 | /* The purpose of this register is to speed up the execution */ 50 | extern DEVICE_PROP* pProperty; 51 | /* Temporary save the state of Rx & Tx status. */ 52 | /* Whenever the Rx or Tx state is changed, its value is saved */ 53 | /* in this variable first and will be set to the EPRB or EPRA */ 54 | /* at the end of interrupt process */ 55 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 56 | 57 | extern uint16_t SaveState ; 58 | extern uint16_t wInterrupt_Mask; 59 | 60 | #endif /* __USB_INIT_H */ 61 | 62 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 63 | -------------------------------------------------------------------------------- /src/USER/serprog.h: -------------------------------------------------------------------------------- 1 | #ifndef __SERPROG_H__ 2 | #define __SERPROG_H__ 3 | 4 | #define S_IFACE_VERSION 0x01 /* Version of the protocol */ 5 | 6 | /* According to Serial Flasher Protocol Specification - version 1 */ 7 | #define S_ACK 0x06 8 | #define S_NAK 0x15 9 | #define S_CMD_NOP 0x00 /* No operation */ 10 | #define S_CMD_Q_IFACE 0x01 /* Query interface version */ 11 | #define S_CMD_Q_CMDMAP 0x02 /* Query supported commands bitmap */ 12 | #define S_CMD_Q_PGMNAME 0x03 /* Query programmer name */ 13 | #define S_CMD_Q_SERBUF 0x04 /* Query Serial Buffer Size */ 14 | #define S_CMD_Q_BUSTYPE 0x05 /* Query supported bustypes */ 15 | #define S_CMD_Q_CHIPSIZE 0x06 /* Query supported chipsize (2^n format) */ 16 | #define S_CMD_Q_OPBUF 0x07 /* Query operation buffer size */ 17 | #define S_CMD_Q_WRNMAXLEN 0x08 /* Query Write to opbuf: Write-N maximum length */ 18 | #define S_CMD_R_BYTE 0x09 /* Read a single byte */ 19 | #define S_CMD_R_NBYTES 0x0A /* Read n bytes */ 20 | #define S_CMD_O_INIT 0x0B /* Initialize operation buffer */ 21 | #define S_CMD_O_WRITEB 0x0C /* Write opbuf: Write byte with address */ 22 | #define S_CMD_O_WRITEN 0x0D /* Write to opbuf: Write-N */ 23 | #define S_CMD_O_DELAY 0x0E /* Write opbuf: udelay */ 24 | #define S_CMD_O_EXEC 0x0F /* Execute operation buffer */ 25 | #define S_CMD_SYNCNOP 0x10 /* Special no-operation that returns NAK+ACK */ 26 | #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ 27 | #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s) */ 28 | #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation */ 29 | #define S_CMD_S_SPI_FREQ 0x14 /* Set SPI clock frequency */ 30 | #define S_CMD_S_PIN_STATE 0x15 /* Enable/disable output drivers */ 31 | 32 | /* flashrom bus types */ 33 | #define BUS_NONE 0x00 34 | #define BUS_PARALLEL 0x01 35 | #define BUS_LPC 0x02 36 | #define BUS_FWH 0x04 37 | #define BUS_SPI 0x08 38 | #define BUS_PROG 0x10 39 | #define BUS_NONSPI (BUS_PARALLEL | BUS_LPC | BUS_FWH) 40 | 41 | /* serprog */ 42 | #define S_PGM_NAME "serprog-STM32/GD" /* The program's name, must < 16 bytes */ 43 | #define S_SUPPORTED_BUS BUS_SPI 44 | #define S_CMD_MAP ( \ 45 | (1 << S_CMD_NOP) | \ 46 | (1 << S_CMD_Q_IFACE) | \ 47 | (1 << S_CMD_Q_CMDMAP) | \ 48 | (1 << S_CMD_Q_PGMNAME) | \ 49 | (1 << S_CMD_Q_SERBUF) | \ 50 | (1 << S_CMD_Q_BUSTYPE) | \ 51 | (1 << S_CMD_SYNCNOP) | \ 52 | (1 << S_CMD_O_SPIOP) | \ 53 | (1 << S_CMD_S_BUSTYPE) | \ 54 | (1 << S_CMD_S_SPI_FREQ) \ 55 | ) 56 | 57 | #endif /* __SERPROG_H__ */ 58 | -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

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

© COPYRIGHT 2013 STMicroelectronics

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

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_DEF_H 30 | #define __USB_DEF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported types ------------------------------------------------------------*/ 34 | typedef enum _RECIPIENT_TYPE 35 | { 36 | DEVICE_RECIPIENT, /* Recipient device */ 37 | INTERFACE_RECIPIENT, /* Recipient interface */ 38 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 39 | OTHER_RECIPIENT 40 | } RECIPIENT_TYPE; 41 | 42 | 43 | typedef enum _STANDARD_REQUESTS 44 | { 45 | GET_STATUS = 0, 46 | CLEAR_FEATURE, 47 | RESERVED1, 48 | SET_FEATURE, 49 | RESERVED2, 50 | SET_ADDRESS, 51 | GET_DESCRIPTOR, 52 | SET_DESCRIPTOR, 53 | GET_CONFIGURATION, 54 | SET_CONFIGURATION, 55 | GET_INTERFACE, 56 | SET_INTERFACE, 57 | TOTAL_sREQUEST, /* Total number of Standard request */ 58 | SYNCH_FRAME = 12 59 | } STANDARD_REQUESTS; 60 | 61 | /* Definition of "USBwValue" */ 62 | typedef enum _DESCRIPTOR_TYPE 63 | { 64 | DEVICE_DESCRIPTOR = 1, 65 | CONFIG_DESCRIPTOR, 66 | STRING_DESCRIPTOR, 67 | INTERFACE_DESCRIPTOR, 68 | ENDPOINT_DESCRIPTOR 69 | } DESCRIPTOR_TYPE; 70 | 71 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 72 | typedef enum _FEATURE_SELECTOR 73 | { 74 | ENDPOINT_STALL, 75 | DEVICE_REMOTE_WAKEUP 76 | } FEATURE_SELECTOR; 77 | 78 | /* Exported constants --------------------------------------------------------*/ 79 | /* Definition of "USBbmRequestType" */ 80 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 81 | #define STANDARD_REQUEST 0x00 /* Standard request */ 82 | #define CLASS_REQUEST 0x20 /* Class request */ 83 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 84 | 85 | #define RECIPIENT 0x1F /* Mask to get recipient */ 86 | 87 | /* Exported macro ------------------------------------------------------------*/ 88 | /* Exported functions ------------------------------------------------------- */ 89 | 90 | #endif /* __USB_DEF_H */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /src/USER/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

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

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_WWDG_H 25 | #define __STM32F10x_WWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup WWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup WWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Exported_Macros 78 | * @{ 79 | */ 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | void WWDG_DeInit(void); 89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 90 | void WWDG_SetWindowValue(uint8_t WindowValue); 91 | void WWDG_EnableIT(void); 92 | void WWDG_SetCounter(uint8_t Counter); 93 | void WWDG_Enable(uint8_t Counter); 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F10x_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /example/interrupts.h: -------------------------------------------------------------------------------- 1 | #ifndef __INTERRUPTS_H__ 2 | #define __INTERRUPTS_H__ 3 | 4 | extern void USB_Istr(void); 5 | 6 | #define NMIException EmptyVect 7 | 8 | #define HardFaultException FaultVect 9 | #define MemManageException FaultVect 10 | #define BusFaultException FaultVect 11 | #define UsageFaultException FaultVect 12 | 13 | #define DebugMonitor EmptyVect 14 | #define SVCHandler EmptyVect 15 | #define PendSVC EmptyVect 16 | #define SysTickHandler EmptyVect 17 | #define WWDG_IRQHandler EmptyVect 18 | #define PVD_IRQHandler EmptyVect 19 | #define TAMPER_IRQHandler EmptyVect 20 | #define RTC_IRQHandler EmptyVect 21 | #define FLASH_IRQHandler EmptyVect 22 | #define RCC_IRQHandler EmptyVect 23 | #define EXTI0_IRQHandler EmptyVect 24 | #define EXTI1_IRQHandler EmptyVect 25 | #define EXTI2_IRQHandler EmptyVect 26 | #define EXTI3_IRQHandler EmptyVect 27 | #define EXTI4_IRQHandler EmptyVect 28 | #define DMA1_Channel1_IRQHandler EmptyVect 29 | #define DMA1_Channel2_IRQHandler EmptyVect 30 | #define DMA1_Channel3_IRQHandler EmptyVect 31 | #define DMA1_Channel4_IRQHandler EmptyVect 32 | #define DMA1_Channel5_IRQHandler EmptyVect 33 | #define DMA1_Channel6_IRQHandler EmptyVect 34 | #define DMA1_Channel7_IRQHandler EmptyVect 35 | #define ADC1_2_IRQHandler EmptyVect 36 | #define USB_HP_CAN_TX_IRQHandler EmptyVect 37 | 38 | #define USB_LP_CAN_RX0_IRQHandler USB_Istr 39 | 40 | #define CAN_RX1_IRQHandler EmptyVect 41 | #define CAN_SCE_IRQHandler EmptyVect 42 | #define EXTI9_5_IRQHandler EmptyVect 43 | #define TIM1_BRK_IRQHandler EmptyVect 44 | #define TIM1_UP_IRQHandler EmptyVect 45 | #define TIM1_TRG_COM_IRQHandler EmptyVect 46 | #define TIM1_CC_IRQHandler EmptyVect 47 | #define TIM2_IRQHandler EmptyVect 48 | #define TIM3_IRQHandler EmptyVect 49 | #define TIM4_IRQHandler EmptyVect 50 | #define I2C1_EV_IRQHandler EmptyVect 51 | #define I2C1_ER_IRQHandler EmptyVect 52 | #define I2C2_EV_IRQHandler EmptyVect 53 | #define I2C2_ER_IRQHandler EmptyVect 54 | #define SPI1_IRQHandler EmptyVect 55 | #define SPI2_IRQHandler EmptyVect 56 | #define USART1_IRQHandler EmptyVect 57 | #define USART2_IRQHandler EmptyVect 58 | #define USART3_IRQHandler EmptyVect 59 | #define EXTI15_10_IRQHandler EmptyVect 60 | #define RTCAlarm_IRQHandler EmptyVect 61 | #define USBWakeUp_IRQHandler EmptyVect 62 | #define TIM8_BRK_IRQHandler EmptyVect 63 | #define TIM8_UP_IRQHandler EmptyVect 64 | #define TIM8_TRG_COM_IRQHandler EmptyVect 65 | #define TIM8_CC_IRQHandler EmptyVect 66 | #define ADC3_IRQHandler EmptyVect 67 | #define FSMC_IRQHandler EmptyVect 68 | #define SDIO_IRQHandler EmptyVect 69 | #define TIM5_IRQHandler EmptyVect 70 | #define SPI3_IRQHandler EmptyVect 71 | #define UART4_IRQHandler EmptyVect 72 | #define UART5_IRQHandler EmptyVect 73 | #define TIM6_IRQHandler EmptyVect 74 | #define TIM7_IRQHandler EmptyVect 75 | #define DMA2_Channel1_IRQHandler EmptyVect 76 | #define DMA2_Channel2_IRQHandler EmptyVect 77 | #define DMA2_Channel3_IRQHandler EmptyVect 78 | #define DMA2_Channel4_5_IRQHandler EmptyVect 79 | 80 | #endif /* __INTERRUPTS_H__ */ -------------------------------------------------------------------------------- /src/USB/STM32_USB-FS-Device_Driver/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

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

© COPYRIGHT 2013 STMicroelectronics

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

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Extern variables ----------------------------------------------------------*/ 36 | /* Private function prototypes -----------------------------------------------*/ 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /******************************************************************************* 40 | * Function Name : UserToPMABufferCopy 41 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 42 | * Input : - pbUsrBuf: pointer to user memory area. 43 | * - wPMABufAddr: address into PMA. 44 | * - wNBytes: no. of bytes to be copied. 45 | * Output : None. 46 | * Return : None . 47 | *******************************************************************************/ 48 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 49 | { 50 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 51 | uint32_t i, temp1, temp2; 52 | uint16_t *pdwVal; 53 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 54 | for (i = n; i != 0; i--) 55 | { 56 | temp1 = (uint16_t) * pbUsrBuf; 57 | pbUsrBuf++; 58 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; 59 | *pdwVal++ = temp2; 60 | pdwVal++; 61 | pbUsrBuf++; 62 | } 63 | } 64 | 65 | /******************************************************************************* 66 | * Function Name : PMAToUserBufferCopy 67 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 68 | * Input : - pbUsrBuf = pointer to user memory area. 69 | * - wPMABufAddr = address into PMA. 70 | * - wNBytes = no. of bytes to be copied. 71 | * Output : None. 72 | * Return : None. 73 | *******************************************************************************/ 74 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 75 | { 76 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 77 | uint32_t i; 78 | uint32_t *pdwVal; 79 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 80 | for (i = n; i != 0; i--) 81 | { 82 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; 83 | pbUsrBuf++; 84 | } 85 | } 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

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

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_DBGMCU_H 25 | #define __STM32F10x_DBGMCU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup DBGMCU 39 | * @{ 40 | */ 41 | 42 | /** @defgroup DBGMCU_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 55 | #define DBGMCU_STOP ((uint32_t)0x00000002) 56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 80 | 81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup DBGMCU_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup DBGMCU_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | uint32_t DBGMCU_GetREVID(void); 99 | uint32_t DBGMCU_GetDEVID(void); 100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __STM32F10x_DBGMCU_H */ 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_conf.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Virtual COM Port Demo configuration header 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __USB_CONF_H 31 | #define __USB_CONF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | /* External variables --------------------------------------------------------*/ 39 | 40 | /*-------------------------------------------------------------*/ 41 | /* EP_NUM */ 42 | /* defines how many endpoints are used by the device */ 43 | /*-------------------------------------------------------------*/ 44 | 45 | #define EP_NUM (4) 46 | 47 | /*-------------------------------------------------------------*/ 48 | /* -------------- Buffer Description Table -----------------*/ 49 | /*-------------------------------------------------------------*/ 50 | /* buffer table base address */ 51 | /* buffer table base address */ 52 | #define BTABLE_ADDRESS (0x00) 53 | 54 | /* EP0 */ 55 | /* rx/tx buffer base address */ 56 | #define ENDP0_RXADDR (0x40) 57 | #define ENDP0_TXADDR (0x80) 58 | 59 | /* EP1 */ 60 | /* tx buffer base address */ 61 | #define ENDP1_TXADDR (0xC0) 62 | #define ENDP2_TXADDR (0x100) 63 | #define ENDP3_RXADDR (0x110) 64 | 65 | 66 | /*-------------------------------------------------------------*/ 67 | /* ------------------- ISTR events -------------------------*/ 68 | /*-------------------------------------------------------------*/ 69 | /* IMR_MSK */ 70 | /* mask defining which events has to be handled */ 71 | /* by the device application software */ 72 | #define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \ 73 | | CNTR_RESETM ) 74 | //| CNTR_ESOFM 75 | /*#define CTR_CALLBACK*/ 76 | /*#define DOVR_CALLBACK*/ 77 | /*#define ERR_CALLBACK*/ 78 | /*#define WKUP_CALLBACK*/ 79 | /*#define SUSP_CALLBACK*/ 80 | /*#define RESET_CALLBACK*/ 81 | #define SOF_CALLBACK 82 | /*#define ESOF_CALLBACK*/ 83 | /* CTR service routines */ 84 | /* associated to defined endpoints */ 85 | /*#define EP1_IN_Callback NOP_Process*/ 86 | #define EP2_IN_Callback NOP_Process 87 | #define EP3_IN_Callback NOP_Process 88 | #define EP4_IN_Callback NOP_Process 89 | #define EP5_IN_Callback NOP_Process 90 | #define EP6_IN_Callback NOP_Process 91 | #define EP7_IN_Callback NOP_Process 92 | 93 | #define EP1_OUT_Callback NOP_Process 94 | #define EP2_OUT_Callback NOP_Process 95 | /*#define EP3_OUT_Callback NOP_Process*/ 96 | #define EP4_OUT_Callback NOP_Process 97 | #define EP5_OUT_Callback NOP_Process 98 | #define EP6_OUT_Callback NOP_Process 99 | #define EP7_OUT_Callback NOP_Process 100 | 101 | #endif /* __USB_CONF_H */ 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

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

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_RTC_H 25 | #define __STM32F10x_RTC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RTC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup RTC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup RTC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup RTC_interrupts_define 55 | * @{ 56 | */ 57 | 58 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 59 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 60 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 61 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 62 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 63 | ((IT) == RTC_IT_SEC)) 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup RTC_interrupts_flags 69 | * @{ 70 | */ 71 | 72 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 73 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 74 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 75 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 76 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 77 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 78 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 79 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 80 | ((FLAG) == RTC_FLAG_SEC)) 81 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @defgroup RTC_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup RTC_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 104 | void RTC_EnterConfigMode(void); 105 | void RTC_ExitConfigMode(void); 106 | uint32_t RTC_GetCounter(void); 107 | void RTC_SetCounter(uint32_t CounterValue); 108 | void RTC_SetPrescaler(uint32_t PrescalerValue); 109 | void RTC_SetAlarm(uint32_t AlarmValue); 110 | uint32_t RTC_GetDivider(void); 111 | void RTC_WaitForLastTask(void); 112 | void RTC_WaitForSynchro(void); 113 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 114 | void RTC_ClearFlag(uint16_t RTC_FLAG); 115 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 116 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* __STM32F10x_RTC_H */ 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 136 | -------------------------------------------------------------------------------- /src/USB/STM32_USB-FS-Device_Driver/src/usb_sil.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer for Global Initialization and Endpoint 8 | * Rea/Write operations. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usb_lib.h" 32 | 33 | /* Private typedef -----------------------------------------------------------*/ 34 | /* Private define ------------------------------------------------------------*/ 35 | /* Private macro -------------------------------------------------------------*/ 36 | /* Private variables ---------------------------------------------------------*/ 37 | /* Extern variables ----------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /******************************************************************************* 42 | * Function Name : USB_SIL_Init 43 | * Description : Initialize the USB Device IP and the Endpoint 0. 44 | * Input : None. 45 | * Output : None. 46 | * Return : Status. 47 | *******************************************************************************/ 48 | uint32_t USB_SIL_Init(void) 49 | { 50 | /* USB interrupts initialization */ 51 | /* clear pending interrupts */ 52 | _SetISTR(0); 53 | wInterrupt_Mask = IMR_MSK; 54 | /* set interrupts mask */ 55 | _SetCNTR(wInterrupt_Mask); 56 | return 0; 57 | } 58 | 59 | /******************************************************************************* 60 | * Function Name : USB_SIL_Write 61 | * Description : Write a buffer of data to a selected endpoint. 62 | * Input : - bEpAddr: The address of the non control endpoint. 63 | * - pBufferPointer: The pointer to the buffer of data to be written 64 | * to the endpoint. 65 | * - wBufferSize: Number of data to be written (in bytes). 66 | * Output : None. 67 | * Return : Status. 68 | *******************************************************************************/ 69 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize) 70 | { 71 | /* Use the memory interface function to write to the selected endpoint */ 72 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); 73 | 74 | /* Update the data length in the control register */ 75 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize); 76 | 77 | return 0; 78 | } 79 | 80 | /******************************************************************************* 81 | * Function Name : USB_SIL_Read 82 | * Description : Write a buffer of data to a selected endpoint. 83 | * Input : - bEpAddr: The address of the non control endpoint. 84 | * - pBufferPointer: The pointer to which will be saved the 85 | * received data buffer. 86 | * Output : None. 87 | * Return : Number of received data (in Bytes). 88 | *******************************************************************************/ 89 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer) 90 | { 91 | uint32_t DataLength = 0; 92 | 93 | /* Get the number of received data on the selected Endpoint */ 94 | DataLength = GetEPRxCount(bEpAddr & 0x7F); 95 | 96 | /* Use the memory interface function to write to the selected endpoint */ 97 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); 98 | 99 | /* Return the number of received data */ 100 | return DataLength; 101 | } 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_PWR_H 25 | #define __STM32F10x_PWR_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup PWR 39 | * @{ 40 | */ 41 | 42 | /** @defgroup PWR_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup PWR_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup PVD_detection_level 55 | * @{ 56 | */ 57 | 58 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 59 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 60 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 61 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 62 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 63 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 64 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 65 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 66 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 67 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 68 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup Regulator_state_is_STOP_mode 75 | * @{ 76 | */ 77 | 78 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 79 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 80 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 81 | ((REGULATOR) == PWR_Regulator_LowPower)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup STOP_mode_entry 87 | * @{ 88 | */ 89 | 90 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 91 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 92 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup PWR_Flag 99 | * @{ 100 | */ 101 | 102 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 103 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 104 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 105 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 106 | ((FLAG) == PWR_FLAG_PVDO)) 107 | 108 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup PWR_Exported_Macros 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup PWR_Exported_Functions 126 | * @{ 127 | */ 128 | 129 | void PWR_DeInit(void); 130 | void PWR_BackupAccessCmd(FunctionalState NewState); 131 | void PWR_PVDCmd(FunctionalState NewState); 132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 133 | void PWR_WakeUpPinCmd(FunctionalState NewState); 134 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 135 | void PWR_EnterSTANDBYMode(void); 136 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 137 | void PWR_ClearFlag(uint32_t PWR_FLAG); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __STM32F10x_PWR_H */ 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /example/startup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "interrupts.h" 6 | 7 | void ResetISR(void); 8 | extern int main(void); 9 | 10 | void EmptyVect(void) {} 11 | 12 | void FaultVect(void) { 13 | while(1); 14 | } 15 | 16 | #ifndef STACK_SIZE 17 | #define STACK_SIZE 1024 18 | #endif /* STACK_SIZE */ 19 | 20 | //***************************************************************************** 21 | // The minimal vector table for a Cortex-M3. Note that the proper constructs 22 | // must be placed on this to ensure that it ends up at physical address 23 | // 0x00000000. 24 | //***************************************************************************** 25 | /* init value for the stack pointer. defined in linker script */ 26 | extern void _estack; 27 | 28 | __attribute__ ((section(".isr_vector"))) 29 | void (* const g_pfnVectors[])(void) = { 30 | &_estack, /* The initial stack pointer*/ 31 | ResetISR, 32 | NMIException, 33 | HardFaultException, 34 | MemManageException, 35 | BusFaultException, 36 | UsageFaultException, 37 | 0, 0, 0, 0, /* Reserved */ 38 | SVCHandler, 39 | DebugMonitor, 40 | 0, /* Reserved */ 41 | PendSVC, 42 | SysTickHandler, 43 | WWDG_IRQHandler, 44 | PVD_IRQHandler, 45 | TAMPER_IRQHandler, 46 | RTC_IRQHandler, 47 | FLASH_IRQHandler, 48 | RCC_IRQHandler, 49 | EXTI0_IRQHandler, 50 | EXTI1_IRQHandler, 51 | EXTI2_IRQHandler, 52 | EXTI3_IRQHandler, 53 | EXTI4_IRQHandler, 54 | DMA1_Channel1_IRQHandler, 55 | DMA1_Channel2_IRQHandler, 56 | DMA1_Channel3_IRQHandler, 57 | DMA1_Channel4_IRQHandler, 58 | DMA1_Channel5_IRQHandler, 59 | DMA1_Channel6_IRQHandler, 60 | DMA1_Channel7_IRQHandler, 61 | ADC1_2_IRQHandler, 62 | USB_HP_CAN_TX_IRQHandler, 63 | USB_LP_CAN_RX0_IRQHandler, 64 | CAN_RX1_IRQHandler, 65 | CAN_SCE_IRQHandler, 66 | EXTI9_5_IRQHandler, 67 | TIM1_BRK_IRQHandler, 68 | TIM1_UP_IRQHandler, 69 | TIM1_TRG_COM_IRQHandler, 70 | TIM1_CC_IRQHandler, 71 | TIM2_IRQHandler, 72 | TIM3_IRQHandler, 73 | TIM4_IRQHandler, 74 | I2C1_EV_IRQHandler, 75 | I2C1_ER_IRQHandler, 76 | I2C2_EV_IRQHandler, 77 | I2C2_ER_IRQHandler, 78 | SPI1_IRQHandler, 79 | SPI2_IRQHandler, 80 | USART1_IRQHandler, 81 | USART2_IRQHandler, 82 | USART3_IRQHandler, 83 | EXTI15_10_IRQHandler, 84 | RTCAlarm_IRQHandler, 85 | USBWakeUp_IRQHandler, 86 | }; 87 | 88 | //***************************************************************************** 89 | // The following are constructs created by the linker, indicating where the 90 | // the "data" and "bss" segments reside in memory. The initializers for the 91 | // for the "data" segment resides immediately following the "text" segment. 92 | //***************************************************************************** 93 | extern uint32_t _etext; 94 | extern uint32_t _data; 95 | extern uint32_t _edata; 96 | extern uint32_t _bss; 97 | extern uint32_t _ebss; 98 | 99 | //***************************************************************************** 100 | // This is the code that gets called when the processor first starts execution 101 | // following a reset event. Only the absolutely necessary set is performed, 102 | // after which the application supplied main() routine is called. Any fancy 103 | // actions (such as making decisions based on the reset cause register, and 104 | // resetting the bits in that register) are left solely in the hands of the 105 | // application. 106 | //***************************************************************************** 107 | void ResetISR(void) { 108 | uint32_t *pulSrc, *pulDest; 109 | 110 | /* Copy the data segment initializers from flash to SRAM, then zero fill the bss segment. */ 111 | pulSrc = &_etext; 112 | for(pulDest = &_data; pulDest < &_edata; ) *pulDest++ = *pulSrc++; 113 | for(pulDest = &_bss; pulDest < &_ebss; ) *pulDest++ = 0; 114 | 115 | /* Configure system clock. */ 116 | RCC_DeInit(); 117 | RCC_HSEConfig(RCC_HSE_ON); 118 | if(RCC_WaitForHSEStartUp() == SUCCESS) { 119 | /* Flash latency have to be set to 2 cycles when SYSCLK > 48MHz */ 120 | FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); 121 | FLASH_SetLatency(FLASH_Latency_2); 122 | 123 | /* AHB Clock set to MAX */ 124 | RCC_HCLKConfig(RCC_SYSCLK_Div1); 125 | /* APB2 Clock set to MAX */ 126 | RCC_PCLK2Config(RCC_HCLK_Div1); 127 | /* APB1 Clock set to MAX (1/2 Sys Clock) */ 128 | RCC_PCLK1Config(RCC_HCLK_Div2); 129 | RCC_ADCCLKConfig(RCC_PCLK2_Div6); 130 | 131 | RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* 8x9 = 72MHz */ 132 | RCC_PLLCmd(ENABLE); 133 | while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); 134 | RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); 135 | while(RCC_GetSYSCLKSource() != 0x08); 136 | 137 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE); 138 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_DMA2, ENABLE); 139 | GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); 140 | } 141 | 142 | main(); 143 | 144 | while(1); 145 | } 146 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the IWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

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

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_dbgmcu.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup DBGMCU 30 | * @brief DBGMCU driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup DBGMCU_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup DBGMCU_Private_Defines 43 | * @{ 44 | */ 45 | 46 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 47 | /** 48 | * @} 49 | */ 50 | 51 | /** @defgroup DBGMCU_Private_Macros 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup DBGMCU_Private_Variables 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @defgroup DBGMCU_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup DBGMCU_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief Returns the device revision identifier. 81 | * @param None 82 | * @retval Device revision identifier 83 | */ 84 | uint32_t DBGMCU_GetREVID(void) 85 | { 86 | return(DBGMCU->IDCODE >> 16); 87 | } 88 | 89 | /** 90 | * @brief Returns the device identifier. 91 | * @param None 92 | * @retval Device identifier 93 | */ 94 | uint32_t DBGMCU_GetDEVID(void) 95 | { 96 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 97 | } 98 | 99 | /** 100 | * @brief Configures the specified peripheral and low power mode behavior 101 | * when the MCU under Debug mode. 102 | * @param DBGMCU_Periph: specifies the peripheral and low power mode. 103 | * This parameter can be any combination of the following values: 104 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 105 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 106 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 107 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 108 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 109 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 112 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 113 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 114 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 115 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 116 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 117 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 118 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 119 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 120 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted 121 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted 122 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted 123 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted 124 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 125 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 126 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 127 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 128 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 129 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 130 | * @param NewState: new state of the specified peripheral in Debug mode. 131 | * This parameter can be: ENABLE or DISABLE. 132 | * @retval None 133 | */ 134 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 135 | { 136 | /* Check the parameters */ 137 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 138 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 139 | 140 | if (NewState != DISABLE) 141 | { 142 | DBGMCU->CR |= DBGMCU_Periph; 143 | } 144 | else 145 | { 146 | DBGMCU->CR &= ~DBGMCU_Periph; 147 | } 148 | } 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 163 | -------------------------------------------------------------------------------- /example/serprog-protocol.txt: -------------------------------------------------------------------------------- 1 | Serial Flasher Protocol Specification - version 1 (0x01 return value == 1) 2 | 3 | Command And Answer Sequence - all commands give an answer. 4 | PC: COMMAND(8bit) 5 | DEV: ACK/NAK(8bit) / nothing 6 | Command 0x10 (SYNCNOP) has a special return of NAK+ACK for synchronization. 7 | 8 | ACK = 0x06 9 | NAK = 0x15 10 | 11 | All multibyte values are little-endian. Addresses and lengths are 24-bit. 12 | 13 | COMMAND Description Parameters Return Value 14 | 0x00 NOP none ACK 15 | 0x01 Query programmer iface version none ACK + 16bit version (nonzero) 16 | 0x02 Query supported commands bitmap none ACK + 32 bytes (256 bits) of supported cmds flags 17 | 0x03 Query programmer name none ACK + 16 bytes string (null padding) / NAK 18 | 0x04 Query serial buffer size none ACK + 16bit size / NAK 19 | 0x05 Query supported bustypes none ACK + 8-bit flags (as per flashrom) / NAK 20 | 0x06 Query connected address lines none ACK + 8bit line count / NAK 21 | 0x07 Query operation buffer size none ACK + 16bit size / NAK 22 | 0x08 Query maximum write-n length none ACK + 24bit length (0==2^24) / NAK 23 | 0x09 Read byte 24-bit addr ACK + BYTE / NAK 24 | 0x0A Read n bytes 24-bit addr + 24-bit length ACK + length bytes / NAK 25 | 0x0B Initialize operation buffer none ACK / NAK 26 | 0x0C Write to opbuf: Write byte 24-bit addr + 8-bit byte ACK / NAK (NOTE: takes 5 bytes in opbuf) 27 | 0x0D Write to opbuf: Write n 24-bit length + 24-bit addr + ACK / NAK (NOTE: takes 7+n bytes in opbuf) 28 | + length bytes of data 29 | 0x0E Write to opbuf: delay 32-bit usecs ACK / NAK (NOTE: takes 5 bytes in opbuf) 30 | 0x0F Execute operation buffer none ACK / NAK 31 | 0x10 Sync NOP none NAK + ACK (for synchronization) 32 | 0x11 Query maximum read-n length none ACK + 24-bit length (0==2^24) / NAK 33 | 0x12 Set used bustype 8-bit flags (as with 0x05) ACK / NAK 34 | 0x13 Perform SPI operation 24-bit slen + 24-bit rlen ACK + rlen bytes of data / NAK 35 | + slen bytes of data 36 | 0x14 Set SPI clock frequency in Hz 32-bit requested frequency ACK + 32-bit set frequency / NAK 37 | 0x15 Toggle flash chip pin drivers 8-bit (0 disable, else enable) ACK / NAK 38 | 0x?? unimplemented command - invalid. 39 | 40 | 41 | Additional information of the above commands: 42 | About unimplemented commands / startup sequence: 43 | Only commands allowed to be used without checking anything are 0x00,0x10 and 0x01 (NOP,SYNCNOP,Q_IFACE). 44 | If 0x01 doesn't return 1, dont do anything if you dont support a newer protocol. 45 | Then, check support for any other opcode (except 0x02) by using 0x02 (Q_CMDMAP). 46 | 0x02 (Q_CMDMAP): 47 | The map's bits are mapped as follows: 48 | cmd 0 support: byte 0 bit 0 49 | cmd 1 support: byte 0 bit 1 50 | cmd 7 support: byte 0 bit 7 51 | cmd 8 support: byte 1 bit 0, and so on. 52 | 0x04 (Q_SERBUF): 53 | If the programmer has a guaranteed working flow control, 54 | it should return a big bogus value - eg 0xFFFF. 55 | 0x05 (Q_BUSTYPE): 56 | The bit's are defined as follows: 57 | bit 0: PARALLEL, bit 1: LPC, bit 2: FWH, bit 3: SPI. 58 | 0x06 (Q_CHIPSIZE): 59 | Only applicable to parallel programmers. 60 | An LPC/FWH/SPI-programmer can report this as not supported in the command bitmap. 61 | 0x08 (Q_WRNMAXLEN): 62 | If a programmer reports a bigger maximum write-n length than the serial buffer size, 63 | it is assumed that the programmer can process the data fast enough to take in the 64 | reported maximum write-n without problems. 65 | 0x0F (O_EXEC): 66 | Execute operation buffer will also clear it, regardless of the return value. 67 | 0x11 (Q_RDNMAXLEN): 68 | If this command is not supported, assume return of 0 (2^24). 69 | 0x12 (S_BUSTYPE): 70 | Set's the used bustype if the programmer can support more than one flash protocol. 71 | Sending a byte with more than 1 bit set will make the programmer decide among them 72 | on it's own. Bit values as with Q_BUSTYPE. 73 | 0x13 (O_SPIOP): 74 | Send and receive bytes via SPI. 75 | Maximum slen is Q_WRNMAXLEN in case Q_BUSTYPE returns SPI only or S_BUSTYPE was used 76 | to set SPI exclusively before. Same for rlen and Q_RDNMAXLEN. 77 | This operation is immediate, meaning it doesnt use the operation buffer. 78 | 0x14 (S_SPI_FREQ): 79 | Set the SPI clock frequency. The 32-bit value indicates the 80 | requested frequency in Hertz. Value 0 is reserved and should 81 | be NAKed by the programmer. The requested frequency should be 82 | mapped by the programmer software to a supported frequency 83 | lower than the one requested. If there is no lower frequency 84 | available the lowest possible should be used. The value 85 | chosen is sent back in the reply with an ACK. 86 | 0x15 (S_CMD_S_PIN_STATE): 87 | Sets the state of the pin drivers connected to the flash chip. Disabling them allows other 88 | devices (e.g. a mainboard's chipset) to access the chip. This way the serprog controller can 89 | remain attached to the flash chip even when the board is running. The user is responsible to 90 | NOT connect VCC and other permanently externally driven signals to the programmer as needed. 91 | If the value is 0, then the drivers should be disabled, otherwise they should be enabled. 92 | About mandatory commands: 93 | The only truly mandatory commands for any device are 0x00, 0x01, 0x02 and 0x10, 94 | but one can't really do anything with these commands. 95 | Support for the following commands is necessary for flashrom to operate properly: 96 | S_CMD_Q_SERBUF, S_CMD_Q_OPBUF, S_CMD_Q_WRNMAXLEN, S_CMD_R_BYTE, 97 | S_CMD_R_NBYTES, S_CMD_O_INIT, S_CMD_O_WRITEB, S_CMD_O_WRITEN, 98 | S_CMD_O_DELAY, S_CMD_O_EXEC. 99 | In addition, support for these commands is recommended: 100 | S_CMD_Q_PGMNAME, S_CMD_Q_BUSTYPE, S_CMD_Q_CHIPSIZE (if parallel). 101 | 102 | See also serprog.h. 103 | -------------------------------------------------------------------------------- /example/serprog.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "io_usb.h" 6 | #include "io_spi.h" 7 | #include "serprog.h" 8 | #include "config.h" 9 | 10 | GPIO_InitTypeDef GPIO_InitStructure_LED = { 11 | .GPIO_Pin = PIN_LED, 12 | .GPIO_Speed = GPIO_Speed_2MHz, 13 | .GPIO_Mode = GPIO_Mode_Out_PP, 14 | }; 15 | 16 | GPIO_InitTypeDef GPIO_InitStructure_SPIOUT = { 17 | .GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7, 18 | .GPIO_Speed = GPIO_Speed_50MHz, 19 | .GPIO_Mode = GPIO_Mode_AF_PP, 20 | }; 21 | 22 | GPIO_InitTypeDef GPIO_InitStructure_SPIIN = { 23 | .GPIO_Pin = GPIO_Pin_6, 24 | .GPIO_Speed = GPIO_Speed_50MHz, 25 | .GPIO_Mode = GPIO_Mode_IN_FLOATING, 26 | }; 27 | 28 | GPIO_InitTypeDef GPIO_InitStructure_SPISS = { 29 | .GPIO_Pin = PIN_SS, 30 | .GPIO_Speed = GPIO_Speed_50MHz, 31 | .GPIO_Mode = GPIO_Mode_Out_PP, 32 | }; 33 | 34 | NVIC_InitTypeDef NVIC_InitStructure = { 35 | .NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn, 36 | .NVIC_IRQChannelPreemptionPriority = 1, 37 | .NVIC_IRQChannelSubPriority = 0, 38 | .NVIC_IRQChannelCmd = ENABLE, 39 | }; 40 | 41 | void serprog_handle_command(unsigned char command); 42 | 43 | /* 72MHz, 3 cycles per loop. */ 44 | void delay(volatile uint32_t cycles) { 45 | while(cycles -- != 0); 46 | } 47 | 48 | int main(void) { 49 | /* Configure Clocks (GPIO and DMA clocks already enabled by startup.c) */ 50 | RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); 51 | RCC_APB2PeriphClockCmd( SPI_ENGINE_RCC, ENABLE); 52 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); 53 | 54 | /* Configure On-board LED */ 55 | GPIO_Init(PORT_LED, &GPIO_InitStructure_LED); 56 | 57 | /* Configure SPI Port */ 58 | GPIO_Init( GPIOA, &GPIO_InitStructure_SPIOUT); 59 | GPIO_Init( GPIOA, &GPIO_InitStructure_SPIIN); 60 | GPIO_Init( PORT_SS, &GPIO_InitStructure_SPISS); 61 | 62 | /* Configure SPI Engine with DMA */ 63 | spi_conf(SPI_DEFAULT_SPEED); 64 | 65 | /* Configure USB Interrupt */ 66 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); 67 | NVIC_Init(&NVIC_InitStructure); 68 | 69 | /* Enable all peripherals */ 70 | USB_Init(); 71 | 72 | /* Main loop */ 73 | while(1) { 74 | /* Get command */ 75 | serprog_handle_command(usb_getc()); 76 | /* Flush output via USB */ 77 | usb_sync(); 78 | } 79 | 80 | return 0; 81 | } 82 | 83 | void serprog_handle_command(unsigned char command) { 84 | led_off(); 85 | 86 | static uint8_t i; /* Loop */ 87 | static uint8_t l; /* Length */ 88 | static uint32_t slen; /* SPIOP write len */ 89 | static uint32_t rlen; /* SPIOP read len */ 90 | static uint32_t freq_req; 91 | 92 | switch(command) { 93 | case S_CMD_NOP: 94 | usb_putc(S_ACK); 95 | break; 96 | case S_CMD_Q_IFACE: 97 | usb_putc(S_ACK); 98 | /* little endian multibyte value to complete to 16bit */ 99 | usb_putc(S_IFACE_VERSION); 100 | usb_putc(0); 101 | break; 102 | case S_CMD_Q_CMDMAP: 103 | usb_putc(S_ACK); 104 | /* little endian */ 105 | usb_putu32(S_CMD_MAP); 106 | for(i = 0; i < 32 - sizeof(uint32_t); i++) usb_putc(0); 107 | break; 108 | case S_CMD_Q_PGMNAME: 109 | usb_putc(S_ACK); 110 | l = 0; 111 | while(S_PGM_NAME[l]) { 112 | usb_putc(S_PGM_NAME[l]); 113 | l ++; 114 | } 115 | for(i = l; i < 16; i++) usb_putc(0); 116 | break; 117 | case S_CMD_Q_SERBUF: 118 | usb_putc(S_ACK); 119 | /* Pretend to be 64K (0xffff) */ 120 | usb_putc(0xff); 121 | usb_putc(0xff); 122 | break; 123 | case S_CMD_Q_BUSTYPE: 124 | // TODO: LPC / FWH IO support via PP-Mode 125 | usb_putc(S_ACK); 126 | usb_putc(S_SUPPORTED_BUS); 127 | break; 128 | case S_CMD_Q_CHIPSIZE: break; 129 | case S_CMD_Q_OPBUF: 130 | // TODO: opbuf function 0 131 | break; 132 | case S_CMD_Q_WRNMAXLEN: break; 133 | case S_CMD_R_BYTE: break; 134 | case S_CMD_R_NBYTES: break; 135 | case S_CMD_O_INIT: break; 136 | case S_CMD_O_WRITEB: 137 | // TODO: opbuf function 1 138 | break; 139 | case S_CMD_O_WRITEN: 140 | // TODO: opbuf function 2 141 | break; 142 | case S_CMD_O_DELAY: 143 | // TODO: opbuf function 3 144 | break; 145 | case S_CMD_O_EXEC: 146 | // TODO: opbuf function 4 147 | break; 148 | case S_CMD_SYNCNOP: 149 | usb_putc(S_NAK); 150 | usb_putc(S_ACK); 151 | break; 152 | case S_CMD_Q_RDNMAXLEN: 153 | // TODO 154 | break; 155 | case S_CMD_S_BUSTYPE: 156 | /* We do not have multiplexed bus interfaces, 157 | * so simply ack on supported types, no setup needed. */ 158 | if((usb_getc() | S_SUPPORTED_BUS) == S_SUPPORTED_BUS) usb_putc(S_ACK); 159 | else usb_putc(S_NAK); 160 | break; 161 | case S_CMD_O_SPIOP: 162 | slen = usb_getu24(); 163 | rlen = usb_getu24(); 164 | 165 | select_chip(); 166 | 167 | /* TODO: handle errors with S_NAK */ 168 | if(slen) spi_bulk_write(slen); 169 | usb_putc(S_ACK); 170 | if(rlen) spi_bulk_read(rlen); 171 | 172 | unselect_chip(); 173 | break; 174 | case S_CMD_S_SPI_FREQ: 175 | freq_req = usb_getu32(); 176 | if(freq_req == 0) usb_putc(S_NAK); 177 | else { 178 | usb_putc(S_ACK); 179 | usb_putu32(spi_conf(freq_req)); 180 | } 181 | break; 182 | default: break; // TODO: Debug malformed command 183 | } 184 | 185 | led_on(); 186 | } 187 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_wwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the WWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_wwdg.h" 24 | #include "stm32f10x_rcc.h" 25 | 26 | /** @addtogroup STM32F10x_StdPeriph_Driver 27 | * @{ 28 | */ 29 | 30 | /** @defgroup WWDG 31 | * @brief WWDG driver modules 32 | * @{ 33 | */ 34 | 35 | /** @defgroup WWDG_Private_TypesDefinitions 36 | * @{ 37 | */ 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | /** @defgroup WWDG_Private_Defines 44 | * @{ 45 | */ 46 | 47 | /* ----------- WWDG registers bit address in the alias region ----------- */ 48 | #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE) 49 | 50 | /* Alias word address of EWI bit */ 51 | #define CFR_OFFSET (WWDG_OFFSET + 0x04) 52 | #define EWI_BitNumber 0x09 53 | #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4)) 54 | 55 | /* --------------------- WWDG registers bit mask ------------------------ */ 56 | 57 | /* CR register bit mask */ 58 | #define CR_WDGA_Set ((uint32_t)0x00000080) 59 | 60 | /* CFR register bit mask */ 61 | #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F) 62 | #define CFR_W_Mask ((uint32_t)0xFFFFFF80) 63 | #define BIT_Mask ((uint8_t)0x7F) 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup WWDG_Private_Macros 70 | * @{ 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Private_Variables 78 | * @{ 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup WWDG_Private_FunctionPrototypes 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** @defgroup WWDG_Private_Functions 94 | * @{ 95 | */ 96 | 97 | /** 98 | * @brief Deinitializes the WWDG peripheral registers to their default reset values. 99 | * @param None 100 | * @retval None 101 | */ 102 | void WWDG_DeInit(void) 103 | { 104 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE); 105 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE); 106 | } 107 | 108 | /** 109 | * @brief Sets the WWDG Prescaler. 110 | * @param WWDG_Prescaler: specifies the WWDG Prescaler. 111 | * This parameter can be one of the following values: 112 | * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1 113 | * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2 114 | * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4 115 | * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 116 | * @retval None 117 | */ 118 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) 119 | { 120 | uint32_t tmpreg = 0; 121 | /* Check the parameters */ 122 | assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler)); 123 | /* Clear WDGTB[1:0] bits */ 124 | tmpreg = WWDG->CFR & CFR_WDGTB_Mask; 125 | /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ 126 | tmpreg |= WWDG_Prescaler; 127 | /* Store the new value */ 128 | WWDG->CFR = tmpreg; 129 | } 130 | 131 | /** 132 | * @brief Sets the WWDG window value. 133 | * @param WindowValue: specifies the window value to be compared to the downcounter. 134 | * This parameter value must be lower than 0x80. 135 | * @retval None 136 | */ 137 | void WWDG_SetWindowValue(uint8_t WindowValue) 138 | { 139 | __IO uint32_t tmpreg = 0; 140 | 141 | /* Check the parameters */ 142 | assert_param(IS_WWDG_WINDOW_VALUE(WindowValue)); 143 | /* Clear W[6:0] bits */ 144 | 145 | tmpreg = WWDG->CFR & CFR_W_Mask; 146 | 147 | /* Set W[6:0] bits according to WindowValue value */ 148 | tmpreg |= WindowValue & (uint32_t) BIT_Mask; 149 | 150 | /* Store the new value */ 151 | WWDG->CFR = tmpreg; 152 | } 153 | 154 | /** 155 | * @brief Enables the WWDG Early Wakeup interrupt(EWI). 156 | * @param None 157 | * @retval None 158 | */ 159 | void WWDG_EnableIT(void) 160 | { 161 | *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE; 162 | } 163 | 164 | /** 165 | * @brief Sets the WWDG counter value. 166 | * @param Counter: specifies the watchdog counter value. 167 | * This parameter must be a number between 0x40 and 0x7F. 168 | * @retval None 169 | */ 170 | void WWDG_SetCounter(uint8_t Counter) 171 | { 172 | /* Check the parameters */ 173 | assert_param(IS_WWDG_COUNTER(Counter)); 174 | /* Write to T[6:0] bits to configure the counter value, no need to do 175 | a read-modify-write; writing a 0 to WDGA bit does nothing */ 176 | WWDG->CR = Counter & BIT_Mask; 177 | } 178 | 179 | /** 180 | * @brief Enables WWDG and load the counter value. 181 | * @param Counter: specifies the watchdog counter value. 182 | * This parameter must be a number between 0x40 and 0x7F. 183 | * @retval None 184 | */ 185 | void WWDG_Enable(uint8_t Counter) 186 | { 187 | /* Check the parameters */ 188 | assert_param(IS_WWDG_COUNTER(Counter)); 189 | WWDG->CR = CR_WDGA_Set | Counter; 190 | } 191 | 192 | /** 193 | * @brief Checks whether the Early Wakeup interrupt flag is set or not. 194 | * @param None 195 | * @retval The new state of the Early Wakeup interrupt flag (SET or RESET) 196 | */ 197 | FlagStatus WWDG_GetFlagStatus(void) 198 | { 199 | return (FlagStatus)(WWDG->SR); 200 | } 201 | 202 | /** 203 | * @brief Clears Early Wakeup interrupt flag. 204 | * @param None 205 | * @retval None 206 | */ 207 | void WWDG_ClearFlag(void) 208 | { 209 | WWDG->SR = (uint32_t)RESET; 210 | } 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | /** 221 | * @} 222 | */ 223 | 224 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 225 | -------------------------------------------------------------------------------- /src/USB/STM32_USB-FS-Device_Driver/src/usb_int.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usb_lib.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | __IO uint16_t SaveRState; 36 | __IO uint16_t SaveTState; 37 | 38 | /* Extern variables ----------------------------------------------------------*/ 39 | extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */ 40 | extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */ 41 | 42 | /* Private function prototypes -----------------------------------------------*/ 43 | /* Private functions ---------------------------------------------------------*/ 44 | 45 | /******************************************************************************* 46 | * Function Name : CTR_LP. 47 | * Description : Low priority Endpoint Correct Transfer interrupt's service 48 | * routine. 49 | * Input : None. 50 | * Output : None. 51 | * Return : None. 52 | *******************************************************************************/ 53 | void CTR_LP(void) 54 | { 55 | __IO uint16_t wEPVal = 0; 56 | /* stay in loop while pending interrupts */ 57 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0) 58 | { 59 | /* extract highest priority endpoint number */ 60 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID); 61 | if (EPindex == 0) 62 | { 63 | /* Decode and service control endpoint interrupt */ 64 | /* calling related service routine */ 65 | /* (Setup0_Process, In0_Process, Out0_Process) */ 66 | 67 | /* save RX & TX status */ 68 | /* and set both to NAK */ 69 | 70 | SaveRState = _GetENDPOINT(ENDP0); 71 | SaveTState = SaveRState & EPTX_STAT; 72 | SaveRState &= EPRX_STAT; 73 | 74 | _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK); 75 | 76 | /* DIR bit = origin of the interrupt */ 77 | 78 | if ((wIstr & ISTR_DIR) == 0) 79 | { 80 | /* DIR = 0 */ 81 | 82 | /* DIR = 0 => IN int */ 83 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ 84 | 85 | _ClearEP_CTR_TX(ENDP0); 86 | In0_Process(); 87 | 88 | /* before terminate set Tx & Rx status */ 89 | 90 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 91 | return; 92 | } 93 | else 94 | { 95 | /* DIR = 1 */ 96 | 97 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ 98 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ 99 | 100 | wEPVal = _GetENDPOINT(ENDP0); 101 | 102 | if ((wEPVal &EP_SETUP) != 0) 103 | { 104 | _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ 105 | Setup0_Process(); 106 | /* before terminate set Tx & Rx status */ 107 | 108 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 109 | return; 110 | } 111 | 112 | else if ((wEPVal & EP_CTR_RX) != 0) 113 | { 114 | _ClearEP_CTR_RX(ENDP0); 115 | Out0_Process(); 116 | /* before terminate set Tx & Rx status */ 117 | 118 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 119 | return; 120 | } 121 | } 122 | }/* if(EPindex == 0) */ 123 | else 124 | { 125 | /* Decode and service non control endpoints interrupt */ 126 | 127 | /* process related endpoint register */ 128 | wEPVal = _GetENDPOINT(EPindex); 129 | if ((wEPVal & EP_CTR_RX) != 0) 130 | { 131 | /* clear int flag */ 132 | _ClearEP_CTR_RX(EPindex); 133 | 134 | /* call OUT service function */ 135 | (*pEpInt_OUT[EPindex-1])(); 136 | 137 | } /* if((wEPVal & EP_CTR_RX) */ 138 | 139 | if ((wEPVal & EP_CTR_TX) != 0) 140 | { 141 | /* clear int flag */ 142 | _ClearEP_CTR_TX(EPindex); 143 | 144 | /* call IN service function */ 145 | (*pEpInt_IN[EPindex-1])(); 146 | } /* if((wEPVal & EP_CTR_TX) != 0) */ 147 | 148 | }/* if(EPindex == 0) else */ 149 | 150 | }/* while(...) */ 151 | } 152 | 153 | /******************************************************************************* 154 | * Function Name : CTR_HP. 155 | * Description : High Priority Endpoint Correct Transfer interrupt's service 156 | * routine. 157 | * Input : None. 158 | * Output : None. 159 | * Return : None. 160 | *******************************************************************************/ 161 | void CTR_HP(void) 162 | { 163 | uint32_t wEPVal = 0; 164 | 165 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0) 166 | { 167 | _SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */ 168 | /* extract highest priority endpoint number */ 169 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID); 170 | /* process related endpoint register */ 171 | wEPVal = _GetENDPOINT(EPindex); 172 | if ((wEPVal & EP_CTR_RX) != 0) 173 | { 174 | /* clear int flag */ 175 | _ClearEP_CTR_RX(EPindex); 176 | 177 | /* call OUT service function */ 178 | (*pEpInt_OUT[EPindex-1])(); 179 | 180 | } /* if((wEPVal & EP_CTR_RX) */ 181 | else if ((wEPVal & EP_CTR_TX) != 0) 182 | { 183 | /* clear int flag */ 184 | _ClearEP_CTR_TX(EPindex); 185 | 186 | /* call IN service function */ 187 | (*pEpInt_IN[EPindex-1])(); 188 | 189 | 190 | } /* if((wEPVal & EP_CTR_TX) != 0) */ 191 | 192 | }/* while(...) */ 193 | } 194 | 195 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 196 | -------------------------------------------------------------------------------- /example/io_spi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "config.h" 4 | #include "io_spi.h" 5 | 6 | /* Do not place const in front of declarations. * 7 | * const variables are stored in flash that needs a 2-cycle wait */ 8 | uint8_t DMA_Clk_Buf = 0; 9 | 10 | /* Refer to USB IO for bulk transfer */ 11 | extern uint8_t USB_Tx_Buf[]; 12 | extern uint16_t USB_Tx_ptr_in; 13 | extern uint8_t USB_Rx_Buf[]; 14 | extern uint16_t USB_Rx_ptr_out; 15 | extern uint8_t USB_Rx_len; 16 | 17 | extern void usb_putp(void); 18 | extern void usb_getp(void); 19 | extern char usb_getc(void); 20 | 21 | /* Quick init definations */ 22 | DMA_InitTypeDef DMA_InitStructure_RX = { 23 | .DMA_PeripheralBaseAddr = (uint32_t)SPI_DR_Base, 24 | .DMA_MemoryBaseAddr = (uint32_t)USB_Tx_Buf, 25 | .DMA_DIR = DMA_DIR_PeripheralSRC, 26 | .DMA_BufferSize = VCP_DATA_SIZE, 27 | .DMA_PeripheralInc = DMA_PeripheralInc_Disable, 28 | .DMA_MemoryInc = DMA_MemoryInc_Enable, 29 | .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte, 30 | .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte, 31 | .DMA_Mode = DMA_Mode_Normal, 32 | .DMA_Priority = DMA_Priority_High, 33 | .DMA_M2M = DMA_M2M_Disable, 34 | }; 35 | 36 | DMA_InitTypeDef DMA_InitStructure_TX = { 37 | .DMA_PeripheralBaseAddr = (uint32_t)SPI_DR_Base, 38 | .DMA_MemoryBaseAddr = (uint32_t)USB_Rx_Buf, 39 | .DMA_DIR = DMA_DIR_PeripheralDST, 40 | .DMA_BufferSize = VCP_DATA_SIZE, 41 | .DMA_PeripheralInc = DMA_PeripheralInc_Disable, 42 | .DMA_MemoryInc = DMA_MemoryInc_Enable, 43 | .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte, 44 | .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte, 45 | .DMA_Mode = DMA_Mode_Normal, 46 | .DMA_Priority = DMA_Priority_Low, 47 | .DMA_M2M = DMA_M2M_Disable, 48 | }; 49 | 50 | DMA_InitTypeDef DMA_InitStructure_CLK = { 51 | .DMA_PeripheralBaseAddr = (uint32_t)SPI_DR_Base, 52 | .DMA_MemoryBaseAddr = (uint32_t)&DMA_Clk_Buf, 53 | .DMA_DIR = DMA_DIR_PeripheralDST, 54 | .DMA_BufferSize = VCP_DATA_SIZE, 55 | .DMA_PeripheralInc = DMA_PeripheralInc_Disable, 56 | .DMA_MemoryInc = DMA_MemoryInc_Disable, 57 | .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte, 58 | .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte, 59 | .DMA_Mode = DMA_Mode_Normal, 60 | .DMA_Priority = DMA_Priority_Low, 61 | .DMA_M2M = DMA_M2M_Disable, 62 | }; 63 | 64 | SPI_InitTypeDef SPI_InitStructure = { 65 | .SPI_Direction = SPI_Direction_2Lines_FullDuplex, 66 | .SPI_Mode = SPI_Mode_Master, 67 | .SPI_DataSize = SPI_DataSize_8b, 68 | .SPI_CPOL = SPI_CPOL_Low, 69 | .SPI_CPHA = SPI_CPHA_1Edge, 70 | .SPI_NSS = SPI_NSS_Soft, 71 | .SPI_FirstBit = SPI_FirstBit_MSB, 72 | .SPI_CRCPolynomial = 7, 73 | }; 74 | 75 | void dma_conf_spiwrite(void) { 76 | DMA_Init(SPI_RX_DMA_CH, &DMA_InitStructure_RX); 77 | DMA_Init(SPI_TX_DMA_CH, &DMA_InitStructure_TX); 78 | } 79 | 80 | void dma_conf_spiread(void) { 81 | DMA_Init(SPI_RX_DMA_CH, &DMA_InitStructure_RX); 82 | DMA_Init(SPI_TX_DMA_CH, &DMA_InitStructure_CLK); 83 | } 84 | 85 | void dma_commit(void) { 86 | /* Always enable TX channel first, especially under 36MHz clock. */ 87 | SPI_I2S_DMACmd(SPI_BUS_USED, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, ENABLE); 88 | DMA_Cmd(SPI_RX_DMA_CH, ENABLE); 89 | DMA_Cmd(SPI_TX_DMA_CH, ENABLE); 90 | 91 | /* Wait for transfer to complete */ 92 | while(!DMA_GetFlagStatus(SPI_RX_DMA_FLAG)); 93 | 94 | /* Clear up */ 95 | SPI_I2S_DMACmd(SPI_BUS_USED, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, DISABLE); 96 | DMA_DeInit(SPI_RX_DMA_CH); 97 | DMA_DeInit(SPI_TX_DMA_CH); 98 | } 99 | 100 | uint32_t spi_conf(uint32_t speed_hz) { 101 | static uint16_t clkdiv; 102 | static uint32_t relspd; 103 | 104 | /* SPI_BUS_USED is on APB2 which runs @ 72MHz. */ 105 | /* Lowest available */ 106 | clkdiv = SPI_BaudRatePrescaler_256; 107 | relspd = 281250; 108 | if(speed_hz >= 562500) { 109 | clkdiv = SPI_BaudRatePrescaler_128; 110 | relspd = 562500; 111 | } 112 | if(speed_hz >= 1125000) { 113 | clkdiv = SPI_BaudRatePrescaler_64; 114 | relspd = 1125000; 115 | } 116 | if(speed_hz >= 2250000) { 117 | clkdiv = SPI_BaudRatePrescaler_32; 118 | relspd = 2250000; 119 | } 120 | if(speed_hz >= 4500000) { 121 | clkdiv = SPI_BaudRatePrescaler_16; 122 | relspd = 4500000; 123 | } 124 | if(speed_hz >= 9000000) { 125 | clkdiv = SPI_BaudRatePrescaler_8; 126 | relspd = 9000000; 127 | } 128 | if(speed_hz >= 18000000) { 129 | clkdiv = SPI_BaudRatePrescaler_4; 130 | relspd = 18000000; 131 | } 132 | if(speed_hz >= 36000000) { 133 | clkdiv = SPI_BaudRatePrescaler_2; 134 | relspd = 36000000; 135 | } 136 | 137 | SPI_I2S_DeInit(SPI_BUS_USED); 138 | 139 | SPI_InitStructure.SPI_BaudRatePrescaler = clkdiv; 140 | 141 | SPI_Init(SPI_BUS_USED, &SPI_InitStructure); 142 | SPI_CalculateCRC(SPI_BUS_USED, DISABLE); 143 | SPI_Cmd(SPI_BUS_USED, ENABLE); 144 | 145 | return relspd; 146 | } 147 | 148 | void spi_putc(uint8_t c) { 149 | /* transmit c on the SPI bus */ 150 | SPI_I2S_SendData(SPI_BUS_USED, c); 151 | 152 | /* Those useless data just needs to be collected, or SPI engine will go crazy. */ 153 | while(SPI_I2S_GetFlagStatus(SPI_BUS_USED, SPI_I2S_FLAG_RXNE) == RESET); 154 | SPI_I2S_ReceiveData(SPI_BUS_USED); 155 | } 156 | 157 | void spi_bulk_write(uint32_t size) { 158 | /* Prepare alignment */ 159 | if(size >= (USB_Rx_len - USB_Rx_ptr_out)) { 160 | size -= (USB_Rx_len - USB_Rx_ptr_out); 161 | while(USB_Rx_ptr_out != USB_Rx_len) spi_putc(usb_getc()); 162 | } 163 | /* else: size << VCP_DATA_SIZE, no bulk transfer */ 164 | 165 | /* Do bulk transfer */ 166 | while(size != 0) { 167 | usb_getp(); 168 | 169 | if(USB_Rx_len < VCP_DATA_SIZE) { 170 | /* Host is not feeding fast enough / finish the left-over bytes */ 171 | size -= USB_Rx_len; 172 | while(USB_Rx_ptr_out != USB_Rx_len) spi_putc(usb_getc()); 173 | } 174 | else { 175 | size -= VCP_DATA_SIZE; 176 | /* DMA Engine must be configured for EVERY transfer */ 177 | dma_conf_spiwrite(); 178 | dma_commit(); 179 | } 180 | } 181 | } 182 | 183 | void spi_bulk_read(uint32_t size) { 184 | /* Flush buffer and make room for DMA */ 185 | if(USB_Tx_ptr_in != 0) usb_putp(); 186 | 187 | static int i; 188 | 189 | /* Do bulk transfer */ 190 | while(size >= VCP_DATA_SIZE) { 191 | /* DMA Engine must be configured for EVERY transfer */ 192 | dma_conf_spiread(); 193 | dma_commit(); 194 | 195 | USB_Tx_ptr_in = VCP_DATA_SIZE; 196 | usb_putp(); 197 | size -= VCP_DATA_SIZE; 198 | } 199 | 200 | /* Finish the left-over bytes */ 201 | if(size != 0) { 202 | for(i = 0; i < size; i ++) { 203 | SPI_I2S_SendData(SPI_BUS_USED, 0); 204 | while(SPI_I2S_GetFlagStatus(SPI_BUS_USED, SPI_I2S_FLAG_RXNE) == RESET); 205 | USB_Tx_Buf[i] = SPI_I2S_ReceiveData(SPI_BUS_USED); 206 | } 207 | USB_Tx_ptr_in = size; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/inc/stm32f10x_cec.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_cec.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CEC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CEC_H 25 | #define __STM32F10x_CEC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CEC 39 | * @{ 40 | */ 41 | 42 | 43 | /** @defgroup CEC_Exported_Types 44 | * @{ 45 | */ 46 | 47 | /** 48 | * @brief CEC Init structure definition 49 | */ 50 | typedef struct 51 | { 52 | uint16_t CEC_BitTimingMode; /*!< Configures the CEC Bit Timing Error Mode. 53 | This parameter can be a value of @ref CEC_BitTiming_Mode */ 54 | uint16_t CEC_BitPeriodMode; /*!< Configures the CEC Bit Period Error Mode. 55 | This parameter can be a value of @ref CEC_BitPeriod_Mode */ 56 | }CEC_InitTypeDef; 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup CEC_Exported_Constants 63 | * @{ 64 | */ 65 | 66 | /** @defgroup CEC_BitTiming_Mode 67 | * @{ 68 | */ 69 | #define CEC_BitTimingStdMode ((uint16_t)0x00) /*!< Bit timing error Standard Mode */ 70 | #define CEC_BitTimingErrFreeMode CEC_CFGR_BTEM /*!< Bit timing error Free Mode */ 71 | 72 | #define IS_CEC_BIT_TIMING_ERROR_MODE(MODE) (((MODE) == CEC_BitTimingStdMode) || \ 73 | ((MODE) == CEC_BitTimingErrFreeMode)) 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup CEC_BitPeriod_Mode 79 | * @{ 80 | */ 81 | #define CEC_BitPeriodStdMode ((uint16_t)0x00) /*!< Bit period error Standard Mode */ 82 | #define CEC_BitPeriodFlexibleMode CEC_CFGR_BPEM /*!< Bit period error Flexible Mode */ 83 | 84 | #define IS_CEC_BIT_PERIOD_ERROR_MODE(MODE) (((MODE) == CEC_BitPeriodStdMode) || \ 85 | ((MODE) == CEC_BitPeriodFlexibleMode)) 86 | /** 87 | * @} 88 | */ 89 | 90 | 91 | /** @defgroup CEC_interrupts_definition 92 | * @{ 93 | */ 94 | #define CEC_IT_TERR CEC_CSR_TERR 95 | #define CEC_IT_TBTRF CEC_CSR_TBTRF 96 | #define CEC_IT_RERR CEC_CSR_RERR 97 | #define CEC_IT_RBTF CEC_CSR_RBTF 98 | #define IS_CEC_GET_IT(IT) (((IT) == CEC_IT_TERR) || ((IT) == CEC_IT_TBTRF) || \ 99 | ((IT) == CEC_IT_RERR) || ((IT) == CEC_IT_RBTF)) 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /** @defgroup CEC_Own_Address 106 | * @{ 107 | */ 108 | #define IS_CEC_ADDRESS(ADDRESS) ((ADDRESS) < 0x10) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** @defgroup CEC_Prescaler 114 | * @{ 115 | */ 116 | #define IS_CEC_PRESCALER(PRESCALER) ((PRESCALER) <= 0x3FFF) 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** @defgroup CEC_flags_definition 123 | * @{ 124 | */ 125 | 126 | /** 127 | * @brief ESR register flags 128 | */ 129 | #define CEC_FLAG_BTE ((uint32_t)0x10010000) 130 | #define CEC_FLAG_BPE ((uint32_t)0x10020000) 131 | #define CEC_FLAG_RBTFE ((uint32_t)0x10040000) 132 | #define CEC_FLAG_SBE ((uint32_t)0x10080000) 133 | #define CEC_FLAG_ACKE ((uint32_t)0x10100000) 134 | #define CEC_FLAG_LINE ((uint32_t)0x10200000) 135 | #define CEC_FLAG_TBTFE ((uint32_t)0x10400000) 136 | 137 | /** 138 | * @brief CSR register flags 139 | */ 140 | #define CEC_FLAG_TEOM ((uint32_t)0x00000002) 141 | #define CEC_FLAG_TERR ((uint32_t)0x00000004) 142 | #define CEC_FLAG_TBTRF ((uint32_t)0x00000008) 143 | #define CEC_FLAG_RSOM ((uint32_t)0x00000010) 144 | #define CEC_FLAG_REOM ((uint32_t)0x00000020) 145 | #define CEC_FLAG_RERR ((uint32_t)0x00000040) 146 | #define CEC_FLAG_RBTF ((uint32_t)0x00000080) 147 | 148 | #define IS_CEC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF03) == 0x00) && ((FLAG) != 0x00)) 149 | 150 | #define IS_CEC_GET_FLAG(FLAG) (((FLAG) == CEC_FLAG_BTE) || ((FLAG) == CEC_FLAG_BPE) || \ 151 | ((FLAG) == CEC_FLAG_RBTFE) || ((FLAG)== CEC_FLAG_SBE) || \ 152 | ((FLAG) == CEC_FLAG_ACKE) || ((FLAG) == CEC_FLAG_LINE) || \ 153 | ((FLAG) == CEC_FLAG_TBTFE) || ((FLAG) == CEC_FLAG_TEOM) || \ 154 | ((FLAG) == CEC_FLAG_TERR) || ((FLAG) == CEC_FLAG_TBTRF) || \ 155 | ((FLAG) == CEC_FLAG_RSOM) || ((FLAG) == CEC_FLAG_REOM) || \ 156 | ((FLAG) == CEC_FLAG_RERR) || ((FLAG) == CEC_FLAG_RBTF)) 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /** @defgroup CEC_Exported_Macros 167 | * @{ 168 | */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | /** @defgroup CEC_Exported_Functions 175 | * @{ 176 | */ 177 | void CEC_DeInit(void); 178 | void CEC_Init(CEC_InitTypeDef* CEC_InitStruct); 179 | void CEC_Cmd(FunctionalState NewState); 180 | void CEC_ITConfig(FunctionalState NewState); 181 | void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress); 182 | void CEC_SetPrescaler(uint16_t CEC_Prescaler); 183 | void CEC_SendDataByte(uint8_t Data); 184 | uint8_t CEC_ReceiveDataByte(void); 185 | void CEC_StartOfMessage(void); 186 | void CEC_EndOfMessageCmd(FunctionalState NewState); 187 | FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG); 188 | void CEC_ClearFlag(uint32_t CEC_FLAG); 189 | ITStatus CEC_GetITStatus(uint8_t CEC_IT); 190 | void CEC_ClearITPendingBit(uint16_t CEC_IT); 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif /* __STM32F10x_CEC_H */ 197 | 198 | /** 199 | * @} 200 | */ 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | /** 207 | * @} 208 | */ 209 | 210 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 211 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/inc/stm32f10x_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the EXTI firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_EXTI_H 25 | #define __STM32F10x_EXTI_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup EXTI 39 | * @{ 40 | */ 41 | 42 | /** @defgroup EXTI_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief EXTI mode enumeration 48 | */ 49 | 50 | typedef enum 51 | { 52 | EXTI_Mode_Interrupt = 0x00, 53 | EXTI_Mode_Event = 0x04 54 | }EXTIMode_TypeDef; 55 | 56 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 57 | 58 | /** 59 | * @brief EXTI Trigger enumeration 60 | */ 61 | 62 | typedef enum 63 | { 64 | EXTI_Trigger_Rising = 0x08, 65 | EXTI_Trigger_Falling = 0x0C, 66 | EXTI_Trigger_Rising_Falling = 0x10 67 | }EXTITrigger_TypeDef; 68 | 69 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 70 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 71 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 72 | /** 73 | * @brief EXTI Init Structure definition 74 | */ 75 | 76 | typedef struct 77 | { 78 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. 79 | This parameter can be any combination of @ref EXTI_Lines */ 80 | 81 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. 82 | This parameter can be a value of @ref EXTIMode_TypeDef */ 83 | 84 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. 85 | This parameter can be a value of @ref EXTIMode_TypeDef */ 86 | 87 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. 88 | This parameter can be set either to ENABLE or DISABLE */ 89 | }EXTI_InitTypeDef; 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** @defgroup EXTI_Exported_Constants 96 | * @{ 97 | */ 98 | 99 | /** @defgroup EXTI_Lines 100 | * @{ 101 | */ 102 | 103 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */ 104 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */ 105 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */ 106 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */ 107 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */ 108 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */ 109 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */ 110 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */ 111 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */ 112 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */ 113 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */ 114 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */ 115 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */ 116 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */ 117 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */ 118 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */ 119 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */ 120 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 121 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS 122 | Wakeup from suspend event */ 123 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */ 124 | 125 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00)) 126 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 127 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 128 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 129 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 130 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 131 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 132 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 133 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 134 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 135 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19)) 136 | 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup EXTI_Exported_Macros 147 | * @{ 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** @defgroup EXTI_Exported_Functions 155 | * @{ 156 | */ 157 | 158 | void EXTI_DeInit(void); 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 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 163 | void EXTI_ClearFlag(uint32_t EXTI_Line); 164 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 165 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 166 | 167 | #ifdef __cplusplus 168 | } 169 | #endif 170 | 171 | #endif /* __STM32F10x_EXTI_H */ 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 185 | -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_istr.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief ISTR events interrupt service routines 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_prop.h" 32 | #include "usb_pwr.h" 33 | #include "usb_istr.h" 34 | 35 | /* Private typedef -----------------------------------------------------------*/ 36 | /* Private define ------------------------------------------------------------*/ 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | __IO uint16_t wIstr; /* ISTR register last read value */ 40 | __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */ 41 | __IO uint32_t esof_counter =0; /* expected SOF counter */ 42 | __IO uint32_t wCNTR=0; 43 | 44 | /* Extern variables ----------------------------------------------------------*/ 45 | /* Private function prototypes -----------------------------------------------*/ 46 | /* Private functions ---------------------------------------------------------*/ 47 | /* function pointers to non-control endpoints service routines */ 48 | void (*pEpInt_IN[7])(void) = 49 | { 50 | EP1_IN_Callback, 51 | EP2_IN_Callback, 52 | EP3_IN_Callback, 53 | EP4_IN_Callback, 54 | EP5_IN_Callback, 55 | EP6_IN_Callback, 56 | EP7_IN_Callback, 57 | }; 58 | 59 | void (*pEpInt_OUT[7])(void) = 60 | { 61 | EP1_OUT_Callback, 62 | EP2_OUT_Callback, 63 | EP3_OUT_Callback, 64 | EP4_OUT_Callback, 65 | EP5_OUT_Callback, 66 | EP6_OUT_Callback, 67 | EP7_OUT_Callback, 68 | }; 69 | 70 | /******************************************************************************* 71 | * Function Name : USB_Istr 72 | * Description : ISTR events interrupt service routine 73 | * Input : None. 74 | * Output : None. 75 | * Return : None. 76 | *******************************************************************************/ 77 | void USB_Istr(void) 78 | { 79 | uint32_t i=0; 80 | __IO uint32_t EP[8]; 81 | 82 | wIstr = _GetISTR(); 83 | 84 | #if (IMR_MSK & ISTR_SOF) 85 | if (wIstr & ISTR_SOF & wInterrupt_Mask) 86 | { 87 | _SetISTR((uint16_t)CLR_SOF); 88 | bIntPackSOF++; 89 | 90 | #ifdef SOF_CALLBACK 91 | SOF_Callback(); 92 | #endif 93 | } 94 | #endif 95 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 96 | 97 | #if (IMR_MSK & ISTR_CTR) 98 | if (wIstr & ISTR_CTR & wInterrupt_Mask) 99 | { 100 | /* servicing of the endpoint correct transfer interrupt */ 101 | /* clear of the CTR flag into the sub */ 102 | CTR_LP(); 103 | #ifdef CTR_CALLBACK 104 | CTR_Callback(); 105 | #endif 106 | } 107 | #endif 108 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 109 | #if (IMR_MSK & ISTR_RESET) 110 | if (wIstr & ISTR_RESET & wInterrupt_Mask) 111 | { 112 | _SetISTR((uint16_t)CLR_RESET); 113 | Device_Property.Reset(); 114 | #ifdef RESET_CALLBACK 115 | RESET_Callback(); 116 | #endif 117 | } 118 | #endif 119 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 120 | #if (IMR_MSK & ISTR_DOVR) 121 | if (wIstr & ISTR_DOVR & wInterrupt_Mask) 122 | { 123 | _SetISTR((uint16_t)CLR_DOVR); 124 | #ifdef DOVR_CALLBACK 125 | DOVR_Callback(); 126 | #endif 127 | } 128 | #endif 129 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 130 | #if (IMR_MSK & ISTR_ERR) 131 | if (wIstr & ISTR_ERR & wInterrupt_Mask) 132 | { 133 | _SetISTR((uint16_t)CLR_ERR); 134 | #ifdef ERR_CALLBACK 135 | ERR_Callback(); 136 | #endif 137 | } 138 | #endif 139 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 140 | #if (IMR_MSK & ISTR_WKUP) 141 | if (wIstr & ISTR_WKUP & wInterrupt_Mask) 142 | { 143 | _SetISTR((uint16_t)CLR_WKUP); 144 | Resume(RESUME_EXTERNAL); 145 | #ifdef WKUP_CALLBACK 146 | WKUP_Callback(); 147 | #endif 148 | } 149 | #endif 150 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 151 | #if (IMR_MSK & ISTR_SUSP) 152 | if (wIstr & ISTR_SUSP & wInterrupt_Mask) 153 | { 154 | 155 | /* check if SUSPEND is possible */ 156 | if (fSuspendEnabled) 157 | { 158 | Suspend(); 159 | } 160 | else 161 | { 162 | /* if not possible then resume after xx ms */ 163 | Resume(RESUME_LATER); 164 | } 165 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ 166 | _SetISTR((uint16_t)CLR_SUSP); 167 | #ifdef SUSP_CALLBACK 168 | SUSP_Callback(); 169 | #endif 170 | } 171 | #endif 172 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 173 | 174 | #if (IMR_MSK & ISTR_ESOF) 175 | if (wIstr & ISTR_ESOF & wInterrupt_Mask) 176 | { 177 | /* clear ESOF flag in ISTR */ 178 | _SetISTR((uint16_t)CLR_ESOF); 179 | 180 | if ((_GetFNR()&FNR_RXDP)!=0) 181 | { 182 | /* increment ESOF counter */ 183 | esof_counter ++; 184 | 185 | /* test if we enter in ESOF more than 3 times with FSUSP =0 and RXDP =1=>> possible missing SUSP flag*/ 186 | if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0)) 187 | { 188 | /* this a sequence to apply a force RESET*/ 189 | 190 | /*Store CNTR value */ 191 | wCNTR = _GetCNTR(); 192 | 193 | /*Store endpoints registers status */ 194 | for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i); 195 | 196 | /*apply FRES */ 197 | wCNTR|=CNTR_FRES; 198 | _SetCNTR(wCNTR); 199 | 200 | /*clear FRES*/ 201 | wCNTR&=~CNTR_FRES; 202 | _SetCNTR(wCNTR); 203 | 204 | /*poll for RESET flag in ISTR*/ 205 | while((_GetISTR()&ISTR_RESET) == 0); 206 | 207 | /* clear RESET flag in ISTR */ 208 | _SetISTR((uint16_t)CLR_RESET); 209 | 210 | /*restore Enpoints*/ 211 | for (i=0;i<8;i++) 212 | _SetENDPOINT(i, EP[i]); 213 | 214 | esof_counter = 0; 215 | } 216 | } 217 | else 218 | { 219 | esof_counter = 0; 220 | } 221 | 222 | /* resume handling timing is made with ESOFs */ 223 | Resume(RESUME_ESOF); /* request without change of the machine state */ 224 | 225 | #ifdef ESOF_CALLBACK 226 | ESOF_Callback(); 227 | #endif 228 | } 229 | #endif 230 | } /* USB_Istr */ 231 | 232 | 233 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 234 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/misc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the miscellaneous firmware functions (add-on 8 | * to CMSIS functions). 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes ------------------------------------------------------------------*/ 24 | #include "misc.h" 25 | 26 | /** @addtogroup STM32F10x_StdPeriph_Driver 27 | * @{ 28 | */ 29 | 30 | /** @defgroup MISC 31 | * @brief MISC driver modules 32 | * @{ 33 | */ 34 | 35 | /** @defgroup MISC_Private_TypesDefinitions 36 | * @{ 37 | */ 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | /** @defgroup MISC_Private_Defines 44 | * @{ 45 | */ 46 | 47 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 48 | /** 49 | * @} 50 | */ 51 | 52 | /** @defgroup MISC_Private_Macros 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup MISC_Private_Variables 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup MISC_Private_FunctionPrototypes 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup MISC_Private_Functions 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @brief Configures the priority grouping: pre-emption priority and subpriority. 82 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 83 | * This parameter can be one of the following values: 84 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 85 | * 4 bits for subpriority 86 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 87 | * 3 bits for subpriority 88 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 89 | * 2 bits for subpriority 90 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 91 | * 1 bits for subpriority 92 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 93 | * 0 bits for subpriority 94 | * @retval None 95 | */ 96 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 97 | { 98 | /* Check the parameters */ 99 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 100 | 101 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 102 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 103 | } 104 | 105 | /** 106 | * @brief Initializes the NVIC peripheral according to the specified 107 | * parameters in the NVIC_InitStruct. 108 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 109 | * the configuration information for the specified NVIC peripheral. 110 | * @retval None 111 | */ 112 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 113 | { 114 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 115 | 116 | /* Check the parameters */ 117 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 118 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 119 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 120 | 121 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 122 | { 123 | /* Compute the Corresponding IRQ Priority --------------------------------*/ 124 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 125 | tmppre = (0x4 - tmppriority); 126 | tmpsub = tmpsub >> tmppriority; 127 | 128 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 129 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 130 | tmppriority = tmppriority << 0x04; 131 | 132 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 133 | 134 | /* Enable the Selected IRQ Channels --------------------------------------*/ 135 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 136 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 137 | } 138 | else 139 | { 140 | /* Disable the Selected IRQ Channels -------------------------------------*/ 141 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 142 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 143 | } 144 | } 145 | 146 | /** 147 | * @brief Sets the vector table location and Offset. 148 | * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 149 | * This parameter can be one of the following values: 150 | * @arg NVIC_VectTab_RAM 151 | * @arg NVIC_VectTab_FLASH 152 | * @param Offset: Vector Table base offset field. This value must be a multiple 153 | * of 0x200. 154 | * @retval None 155 | */ 156 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 157 | { 158 | /* Check the parameters */ 159 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 160 | assert_param(IS_NVIC_OFFSET(Offset)); 161 | 162 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 163 | } 164 | 165 | /** 166 | * @brief Selects the condition for the system to enter low power mode. 167 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 168 | * This parameter can be one of the following values: 169 | * @arg NVIC_LP_SEVONPEND 170 | * @arg NVIC_LP_SLEEPDEEP 171 | * @arg NVIC_LP_SLEEPONEXIT 172 | * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 173 | * @retval None 174 | */ 175 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 176 | { 177 | /* Check the parameters */ 178 | assert_param(IS_NVIC_LP(LowPowerMode)); 179 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 180 | 181 | if (NewState != DISABLE) 182 | { 183 | SCB->SCR |= LowPowerMode; 184 | } 185 | else 186 | { 187 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 188 | } 189 | } 190 | 191 | /** 192 | * @brief Configures the SysTick clock source. 193 | * @param SysTick_CLKSource: specifies the SysTick clock source. 194 | * This parameter can be one of the following values: 195 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 196 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 197 | * @retval None 198 | */ 199 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 200 | { 201 | /* Check the parameters */ 202 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 203 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 204 | { 205 | SysTick->CTRL |= SysTick_CLKSource_HCLK; 206 | } 207 | else 208 | { 209 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 210 | } 211 | } 212 | 213 | /** 214 | * @} 215 | */ 216 | 217 | /** 218 | * @} 219 | */ 220 | 221 | /** 222 | * @} 223 | */ 224 | 225 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 226 | -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Descriptors for Virtual Com Port Demo 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_desc.h" 32 | 33 | /* USB Standard Device Descriptor */ 34 | const uint8_t Virtual_Com_Port_DeviceDescriptor[] = 35 | { 36 | 0x12, /* bLength */ 37 | USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ 38 | 0x00, 39 | 0x02, /* bcdUSB = 2.00 */ 40 | 0x02, /* bDeviceClass: CDC */ 41 | 0x00, /* bDeviceSubClass */ 42 | 0x00, /* bDeviceProtocol */ 43 | 0x40, /* bMaxPacketSize0 */ 44 | 0x83, 45 | 0x04, /* idVendor = 0x0483 */ 46 | 0x40, 47 | 0x57, /* idProduct = 0x7540 */ 48 | 0x00, 49 | 0x02, /* bcdDevice = 2.00 */ 50 | 1, /* Index of string descriptor describing manufacturer */ 51 | 2, /* Index of string descriptor describing product */ 52 | 3, /* Index of string descriptor describing the device's serial number */ 53 | 0x01 /* bNumConfigurations */ 54 | }; 55 | 56 | const uint8_t Virtual_Com_Port_ConfigDescriptor[] = 57 | { 58 | /*Configuration Descriptor*/ 59 | 0x09, /* bLength: Configuration Descriptor size */ 60 | USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ 61 | VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */ 62 | 0x00, 63 | 0x02, /* bNumInterfaces: 2 interface */ 64 | 0x01, /* bConfigurationValue: Configuration value */ 65 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 66 | 0xC0, /* bmAttributes: self powered */ 67 | 0x32, /* MaxPower 0 mA */ 68 | /*Interface Descriptor*/ 69 | 0x09, /* bLength: Interface Descriptor size */ 70 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ 71 | /* Interface descriptor type */ 72 | 0x00, /* bInterfaceNumber: Number of Interface */ 73 | 0x00, /* bAlternateSetting: Alternate setting */ 74 | 0x01, /* bNumEndpoints: One endpoints used */ 75 | 0x02, /* bInterfaceClass: Communication Interface Class */ 76 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ 77 | 0x01, /* bInterfaceProtocol: Common AT commands */ 78 | 0x00, /* iInterface: */ 79 | /*Header Functional Descriptor*/ 80 | 0x05, /* bLength: Endpoint Descriptor size */ 81 | 0x24, /* bDescriptorType: CS_INTERFACE */ 82 | 0x00, /* bDescriptorSubtype: Header Func Desc */ 83 | 0x10, /* bcdCDC: spec release number */ 84 | 0x01, 85 | /*Call Management Functional Descriptor*/ 86 | 0x05, /* bFunctionLength */ 87 | 0x24, /* bDescriptorType: CS_INTERFACE */ 88 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 89 | 0x00, /* bmCapabilities: D0+D1 */ 90 | 0x01, /* bDataInterface: 1 */ 91 | /*ACM Functional Descriptor*/ 92 | 0x04, /* bFunctionLength */ 93 | 0x24, /* bDescriptorType: CS_INTERFACE */ 94 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 95 | 0x02, /* bmCapabilities */ 96 | /*Union Functional Descriptor*/ 97 | 0x05, /* bFunctionLength */ 98 | 0x24, /* bDescriptorType: CS_INTERFACE */ 99 | 0x06, /* bDescriptorSubtype: Union func desc */ 100 | 0x00, /* bMasterInterface: Communication class interface */ 101 | 0x01, /* bSlaveInterface0: Data Class Interface */ 102 | /*Endpoint 2 Descriptor*/ 103 | 0x07, /* bLength: Endpoint Descriptor size */ 104 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 105 | 0x82, /* bEndpointAddress: (IN2) */ 106 | 0x03, /* bmAttributes: Interrupt */ 107 | VIRTUAL_COM_PORT_INT_SIZE, /* wMaxPacketSize: */ 108 | 0x00, 109 | 0xFF, /* bInterval: */ 110 | /*Data class interface descriptor*/ 111 | 0x09, /* bLength: Endpoint Descriptor size */ 112 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ 113 | 0x01, /* bInterfaceNumber: Number of Interface */ 114 | 0x00, /* bAlternateSetting: Alternate setting */ 115 | 0x02, /* bNumEndpoints: Two endpoints used */ 116 | 0x0A, /* bInterfaceClass: CDC */ 117 | 0x00, /* bInterfaceSubClass: */ 118 | 0x00, /* bInterfaceProtocol: */ 119 | 0x00, /* iInterface: */ 120 | /*Endpoint 3 Descriptor*/ 121 | 0x07, /* bLength: Endpoint Descriptor size */ 122 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 123 | 0x03, /* bEndpointAddress: (OUT3) */ 124 | 0x02, /* bmAttributes: Bulk */ 125 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 126 | 0x00, 127 | 0x00, /* bInterval: ignore for Bulk transfer */ 128 | /*Endpoint 1 Descriptor*/ 129 | 0x07, /* bLength: Endpoint Descriptor size */ 130 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 131 | 0x81, /* bEndpointAddress: (IN1) */ 132 | 0x02, /* bmAttributes: Bulk */ 133 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 134 | 0x00, 135 | 0x00 /* bInterval */ 136 | }; 137 | 138 | /* USB String Descriptors */ 139 | const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID] = 140 | { 141 | VIRTUAL_COM_PORT_SIZ_STRING_LANGID, 142 | USB_STRING_DESCRIPTOR_TYPE, 143 | 0x09, 144 | 0x04 /* LangID = 0x0409: U.S. English */ 145 | }; 146 | 147 | const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR] = 148 | { 149 | VIRTUAL_COM_PORT_SIZ_STRING_VENDOR, /* Size of Vendor string */ 150 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/ 151 | /* Manufacturer: "STMicroelectronics" */ 152 | 'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0, 153 | 'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0, 154 | 'c', 0, 's', 0 155 | }; 156 | 157 | const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT] = 158 | { 159 | VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT, /* bLength */ 160 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 161 | /* Product name: "STM32 Virtual COM Port" */ 162 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'V', 0, 'i', 0, 163 | 'r', 0, 't', 0, 'u', 0, 'a', 0, 'l', 0, ' ', 0, 'C', 0, 'O', 0, 164 | 'M', 0, ' ', 0, 'P', 0, 'o', 0, 'r', 0, 't', 0, ' ', 0, ' ', 0 165 | }; 166 | 167 | uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL] = 168 | { 169 | VIRTUAL_COM_PORT_SIZ_STRING_SERIAL, /* bLength */ 170 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 171 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0 172 | }; 173 | 174 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 175 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/src/stm32f10x_exti.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the EXTI firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_exti.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup EXTI 30 | * @brief EXTI driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup EXTI_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup EXTI_Private_Defines 43 | * @{ 44 | */ 45 | 46 | #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */ 47 | 48 | /** 49 | * @} 50 | */ 51 | 52 | /** @defgroup EXTI_Private_Macros 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup EXTI_Private_Variables 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup EXTI_Private_FunctionPrototypes 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup EXTI_Private_Functions 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @brief Deinitializes the EXTI peripheral registers to their default reset values. 82 | * @param None 83 | * @retval None 84 | */ 85 | void EXTI_DeInit(void) 86 | { 87 | EXTI->IMR = 0x00000000; 88 | EXTI->EMR = 0x00000000; 89 | EXTI->RTSR = 0x00000000; 90 | EXTI->FTSR = 0x00000000; 91 | EXTI->PR = 0x000FFFFF; 92 | } 93 | 94 | /** 95 | * @brief Initializes the EXTI peripheral according to the specified 96 | * parameters in the EXTI_InitStruct. 97 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 98 | * that contains the configuration information for the EXTI peripheral. 99 | * @retval None 100 | */ 101 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 102 | { 103 | uint32_t tmp = 0; 104 | 105 | /* Check the parameters */ 106 | assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 107 | assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 108 | assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 109 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 110 | 111 | tmp = (uint32_t)EXTI_BASE; 112 | 113 | if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 114 | { 115 | /* Clear EXTI line configuration */ 116 | EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 117 | EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 118 | 119 | tmp += EXTI_InitStruct->EXTI_Mode; 120 | 121 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 122 | 123 | /* Clear Rising Falling edge configuration */ 124 | EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 125 | EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 126 | 127 | /* Select the trigger for the selected external interrupts */ 128 | if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 129 | { 130 | /* Rising Falling edge */ 131 | EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 132 | EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 133 | } 134 | else 135 | { 136 | tmp = (uint32_t)EXTI_BASE; 137 | tmp += EXTI_InitStruct->EXTI_Trigger; 138 | 139 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 140 | } 141 | } 142 | else 143 | { 144 | tmp += EXTI_InitStruct->EXTI_Mode; 145 | 146 | /* Disable the selected external lines */ 147 | *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 148 | } 149 | } 150 | 151 | /** 152 | * @brief Fills each EXTI_InitStruct member with its reset value. 153 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will 154 | * be initialized. 155 | * @retval None 156 | */ 157 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 158 | { 159 | EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; 160 | EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 161 | EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 162 | EXTI_InitStruct->EXTI_LineCmd = DISABLE; 163 | } 164 | 165 | /** 166 | * @brief Generates a Software interrupt. 167 | * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled. 168 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 169 | * @retval None 170 | */ 171 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 172 | { 173 | /* Check the parameters */ 174 | assert_param(IS_EXTI_LINE(EXTI_Line)); 175 | 176 | EXTI->SWIER |= EXTI_Line; 177 | } 178 | 179 | /** 180 | * @brief Checks whether the specified EXTI line flag is set or not. 181 | * @param EXTI_Line: specifies the EXTI line flag to check. 182 | * This parameter can be: 183 | * @arg EXTI_Linex: External interrupt line x where x(0..19) 184 | * @retval The new state of EXTI_Line (SET or RESET). 185 | */ 186 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 187 | { 188 | FlagStatus bitstatus = RESET; 189 | /* Check the parameters */ 190 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 191 | 192 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 193 | { 194 | bitstatus = SET; 195 | } 196 | else 197 | { 198 | bitstatus = RESET; 199 | } 200 | return bitstatus; 201 | } 202 | 203 | /** 204 | * @brief Clears the EXTI's line pending flags. 205 | * @param EXTI_Line: specifies the EXTI lines flags to clear. 206 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 207 | * @retval None 208 | */ 209 | void EXTI_ClearFlag(uint32_t EXTI_Line) 210 | { 211 | /* Check the parameters */ 212 | assert_param(IS_EXTI_LINE(EXTI_Line)); 213 | 214 | EXTI->PR = EXTI_Line; 215 | } 216 | 217 | /** 218 | * @brief Checks whether the specified EXTI line is asserted or not. 219 | * @param EXTI_Line: specifies the EXTI line to check. 220 | * This parameter can be: 221 | * @arg EXTI_Linex: External interrupt line x where x(0..19) 222 | * @retval The new state of EXTI_Line (SET or RESET). 223 | */ 224 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 225 | { 226 | ITStatus bitstatus = RESET; 227 | uint32_t enablestatus = 0; 228 | /* Check the parameters */ 229 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 230 | 231 | enablestatus = EXTI->IMR & EXTI_Line; 232 | if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 233 | { 234 | bitstatus = SET; 235 | } 236 | else 237 | { 238 | bitstatus = RESET; 239 | } 240 | return bitstatus; 241 | } 242 | 243 | /** 244 | * @brief Clears the EXTI's line pending bits. 245 | * @param EXTI_Line: specifies the EXTI lines to clear. 246 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 247 | * @retval None 248 | */ 249 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 250 | { 251 | /* Check the parameters */ 252 | assert_param(IS_EXTI_LINE(EXTI_Line)); 253 | 254 | EXTI->PR = EXTI_Line; 255 | } 256 | 257 | /** 258 | * @} 259 | */ 260 | 261 | /** 262 | * @} 263 | */ 264 | 265 | /** 266 | * @} 267 | */ 268 | 269 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 270 | -------------------------------------------------------------------------------- /src/STM32F10x_FWLib/inc/stm32f10x_bkp.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_bkp.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the BKP firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_BKP_H 25 | #define __STM32F10x_BKP_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup BKP 39 | * @{ 40 | */ 41 | 42 | /** @defgroup BKP_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup BKP_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup Tamper_Pin_active_level 55 | * @{ 56 | */ 57 | 58 | #define BKP_TamperPinLevel_High ((uint16_t)0x0000) 59 | #define BKP_TamperPinLevel_Low ((uint16_t)0x0001) 60 | #define IS_BKP_TAMPER_PIN_LEVEL(LEVEL) (((LEVEL) == BKP_TamperPinLevel_High) || \ 61 | ((LEVEL) == BKP_TamperPinLevel_Low)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup RTC_output_source_to_output_on_the_Tamper_pin 67 | * @{ 68 | */ 69 | 70 | #define BKP_RTCOutputSource_None ((uint16_t)0x0000) 71 | #define BKP_RTCOutputSource_CalibClock ((uint16_t)0x0080) 72 | #define BKP_RTCOutputSource_Alarm ((uint16_t)0x0100) 73 | #define BKP_RTCOutputSource_Second ((uint16_t)0x0300) 74 | #define IS_BKP_RTC_OUTPUT_SOURCE(SOURCE) (((SOURCE) == BKP_RTCOutputSource_None) || \ 75 | ((SOURCE) == BKP_RTCOutputSource_CalibClock) || \ 76 | ((SOURCE) == BKP_RTCOutputSource_Alarm) || \ 77 | ((SOURCE) == BKP_RTCOutputSource_Second)) 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup Data_Backup_Register 83 | * @{ 84 | */ 85 | 86 | #define BKP_DR1 ((uint16_t)0x0004) 87 | #define BKP_DR2 ((uint16_t)0x0008) 88 | #define BKP_DR3 ((uint16_t)0x000C) 89 | #define BKP_DR4 ((uint16_t)0x0010) 90 | #define BKP_DR5 ((uint16_t)0x0014) 91 | #define BKP_DR6 ((uint16_t)0x0018) 92 | #define BKP_DR7 ((uint16_t)0x001C) 93 | #define BKP_DR8 ((uint16_t)0x0020) 94 | #define BKP_DR9 ((uint16_t)0x0024) 95 | #define BKP_DR10 ((uint16_t)0x0028) 96 | #define BKP_DR11 ((uint16_t)0x0040) 97 | #define BKP_DR12 ((uint16_t)0x0044) 98 | #define BKP_DR13 ((uint16_t)0x0048) 99 | #define BKP_DR14 ((uint16_t)0x004C) 100 | #define BKP_DR15 ((uint16_t)0x0050) 101 | #define BKP_DR16 ((uint16_t)0x0054) 102 | #define BKP_DR17 ((uint16_t)0x0058) 103 | #define BKP_DR18 ((uint16_t)0x005C) 104 | #define BKP_DR19 ((uint16_t)0x0060) 105 | #define BKP_DR20 ((uint16_t)0x0064) 106 | #define BKP_DR21 ((uint16_t)0x0068) 107 | #define BKP_DR22 ((uint16_t)0x006C) 108 | #define BKP_DR23 ((uint16_t)0x0070) 109 | #define BKP_DR24 ((uint16_t)0x0074) 110 | #define BKP_DR25 ((uint16_t)0x0078) 111 | #define BKP_DR26 ((uint16_t)0x007C) 112 | #define BKP_DR27 ((uint16_t)0x0080) 113 | #define BKP_DR28 ((uint16_t)0x0084) 114 | #define BKP_DR29 ((uint16_t)0x0088) 115 | #define BKP_DR30 ((uint16_t)0x008C) 116 | #define BKP_DR31 ((uint16_t)0x0090) 117 | #define BKP_DR32 ((uint16_t)0x0094) 118 | #define BKP_DR33 ((uint16_t)0x0098) 119 | #define BKP_DR34 ((uint16_t)0x009C) 120 | #define BKP_DR35 ((uint16_t)0x00A0) 121 | #define BKP_DR36 ((uint16_t)0x00A4) 122 | #define BKP_DR37 ((uint16_t)0x00A8) 123 | #define BKP_DR38 ((uint16_t)0x00AC) 124 | #define BKP_DR39 ((uint16_t)0x00B0) 125 | #define BKP_DR40 ((uint16_t)0x00B4) 126 | #define BKP_DR41 ((uint16_t)0x00B8) 127 | #define BKP_DR42 ((uint16_t)0x00BC) 128 | 129 | #define IS_BKP_DR(DR) (((DR) == BKP_DR1) || ((DR) == BKP_DR2) || ((DR) == BKP_DR3) || \ 130 | ((DR) == BKP_DR4) || ((DR) == BKP_DR5) || ((DR) == BKP_DR6) || \ 131 | ((DR) == BKP_DR7) || ((DR) == BKP_DR8) || ((DR) == BKP_DR9) || \ 132 | ((DR) == BKP_DR10) || ((DR) == BKP_DR11) || ((DR) == BKP_DR12) || \ 133 | ((DR) == BKP_DR13) || ((DR) == BKP_DR14) || ((DR) == BKP_DR15) || \ 134 | ((DR) == BKP_DR16) || ((DR) == BKP_DR17) || ((DR) == BKP_DR18) || \ 135 | ((DR) == BKP_DR19) || ((DR) == BKP_DR20) || ((DR) == BKP_DR21) || \ 136 | ((DR) == BKP_DR22) || ((DR) == BKP_DR23) || ((DR) == BKP_DR24) || \ 137 | ((DR) == BKP_DR25) || ((DR) == BKP_DR26) || ((DR) == BKP_DR27) || \ 138 | ((DR) == BKP_DR28) || ((DR) == BKP_DR29) || ((DR) == BKP_DR30) || \ 139 | ((DR) == BKP_DR31) || ((DR) == BKP_DR32) || ((DR) == BKP_DR33) || \ 140 | ((DR) == BKP_DR34) || ((DR) == BKP_DR35) || ((DR) == BKP_DR36) || \ 141 | ((DR) == BKP_DR37) || ((DR) == BKP_DR38) || ((DR) == BKP_DR39) || \ 142 | ((DR) == BKP_DR40) || ((DR) == BKP_DR41) || ((DR) == BKP_DR42)) 143 | 144 | #define IS_BKP_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x7F) 145 | /** 146 | * @} 147 | */ 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @defgroup BKP_Exported_Macros 154 | * @{ 155 | */ 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** @defgroup BKP_Exported_Functions 162 | * @{ 163 | */ 164 | 165 | void BKP_DeInit(void); 166 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel); 167 | void BKP_TamperPinCmd(FunctionalState NewState); 168 | void BKP_ITConfig(FunctionalState NewState); 169 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource); 170 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue); 171 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data); 172 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR); 173 | FlagStatus BKP_GetFlagStatus(void); 174 | void BKP_ClearFlag(void); 175 | ITStatus BKP_GetITStatus(void); 176 | void BKP_ClearITPendingBit(void); 177 | 178 | #ifdef __cplusplus 179 | } 180 | #endif 181 | 182 | #endif /* __STM32F10x_BKP_H */ 183 | /** 184 | * @} 185 | */ 186 | 187 | /** 188 | * @} 189 | */ 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 196 | -------------------------------------------------------------------------------- /src/USB/CONFIG/usb_pwr.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Connection/disconnection & power management 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_conf.h" 32 | #include "usb_pwr.h" 33 | #include "hw_config.h" 34 | 35 | /* Private typedef -----------------------------------------------------------*/ 36 | /* Private define ------------------------------------------------------------*/ 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | __IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */ 40 | __IO bool fSuspendEnabled = TRUE; /* true when suspend is possible */ 41 | __IO uint32_t EP[8]; 42 | 43 | struct 44 | { 45 | __IO RESUME_STATE eState; 46 | __IO uint8_t bESOFcnt; 47 | } 48 | ResumeS; 49 | 50 | __IO uint32_t remotewakeupon=0; 51 | 52 | /* Extern variables ----------------------------------------------------------*/ 53 | /* Private function prototypes -----------------------------------------------*/ 54 | /* Extern function prototypes ------------------------------------------------*/ 55 | /* Private functions ---------------------------------------------------------*/ 56 | 57 | /******************************************************************************* 58 | * Function Name : PowerOn 59 | * Description : 60 | * Input : None. 61 | * Output : None. 62 | * Return : USB_SUCCESS. 63 | *******************************************************************************/ 64 | RESULT PowerOn(void) 65 | { 66 | uint16_t wRegVal; 67 | 68 | /*** cable plugged-in ? ***/ 69 | USB_Cable_Config(ENABLE); 70 | 71 | /*** CNTR_PWDN = 0 ***/ 72 | wRegVal = CNTR_FRES; 73 | _SetCNTR(wRegVal); 74 | 75 | /*** CNTR_FRES = 0 ***/ 76 | wInterrupt_Mask = 0; 77 | _SetCNTR(wInterrupt_Mask); 78 | /*** Clear pending interrupts ***/ 79 | _SetISTR(0); 80 | /*** Set interrupt mask ***/ 81 | wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM; 82 | _SetCNTR(wInterrupt_Mask); 83 | 84 | return USB_SUCCESS; 85 | } 86 | 87 | /******************************************************************************* 88 | * Function Name : PowerOff 89 | * Description : handles switch-off conditions 90 | * Input : None. 91 | * Output : None. 92 | * Return : USB_SUCCESS. 93 | *******************************************************************************/ 94 | RESULT PowerOff() 95 | { 96 | /* disable all interrupts and force USB reset */ 97 | _SetCNTR(CNTR_FRES); 98 | /* clear interrupt status register */ 99 | _SetISTR(0); 100 | /* Disable the Pull-Up*/ 101 | USB_Cable_Config(DISABLE); 102 | /* switch-off device */ 103 | _SetCNTR(CNTR_FRES + CNTR_PDWN); 104 | /* sw variables reset */ 105 | /* ... */ 106 | 107 | return USB_SUCCESS; 108 | } 109 | 110 | /******************************************************************************* 111 | * Function Name : Suspend 112 | * Description : sets suspend mode operating conditions 113 | * Input : None. 114 | * Output : None. 115 | * Return : USB_SUCCESS. 116 | *******************************************************************************/ 117 | void Suspend(void) 118 | { 119 | uint32_t i =0; 120 | uint16_t wCNTR; 121 | __IO uint32_t savePWR_CR=0; 122 | /* suspend preparation */ 123 | /* ... */ 124 | 125 | /*Store CNTR value */ 126 | wCNTR = _GetCNTR(); 127 | 128 | /* This a sequence to apply a force RESET to handle a robustness case */ 129 | 130 | /*Store endpoints registers status */ 131 | for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i); 132 | 133 | /* unmask RESET flag */ 134 | wCNTR|=CNTR_RESETM; 135 | _SetCNTR(wCNTR); 136 | 137 | /*apply FRES */ 138 | wCNTR|=CNTR_FRES; 139 | _SetCNTR(wCNTR); 140 | 141 | /*clear FRES*/ 142 | wCNTR&=~CNTR_FRES; 143 | _SetCNTR(wCNTR); 144 | 145 | /*poll for RESET flag in ISTR*/ 146 | while((_GetISTR()&ISTR_RESET) == 0); 147 | 148 | /* clear RESET flag in ISTR */ 149 | _SetISTR((uint16_t)CLR_RESET); 150 | 151 | /*restore Enpoints*/ 152 | for (i=0;i<8;i++) 153 | _SetENDPOINT(i, EP[i]); 154 | 155 | /* Now it is safe to enter macrocell in suspend mode */ 156 | wCNTR |= CNTR_FSUSP; 157 | _SetCNTR(wCNTR); 158 | 159 | /* force low-power mode in the macrocell */ 160 | wCNTR = _GetCNTR(); 161 | wCNTR |= CNTR_LPMODE; 162 | _SetCNTR(wCNTR); 163 | 164 | Enter_LowPowerMode(); 165 | } 166 | 167 | /******************************************************************************* 168 | * Function Name : Resume_Init 169 | * Description : Handles wake-up restoring normal operations 170 | * Input : None. 171 | * Output : None. 172 | * Return : USB_SUCCESS. 173 | *******************************************************************************/ 174 | void Resume_Init(void) 175 | { 176 | uint16_t wCNTR; 177 | 178 | /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */ 179 | /* restart the clocks */ 180 | /* ... */ 181 | 182 | /* CNTR_LPMODE = 0 */ 183 | wCNTR = _GetCNTR(); 184 | wCNTR &= (~CNTR_LPMODE); 185 | _SetCNTR(wCNTR); 186 | 187 | /* restore full power */ 188 | /* ... on connected devices */ 189 | Leave_LowPowerMode(); 190 | 191 | /* reset FSUSP bit */ 192 | _SetCNTR(IMR_MSK); 193 | 194 | /* reverse suspend preparation */ 195 | /* ... */ 196 | 197 | } 198 | 199 | /******************************************************************************* 200 | * Function Name : Resume 201 | * Description : This is the state machine handling resume operations and 202 | * timing sequence. The control is based on the Resume structure 203 | * variables and on the ESOF interrupt calling this subroutine 204 | * without changing machine state. 205 | * Input : a state machine value (RESUME_STATE) 206 | * RESUME_ESOF doesn't change ResumeS.eState allowing 207 | * decrementing of the ESOF counter in different states. 208 | * Output : None. 209 | * Return : None. 210 | *******************************************************************************/ 211 | void Resume(RESUME_STATE eResumeSetVal) 212 | { 213 | uint16_t wCNTR; 214 | 215 | if (eResumeSetVal != RESUME_ESOF) 216 | ResumeS.eState = eResumeSetVal; 217 | switch (ResumeS.eState) 218 | { 219 | case RESUME_EXTERNAL: 220 | if (remotewakeupon ==0) 221 | { 222 | Resume_Init(); 223 | ResumeS.eState = RESUME_OFF; 224 | } 225 | else /* RESUME detected during the RemoteWAkeup signalling => keep RemoteWakeup handling*/ 226 | { 227 | ResumeS.eState = RESUME_ON; 228 | } 229 | break; 230 | case RESUME_INTERNAL: 231 | Resume_Init(); 232 | ResumeS.eState = RESUME_START; 233 | remotewakeupon = 1; 234 | break; 235 | case RESUME_LATER: 236 | ResumeS.bESOFcnt = 2; 237 | ResumeS.eState = RESUME_WAIT; 238 | break; 239 | case RESUME_WAIT: 240 | ResumeS.bESOFcnt--; 241 | if (ResumeS.bESOFcnt == 0) 242 | ResumeS.eState = RESUME_START; 243 | break; 244 | case RESUME_START: 245 | wCNTR = _GetCNTR(); 246 | wCNTR |= CNTR_RESUME; 247 | _SetCNTR(wCNTR); 248 | ResumeS.eState = RESUME_ON; 249 | ResumeS.bESOFcnt = 10; 250 | break; 251 | case RESUME_ON: 252 | ResumeS.bESOFcnt--; 253 | if (ResumeS.bESOFcnt == 0) 254 | { 255 | wCNTR = _GetCNTR(); 256 | wCNTR &= (~CNTR_RESUME); 257 | _SetCNTR(wCNTR); 258 | ResumeS.eState = RESUME_OFF; 259 | remotewakeupon = 0; 260 | } 261 | break; 262 | case RESUME_OFF: 263 | case RESUME_ESOF: 264 | default: 265 | ResumeS.eState = RESUME_OFF; 266 | break; 267 | } 268 | } 269 | 270 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 271 | --------------------------------------------------------------------------------