diff --git a/bsp/src/SamplingBoard/SamplingBoard.pro b/bsp/src/SamplingBoard/SamplingBoard.pro deleted file mode 100644 --- a/bsp/src/SamplingBoard/SamplingBoard.pro +++ /dev/null @@ -1,35 +0,0 @@ -TEMPLATE = lib - -TARGET=bsp -OBJECTS_DIR = obj - -BSP=SamplingBoard - - -UCMODEL=stm32f4 - -SOURCES += bsp.c - -HEADERS += bsp.h - - -BSPFILE = bsp.pri - - - - -INCLUDEPATH += $${PWD} - -SOURCES += bsp.c -contains(CONFIG , USB){ -SOURCES += usbd_usr.c \ - usbd_desc.c \ - usbd_cdc_vcp.c \ - usb_bsp.c -} - -HEADERS += $$libuc2/bsp/includes/$$BSP/bsp.h \ - usbd_desc.h \ - usbd_conf.h \ - usbd_cdc_vcp.h \ - usb_conf.h diff --git a/bsp/src/SamplingBoard/bsp.c b/bsp/src/SamplingBoard/bsp.c deleted file mode 100644 --- a/bsp/src/SamplingBoard/bsp.c +++ /dev/null @@ -1,141 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the libuc, microcontroler library --- Copyright (C) 2011, Alexis Jeandet --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------- --- Author : Alexis Jeandet --- Mail : alexis.jeandet@gmail.com --------------------------------------------------------------------------------*/ -#include "bsp.h" -#include -#include -#include -#include -#include -#include -#include -uint32_t OSC0 =8000000; -uint32_t INTOSC =16000000; -uint32_t RTCOSC =32768; -uint32_t currentCpuFreq=0; -extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; - -float VREF0 =(float)3.3; - -int bsp_init() -{ - int i=0; - for(i=0;i<32;i++) - { - __opnfiles__[i] = NULL; - } - bsp_GPIO_init(); - bsp_uart_init(); - bsp_spi_init(); - printf("\r================================================================\n\r"); - printf("================================================================\n\r"); - printf(BSP); - printf(" initialised\n\r"); - printf("================================================================\n\r"); - return 1; -} - -void bsp_GPIO_init() -{ -// gpio_t GPIOList[]={LED1,LED2,LED3,ADC_MODE0,ADC_MODE1,ADC_FSYNC -// ,ADC_SYNC,ADC_CLKDIV}; -// gpio_t GPIOx; -// for(int i=0;i<8;i++) -// { -// GPIOx = gpioopen(GPIOList[i]); -// gpiosetspeed(&GPIOx,gpiohighspeed); -// gpiosetdir(&GPIOx,gpiooutdir); -// gpiosetouttype(&GPIOx,gpiopushpulltype); -// } -// gpioset(ADC_CLKDIV); -// gpioset(ADC_MODE0); -// gpioset(ADC_MODE1); -// gpioclr(ADC_SYNC); -// gpioclr(ADC_FSYNC); -// delay_100us(10); -// gpioset(ADC_SYNC); - -} - -void bsp_uart_init() -{ - if(__opnfiles__[1]==NULL) - { - //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); - streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); - uart_t uart = uartopenandconfig(uart6,uartparitynone | uart8bits | uartonestop,19200,PC6,PC7,-1,-1); - uartmkstreamdev(uart,fd1); - __opnfiles__[1] = fd1; - } - else - { - uartopenandconfig(uart6,uartparitynone | uart8bits | uartonestop,19200,PC6,PC7,-1,-1); - } -} - -void bsp_spi_init() -{ - //spiopenandconfig(spi1,spi8bits | spimaster |spiclkinhlow | spiclkfirstedge | spimsbfirst,1000000,DAC_DIN,ADC_DOUT1,ADC_SCLK,-1); -} - - -void bsp_iic_init() -{ - -} - -void bsp_SD_init() -{ - -} - -void vs10XXclearXCS(){} -void vs10XXsetXCS(){} -int vs10XXDREQ() -{ - return 1; -} - - -void bsppowersdcard(char onoff) //always ON -{ - -} - -char bspsdcardpresent() -{ - return 0; -} - -char bspsdcardwriteprotected() -{ - return 0; -} - -void bspsdcardselect(char YESNO) -{ - -} - - - - - diff --git a/bsp/src/SamplingBoard/bsp.h b/bsp/src/SamplingBoard/bsp.h deleted file mode 100644 --- a/bsp/src/SamplingBoard/bsp.h +++ /dev/null @@ -1,92 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the libuc, microcontroler library --- Copyright (C) 2011, Alexis Jeandet --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------- --- Author : Alexis Jeandet --- Mail : alexis.jeandet@gmail.com --------------------------------------------------------------------------------*/ -#ifndef BSP_H -#define BSP_H -#include -#include -#include -#include - - -#define __MAX_OPENED_FILES__ 32 -#define __FS_ROOT_SIZE__ 32 - -#define LED1 PD9 -#define LED2 PD8 -#define LED3 PB15 - -#define DAC_CS PA1 -#define DAC_DIN PA7 - -#define ADC_MODE0 PA2 -#define ADC_MODE1 PA3 -#define ADC_FSYNC PA4 -#define ADC_SCLK PA5 -#define ADC_DOUT1 PA6 - -#define ADC_SYNC PB10 -#define ADC_CLKDIV PB11 - - -extern float VREF0; - -extern uint32_t currentCpuFreq; - -extern int bsp_init(); - -extern void bsp_GPIO_init(); -extern void bsp_uart_init(); -extern void bsp_iic_init(); -extern void bsp_spi_init(); -extern void bsp_SD_init(); - -/* VS1053 */ -extern void clearXCS(); -extern void setXCS(); -extern int vs10XXDREQ(); - -/* SD CARD */ -void bsppowersdcard(char onoff); -char bspsdcardpresent(); -void bspsdcardselect(char YESNO); -char bspsdcardwriteprotected(); - -#endif - - - - - - - - - - - - - - - - - - - diff --git a/bsp/src/SamplingBoard/bsp.pri b/bsp/src/SamplingBoard/bsp.pri deleted file mode 100644 --- a/bsp/src/SamplingBoard/bsp.pri +++ /dev/null @@ -1,9 +0,0 @@ -CPU=stm32f4xxxG -DEFINES+=BSP=\\\"SamplingBoard\\\" -#CONFIG += USB -USB += cdc -DEFINES+= USE_USB_OTG_FS -DEFINES+=stm32f4 -UCMODEL=stm32f4 - - diff --git a/bsp/src/SamplingBoard/usb_bsp.c b/bsp/src/SamplingBoard/usb_bsp.c deleted file mode 100644 --- a/bsp/src/SamplingBoard/usb_bsp.c +++ /dev/null @@ -1,320 +0,0 @@ -/** - ****************************************************************************** - * @file usb_bsp.c - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief This file is responsible to offer board support package and is - * configurable by user. - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_bsp.h" -#include "usbd_conf.h" - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY -* @{ -*/ - -/** @defgroup USB_BSP -* @brief This file is responsible to offer board support package -* @{ -*/ - -/** @defgroup USB_BSP_Private_Defines -* @{ -*/ -/** -* @} -*/ - - -/** @defgroup USB_BSP_Private_TypesDefinitions -* @{ -*/ -/** -* @} -*/ - - - - - -/** @defgroup USB_BSP_Private_Macros -* @{ -*/ -/** -* @} -*/ - -/** @defgroup USBH_BSP_Private_Variables -* @{ -*/ - -/** -* @} -*/ - -/** @defgroup USBH_BSP_Private_FunctionPrototypes -* @{ -*/ -/** -* @} -*/ - -/** @defgroup USB_BSP_Private_Functions -* @{ -*/ - - -/** -* @brief USB_OTG_BSP_Init -* Initilizes BSP configurations -* @param None -* @retval None -*/ - -void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) -{ -#ifdef USE_STM3210C_EVAL - - RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3); - RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE) ; - -#else // USE_STM322xG_EVAL - GPIO_InitTypeDef GPIO_InitStructure; - #ifdef USE_USB_OTG_FS - RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE); - - /* Configure SOF ID DM DP Pins */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | - GPIO_Pin_11 | - GPIO_Pin_12; - - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ; - GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ; - GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ; - - /* Configure VBUS Pin */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - /* Configure ID pin */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ; - - RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); - RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ; - #else // USE_USB_OTG_HS - - #ifdef USE_ULPI_PHY // ULPI - RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | - RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOH | - RCC_AHB1Periph_GPIOI, ENABLE); - - - GPIO_PinAFConfig(GPIOA,GPIO_PinSource3, GPIO_AF_OTG2_HS) ; // D0 - GPIO_PinAFConfig(GPIOA,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // CLK - GPIO_PinAFConfig(GPIOB,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // D1 - GPIO_PinAFConfig(GPIOB,GPIO_PinSource1, GPIO_AF_OTG2_HS) ; // D2 - GPIO_PinAFConfig(GPIOB,GPIO_PinSource5, GPIO_AF_OTG2_HS) ; // D7 - GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_OTG2_HS) ; // D3 - GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // D4 - GPIO_PinAFConfig(GPIOB,GPIO_PinSource12,GPIO_AF_OTG2_HS) ; // D5 - GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_OTG2_HS) ; // D6 - GPIO_PinAFConfig(GPIOH,GPIO_PinSource4, GPIO_AF_OTG2_HS) ; // NXT - GPIO_PinAFConfig(GPIOI,GPIO_PinSource11,GPIO_AF_OTG2_HS) ; // DIR - GPIO_PinAFConfig(GPIOC,GPIO_PinSource0, GPIO_AF_OTG2_HS) ; // STP - - // CLK - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - // D0 - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 ; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - - - // D1 D2 D3 D4 D5 D6 D7 - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | - GPIO_Pin_5 | GPIO_Pin_10 | - GPIO_Pin_11| GPIO_Pin_12 | - GPIO_Pin_13 ; - - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - - // STP - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_Init(GPIOC, &GPIO_InitStructure); - - //NXT - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_Init(GPIOH, &GPIO_InitStructure); - - - //DIR - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_Init(GPIOI, &GPIO_InitStructure); - - - RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS | - RCC_AHB1Periph_OTG_HS_ULPI, ENABLE) ; - - #else - - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE); - - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | - GPIO_Pin_14 | - GPIO_Pin_15; - - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - GPIO_PinAFConfig(GPIOB,GPIO_PinSource12, GPIO_AF_OTG2_FS) ; - GPIO_PinAFConfig(GPIOB,GPIO_PinSource14,GPIO_AF_OTG2_FS) ; - GPIO_PinAFConfig(GPIOB,GPIO_PinSource15,GPIO_AF_OTG2_FS) ; - - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - - RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_OTG_HS, ENABLE) ; - - #endif - #endif //USB_OTG_HS -#endif //USE_STM322xG_EVAL -} -/** -* @brief USB_OTG_BSP_EnableInterrupt -* Enabele USB Global interrupt -* @param None -* @retval None -*/ -void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev) -{ - NVIC_InitTypeDef NVIC_InitStructure; - - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); -#ifdef USE_USB_OTG_HS - NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn; -#else - NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn; -#endif - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); - NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_OUT_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); - NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_IN_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -#endif -} -/** -* @brief USB_OTG_BSP_uDelay -* This function provides delay time in micro sec -* @param usec : Value of delay required in micro sec -* @retval None -*/ -void USB_OTG_BSP_uDelay (const uint32_t usec) -{ - uint32_t count = 0; - const uint32_t utime = (120 * usec / 7); - do - { - if ( ++count > utime ) - { - return ; - } - } - while (1); -} - - -/** -* @brief USB_OTG_BSP_mDelay -* This function provides delay time in milli sec -* @param msec : Value of delay required in milli sec -* @retval None -*/ -void USB_OTG_BSP_mDelay (const uint32_t msec) -{ - USB_OTG_BSP_uDelay(msec * 1000); -} -/** -* @} -*/ - -/** -* @} -*/ - -/** -* @} -*/ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp/src/SamplingBoard/usb_conf.h b/bsp/src/SamplingBoard/usb_conf.h deleted file mode 100644 --- a/bsp/src/SamplingBoard/usb_conf.h +++ /dev/null @@ -1,310 +0,0 @@ -/** - ****************************************************************************** - * @file usb_conf.h - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief General low level driver configuration - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_CONF__H__ -#define __USB_CONF__H__ - -/* Includes ------------------------------------------------------------------*/ -#if defined (USE_STM322xG_EVAL) - #include "stm322xg_eval.h" - #include "stm322xg_eval_lcd.h" - #include "stm322xg_eval_ioe.h" - #include "stm322xg_eval_sdio_sd.h" -#elif defined(USE_STM324xG_EVAL) - #include "stm32f4xx.h" - #include "stm324xg_eval.h" - #include "stm324xg_eval_lcd.h" - #include "stm324xg_eval_ioe.h" - #include "stm324xg_eval_sdio_sd.h" -#elif defined (USE_STM3210C_EVAL) - #include "stm32f10x.h" - #include "stm3210c_eval.h" - #include "stm3210c_eval_lcd.h" - #include "stm3210c_eval_ioe.h" - #include "stm3210c_eval_spi_sd.h" -#elif defined (stm32f4) - #include "stm32f4xx.h" -#else - #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)" -#endif - - -/** @addtogroup USB_OTG_DRIVER - * @{ - */ - -/** @defgroup USB_CONF - * @brief USB low level driver configuration file - * @{ - */ - -/** @defgroup USB_CONF_Exported_Defines - * @{ - */ - -/* USB Core and PHY interface configuration. - Tip: To avoid modifying these defines each time you need to change the USB - configuration, you can declare the needed define in your toolchain - compiler preprocessor. - */ -/****************** USB OTG FS PHY CONFIGURATION ******************************* -* The USB OTG FS Core supports one on-chip Full Speed PHY. -* -* The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor -* when FS core is used. -*******************************************************************************/ -#ifndef USE_USB_OTG_FS - //#define USE_USB_OTG_FS -#endif /* USE_USB_OTG_FS */ - -#ifdef USE_USB_OTG_FS - #define USB_OTG_FS_CORE -#endif - -/****************** USB OTG HS PHY CONFIGURATION ******************************* -* The USB OTG HS Core supports two PHY interfaces: -* (i) An ULPI interface for the external High Speed PHY: the USB HS Core will -* operate in High speed mode -* (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode -* -* You can select the PHY to be used using one of these two defines: -* (i) USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode -* (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode -* -* Notes: -* - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as -* default PHY when HS core is used. -* - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available. -* Configuration (ii) need a different hardware, for more details refer to your -* STM32 device datasheet. -*******************************************************************************/ -#ifndef USE_USB_OTG_HS - //#define USE_USB_OTG_HS -#endif /* USE_USB_OTG_HS */ - -#ifndef USE_ULPI_PHY - //#define USE_ULPI_PHY -#endif /* USE_ULPI_PHY */ - -#ifndef USE_EMBEDDED_PHY - //#define USE_EMBEDDED_PHY -#endif /* USE_EMBEDDED_PHY */ - -#ifdef USE_USB_OTG_HS - #define USB_OTG_HS_CORE -#endif - -/******************************************************************************* -* FIFO Size Configuration in Device mode -* -* (i) Receive data FIFO size = RAM for setup packets + -* OUT endpoint control information + -* data OUT packets + miscellaneous -* Space = ONE 32-bits words -* --> RAM for setup packets = 10 spaces -* (n is the nbr of CTRL EPs the device core supports) -* --> OUT EP CTRL info = 1 space -* (one space for status information written to the FIFO along with each -* received packet) -* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces -* (MINIMUM to receive packets) -* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces -* (if high-bandwidth EP is enabled or multiple isochronous EPs) -* --> miscellaneous = 1 space per OUT EP -* (one space for transfer complete status information also pushed to the -* FIFO with each endpoint's last packet) -* -* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for -* that particular IN EP. More space allocated in the IN EP Tx FIFO results -* in a better performance on the USB and can hide latencies on the AHB. -* -* (iii) TXn min size = 16 words. (n : Transmit FIFO index) -* (iv) When a TxFIFO is not used, the Configuration should be as follows: -* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) -* --> Txm can use the space allocated for Txn. -* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) -* --> Txn should be configured with the minimum space of 16 words -* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top -* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. -* (vi) In HS case 12 FIFO locations should be reserved for internal DMA registers -* so total FIFO size should be 1012 Only instead of 1024 -*******************************************************************************/ - -/****************** USB OTG HS CONFIGURATION **********************************/ -#ifdef USB_OTG_HS_CORE - #define RX_FIFO_HS_SIZE 512 - #define TX0_FIFO_HS_SIZE 64 - #define TX1_FIFO_HS_SIZE 372 - #define TX2_FIFO_HS_SIZE 64 - #define TX3_FIFO_HS_SIZE 0 - #define TX4_FIFO_HS_SIZE 0 - #define TX5_FIFO_HS_SIZE 0 - -// #define USB_OTG_HS_SOF_OUTPUT_ENABLED - - #ifdef USE_ULPI_PHY - #define USB_OTG_ULPI_PHY_ENABLED - #endif - #ifdef USE_EMBEDDED_PHY - #define USB_OTG_EMBEDDED_PHY_ENABLED - /* wakeup is working only when HS core is configured in FS mode */ - #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT - #endif - /* #define USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* Be aware that enabling DMA mode will result in data being sent only by - multiple of 4 packet sizes. This is due to the fact that USB DMA does - not allow sending data from non word-aligned addresses. - For this specific application, it is advised to not enable this option - unless required. */ - #define USB_OTG_HS_DEDICATED_EP1_ENABLED -#endif - -/****************** USB OTG FS CONFIGURATION **********************************/ -#ifdef USB_OTG_FS_CORE - #define RX_FIFO_FS_SIZE 128 - #define TX0_FIFO_FS_SIZE 32 - #define TX1_FIFO_FS_SIZE 128 - #define TX2_FIFO_FS_SIZE 32 - #define TX3_FIFO_FS_SIZE 0 - -// #define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT -// #define USB_OTG_FS_SOF_OUTPUT_ENABLED -#endif - -/****************** USB OTG MISC CONFIGURATION ********************************/ -#define VBUS_SENSING_ENABLED - -/****************** USB OTG MODE CONFIGURATION ********************************/ -//#define USE_HOST_MODE -#define USE_DEVICE_MODE -//#define USE_OTG_MODE - -#ifndef USB_OTG_FS_CORE - #ifndef USB_OTG_HS_CORE - #error "USB_OTG_HS_CORE or USB_OTG_FS_CORE should be defined" - #endif -#endif - -#ifndef USE_DEVICE_MODE - #ifndef USE_HOST_MODE - #error "USE_DEVICE_MODE or USE_HOST_MODE should be defined" - #endif -#endif - -#ifndef USE_USB_OTG_HS - #ifndef USE_USB_OTG_FS - #error "USE_USB_OTG_HS or USE_USB_OTG_FS should be defined" - #endif -#else //USE_USB_OTG_HS - #ifndef USE_ULPI_PHY - #ifndef USE_EMBEDDED_PHY - #error "USE_ULPI_PHY or USE_EMBEDDED_PHY should be defined" - #endif - #endif -#endif - -/****************** C Compilers dependant keywords ****************************/ -/* In HS mode and when the DMA is used, all variables and data structures dealing - with the DMA during the transaction process should be 4-bytes aligned */ -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined (__GNUC__) /* GNU Compiler */ - #define __ALIGN_END __attribute__ ((aligned (4))) - #define __ALIGN_BEGIN - #else - #define __ALIGN_END - #if defined (__CC_ARM) /* ARM Compiler */ - #define __ALIGN_BEGIN __align(4) - #elif defined (__ICCARM__) /* IAR Compiler */ - #define __ALIGN_BEGIN - #elif defined (__TASKING__) /* TASKING Compiler */ - #define __ALIGN_BEGIN __align(4) - #endif /* __CC_ARM */ - #endif /* __GNUC__ */ -#else - #define __ALIGN_BEGIN - #define __ALIGN_END -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ - -/* __packed keyword used to decrease the data type alignment to 1-byte */ -#if defined (__CC_ARM) /* ARM Compiler */ - #define __packed __packed -#elif defined (__ICCARM__) /* IAR Compiler */ - #define __packed __packed -#elif defined ( __GNUC__ ) /* GNU Compiler */ - #define __packed __attribute__ ((__packed__)) -#elif defined (__TASKING__) /* TASKING Compiler */ - #define __packed __unaligned -#endif /* __CC_ARM */ - -/** - * @} - */ - - -/** @defgroup USB_CONF_Exported_Types - * @{ - */ -/** - * @} - */ - - -/** @defgroup USB_CONF_Exported_Macros - * @{ - */ -/** - * @} - */ - -/** @defgroup USB_CONF_Exported_Variables - * @{ - */ -/** - * @} - */ - -/** @defgroup USB_CONF_Exported_FunctionsPrototype - * @{ - */ -/** - * @} - */ - - -#endif //__USB_CONF__H__ - - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/bsp/src/SamplingBoard/usbd_cdc_vcp.c b/bsp/src/SamplingBoard/usbd_cdc_vcp.c deleted file mode 100644 --- a/bsp/src/SamplingBoard/usbd_cdc_vcp.c +++ /dev/null @@ -1,381 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_cdc_vcp.c - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief Generic media access Layer. - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED -#pragma data_alignment = 4 -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_cdc_vcp.h" -#include "usb_conf.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -LINE_CODING linecoding = - { - 115200, /* baud rate*/ - 0x00, /* stop bits-1*/ - 0x00, /* parity - none*/ - 0x08 /* nb. of bits 8*/ - }; - - -USART_InitTypeDef USART_InitStructure; - -/* These are external variables imported from CDC core to be used for IN - transfer management. */ -extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer. - These data will be sent over USB IN endpoint - in the CDC core functions. */ -extern uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to - start address when writing received data - in the buffer APP_Rx_Buffer. */ - -/* Private function prototypes -----------------------------------------------*/ -static uint16_t VCP_Init (void); -static uint16_t VCP_DeInit (void); -static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len); -static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len); -static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len); - -static uint16_t VCP_COMConfig(uint8_t Conf); - -CDC_IF_Prop_TypeDef VCP_fops = -{ - VCP_Init, - VCP_DeInit, - VCP_Ctrl, - VCP_DataTx, - VCP_DataRx -}; - -/* Private functions ---------------------------------------------------------*/ -/** - * @brief VCP_Init - * Initializes the Media on the STM32 - * @param None - * @retval Result of the opeartion (USBD_OK in all cases) - */ -static uint16_t VCP_Init(void) -{ - NVIC_InitTypeDef NVIC_InitStructure; - - /* EVAL_COM1 default configuration */ - /* EVAL_COM1 configured as follow: - - BaudRate = 115200 baud - - Word Length = 8 Bits - - One Stop Bit - - Parity Odd - - Hardware flow control disabled - - Receive and transmit enabled - */ - USART_InitStructure.USART_BaudRate = 115200; - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - USART_InitStructure.USART_StopBits = USART_StopBits_1; - USART_InitStructure.USART_Parity = USART_Parity_Odd; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; - - /* Configure and enable the USART */ - STM_EVAL_COMInit(COM1, &USART_InitStructure); - - /* Enable the USART Receive interrupt */ - USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); - - /* Enable USART Interrupt */ - NVIC_InitStructure.NVIC_IRQChannel = EVAL_COM1_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - - return USBD_OK; -} - -/** - * @brief VCP_DeInit - * DeInitializes the Media on the STM32 - * @param None - * @retval Result of the opeartion (USBD_OK in all cases) - */ -static uint16_t VCP_DeInit(void) -{ - - return USBD_OK; -} - - -/** - * @brief VCP_Ctrl - * Manage the CDC class requests - * @param Cmd: Command code - * @param Buf: Buffer containing command data (request parameters) - * @param Len: Number of data to be sent (in bytes) - * @retval Result of the opeartion (USBD_OK in all cases) - */ -static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len) -{ - switch (Cmd) - { - case SEND_ENCAPSULATED_COMMAND: - /* Not needed for this driver */ - break; - - case GET_ENCAPSULATED_RESPONSE: - /* Not needed for this driver */ - break; - - case SET_COMM_FEATURE: - /* Not needed for this driver */ - break; - - case GET_COMM_FEATURE: - /* Not needed for this driver */ - break; - - case CLEAR_COMM_FEATURE: - /* Not needed for this driver */ - break; - - case SET_LINE_CODING: - linecoding.bitrate = (uint32_t)(Buf[0] | (Buf[1] << 8) | (Buf[2] << 16) | (Buf[3] << 24)); - linecoding.format = Buf[4]; - linecoding.paritytype = Buf[5]; - linecoding.datatype = Buf[6]; - /* Set the new configuration */ - VCP_COMConfig(OTHER_CONFIG); - break; - - case GET_LINE_CODING: - Buf[0] = (uint8_t)(linecoding.bitrate); - Buf[1] = (uint8_t)(linecoding.bitrate >> 8); - Buf[2] = (uint8_t)(linecoding.bitrate >> 16); - Buf[3] = (uint8_t)(linecoding.bitrate >> 24); - Buf[4] = linecoding.format; - Buf[5] = linecoding.paritytype; - Buf[6] = linecoding.datatype; - break; - - case SET_CONTROL_LINE_STATE: - /* Not needed for this driver */ - break; - - case SEND_BREAK: - /* Not needed for this driver */ - break; - - default: - break; - } - - return USBD_OK; -} - -/** - * @brief VCP_DataTx - * CDC received data to be send over USB IN endpoint are managed in - * this function. - * @param Buf: Buffer of data to be sent - * @param Len: Number of data to be sent (in bytes) - * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL - */ -static uint16_t VCP_DataTx (uint8_t* Buf, uint32_t Len) -{ - if (linecoding.datatype == 7) - { - APP_Rx_Buffer[APP_Rx_ptr_in] = USART_ReceiveData(EVAL_COM1) & 0x7F; - } - else if (linecoding.datatype == 8) - { - APP_Rx_Buffer[APP_Rx_ptr_in] = USART_ReceiveData(EVAL_COM1); - } - - APP_Rx_ptr_in++; - - /* To avoid buffer overflow */ - if(APP_Rx_ptr_in == APP_RX_DATA_SIZE) - { - APP_Rx_ptr_in = 0; - } - - return USBD_OK; -} - -/** - * @brief VCP_DataRx - * Data received over USB OUT endpoint are sent over CDC interface - * through this function. - * - * @note - * This function will block any OUT packet reception on USB endpoint - * untill exiting this function. If you exit this function before transfer - * is complete on CDC interface (ie. using DMA controller) it will result - * in receiving more data while previous ones are still not sent. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL - */ -static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len) -{ - uint32_t i; - - for (i = 0; i < Len; i++) - { - USART_SendData(EVAL_COM1, *(Buf + i) ); - while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET); - } - - return USBD_OK; -} - -/** - * @brief VCP_COMConfig - * Configure the COM Port with default values or values received from host. - * @param Conf: can be DEFAULT_CONFIG to set the default configuration or OTHER_CONFIG - * to set a configuration received from the host. - * @retval None. - */ -static uint16_t VCP_COMConfig(uint8_t Conf) -{ - if (Conf == DEFAULT_CONFIG) - { - /* EVAL_COM1 default configuration */ - /* EVAL_COM1 configured as follow: - - BaudRate = 115200 baud - - Word Length = 8 Bits - - One Stop Bit - - Parity Odd - - Hardware flow control disabled - - Receive and transmit enabled - */ - USART_InitStructure.USART_BaudRate = 115200; - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - USART_InitStructure.USART_StopBits = USART_StopBits_1; - USART_InitStructure.USART_Parity = USART_Parity_Odd; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; - - /* Configure and enable the USART */ - STM_EVAL_COMInit(COM1, &USART_InitStructure); - - /* Enable the USART Receive interrupt */ - USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE); - } - else - { - /* set the Stop bit*/ - switch (linecoding.format) - { - case 0: - USART_InitStructure.USART_StopBits = USART_StopBits_1; - break; - case 1: - USART_InitStructure.USART_StopBits = USART_StopBits_1_5; - break; - case 2: - USART_InitStructure.USART_StopBits = USART_StopBits_2; - break; - default : - VCP_COMConfig(DEFAULT_CONFIG); - return (USBD_FAIL); - } - - /* set the parity bit*/ - switch (linecoding.paritytype) - { - case 0: - USART_InitStructure.USART_Parity = USART_Parity_No; - break; - case 1: - USART_InitStructure.USART_Parity = USART_Parity_Even; - break; - case 2: - USART_InitStructure.USART_Parity = USART_Parity_Odd; - break; - default : - VCP_COMConfig(DEFAULT_CONFIG); - return (USBD_FAIL); - } - - /*set the data type : only 8bits and 9bits is supported */ - switch (linecoding.datatype) - { - case 0x07: - /* With this configuration a parity (Even or Odd) should be set */ - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - break; - case 0x08: - if (USART_InitStructure.USART_Parity == USART_Parity_No) - { - USART_InitStructure.USART_WordLength = USART_WordLength_8b; - } - else - { - USART_InitStructure.USART_WordLength = USART_WordLength_9b; - } - - break; - default : - VCP_COMConfig(DEFAULT_CONFIG); - return (USBD_FAIL); - } - - USART_InitStructure.USART_BaudRate = linecoding.bitrate; - USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; - - /* Configure and enable the USART */ - STM_EVAL_COMInit(COM1, &USART_InitStructure); - } - return USBD_OK; -} - -/** - * @brief EVAL_COM_IRQHandler - * - * @param None. - * @retval None. - */ -void EVAL_COM_IRQHandler(void) -{ - if (USART_GetITStatus(EVAL_COM1, USART_IT_RXNE) != RESET) - { - /* Send the received data to the PC Host*/ - VCP_DataTx (0,0); - } - - /* If overrun condition occurs, clear the ORE flag and recover communication */ - if (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_ORE) != RESET) - { - (void)USART_ReceiveData(EVAL_COM1); - } -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp/src/SamplingBoard/usbd_cdc_vcp.h b/bsp/src/SamplingBoard/usbd_cdc_vcp.h deleted file mode 100644 --- a/bsp/src/SamplingBoard/usbd_cdc_vcp.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_cdc_vcp.h - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief Header for usbd_cdc_vcp.c file. - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CDC_VCP_H -#define __USBD_CDC_VCP_H - -/* Includes ------------------------------------------------------------------*/ -#ifdef STM32F2XX - #include "stm32f2xx.h" -#elif defined(STM32F10X_CL) - #include "stm32f10x.h" -#endif /* STM32F2XX */ - -#include "usbd_cdc_core.h" -#include "usbd_conf.h" - - -/* Exported typef ------------------------------------------------------------*/ -/* The following structures groups all needed parameters to be configured for the - ComPort. These parameters can modified on the fly by the host through CDC class - command class requests. */ -typedef struct -{ - uint32_t bitrate; - uint8_t format; - uint8_t paritytype; - uint8_t datatype; -}LINE_CODING; - -/* Exported constants --------------------------------------------------------*/ -/* The following define is used to route the USART IRQ handler to be used. - The IRQ handler function is implemented in the usbd_cdc_vcp.c file. */ - -#ifdef USE_STM3210C_EVAL - #define EVAL_COM_IRQHandler USART2_IRQHandler -#else - #define EVAL_COM_IRQHandler USART3_IRQHandler -#endif /* USE_STM322xG_EVAL */ - - -#define DEFAULT_CONFIG 0 -#define OTHER_CONFIG 1 - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - -#endif /* __USBD_CDC_VCP_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp/src/SamplingBoard/usbd_conf.h b/bsp/src/SamplingBoard/usbd_conf.h deleted file mode 100644 --- a/bsp/src/SamplingBoard/usbd_conf.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_conf.h - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief USB Device configuration file - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CONF__H__ -#define __USBD_CONF__H__ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_conf.h" - -/** @defgroup USB_CONF_Exported_Defines - * @{ - */ -#define USBD_CFG_MAX_NUM 1 -#define USBD_ITF_MAX_NUM 1 - -#define USBD_SELF_POWERED - -#define USB_MAX_STR_DESC_SIZ 255 - -/** @defgroup USB_VCP_Class_Layer_Parameter - * @{ - */ -#define CDC_IN_EP 0x81 /* EP1 for data IN */ -#define CDC_OUT_EP 0x01 /* EP1 for data OUT */ -#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */ - -/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ -#ifdef USE_USB_OTG_HS - #define CDC_DATA_MAX_PACKET_SIZE 512 /* Endpoint IN & OUT Packet size */ - #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */ - - #define CDC_IN_FRAME_INTERVAL 40 /* Number of micro-frames between IN transfers */ - #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: - APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL*8 */ -#else - #define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */ - #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */ - - #define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */ - #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: - APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */ -#endif /* USE_USB_OTG_HS */ - -#define APP_FOPS VCP_fops -/** - * @} - */ - -/** @defgroup USB_CONF_Exported_Types - * @{ - */ -/** - * @} - */ - - -/** @defgroup USB_CONF_Exported_Macros - * @{ - */ -/** - * @} - */ - -/** @defgroup USB_CONF_Exported_Variables - * @{ - */ -/** - * @} - */ - -/** @defgroup USB_CONF_Exported_FunctionsPrototype - * @{ - */ -/** - * @} - */ - - -#endif //__USBD_CONF__H__ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/bsp/src/SamplingBoard/usbd_desc.c b/bsp/src/SamplingBoard/usbd_desc.c deleted file mode 100644 --- a/bsp/src/SamplingBoard/usbd_desc.c +++ /dev/null @@ -1,322 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_desc.c - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief This file provides the USBD descriptors and string formating method. - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" -#include "usbd_desc.h" -#include "usbd_req.h" -#include "usbd_conf.h" -#include "usb_regs.h" - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup USBD_DESC - * @brief USBD descriptors module - * @{ - */ - -/** @defgroup USBD_DESC_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_DESC_Private_Defines - * @{ - */ -#define USBD_VID 0x0483 - -#define USBD_PID 0x5740 - -/** @defgroup USB_String_Descriptors - * @{ - */ -#define USBD_LANGID_STRING 0x409 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" - -#define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS mode" -#define USBD_SERIALNUMBER_HS_STRING "00000000050B" - -#define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode" -#define USBD_SERIALNUMBER_FS_STRING "00000000050C" - -#define USBD_CONFIGURATION_HS_STRING "VCP Config" -#define USBD_INTERFACE_HS_STRING "VCP Interface" - -#define USBD_CONFIGURATION_FS_STRING "VCP Config" -#define USBD_INTERFACE_FS_STRING "VCP Interface" -/** - * @} - */ - - -/** @defgroup USBD_DESC_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_DESC_Private_Variables - * @{ - */ - -USBD_DEVICE USR_desc = -{ - USBD_USR_DeviceDescriptor, - USBD_USR_LangIDStrDescriptor, - USBD_USR_ManufacturerStrDescriptor, - USBD_USR_ProductStrDescriptor, - USBD_USR_SerialStrDescriptor, - USBD_USR_ConfigStrDescriptor, - USBD_USR_InterfaceStrDescriptor, - -}; - -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -/* USB Standard Device Descriptor */ -__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END = - { - 0x12, /*bLength */ - USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/ - 0x00, /*bcdUSB */ - 0x02, - 0x00, /*bDeviceClass*/ - 0x00, /*bDeviceSubClass*/ - 0x00, /*bDeviceProtocol*/ - USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/ - LOBYTE(USBD_VID), /*idVendor*/ - HIBYTE(USBD_VID), /*idVendor*/ - LOBYTE(USBD_PID), /*idVendor*/ - HIBYTE(USBD_PID), /*idVendor*/ - 0x00, /*bcdDevice rel. 2.00*/ - 0x02, - USBD_IDX_MFC_STR, /*Index of manufacturer string*/ - USBD_IDX_PRODUCT_STR, /*Index of product string*/ - USBD_IDX_SERIAL_STR, /*Index of serial number string*/ - USBD_CFG_MAX_NUM /*bNumConfigurations*/ - } ; /* USB_DeviceDescriptor */ - -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -/* USB Standard Device Descriptor */ -__ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ - USB_LEN_DEV_QUALIFIER_DESC, - USB_DESC_TYPE_DEVICE_QUALIFIER, - 0x00, - 0x02, - 0x00, - 0x00, - 0x00, - 0x40, - 0x01, - 0x00, -}; - -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -/* USB Standard Device Descriptor */ -__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END = -{ - USB_SIZ_STRING_LANGID, - USB_DESC_TYPE_STRING, - LOBYTE(USBD_LANGID_STRING), - HIBYTE(USBD_LANGID_STRING), -}; -/** - * @} - */ - - -/** @defgroup USBD_DESC_Private_FunctionPrototypes - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_DESC_Private_Functions - * @{ - */ - -/** -* @brief USBD_USR_DeviceDescriptor -* return the device descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length) -{ - *length = sizeof(USBD_DeviceDesc); - return USBD_DeviceDesc; -} - -/** -* @brief USBD_USR_LangIDStrDescriptor -* return the LangID string descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length) -{ - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; -} - - -/** -* @brief USBD_USR_ProductStrDescriptor -* return the product string descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length) -{ - - - if(speed == 0) - { - USBD_GetString (USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString (USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** -* @brief USBD_USR_ManufacturerStrDescriptor -* return the manufacturer string descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length) -{ - USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; -} - -/** -* @brief USBD_USR_SerialStrDescriptor -* return the serial number string descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length) -{ - if(speed == USB_OTG_SPEED_HIGH) - { - USBD_GetString (USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString (USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** -* @brief USBD_USR_ConfigStrDescriptor -* return the configuration string descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length) -{ - if(speed == USB_OTG_SPEED_HIGH) - { - USBD_GetString (USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString (USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - - -/** -* @brief USBD_USR_InterfaceStrDescriptor -* return the interface string descriptor -* @param speed : current device speed -* @param length : pointer to data length variable -* @retval pointer to descriptor buffer -*/ -uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString (USBD_INTERFACE_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString (USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/bsp/src/SamplingBoard/usbd_desc.h b/bsp/src/SamplingBoard/usbd_desc.h deleted file mode 100644 --- a/bsp/src/SamplingBoard/usbd_desc.h +++ /dev/null @@ -1,120 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_desc.h - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief header file for the usbd_desc.c file - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ - -#ifndef __USB_DESC_H -#define __USB_DESC_H - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USB_DESC - * @brief general defines for the usb device library file - * @{ - */ - -/** @defgroup USB_DESC_Exported_Defines - * @{ - */ -#define USB_DEVICE_DESCRIPTOR_TYPE 0x01 -#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 -#define USB_STRING_DESCRIPTOR_TYPE 0x03 -#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 -#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 -#define USB_SIZ_DEVICE_DESC 18 -#define USB_SIZ_STRING_LANGID 4 - -/** - * @} - */ - - -/** @defgroup USBD_DESC_Exported_TypesDefinitions - * @{ - */ -/** - * @} - */ - - - -/** @defgroup USBD_DESC_Exported_Macros - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Variables - * @{ - */ -extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; -extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ]; -extern uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC]; -extern uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]; -extern uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID]; -extern USBD_DEVICE USR_desc; -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_FunctionsPrototype - * @{ - */ - - -uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length); -uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length); -uint8_t * USBD_USR_ManufacturerStrDescriptor ( uint8_t speed , uint16_t *length); -uint8_t * USBD_USR_ProductStrDescriptor ( uint8_t speed , uint16_t *length); -uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length); -uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length); -uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length); - -#ifdef USB_SUPPORT_USER_STRING_DESC -uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length); -#endif /* USB_SUPPORT_USER_STRING_DESC */ - -/** - * @} - */ - -#endif /* __USBD_DESC_H */ - -/** - * @} - */ - -/** -* @} -*/ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp/src/SamplingBoard/usbd_usr.c b/bsp/src/SamplingBoard/usbd_usr.c deleted file mode 100644 --- a/bsp/src/SamplingBoard/usbd_usr.c +++ /dev/null @@ -1,203 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_usr.c - * @author MCD Application Team - * @version V1.1.0 - * @date 19-March-2012 - * @brief This file includes the user application layer - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2012 STMicroelectronics

- * - * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.st.com/software_license_agreement_liberty_v2 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_usr.h" -#include "usbd_ioreq.h" -//#include "lcd_log.h" - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY -* @{ -*/ - -/** @defgroup USBD_USR -* @brief This file includes the user application layer -* @{ -*/ - -/** @defgroup USBD_USR_Private_TypesDefinitions -* @{ -*/ -/** -* @} -*/ - - -/** @defgroup USBD_USR_Private_Defines -* @{ -*/ -/** -* @} -*/ - - -/** @defgroup USBD_USR_Private_Macros -* @{ -*/ -/** -* @} -*/ - - -/** @defgroup USBD_USR_Private_Variables -* @{ -*/ - -USBD_Usr_cb_TypeDef USR_cb = -{ - USBD_USR_Init, - USBD_USR_DeviceReset, - USBD_USR_DeviceConfigured, - USBD_USR_DeviceSuspended, - USBD_USR_DeviceResumed, - - - USBD_USR_DeviceConnected, - USBD_USR_DeviceDisconnected, -}; - -/** -* @} -*/ - -/** @defgroup USBD_USR_Private_Constants -* @{ -*/ - -/** -* @} -*/ - - - -/** @defgroup USBD_USR_Private_FunctionPrototypes -* @{ -*/ -/** -* @} -*/ - - -/** @defgroup USBD_USR_Private_Functions -* @{ -*/ - -/** -* @brief USBD_USR_Init -* Displays the message on LCD for host lib initialization -* @param None -* @retval None -*/ -void USBD_USR_Init(void) -{ - /* Initialize LEDs */ - //STM_EVAL_LEDInit(LED1); - //STM_EVAL_LEDInit(LED2); - //STM_EVAL_LEDInit(LED3); - //STM_EVAL_LEDInit(LED4); - -} - -/** -* @brief USBD_USR_DeviceReset -* Displays the message on LCD on device Reset Event -* @param speed : device speed -* @retval None -*/ -void USBD_USR_DeviceReset(uint8_t speed ) -{ - -} - - -/** -* @brief USBD_USR_DeviceConfigured -* Displays the message on LCD on device configuration Event -* @param None -* @retval Staus -*/ -void USBD_USR_DeviceConfigured (void) -{ -} - -/** -* @brief USBD_USR_DeviceSuspended -* Displays the message on LCD on device suspend Event -* @param None -* @retval None -*/ -void USBD_USR_DeviceSuspended(void) -{ - - /* Users can do their application actions here for the USB-Reset */ -} - - -/** -* @brief USBD_USR_DeviceResumed -* Displays the message on LCD on device resume Event -* @param None -* @retval None -*/ -void USBD_USR_DeviceResumed(void) -{ - - /* Users can do their application actions here for the USB-Reset */ -} - - -/** -* @brief USBD_USR_DeviceConnected -* Displays the message on LCD on device connection Event -* @param None -* @retval Staus -*/ -void USBD_USR_DeviceConnected (void) -{ - -} - - -/** -* @brief USBD_USR_DeviceDisonnected -* Displays the message on LCD on device disconnection Event -* @param None -* @retval Staus -*/ -void USBD_USR_DeviceDisconnected (void) -{ - -} -/** -* @} -*/ - -/** -* @} -*/ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp/src/stm32f4/STM32F4Discovery/STM32F4Discovery.pro b/bsp/src/stm32f4/STM32F4Discovery/STM32F4Discovery.pro --- a/bsp/src/stm32f4/STM32F4Discovery/STM32F4Discovery.pro +++ b/bsp/src/stm32f4/STM32F4Discovery/STM32F4Discovery.pro @@ -11,7 +11,7 @@ SOURCES += bsp.c HEADERS += bsp.h -LIBS+= -lgpio -luart -li2c -lspi +LIBS+= -lgpio -luart -li2c -lspi -lpwm BSPFILE = bsp.pri diff --git a/include/PERIPHERALS/pwm.h b/include/PERIPHERALS/pwm.h new file mode 100644 --- /dev/null +++ b/include/PERIPHERALS/pwm.h @@ -0,0 +1,340 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2014, Kaveh Mohamadabadi +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Kaveh Mohamadabadi +-- Mail : kaveh.mohamadabadi@gmail.com +-------------------------------------------------------------------------------*/ + +/*! \file pwm.h +\brief PWM api. + +The pwm api gives you a standard way to drive any pwm pin on any processor. +With this api you will be able to open and configure your PWM module, define the +associated pins when applicable and set the duty cycle and frequency. Note that depending +on the target architecture you can have soft or hard PWM. + +A simple example to configure and use PWM4_CH4 on STM32 discovery for example. + \code + // lets open PWM4_CH4 + //config : + // -TIMER = TIMER4 (PWM4=TIMER4) + // -PWM channel = 4 + // -PWM output = PD15 + // -PWM frequency = 1kHz + // -PWM duty cycle = 40.5% + pwmopen(PWM4_CH4,PD15); + int error = pwmsetconfig(PWM4_CH4,1000,40.5); + //check that everything is ok + if(error!=-1) //=> no error + { + //to change duty cycle to 15% for example: + pwmsetdutycycle(PWM4_CH4,15.0); + //you can also change the frequency: + pwmsetfrequency(PWM4_CH4,455000); + } + + \endcode + +*/ +#ifndef PWM_H +#define PWM_H + +#include +#ifdef __cplusplus +extern "C" { +#endif +extern int pwmopen(int PWM,uint32_t pin); +extern int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle); +extern int pwmsetdutycycle(int PWM,float dutyCycle); +extern int pwmsetfrequency(int PWM,uint32_t freq); + +#ifdef __cplusplus +} +#endif + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + #define UARTPARITYMASK 0x3 + #define UARTBITSMASK 0xC + #define UARTSTOPBITSMASK 0x70 + +typedef enum +{ + channel1 = 0, + channel2 = 1, + channel3 = 2, + channel4 = 3, +}channelx; + +#define PWM1_CH1 ((0 << 8) + 0 ) +#define PWM1_CH2 ((0 << 8) + 1 ) +#define PWM1_CH3 ((0 << 8) + 2 ) +#define PWM1_CH4 ((0 << 8) + 3 ) +#define PWM1_CH5 ((0 << 8) + 4 ) +#define PWM1_CH6 ((0 << 8) + 5 ) +#define PWM1_CH7 ((0 << 8) + 6 ) +#define PWM1_CH8 ((0 << 8) + 7 ) +#define PWM1_CH9 ((0 << 8) + 8 ) +#define PWM1_CH10 ((0 << 8) + 9 ) +#define PWM1_CH11 ((0 << 8) + 10 ) +#define PWM1_CH12 ((0 << 8) + 11 ) +#define PWM1_CH13 ((0 << 8) + 12 ) +#define PWM1_CH14 ((0 << 8) + 13 ) +#define PWM1_CH15 ((0 << 8) + 14 ) +#define PWM1_CH16 ((0 << 8) + 15 ) +#define PWM2_CH1 ((1 << 8) + 0 ) +#define PWM2_CH2 ((1 << 8) + 1 ) +#define PWM2_CH3 ((1 << 8) + 2 ) +#define PWM2_CH4 ((1 << 8) + 3 ) +#define PWM2_CH5 ((1 << 8) + 4 ) +#define PWM2_CH6 ((1 << 8) + 5 ) +#define PWM2_CH7 ((1 << 8) + 6 ) +#define PWM2_CH8 ((1 << 8) + 7 ) +#define PWM2_CH9 ((1 << 8) + 8 ) +#define PWM2_CH10 ((1 << 8) + 9 ) +#define PWM2_CH11 ((1 << 8) + 10 ) +#define PWM2_CH12 ((1 << 8) + 11 ) +#define PWM2_CH13 ((1 << 8) + 12 ) +#define PWM2_CH14 ((1 << 8) + 13 ) +#define PWM2_CH15 ((1 << 8) + 14 ) +#define PWM2_CH16 ((1 << 8) + 15 ) +#define PWM3_CH1 ((2 << 8) + 0 ) +#define PWM3_CH2 ((2 << 8) + 1 ) +#define PWM3_CH3 ((2 << 8) + 2 ) +#define PWM3_CH4 ((2 << 8) + 3 ) +#define PWM3_CH5 ((2 << 8) + 4 ) +#define PWM3_CH6 ((2 << 8) + 5 ) +#define PWM3_CH7 ((2 << 8) + 6 ) +#define PWM3_CH8 ((2 << 8) + 7 ) +#define PWM3_CH9 ((2 << 8) + 8 ) +#define PWM3_CH10 ((2 << 8) + 9 ) +#define PWM3_CH11 ((2 << 8) + 10 ) +#define PWM3_CH12 ((2 << 8) + 11 ) +#define PWM3_CH13 ((2 << 8) + 12 ) +#define PWM3_CH14 ((2 << 8) + 13 ) +#define PWM3_CH15 ((2 << 8) + 14 ) +#define PWM3_CH16 ((2 << 8) + 15 ) +#define PWM4_CH1 ((3 << 8) + 0 ) +#define PWM4_CH2 ((3 << 8) + 1 ) +#define PWM4_CH3 ((3 << 8) + 2 ) +#define PWM4_CH4 ((3 << 8) + 3 ) +#define PWM4_CH5 ((3 << 8) + 4 ) +#define PWM4_CH6 ((3 << 8) + 5 ) +#define PWM4_CH7 ((3 << 8) + 6 ) +#define PWM4_CH8 ((3 << 8) + 7 ) +#define PWM4_CH9 ((3 << 8) + 8 ) +#define PWM4_CH10 ((3 << 8) + 9 ) +#define PWM4_CH11 ((3 << 8) + 10 ) +#define PWM4_CH12 ((3 << 8) + 11 ) +#define PWM4_CH13 ((3 << 8) + 12 ) +#define PWM4_CH14 ((3 << 8) + 13 ) +#define PWM4_CH15 ((3 << 8) + 14 ) +#define PWM4_CH16 ((3 << 8) + 15 ) +#define PWM5_CH1 ((4 << 8) + 0 ) +#define PWM5_CH2 ((4 << 8) + 1 ) +#define PWM5_CH3 ((4 << 8) + 2 ) +#define PWM5_CH4 ((4 << 8) + 3 ) +#define PWM5_CH5 ((4 << 8) + 4 ) +#define PWM5_CH6 ((4 << 8) + 5 ) +#define PWM5_CH7 ((4 << 8) + 6 ) +#define PWM5_CH8 ((4 << 8) + 7 ) +#define PWM5_CH9 ((4 << 8) + 8 ) +#define PWM5_CH10 ((4 << 8) + 9 ) +#define PWM5_CH11 ((4 << 8) + 10 ) +#define PWM5_CH12 ((4 << 8) + 11 ) +#define PWM5_CH13 ((4 << 8) + 12 ) +#define PWM5_CH14 ((4 << 8) + 13 ) +#define PWM5_CH15 ((4 << 8) + 14 ) +#define PWM5_CH16 ((4 << 8) + 15 ) +#define PWM6_CH1 ((5 << 8) + 0 ) +#define PWM6_CH2 ((5 << 8) + 1 ) +#define PWM6_CH3 ((5 << 8) + 2 ) +#define PWM6_CH4 ((5 << 8) + 3 ) +#define PWM6_CH5 ((5 << 8) + 4 ) +#define PWM6_CH6 ((5 << 8) + 5 ) +#define PWM6_CH7 ((5 << 8) + 6 ) +#define PWM6_CH8 ((5 << 8) + 7 ) +#define PWM6_CH9 ((5 << 8) + 8 ) +#define PWM6_CH10 ((5 << 8) + 9 ) +#define PWM6_CH11 ((5 << 8) + 10 ) +#define PWM6_CH12 ((5 << 8) + 11 ) +#define PWM6_CH13 ((5 << 8) + 12 ) +#define PWM6_CH14 ((5 << 8) + 13 ) +#define PWM6_CH15 ((5 << 8) + 14 ) +#define PWM6_CH16 ((5 << 8) + 15 ) +#define PWM7_CH1 ((6 << 8) + 0 ) +#define PWM7_CH2 ((6 << 8) + 1 ) +#define PWM7_CH3 ((6 << 8) + 2 ) +#define PWM7_CH4 ((6 << 8) + 3 ) +#define PWM7_CH5 ((6 << 8) + 4 ) +#define PWM7_CH6 ((6 << 8) + 5 ) +#define PWM7_CH7 ((6 << 8) + 6 ) +#define PWM7_CH8 ((6 << 8) + 7 ) +#define PWM7_CH9 ((6 << 8) + 8 ) +#define PWM7_CH10 ((6 << 8) + 9 ) +#define PWM7_CH11 ((6 << 8) + 10 ) +#define PWM7_CH12 ((6 << 8) + 11 ) +#define PWM7_CH13 ((6 << 8) + 12 ) +#define PWM7_CH14 ((6 << 8) + 13 ) +#define PWM7_CH15 ((6 << 8) + 14 ) +#define PWM7_CH16 ((6 << 8) + 15 ) +#define PWM8_CH1 ((7 << 8) + 0 ) +#define PWM8_CH2 ((7 << 8) + 1 ) +#define PWM8_CH3 ((7 << 8) + 2 ) +#define PWM8_CH4 ((7 << 8) + 3 ) +#define PWM8_CH5 ((7 << 8) + 4 ) +#define PWM8_CH6 ((7 << 8) + 5 ) +#define PWM8_CH7 ((7 << 8) + 6 ) +#define PWM8_CH8 ((7 << 8) + 7 ) +#define PWM8_CH9 ((7 << 8) + 8 ) +#define PWM8_CH10 ((7 << 8) + 9 ) +#define PWM8_CH11 ((7 << 8) + 10 ) +#define PWM8_CH12 ((7 << 8) + 11 ) +#define PWM8_CH13 ((7 << 8) + 12 ) +#define PWM8_CH14 ((7 << 8) + 13 ) +#define PWM8_CH15 ((7 << 8) + 14 ) +#define PWM8_CH16 ((7 << 8) + 15 ) +#define PWM9_CH1 ((8 << 8) + 0 ) +#define PWM9_CH2 ((8 << 8) + 1 ) +#define PWM9_CH3 ((8 << 8) + 2 ) +#define PWM9_CH4 ((8 << 8) + 3 ) +#define PWM9_CH5 ((8 << 8) + 4 ) +#define PWM9_CH6 ((8 << 8) + 5 ) +#define PWM9_CH7 ((8 << 8) + 6 ) +#define PWM9_CH8 ((8 << 8) + 7 ) +#define PWM9_CH9 ((8 << 8) + 8 ) +#define PWM9_CH10 ((8 << 8) + 9 ) +#define PWM9_CH11 ((8 << 8) + 10 ) +#define PWM9_CH12 ((8 << 8) + 11 ) +#define PWM9_CH13 ((8 << 8) + 12 ) +#define PWM9_CH14 ((8 << 8) + 13 ) +#define PWM9_CH15 ((8 << 8) + 14 ) +#define PWM9_CH16 ((8 << 8) + 15 ) +#define PWM10_CH1 ((9 << 8) + 0 ) +#define PWM10_CH2 ((9 << 8) + 1 ) +#define PWM10_CH3 ((9 << 8) + 2 ) +#define PWM10_CH4 ((9 << 8) + 3 ) +#define PWM10_CH5 ((9 << 8) + 4 ) +#define PWM10_CH6 ((9 << 8) + 5 ) +#define PWM10_CH7 ((9 << 8) + 6 ) +#define PWM10_CH8 ((9 << 8) + 7 ) +#define PWM10_CH9 ((9 << 8) + 8 ) +#define PWM10_CH10 ((9 << 8) + 9 ) +#define PWM10_CH11 ((9 << 8) + 10 ) +#define PWM10_CH12 ((9 << 8) + 11 ) +#define PWM10_CH13 ((9 << 8) + 12 ) +#define PWM10_CH14 ((9 << 8) + 13 ) +#define PWM10_CH15 ((9 << 8) + 14 ) +#define PWM10_CH16 ((9 << 8) + 15 ) +#define PWM11_CH1 ((10 << 8) + 0 ) +#define PWM11_CH2 ((10 << 8) + 1 ) +#define PWM11_CH3 ((10 << 8) + 2 ) +#define PWM11_CH4 ((10 << 8) + 3 ) +#define PWM11_CH5 ((10 << 8) + 4 ) +#define PWM11_CH6 ((10 << 8) + 5 ) +#define PWM11_CH7 ((10 << 8) + 6 ) +#define PWM11_CH8 ((10 << 8) + 7 ) +#define PWM11_CH9 ((10 << 8) + 8 ) +#define PWM11_CH10 ((10 << 8) + 9 ) +#define PWM11_CH11 ((10 << 8) + 10 ) +#define PWM11_CH12 ((10 << 8) + 11 ) +#define PWM11_CH13 ((10 << 8) + 12 ) +#define PWM11_CH14 ((10 << 8) + 13 ) +#define PWM11_CH15 ((10 << 8) + 14 ) +#define PWM11_CH16 ((10 << 8) + 15 ) +#define PWM12_CH1 ((11 << 8) + 0 ) +#define PWM12_CH2 ((11 << 8) + 1 ) +#define PWM12_CH3 ((11 << 8) + 2 ) +#define PWM12_CH4 ((11 << 8) + 3 ) +#define PWM12_CH5 ((11 << 8) + 4 ) +#define PWM12_CH6 ((11 << 8) + 5 ) +#define PWM12_CH7 ((11 << 8) + 6 ) +#define PWM12_CH8 ((11 << 8) + 7 ) +#define PWM12_CH9 ((11 << 8) + 8 ) +#define PWM12_CH10 ((11 << 8) + 9 ) +#define PWM12_CH11 ((11 << 8) + 10 ) +#define PWM12_CH12 ((11 << 8) + 11 ) +#define PWM12_CH13 ((11 << 8) + 12 ) +#define PWM12_CH14 ((11 << 8) + 13 ) +#define PWM12_CH15 ((11 << 8) + 14 ) +#define PWM12_CH16 ((11 << 8) + 15 ) +#define PWM13_CH1 ((12 << 8) + 0 ) +#define PWM13_CH2 ((12 << 8) + 1 ) +#define PWM13_CH3 ((12 << 8) + 2 ) +#define PWM13_CH4 ((12 << 8) + 3 ) +#define PWM13_CH5 ((12 << 8) + 4 ) +#define PWM13_CH6 ((12 << 8) + 5 ) +#define PWM13_CH7 ((12 << 8) + 6 ) +#define PWM13_CH8 ((12 << 8) + 7 ) +#define PWM13_CH9 ((12 << 8) + 8 ) +#define PWM13_CH10 ((12 << 8) + 9 ) +#define PWM13_CH11 ((12 << 8) + 10 ) +#define PWM13_CH12 ((12 << 8) + 11 ) +#define PWM13_CH13 ((12 << 8) + 12 ) +#define PWM13_CH14 ((12 << 8) + 13 ) +#define PWM13_CH15 ((12 << 8) + 14 ) +#define PWM13_CH16 ((12 << 8) + 15 ) +#define PWM14_CH1 ((13 << 8) + 0 ) +#define PWM14_CH2 ((13 << 8) + 1 ) +#define PWM14_CH3 ((13 << 8) + 2 ) +#define PWM14_CH4 ((13 << 8) + 3 ) +#define PWM14_CH5 ((13 << 8) + 4 ) +#define PWM14_CH6 ((13 << 8) + 5 ) +#define PWM14_CH7 ((13 << 8) + 6 ) +#define PWM14_CH8 ((13 << 8) + 7 ) +#define PWM14_CH9 ((13 << 8) + 8 ) +#define PWM14_CH10 ((13 << 8) + 9 ) +#define PWM14_CH11 ((13 << 8) + 10 ) +#define PWM14_CH12 ((13 << 8) + 11 ) +#define PWM14_CH13 ((13 << 8) + 12 ) +#define PWM14_CH14 ((13 << 8) + 13 ) +#define PWM14_CH15 ((13 << 8) + 14 ) +#define PWM14_CH16 ((13 << 8) + 15 ) +#define PWM15_CH1 ((14 << 8) + 0 ) +#define PWM15_CH2 ((14 << 8) + 1 ) +#define PWM15_CH3 ((14 << 8) + 2 ) +#define PWM15_CH4 ((14 << 8) + 3 ) +#define PWM15_CH5 ((14 << 8) + 4 ) +#define PWM15_CH6 ((14 << 8) + 5 ) +#define PWM15_CH7 ((14 << 8) + 6 ) +#define PWM15_CH8 ((14 << 8) + 7 ) +#define PWM15_CH9 ((14 << 8) + 8 ) +#define PWM15_CH10 ((14 << 8) + 9 ) +#define PWM15_CH11 ((14 << 8) + 10 ) +#define PWM15_CH12 ((14 << 8) + 11 ) +#define PWM15_CH13 ((14 << 8) + 12 ) +#define PWM15_CH14 ((14 << 8) + 13 ) +#define PWM15_CH15 ((14 << 8) + 14 ) +#define PWM15_CH16 ((14 << 8) + 15 ) +#define PWM16_CH1 ((15 << 8) + 0 ) +#define PWM16_CH2 ((15 << 8) + 1 ) +#define PWM16_CH3 ((15 << 8) + 2 ) +#define PWM16_CH4 ((15 << 8) + 3 ) +#define PWM16_CH5 ((15 << 8) + 4 ) +#define PWM16_CH6 ((15 << 8) + 5 ) +#define PWM16_CH7 ((15 << 8) + 6 ) +#define PWM16_CH8 ((15 << 8) + 7 ) +#define PWM16_CH9 ((15 << 8) + 8 ) +#define PWM16_CH10 ((15 << 8) + 9 ) +#define PWM16_CH11 ((15 << 8) + 10 ) +#define PWM16_CH12 ((15 << 8) + 11 ) +#define PWM16_CH13 ((15 << 8) + 12 ) +#define PWM16_CH14 ((15 << 8) + 13 ) +#define PWM16_CH15 ((15 << 8) + 14 ) +#define PWM16_CH16 ((15 << 8) + 15 ) +#endif +#endif // PWM_H diff --git a/src/stm32f4/PWM/pwm.c b/src/stm32f4/PWM/pwm.c new file mode 100644 --- /dev/null +++ b/src/stm32f4/PWM/pwm.c @@ -0,0 +1,222 @@ +#include +#include +#include +#include +#include +#include +#include +const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, + TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; + +#define timer1 0 +#define timer2 1 +#define timer3 2 +#define timer4 3 +#define timer5 4 +#define timer6 5 +#define timer7 6 +#define timer8 7 +#define timer9 8 +#define timer10 9 +#define timer11 10 +#define timer12 11 +#define timer13 12 +#define timer14 13 +#define timer15 14 +#define timer16 15 + +#define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8) + +int pwmopen(int PWM,uint32_t pin) +{ +#define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) +#define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) + int timer = PWMGETTIMNUMBER(PWM); + gpio_t PWMOUT; + PWMOUT = gpioopen(pin); + PWMOUT |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; + gpiosetconfig(&PWMOUT); + uint8_t GPIO_AF = -1; + if(timer==timer1 || timer==timer2)GPIO_AF=1; + if(timer==timer3 || timer==timer4 || timer==timer5)GPIO_AF=2; + if(timer==timer8 || timer==timer9 || timer==timer10 || timer==timer11)GPIO_AF=3; + if(timer==timer12 || timer==timer13 || timer==timer14)GPIO_AF=9; + + if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); + if(timer>=timer12 && timer <= timer14)RCC_APB1PeriphClockCmd((1<<(timer-5)), ENABLE); + if(timer==timer1)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); + if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); + if(timer==timer9)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE); + if(timer==timer10)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE); + if(timer==timer11)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE); + + if(GPIO_AF!=-1)GPIO_PinAFConfig(GPIOGETPORT(PWMOUT), (uint8_t)(PWMOUT & 0xF), GPIO_AF); + + return 0; +} + +int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle) +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + TIM_OCInitTypeDef TIM_OCInitStructure; + if(PWM==-1) return -1; + int timer = PWMGETTIMNUMBER(PWM); + TIM_TypeDef* tim = _timer_dev_table[timer]; + uint32_t timfreq = getCpuFreq()/2; + uint32_t period = timfreq/freq - 1; + uint16_t PrescalerValue=0; + + while (period>=0x0FFFF) + { + PrescalerValue++; + timfreq = getCpuFreq()/(2*(PrescalerValue+1)); + period = (timfreq/freq) - 1; + } + + TIM_TimeBaseStructure.TIM_Period = period; + TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); + + TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; + TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; + TIM_OCInitStructure.TIM_Pulse = (uint32_t)((period * dutyCycle)/100); + TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; + + switch (PWM&0x0FF) { + case 0: + TIM_OC1Init(tim, &TIM_OCInitStructure); + TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable); + TIM_ARRPreloadConfig(tim, ENABLE); + TIM_Cmd(tim, ENABLE); + break; + case 1: + TIM_OC2Init(tim, &TIM_OCInitStructure); + TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable); + TIM_ARRPreloadConfig(tim, ENABLE); + TIM_Cmd(tim, ENABLE); + break; + case 2: + TIM_OC3Init(tim, &TIM_OCInitStructure); + TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable); + TIM_ARRPreloadConfig(tim, ENABLE); + TIM_Cmd(tim, ENABLE); + break; + case 3: + TIM_OC4Init(tim, &TIM_OCInitStructure); + TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable); + TIM_ARRPreloadConfig(tim, ENABLE); + TIM_Cmd(tim, ENABLE); + break; + default: + return -1; + break; + } + return 0; +} + + + + + +int pwmsetdutycycle(int PWM,float dutyCycle) +{ + if(PWM==-1) return -1; + int timer = PWMGETTIMNUMBER(PWM); + TIM_TypeDef* tim = _timer_dev_table[timer]; + switch (PWM&0x0FF) { + case 0: + tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); + break; + case 1: + tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); + break; + case 2: + tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); + break; + case 3: + tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); + break; + default: + return -1; + break; + } + return 0; +} + +float pwmgetdutycycle(int PWM) +{ + if(PWM==-1) return -1; + int timer = PWMGETTIMNUMBER(PWM); + TIM_TypeDef* tim = _timer_dev_table[timer]; + switch (PWM&0x0FF) { + case 0: + return (float)((tim->CCR1*100)/tim->ARR); + break; + case 1: + return (float)((tim->CCR2*100)/tim->ARR); + break; + case 2: + return (float)((tim->CCR3*100)/tim->ARR); + break; + case 3: + return (float)((tim->CCR4*100)/tim->ARR); + break; + default: + return -1; + break; + } + return 0; +} + + +int pwmsetfrequency(int PWM,uint32_t freq) +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + if(PWM==-1) return -1; + int timer = PWMGETTIMNUMBER(PWM); + TIM_TypeDef* tim = _timer_dev_table[timer]; + uint32_t timfreq = getCpuFreq()/2; + uint32_t period = timfreq/freq - 1; + uint16_t PrescalerValue=0; + float dutyCycle = pwmgetdutycycle(PWM); + while (period>=0x0FFFF) + { + PrescalerValue++; + timfreq = getCpuFreq()/(2*(PrescalerValue+1)); + period = (timfreq/freq) - 1; + } + + TIM_TimeBaseStructure.TIM_Period = period; + TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; + TIM_TimeBaseStructure.TIM_ClockDivision = 0; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); + + switch (PWM&0x0FF) { + case 0: + tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); + TIM_ARRPreloadConfig(tim, ENABLE); + break; + case 1: + tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); + TIM_ARRPreloadConfig(tim, ENABLE); + break; + case 2: + tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); + TIM_ARRPreloadConfig(tim, ENABLE); + break; + case 3: + tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); + TIM_ARRPreloadConfig(tim, ENABLE); + break; + default: + return -1; + break; + } + return 0; +} + + + diff --git a/src/stm32f4/PWM/pwm.pro b/src/stm32f4/PWM/pwm.pro new file mode 100644 --- /dev/null +++ b/src/stm32f4/PWM/pwm.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += libuc2lib + +SOURCES += pwm.c + + +UCMODEL=stm32f4 + +HEADERS += \ + ../../../include/PERIPHERALS/pwm.h + + + diff --git a/src/stm32f4/stm32f4.pro b/src/stm32f4/stm32f4.pro --- a/src/stm32f4/stm32f4.pro +++ b/src/stm32f4/stm32f4.pro @@ -7,7 +7,9 @@ SUBDIRS = CORE/core.pro \ UART/uart.pro \ SPI/spi.pro \ I2C/i2c.pro \ + PWM/pwm.pro \ SDCARD-SDIO/sdcard-sdio.pro +