diff --git a/src/platform/stm32/FWLib/stm32f10x_conf.h b/src/platform/stm32/FWLib/stm32f10x_conf.h deleted file mode 100755 index ec0f5e38..00000000 --- a/src/platform/stm32/FWLib/stm32f10x_conf.h +++ /dev/null @@ -1,174 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : stm32f10x_conf.h -* Author : MCD Application Team -* Version : V2.0.3 -* Date : 09/22/2008 -* Description : Library configuration file. -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F10x_CONF_H -#define __STM32F10x_CONF_H - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f10x_type.h" - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Uncomment the line below to compile the library in DEBUG mode, this will expanse - the "assert_param" macro in the firmware library code (see "Exported macro" - section below) */ -/* #define DEBUG 1*/ - -/* Comment the line below to disable the specific peripheral inclusion */ -/************************************* ADC ************************************/ -#define _ADC -#define _ADC1 -#define _ADC2 -#define _ADC3 - -/************************************* BKP ************************************/ -#define _BKP - -/************************************* CAN ************************************/ -#define _CAN - -/************************************* CRC ************************************/ -#define _CRC - -/************************************* DAC ************************************/ -#define _DAC - -/************************************* DBGMCU *********************************/ -#define _DBGMCU - -/************************************* DMA ************************************/ -#define _DMA -#define _DMA1_Channel1 -#define _DMA1_Channel2 -#define _DMA1_Channel3 -#define _DMA1_Channel4 -#define _DMA1_Channel5 -#define _DMA1_Channel6 -#define _DMA1_Channel7 -#define _DMA2_Channel1 -#define _DMA2_Channel2 -#define _DMA2_Channel3 -#define _DMA2_Channel4 -#define _DMA2_Channel5 - -/************************************* EXTI ***********************************/ -#define _EXTI - -/************************************* FLASH and Option Bytes *****************/ -#define _FLASH -/* Uncomment the line below to enable FLASH program/erase/protections functions, - otherwise only FLASH configuration (latency, prefetch, half cycle) functions - are enabled */ -/* #define _FLASH_PROG */ - -/************************************* FSMC ***********************************/ -#define _FSMC - -/************************************* GPIO ***********************************/ -#define _GPIO -#define _GPIOA -#define _GPIOB -#define _GPIOC -#define _GPIOD -#define _GPIOE -#define _GPIOF -#define _GPIOG -#define _AFIO - -/************************************* I2C ************************************/ -#define _I2C -#define _I2C1 -#define _I2C2 - -/************************************* IWDG ***********************************/ -#define _IWDG - -/************************************* NVIC ***********************************/ -#define _NVIC - -/************************************* PWR ************************************/ -#define _PWR - -/************************************* RCC ************************************/ -#define _RCC - -/************************************* RTC ************************************/ -#define _RTC - -/************************************* SDIO ***********************************/ -#define _SDIO - -/************************************* SPI ************************************/ -#define _SPI -#define _SPI1 -#define _SPI2 -#define _SPI3 - -/************************************* SysTick ********************************/ -#define _SysTick - -/************************************* TIM ************************************/ -#define _TIM -#define _TIM1 -#define _TIM2 -#define _TIM3 -#define _TIM4 -#define _TIM5 -#define _TIM6 -#define _TIM7 -#define _TIM8 - -/************************************* USART **********************************/ -#define _USART -#define _USART1 -#define _USART2 -#define _USART3 -#define _UART4 -#define _UART5 - -/************************************* WWDG ***********************************/ -#define _WWDG - -/* In the following line adjust the value of External High Speed oscillator (HSE) - used in your application */ -#define HSE_Value ((u32)8000000) /* Value of the External oscillator in Hz*/ - -/* In the following line adjust the External High Speed oscillator (HSE) Startup - Timeout value */ -#define HSEStartUp_TimeOut ((u16)0x0500) /* Time out for HSE start up */ - -/* Exported macro ------------------------------------------------------------*/ -#ifdef DEBUG -/******************************************************************************* -* Macro Name : assert_param -* Description : The assert_param macro is used for function's parameters check. -* It is used only if the library is compiled in DEBUG mode. -* Input : - expr: If expr is false, it calls assert_failed function -* which reports the name of the source file and the source -* line number of the call that failed. -* If expr is true, it returns no value. -* Return : None -*******************************************************************************/ - #define assert_param(expr) ((expr) ? (void)0 : assert_failed((u8 *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(u8* file, u32 line); -#else - #define assert_param(expr) ((void)0) -#endif /* DEBUG */ - -#endif /* __STM32F10x_CONF_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/src/platform/stm32/platform.c b/src/platform/stm32/platform.c index 0538f5ef..21e47a96 100755 --- a/src/platform/stm32/platform.c +++ b/src/platform/stm32/platform.c @@ -95,8 +95,10 @@ int platform_init() static void RCC_Configuration(void) { SystemInit(); + + RCC_PCLK1Config(RCC_HCLK_Div2); - RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); + //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); } // **************************************************************************** @@ -688,10 +690,10 @@ static void timers_init() RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM5, ENABLE ); - RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM8, ENABLE ); + // Configure timers - for( i = 0; i < NUM_TIMER; i ++ ) + for( i = 0; i < NUM_TIMER - 1; i ++ ) { TIM_TimeBaseStructure.TIM_Period = 0xFFFF; TIM_TimeBaseStructure.TIM_Prescaler = TIM_GET_BASE_CLK( i ) / TIM_STARTUP_CLOCK; @@ -789,6 +791,7 @@ static const u16 pwm_gpio_pins[] = { GPIO_Pin_6, GPIO_Pin_7, GPIO_Pin_8, GPIO_Pi static void pwms_init() { + RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM8, ENABLE ); // } @@ -810,7 +813,7 @@ static u32 platform_pwm_set_clock( u32 clock ) TIM_TimeBaseStructure.TIM_Period = 999; //(TIM_GET_BASE_CLK( PWM_TIMER_ID ) / clock) - 1; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; - TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000; TIM_TimeBaseInit( ptimer, &TIM_TimeBaseStructure ); @@ -821,18 +824,17 @@ u32 platform_pwm_setup( unsigned id, u32 frequency, unsigned duty ) { TIM_OCInitTypeDef TIM_OCInitStructure; TIM_TypeDef* ptimer = timer[ PWM_TIMER_ID ]; - TIM_BDTRInitTypeDef TIM_BDTRInitStructure; u32 clock; TIM_Cmd(ptimer, DISABLE); - - clock = platform_pwm_set_clock( frequency ); - - TIM_Cmd( ptimer, ENABLE ); + TIM_SetCounter( ptimer, 0 ); // Set up PIO for output platform_pio_op( 2, pwm_gpio_pins[ id ], PLATFORM_IO_PIN_DIR_OUTPUT ); + clock = platform_pwm_set_clock( frequency ); + TIM_ARRPreloadConfig( ptimer, ENABLE ); + /* PWM Mode configuration */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; @@ -846,34 +848,28 @@ u32 platform_pwm_setup( unsigned id, u32 frequency, unsigned duty ) case 0: TIM_OC1Init( ptimer, &TIM_OCInitStructure ); TIM_OC1PreloadConfig( ptimer, TIM_OCPreload_Enable ); - clock = 0; break; case 1: TIM_OC2Init( ptimer, &TIM_OCInitStructure ); TIM_OC2PreloadConfig( ptimer, TIM_OCPreload_Enable ); - clock = 1; break; case 2: TIM_OC3Init( ptimer, &TIM_OCInitStructure ); TIM_OC3PreloadConfig( ptimer, TIM_OCPreload_Enable ); - clock = 2; break; case 3: TIM_OC4Init( ptimer, &TIM_OCInitStructure ); TIM_OC4PreloadConfig( ptimer, TIM_OCPreload_Enable ) ; - clock = 3; break; default: - return 4; + return 0; } - TIM_ARRPreloadConfig( ptimer, ENABLE ); - - TIM_SelectOCxM( ptimer, TIM_Channel_1, TIM_OCMode_PWM1 ); TIM_CtrlPWMOutputs(ptimer, ENABLE); - ptimer->EGR |= TIM_EventSource_Update; - + + TIM_Cmd( ptimer, ENABLE ); + return clock; }