/**
******************************************************************************
* @file FW_upgrade/src/main.c
* @author MCD Application Team
* @version V1.0.0
* @date 28-October-2011
* @brief IAP thru USB host main file
******************************************************************************
* @attention
*
* 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.
*
*
© COPYRIGHT 2011 STMicroelectronics
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbh_core.h"
#include "usbh_usr.h"
#include "usbh_msc_core.h"
#include "flash_if.h"
#include "rbt.h"
USB_OTG_CORE_HANDLE USB_OTG_Core;
USBH_HOST USB_Host;
pFunction Jump_To_Application;
uint32_t JumpAddress;
/** @addtogroup STM32F4-Discovery_FW_Upgrade
* @{
*/
/* External variables --------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern struct Usart com[6];
extern uint8_t NbrOfDataToTransfer;
extern uint8_t NbrOfDataToRead;
//uint8_t prova[5]; // array for unpack example
//extern __IO uint8_t TxCounter;
//extern __IO uint16_t RxCounter;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
__IO uint16_t CCR1_Val = 40961;
uint16_t PrescalerValue = 0;
void NVIC_Config(int ID);
void TIM_Config(void);
void Int_Config(void);
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief main
* Main routine for IAP application
* @param None
* @retval int
*/int main(void)
{
/* LEDs configuration ------------------------------------------------------*/
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_LEDInit(LED5);
STM_EVAL_LEDInit(LED6);
TIM_Config();
Int_Config();
usart_config() ;
NVIC_Config(3);
NVIC_Config(4);
Init(3);
Init(4);
Init_interrupt(3);
Init_interrupt(4);
while (1)
{
}
}
void TIM_Config(void){
/* -----------------------------------------------------------------------
TIM4 Configuration: Output Compare Timing Mode:
In this example TIM4 input clock (TIM4CLK) is set to 2 * APB1 clock (PCLK1),
since APB1 prescaler is different from 1.
TIM4CLK = 2 * PCLK1
PCLK1 = HCLK / 4
=> TIM4CLK = HCLK / 2 = SystemCoreClock /2
To get TIM4 counter clock at 6 MHz, the prescaler is computed as follows:
Prescaler = (TIM4CLK / TIM4 counter clock) - 1
Prescaler = ((SystemCoreClock /2) /6 MHz) - 1
CC1 update rate = TIM4 counter clock / CCR1_Val = 146.48 Hz
==> Toggling frequency = 73.24 Hz
CC2 update rate = TIM4 counter clock / CCR2_Val = 219.7 Hz
==> Toggling frequency = 109.8 Hz
CC3 update rate = TIM4 counter clock / CCR3_Val = 439.4 Hz
==> Toggling frequency = 219.7 Hz
CC4 update rate = TIM4 counter clock / CCR4_Val = 878.9 Hz
==> Toggling frequency = 439.4 Hz
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
function to update SystemCoreClock variable value. Otherwise, any configuration
based on this variable will be incorrect.
----------------------------------------------------------------------- */
/* Compute the prescaler value */
//(uint16_t) ((SystemCoreClock / 2) / 6000000) - 1;
PrescalerValue = (uint16_t) (20000);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Prescaler configuration */
TIM_PrescalerConfig(TIM4, PrescalerValue, TIM_PSCReloadMode_Immediate);
/* Output Compare Timing Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable);
/* Output Compare Timing Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
}
void Int_Config(void){
NVIC_InitTypeDef NVIC_InitStr;
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* Enable the TIM4 gloabal Interrupt */
NVIC_InitStr.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStr.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStr.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStr.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStr);
}
/**
* @brief Configures the nested vectored interrupt controller.
* @param None
* @retval None
*/
void NVIC_Config(int ID)
{
/* Enable the USARTx Interrupt */
com[ID-1].NVIC_InitStructure.NVIC_IRQChannel =com[ID-1].USARTx_IRQn;
com[ID-1].NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
com[ID-1].NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
com[ID-1].NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&com[ID-1].NVIC_InitStructure);
}
#ifdef USE_FULL_ASSERT
/**
* @brief assert_failed
* Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param File: pointer to the source file name
* @param Line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/