Forráskód Böngészése

2.1.5_20200904 TC033001A-V1
1、指拨信号增加滤波延时,解决松开指拨时电机撞击的声音;
2、解决踏频模式不计算续航的问题;
3、增加变量Firmware_Special,用于存储程序版本特性,并通过CAN发出;
4、增加踏频模式的处理,踏频按照低于50,大于50低于90,大于90分开处理;
5、指拨模式调整各个档位的加速曲线;
6、低压保护增加当电池通信正常时,根据RC低于200mAh的警告,延时10s;
7、踏频模式按照力矩给定;
8、调整SMART档位的助力参数;
9、版本号:V2.1.5_20200904 TC033001A-V1

dail.zhou 4 éve
szülő
commit
43afd4b123

+ 1 - 1
Core/Src/adc.c

@@ -488,7 +488,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
 	//更新指拨
 	Temp_32 = ADC1_Result[ADC1_RANK_GAS] - GasSensor_OffSet;
 	Temp_32 = (Temp_32 <= 0) ? 0 : Temp_32;
-	GasSensorFltSum += ((Temp_32 << 10) - GasSensorFltSum) >> 8;  //滤波延时0.33*256=85.3ms
+	GasSensorFltSum += ((Temp_32 << 10) - GasSensorFltSum) >> 10;  //滤波延时0.33 * 1024 = 338ms
 	ADC_SensorData.GasSensor = GasSensorFltSum >> 10;
 	
 	//更新MCU温度

+ 8 - 1
Core/Src/main.c

@@ -272,7 +272,14 @@ int main(void)
 					RD_RemainDis_Init(MC_ConfigParam1.WheelSize + MC_ConfigParam1.WheelSizeAdj, IsComOK_BMS.IsOK_Flag, MC_RunInfo.BusVoltage / 10, MC_MotorParam.Rate_Voltage, BMS_RunInfo.RC);	
 				}
 				RD_CalculateRemainDis(MC_SpeedSensorData.WheelTurnCount, BMS_RunInfo.RC, BMS_RunInfo.SOC, MC_RunInfo.BusCurrent);
-				RD_SaveAndUpdateInfo(MC_ControlCode.GearSt, MC_CalParam.AssistRunMode);
+				if((MC_ControlCode.GearSt & 0xF0) == 0x10)//踏频模式
+				{
+				  RD_SaveAndUpdateInfo((MC_GearSt_Struct_t)((uint8_t)MC_ControlCode.GearSt & 0x0F), MC_CalParam.AssistRunMode);
+				}
+				else//力矩模式
+				{
+				  RD_SaveAndUpdateInfo(MC_ControlCode.GearSt, MC_CalParam.AssistRunMode);
+				}
 			}
 			
 			//更新电机运行信息

+ 0 - 1424
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c

@@ -1,1424 +0,0 @@
-/**
-  ******************************************************************************
-  * @file    stm32f1xx_hal_pcd.c
-  * @author  MCD Application Team
-  * @brief   PCD HAL module driver.
-  *          This file provides firmware functions to manage the following 
-  *          functionalities of the USB Peripheral Controller:
-  *           + Initialization and de-initialization functions
-  *           + IO operation functions
-  *           + Peripheral Control functions 
-  *           + Peripheral State functions
-  *
-  @verbatim
-  ==============================================================================
-                    ##### How to use this driver #####
-  ==============================================================================
-    [..]
-      The PCD HAL driver can be used as follows:
-
-     (#) Declare a PCD_HandleTypeDef handle structure, for example:
-         PCD_HandleTypeDef  hpcd;
-
-     (#) Fill parameters of Init structure in HCD handle
-
-     (#) Call HAL_PCD_Init() API to initialize the HCD peripheral (Core, Device core, ...)
-
-     (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
-         (##) Enable the PCD/USB Low Level interface clock using the following macro
-              (+++) __HAL_RCC_USB_CLK_ENABLE(); For USB Device FS peripheral available
-                    on STM32F102xx and STM32F103xx devices
-              (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); For USB OTG FS peripheral available
-                    on STM32F105xx and STM32F107xx devices 
-
-         (##) Initialize the related GPIO clocks
-         (##) Configure PCD pin-out
-         (##) Configure PCD NVIC interrupt
-
-     (#)Associate the Upper USB device stack to the HAL PCD Driver:
-         (##) hpcd.pData = pdev;
-
-     (#)Enable HCD transmission and reception:
-         (##) HAL_PCD_Start();
-
-  @endverbatim
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f1xx_hal.h"
-
-/** @addtogroup STM32F1xx_HAL_Driver
-  * @{
-  */
-
-
-
-#ifdef HAL_PCD_MODULE_ENABLED
-
-#if defined(STM32F102x6) || defined(STM32F102xB) || \
-    defined(STM32F103x6) || defined(STM32F103xB) || \
-    defined(STM32F103xE) || defined(STM32F103xG) || \
-    defined(STM32F105xC) || defined(STM32F107xC)
-
-/** @defgroup PCD PCD
-  * @brief PCD HAL module driver
-  * @{
-  */
-
-/* Private types -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private constants ---------------------------------------------------------*/
-/* Private macros ------------------------------------------------------------*/
-/** @defgroup PCD_Private_Macros PCD Private Macros
-  * @{
-  */ 
-#define PCD_MIN(a, b)  (((a) < (b)) ? (a) : (b))
-#define PCD_MAX(a, b)  (((a) > (b)) ? (a) : (b))
-/**
-  * @}
-  */
-
-/* Private functions ---------------------------------------------------------*/
-/** @defgroup PCD_Private_Functions PCD Private Functions
-  * @{
-  */
-#if defined (USB_OTG_FS)
-static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum);
-#endif /* USB_OTG_FS */
-
-#if defined (USB)
-static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd);
-#endif /* USB */
-/**
-  * @}
-  */
-
-/* Exported functions --------------------------------------------------------*/
-/** @defgroup PCD_Exported_Functions PCD Exported Functions
-  * @{
-  */
-
-/** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions 
- *  @brief    Initialization and Configuration functions 
- *
-@verbatim
- ===============================================================================
-            ##### Initialization and de-initialization functions #####
- ===============================================================================
-    [..]  This section provides functions allowing to:
- 
-@endverbatim
-  * @{
-  */
-
-/**
-  * @brief  Initializes the PCD according to the specified
-  *         parameters in the PCD_InitTypeDef and create the associated handle.
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
-{
-  uint32_t index = 0U;
-  
-  /* Check the PCD handle allocation */
-  if(hpcd == NULL)
-  {
-    return HAL_ERROR;
-  }
-  
-  /* Check the parameters */
-  assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
-
-  if(hpcd->State == HAL_PCD_STATE_RESET)
-  {  
-    /* Allocate lock resource and initialize it */
-    hpcd->Lock = HAL_UNLOCKED;
-
-    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
-    HAL_PCD_MspInit(hpcd);
-  }
-  
-  hpcd->State = HAL_PCD_STATE_BUSY;
-  
-  /* Disable the Interrupts */
-  __HAL_PCD_DISABLE(hpcd);
-
-  /*Init the Core (common init.) */
-  USB_CoreInit(hpcd->Instance, hpcd->Init);
- 
-  /* Force Device Mode*/
-  USB_SetCurrentMode(hpcd->Instance , USB_DEVICE_MODE);
- 
-  /* Init endpoints structures */
-  for (index = 0U; index < 15U ; index++)
-  {
-    /* Init ep structure */
-    hpcd->IN_ep[index].is_in = 1U;
-    hpcd->IN_ep[index].num = index;
-    hpcd->IN_ep[index].tx_fifo_num = index;
-    /* Control until ep is actvated */
-    hpcd->IN_ep[index].type = EP_TYPE_CTRL;
-    hpcd->IN_ep[index].maxpacket =  0U;
-    hpcd->IN_ep[index].xfer_buff = 0U;
-    hpcd->IN_ep[index].xfer_len = 0U;
-  }
- 
-  for (index = 0U; index < 15U ; index++)
-  {
-    hpcd->OUT_ep[index].is_in = 0U;
-    hpcd->OUT_ep[index].num = index;
-    hpcd->IN_ep[index].tx_fifo_num = index;
-    /* Control until ep is activated */
-    hpcd->OUT_ep[index].type = EP_TYPE_CTRL;
-    hpcd->OUT_ep[index].maxpacket = 0U;
-    hpcd->OUT_ep[index].xfer_buff = 0U;
-    hpcd->OUT_ep[index].xfer_len = 0U;
-  }
-  
-  /* Init Device */
-  USB_DevInit(hpcd->Instance, hpcd->Init);
-  
-  hpcd->USB_Address = 0U;
-  hpcd->State= HAL_PCD_STATE_READY;
-  
-  USB_DevDisconnect (hpcd->Instance);  
-  return HAL_OK;
-}
-
-/**
-  * @brief  DeInitializes the PCD peripheral 
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
-{
-  /* Check the PCD handle allocation */
-  if(hpcd == NULL)
-  {
-    return HAL_ERROR;
-  }
-
-  hpcd->State = HAL_PCD_STATE_BUSY;
-  
-  /* Stop Device */
-  HAL_PCD_Stop(hpcd);
-  
-  /* DeInit the low level hardware */
-  HAL_PCD_MspDeInit(hpcd);
-  
-  hpcd->State = HAL_PCD_STATE_RESET; 
-  
-  return HAL_OK;
-}
-
-/**
-  * @brief  Initializes the PCD MSP.
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
-__weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_MspInit could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  DeInitializes PCD MSP.
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
-__weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_MspDeInit could be implemented in the user file
-   */
-}
-
-/**
-  * @}
-  */
-
-/** @defgroup PCD_Exported_Functions_Group2 IO operation functions 
- *  @brief   Data transfers functions 
- *
-@verbatim
- ===============================================================================
-                      ##### IO operation functions #####
- ===============================================================================
-    [..]
-    This subsection provides a set of functions allowing to manage the PCD data 
-    transfers.
-
-@endverbatim
-  * @{
-  */
-
-/**
-  * @brief  Start The USB Device.
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
-{
-  __HAL_LOCK(hpcd);
-  HAL_PCDEx_SetConnectionState (hpcd, 1);
-  USB_DevConnect (hpcd->Instance);
-  __HAL_PCD_ENABLE(hpcd);
-  __HAL_UNLOCK(hpcd);
-  return HAL_OK;
-}
-
-/**
-  * @brief  Stop The USB Device.
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
-{
-  __HAL_LOCK(hpcd);
-  __HAL_PCD_DISABLE(hpcd);
-  USB_StopDevice(hpcd->Instance);
-  USB_DevDisconnect (hpcd->Instance);
-  __HAL_UNLOCK(hpcd);
-  return HAL_OK;
-}
-
-#if defined (USB_OTG_FS)
-/**
-  * @brief  This function handles PCD interrupt request.
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
-{
-  USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
-  uint32_t index = 0U, ep_intr = 0U, epint = 0U, epnum = 0U;
-  uint32_t fifoemptymsk = 0U, temp = 0U;
-  USB_OTG_EPTypeDef *ep = NULL;
-  
-  /* ensure that we are in device mode */
-  if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE)
-  {
-    /* avoid spurious interrupt */
-    if(__HAL_PCD_IS_INVALID_INTERRUPT(hpcd))
-    {
-      return;
-    }
-    
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS))
-    {
-     /* incorrect mode, acknowledge the interrupt */
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS);
-    }
-    
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT))
-    {
-      epnum = 0U;
-      
-      /* Read in the device interrupt bits */
-      ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance);
-      
-      while ( ep_intr )
-      {
-        if (ep_intr & 0x1U)
-        {
-          epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, epnum);
-          
-          if(( epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC)
-          {
-            CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC);
-            
-            HAL_PCD_DataOutStageCallback(hpcd, epnum);
-          }
-          
-          if(( epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP)
-          {
-            /* Inform the upper layer that a setup packet is available */
-            HAL_PCD_SetupStageCallback(hpcd);
-            CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP);
-          }
-          
-          if(( epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS)
-          {
-            CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS);
-          }
-        }
-        epnum++;
-        ep_intr >>= 1U;
-      }
-    }
-    
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT))
-    {
-      /* Read in the device interrupt bits */
-      ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance);
-      
-      epnum = 0U;
-      
-      while ( ep_intr )
-      {
-        if (ep_intr & 0x1U) /* In ITR */
-        {
-          epint = USB_ReadDevInEPInterrupt(hpcd->Instance, epnum);
-
-          if(( epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC)
-          {
-            fifoemptymsk = 0x1U << epnum;
-            USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk;
-            
-            CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC);
-            
-            HAL_PCD_DataInStageCallback(hpcd, epnum);
-          }
-          if(( epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC)
-          {
-            CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC);
-          }
-          if(( epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE)
-          {
-            CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE);
-          }
-          if(( epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE)
-          {
-            CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE);
-          }
-          if(( epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD)
-          {
-            CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD);
-          }
-          if(( epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE)
-          {
-            PCD_WriteEmptyTxFifo(hpcd , epnum);
-          }
-        }
-        epnum++;
-        ep_intr >>= 1U;
-      }
-    }
-    
-    /* Handle Resume Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT))
-    {
-     /* Clear the Remote Wake-up signalling */
-      USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
-     
-     HAL_PCD_ResumeCallback(hpcd);
-     
-     __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT);
-    }
-    
-    /* Handle Suspend Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP))
-    {
-      if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
-      {
-        
-        HAL_PCD_SuspendCallback(hpcd);
-      }
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP);
-    }
-
-    /* Handle Reset Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST))
-    {
-      USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; 
-      USB_FlushTxFifo(hpcd->Instance ,  0x10U);
-      
-      for (index = 0U; index < hpcd->Init.dev_endpoints ; index++)
-      {
-        USBx_INEP(index)->DIEPINT = 0xFFU;
-        USBx_OUTEP(index)->DOEPINT = 0xFFU;
-      }
-      USBx_DEVICE->DAINT = 0xFFFFFFFFU;
-      USBx_DEVICE->DAINTMSK |= 0x10001U;
-      
-      USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
-      USBx_DEVICE->DIEPMSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
-      
-      /* Set Default Address to 0 */
-      USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD;
-      
-      /* setup EP0 to receive SETUP packets */
-      USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup);
-      
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST);
-    }
-    
-    /* Handle Enumeration done Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE))
-    {
-      USB_ActivateSetup(hpcd->Instance);
-      hpcd->Instance->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
-      
-      hpcd->Init.speed            = USB_OTG_SPEED_FULL;
-      hpcd->Init.ep0_mps          = USB_OTG_FS_MAX_PACKET_SIZE ;
-      hpcd->Instance->GUSBCFG |= (uint32_t)((USBD_FS_TRDT_VALUE << 10U) & USB_OTG_GUSBCFG_TRDT);
-      
-      HAL_PCD_ResetCallback(hpcd);
-      
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE);
-    }
-
-    /* Handle RxQLevel Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL))
-    {
-      USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
-      temp = USBx->GRXSTSP;
-      ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM];
-      
-      if(((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U) ==  STS_DATA_UPDT)
-      {
-        if((temp & USB_OTG_GRXSTSP_BCNT) != 0U)
-        {
-          USB_ReadPacket(USBx, ep->xfer_buff, (temp & USB_OTG_GRXSTSP_BCNT) >> 4U);
-          ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U;
-          ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U;
-        }
-      }
-      else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U) ==  STS_SETUP_UPDT)
-      {
-        USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8U);
-        ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U;
-      }
-      USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
-    }
-    
-    /* Handle SOF Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF))
-    {
-      HAL_PCD_SOFCallback(hpcd);
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF);
-    }
-    
-    /* Handle Incomplete ISO IN Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR))
-    {
-      HAL_PCD_ISOINIncompleteCallback(hpcd, epnum);
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR);
-    }
-    
-    /* Handle Incomplete ISO OUT Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
-    {
-      HAL_PCD_ISOOUTIncompleteCallback(hpcd, epnum);
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
-    }
-    
-    /* Handle Connection event Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT))
-    {
-      HAL_PCD_ConnectCallback(hpcd);
-      __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT);
-    }
-    
-    /* Handle Disconnection event Interrupt */
-    if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT))
-    {
-      temp = hpcd->Instance->GOTGINT;
-      
-      if((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET)
-      {
-        HAL_PCD_DisconnectCallback(hpcd);
-      }
-      hpcd->Instance->GOTGINT |= temp;
-    }
-  }
-}
-#endif /* USB_OTG_FS */
-
-#if defined (USB)
-/**
-  * @brief  This function handles PCD interrupt request.
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
-{ 
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_CTR))
-  {
-    /* servicing of the endpoint correct transfer interrupt */
-    /* clear of the CTR flag into the sub */
-    PCD_EP_ISR_Handler(hpcd);
-  }
-
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_RESET))
-  {
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET);
-    HAL_PCD_ResetCallback(hpcd);
-    HAL_PCD_SetAddress(hpcd, 0U);
-  }
-
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_PMAOVR))
-  {
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR);    
-  }
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ERR))
-  {
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR); 
-  }
-
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP))
-  {
-    hpcd->Instance->CNTR &= ~(USB_CNTR_LP_MODE);
-    hpcd->Instance->CNTR &= ~(USB_CNTR_FSUSP);
-    
-    HAL_PCD_ResumeCallback(hpcd);
-
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP);     
-  }
-
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SUSP))
-  { 
-    /* Force low-power mode in the macrocell */
-    hpcd->Instance->CNTR |= USB_CNTR_FSUSP;
-    
-    /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP);  
-
-    hpcd->Instance->CNTR |= USB_CNTR_LP_MODE;
-    if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP) == 0U)
-    {
-      HAL_PCD_SuspendCallback(hpcd);
-    }
-  }
-
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SOF))
-  {
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF); 
-    HAL_PCD_SOFCallback(hpcd);
-  }
-
-  if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ESOF))
-  {
-    /* clear ESOF flag in ISTR */
-    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF); 
-  }
-}
-#endif /* USB */
-
-/**
-  * @brief  Data out stage callbacks
-  * @param  hpcd: PCD handle
-  * @param  epnum: endpoint number
-  * @retval None
-  */
- __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  UNUSED(epnum);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_DataOutStageCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Data IN stage callbacks
-  * @param  hpcd: PCD handle
-  * @param  epnum: endpoint number
-  * @retval None
-  */
- __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  UNUSED(epnum);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_DataInStageCallback could be implemented in the user file
-   */
-}
-/**
-  * @brief  Setup stage callback
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_SetupStageCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  USB Start Of Frame callbacks
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_SOFCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  USB Reset callbacks
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_ResetCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Suspend event callbacks
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_SuspendCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Resume event callbacks
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_ResumeCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Incomplete ISO OUT callbacks
-  * @param  hpcd: PCD handle
-  * @param  epnum: endpoint number
-  * @retval None
-  */
- __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  UNUSED(epnum);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Incomplete ISO IN  callbacks
-  * @param  hpcd: PCD handle
-  * @param  epnum: endpoint number
-  * @retval None
-  */
- __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  UNUSED(epnum);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Connection event callbacks
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_ConnectCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @brief  Disconnection event callbacks
-  * @param  hpcd: PCD handle
-  * @retval None
-  */
- __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
-{
-  /* Prevent unused argument(s) compilation warning */
-  UNUSED(hpcd);
-  /* NOTE : This function should not be modified, when the callback is needed,
-            the HAL_PCD_DisconnectCallback could be implemented in the user file
-   */
-}
-
-/**
-  * @}
-  */
-
-/** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions
- *  @brief   management functions
- *
-@verbatim
- ===============================================================================
-                      ##### Peripheral Control functions #####
- ===============================================================================  
-    [..]
-    This subsection provides a set of functions allowing to control the PCD data 
-    transfers.
-
-@endverbatim
-  * @{
-  */
-
-/**
-  * @brief  Connect the USB device
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
-{
-  __HAL_LOCK(hpcd);
-  HAL_PCDEx_SetConnectionState (hpcd, 1);
-  USB_DevConnect(hpcd->Instance);
-  __HAL_UNLOCK(hpcd);
-  return HAL_OK;
-}
-
-/**
-  * @brief  Disconnect the USB device
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
-{
-  __HAL_LOCK(hpcd);
-  HAL_PCDEx_SetConnectionState (hpcd, 0U);
-  USB_DevDisconnect(hpcd->Instance);
-  __HAL_UNLOCK(hpcd);
-  return HAL_OK;
-}
-
-/**
-  * @brief  Set the USB Device address
-  * @param  hpcd: PCD handle
-  * @param  address: new device address
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
-{
-  __HAL_LOCK(hpcd);
-  hpcd->USB_Address = address;
-  USB_SetDevAddress(hpcd->Instance, address);
-  __HAL_UNLOCK(hpcd);
-  return HAL_OK;
-}
-/**
-  * @brief  Open and configure an endpoint
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @param  ep_mps: endpoint max packet size
-  * @param  ep_type: endpoint type   
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
-{
-  HAL_StatusTypeDef  ret = HAL_OK;
-  PCD_EPTypeDef *ep = NULL;
-  
-  if ((ep_addr & 0x80U) == 0x80U)
-  {
-    ep = &hpcd->IN_ep[ep_addr & 0x7FU];
-  }
-  else
-  {
-    ep = &hpcd->OUT_ep[ep_addr & 0x7FU];
-  }
-  ep->num   = ep_addr & 0x7FU;
-  
-  ep->is_in = (0x80U & ep_addr) != 0U;
-  ep->maxpacket = ep_mps;
-  ep->type = ep_type;
-    
-  __HAL_LOCK(hpcd);
-  USB_ActivateEndpoint(hpcd->Instance , ep);
-  __HAL_UNLOCK(hpcd);
-  return ret;
-}
-
-/**
-  * @brief  Deactivate an endpoint
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
-{  
-  PCD_EPTypeDef *ep = NULL;
-  
-  if ((ep_addr & 0x80U) == 0x80U)
-  {
-    ep = &hpcd->IN_ep[ep_addr & 0x7FU];
-  }
-  else
-  {
-    ep = &hpcd->OUT_ep[ep_addr & 0x7FU];
-  }
-  ep->num   = ep_addr & 0x7FU;
-  
-  ep->is_in = (0x80U & ep_addr) != 0U;
-  
-  __HAL_LOCK(hpcd);
-  USB_DeactivateEndpoint(hpcd->Instance , ep);
-  __HAL_UNLOCK(hpcd);
-  return HAL_OK;
-}
-
-
-/**
-  * @brief  Receive an amount of data
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @param  pBuf: pointer to the reception buffer
-  * @param  len: amount of data to be received
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
-{
-  PCD_EPTypeDef *ep = NULL;
-  
-  ep = &hpcd->OUT_ep[ep_addr & 0x7FU];
-  
-  /*setup and start the Xfer */
-  ep->xfer_buff = pBuf;  
-  ep->xfer_len = len;
-  ep->xfer_count = 0U;
-  ep->is_in = 0U;
-  ep->num = ep_addr & 0x7FU;
-
-  if ((ep_addr & 0x7FU) == 0U)
-  {
-    USB_EP0StartXfer(hpcd->Instance , ep);
-  }
-  else
-  {
-    USB_EPStartXfer(hpcd->Instance , ep);
-  }
-
-  return HAL_OK;
-}
-
-/**
-  * @brief  Get Received Data Size
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @retval Data Size
-  */
-uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
-{
-  return hpcd->OUT_ep[ep_addr & 0xF].xfer_count;
-}
-/**
-  * @brief  Send an amount of data
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @param  pBuf: pointer to the transmission buffer
-  * @param  len: amount of data to be sent
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
-{
-  PCD_EPTypeDef *ep = NULL;
-  
-  ep = &hpcd->IN_ep[ep_addr & 0x7FU];
-  
-  /*setup and start the Xfer */
-  ep->xfer_buff = pBuf;  
-  ep->xfer_len = len;
-  ep->xfer_count = 0U;
-  ep->is_in = 1U;
-  ep->num = ep_addr & 0x7FU;
-
-  if ((ep_addr & 0x7FU) == 0U)
-  {
-    USB_EP0StartXfer(hpcd->Instance , ep);
-  }
-  else
-  {
-    USB_EPStartXfer(hpcd->Instance , ep);
-  }
-
-  return HAL_OK;
-}
-
-/**
-  * @brief  Set a STALL condition over an endpoint
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
-{
-  PCD_EPTypeDef *ep = NULL;
-  
-  if ((0x80U & ep_addr) == 0x80U)
-  {
-    ep = &hpcd->IN_ep[ep_addr & 0x7FU];
-  }
-  else
-  {
-    ep = &hpcd->OUT_ep[ep_addr];
-  }
-  
-  ep->is_stall = 1U;
-  ep->num   = ep_addr & 0x7FU;
-  ep->is_in = ((ep_addr & 0x80U) == 0x80U);
-  
-  __HAL_LOCK(hpcd);
-  USB_EPSetStall(hpcd->Instance , ep);
-  if((ep_addr & 0x7FU) == 0U)
-  {
-    USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup);
-  }
-  __HAL_UNLOCK(hpcd); 
-  
-  return HAL_OK;
-}
-
-/**
-  * @brief  Clear a STALL condition over in an endpoint
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
-{
-  PCD_EPTypeDef *ep = NULL;
-  
-  if ((0x80U & ep_addr) == 0x80U)
-  {
-    ep = &hpcd->IN_ep[ep_addr & 0x7FU];
-  }
-  else
-  {
-    ep = &hpcd->OUT_ep[ep_addr];
-  }
-  
-  ep->is_stall = 0U;
-  ep->num   = ep_addr & 0x7FU;
-  ep->is_in = ((ep_addr & 0x80U) == 0x80U);
-  
-  __HAL_LOCK(hpcd); 
-  USB_EPClearStall(hpcd->Instance , ep);
-  __HAL_UNLOCK(hpcd); 
-  
-  return HAL_OK;
-}
-
-/**
-  * @brief  Flush an endpoint
-  * @param  hpcd: PCD handle
-  * @param  ep_addr: endpoint address
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
-{
-  __HAL_LOCK(hpcd);
-  
-  if ((ep_addr & 0x80U) == 0x80U)
-  {
-    USB_FlushTxFifo(hpcd->Instance, ep_addr & 0x7FU);
-  }
-  else
-  {
-    USB_FlushRxFifo(hpcd->Instance);
-  }
-  
-  __HAL_UNLOCK(hpcd); 
-  
-  return HAL_OK;
-}
-
-/**
-  * @brief  HAL_PCD_ActivateRemoteWakeup : active remote wakeup signalling
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
-{
-  return(USB_ActivateRemoteWakeup(hpcd->Instance));
-}
-
-/**
-  * @brief  HAL_PCD_DeActivateRemoteWakeup : de-active remote wakeup signalling
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
-{
-  return(USB_DeActivateRemoteWakeup(hpcd->Instance));
-}
-/**
-  * @}
-  */
-  
-/** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions 
- *  @brief   Peripheral State functions
- *
-@verbatim
- ===============================================================================
-                      ##### Peripheral State functions #####
- ===============================================================================
-    [..]
-    This subsection permits to get in run-time the status of the peripheral 
-    and the data flow.
-
-@endverbatim
-  * @{
-  */
-
-/**
-  * @brief  Return the PCD state
-  * @param  hpcd: PCD handle
-  * @retval HAL state
-  */
-PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
-{
-  return hpcd->State;
-}
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-
-/** @addtogroup PCD_Private_Functions
-  * @{
-  */
-#if defined (USB_OTG_FS)
-/**
-  * @brief  DCD_WriteEmptyTxFifo
-  *         check FIFO for the next packet to be loaded
-  * @param  hpcd: PCD handle
-  * @param  epnum : endpoint number
-  *          This parameter can be a value from 0 to 15  
-  * @retval HAL status
-  */
-static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum)
-{
-  USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;  
-  USB_OTG_EPTypeDef *ep = NULL;
-  int32_t len = 0;
-  uint32_t len32b = 0U;
-  uint32_t fifoemptymsk = 0U;
-  
-  ep = &hpcd->IN_ep[epnum];
-  len = ep->xfer_len - ep->xfer_count;
-  
-  if (len > ep->maxpacket)
-  {
-    len = ep->maxpacket;
-  }
-  
-  len32b = (len + 3U) / 4U;
-  
-  while ((USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b &&
-         ep->xfer_count < ep->xfer_len &&
-         ep->xfer_len != 0U)
-  {
-    /* Write the FIFO */
-    len = ep->xfer_len - ep->xfer_count;
-    
-    if ((uint32_t)len > ep->maxpacket)
-    {
-      len = ep->maxpacket;
-    }
-    len32b = (len + 3U) / 4U;
-    
-    USB_WritePacket(USBx, ep->xfer_buff, epnum, len);
-    
-    ep->xfer_buff  += len;
-    ep->xfer_count += len;
-  }
-  
-  if(len <= 0)
-  {
-    fifoemptymsk = 0x01U << epnum;
-    USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk;
-    
-  }
-  
-  return HAL_OK;
-}
-#endif /* USB_OTG_FS */
-
-#if defined (USB)
-/**
-  * @brief  This function handles PCD Endpoint interrupt request.
-  * @param  hpcd: PCD handle
-  * @retval HAL status
-  */
-static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
-{
-  PCD_EPTypeDef *ep = NULL;
-  uint16_t count = 0;
-  uint8_t epindex = 0;
-  __IO uint16_t wIstr = 0;  
-  __IO uint16_t wEPVal = 0;
-  
-  /* stay in loop while pending interrupts */
-  while (((wIstr = hpcd->Instance->ISTR) & USB_ISTR_CTR) != 0)
-  {
-    /* extract highest priority endpoint number */
-    epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID);
-    
-    if (epindex == 0)
-    {
-      /* Decode and service control endpoint interrupt */
-      
-      /* DIR bit = origin of the interrupt */   
-      if ((wIstr & USB_ISTR_DIR) == 0)
-      {
-        /* DIR = 0 */
-        
-        /* DIR = 0      => IN  int */
-        /* DIR = 0 implies that (EP_CTR_TX = 1) always  */
-        PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0);
-        ep = &hpcd->IN_ep[0];
-        
-        ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
-        ep->xfer_buff += ep->xfer_count;
- 
-        /* TX COMPLETE */
-        HAL_PCD_DataInStageCallback(hpcd, 0U);
-        
-        
-        if((hpcd->USB_Address > 0U)&& ( ep->xfer_len == 0U))
-        {
-          hpcd->Instance->DADDR = (hpcd->USB_Address | USB_DADDR_EF);
-          hpcd->USB_Address = 0U;
-        }
-        
-      }
-      else
-      {
-        /* DIR = 1 */
-        
-        /* DIR = 1 & CTR_RX       => SETUP or OUT int */
-        /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
-        ep = &hpcd->OUT_ep[0U];
-        wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0);
-        
-        if ((wEPVal & USB_EP_SETUP) != 0U)
-        {
-          /* Get SETUP Packet*/
-          ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
-          USB_ReadPMA(hpcd->Instance, (uint8_t*)hpcd->Setup ,ep->pmaadress , ep->xfer_count);       
-          /* SETUP bit kept frozen while CTR_RX = 1*/ 
-          PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); 
-          
-          /* Process SETUP Packet*/
-          HAL_PCD_SetupStageCallback(hpcd);
-        }
-        
-        else if ((wEPVal & USB_EP_CTR_RX) != 0U)
-        {
-          PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
-          /* Get Control Data OUT Packet*/
-          ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
-          
-          if (ep->xfer_count != 0U)
-          {
-            USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
-            ep->xfer_buff+=ep->xfer_count;
-          }
-          
-          /* Process Control Data OUT Packet*/
-           HAL_PCD_DataOutStageCallback(hpcd, 0U);
-          
-          PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket);
-          PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID);
-        }
-      }
-    }
-    else
-    {
-      /* Decode and service non control endpoints interrupt  */
-	  
-      /* process related endpoint register */
-      wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex);
-      if ((wEPVal & USB_EP_CTR_RX) != 0U)
-      {  
-        /* clear int flag */
-        PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex);
-        ep = &hpcd->OUT_ep[epindex];
-        
-        /* OUT double Buffering*/
-        if (ep->doublebuffer == 0U)
-        {
-          count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
-          if (count != 0U)
-          {
-            USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
-          }
-        }
-        else
-        {
-          if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX)
-          {
-            /*read from endpoint BUF0Addr buffer*/
-            count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
-            if (count != 0U)
-            {
-              USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
-            }
-          }
-          else
-          {
-            /*read from endpoint BUF1Addr buffer*/
-            count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
-            if (count != 0U)
-            {
-              USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
-            }
-          }
-          PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_OUT);  
-        }
-        /*multi-packet on the NON control OUT endpoint*/
-        ep->xfer_count+=count;
-        ep->xfer_buff+=count;
-       
-        if ((ep->xfer_len == 0U) || (count < ep->maxpacket))
-        {
-          /* RX COMPLETE */
-          HAL_PCD_DataOutStageCallback(hpcd, ep->num);
-        }
-        else
-        {
-          HAL_PCD_EP_Receive(hpcd, ep->num, ep->xfer_buff, ep->xfer_len);
-        }
-        
-      } /* if((wEPVal & EP_CTR_RX) */
-      
-      if ((wEPVal & USB_EP_CTR_TX) != 0U)
-      {
-        ep = &hpcd->IN_ep[epindex];
-        
-        /* clear int flag */
-        PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex);
-        
-        /* IN double Buffering*/
-        if (ep->doublebuffer == 0U)
-        {
-          ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
-          if (ep->xfer_count != 0U)
-          {
-            USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
-          }
-        }
-        else
-        {
-          if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_TX)
-          {
-            /*read from endpoint BUF0Addr buffer*/
-            ep->xfer_count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
-            if (ep->xfer_count != 0U)
-            {
-              USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, ep->xfer_count);
-            }
-          }
-          else
-          {
-            /*read from endpoint BUF1Addr buffer*/
-            ep->xfer_count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
-            if (ep->xfer_count != 0U)
-            {
-              USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, ep->xfer_count);
-            }
-          }
-          PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_IN);  
-        }
-        /*multi-packet on the NON control IN endpoint*/
-        ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
-        ep->xfer_buff+=ep->xfer_count;
-       
-        /* Zero Length Packet? */
-        if (ep->xfer_len == 0U)
-        {
-          /* TX COMPLETE */
-          HAL_PCD_DataInStageCallback(hpcd, ep->num);
-        }
-        else
-        {
-          HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len);
-        }
-      } 
-    }
-  }
-  return HAL_OK;
-}
-#endif /* USB */
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-  
-#endif /* STM32F102x6 || STM32F102xB || */
-       /* STM32F103x6 || STM32F103xB || */
-       /* STM32F103xE || STM32F103xG || */
-       /* STM32F105xC || STM32F107xC    */
-
-#endif /* HAL_PCD_MODULE_ENABLED */
-
-
-/**
-  * @}
-  */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

BIN
MDK-ARM/bin/MC_VOLANS-TC033001A-V1_V2r1r5_20200904.bin


BIN
MDK-ARM/bin/QD007A_CTL_APP.bin


+ 1 - 0
User/Inc/var.h

@@ -418,6 +418,7 @@ typedef struct
 extern MC_RunInfo_Struct_t MC_RunInfo;
 extern MC_ErrorCode_Struct_t MC_ErrorCode;
 extern MC_VerInfo_Struct_t MC_VerInfo;
+extern char Firmware_Special[32];
 extern OnLine_Status_Struct_t DeviceOnLine_Status;
 extern BMS_RunInfo_Struct_t BMS_RunInfo;
 extern Device_CheckInfo_Struct_t BMS_CheckInfo;

+ 1 - 0
User/Src/can_process.c

@@ -364,6 +364,7 @@ void DataProcess(uint16_t ID, uint8_t Mode, uint16_t Cmd, uint8_t* Data)
 				  ReadDataFromEEPROM_Flash(EEPROM_FLASH_ADDR_MODE, (uint8_t*)MC_VerInfo.Mode, 16);
 					ReadDataFromEEPROM_Flash(EEPROM_FLASH_ADDR_SN, (uint8_t*)MC_VerInfo.SN_Num, 16);
 					SendData(ID_MC_BC, MODE_REPORT, 0x1240, (uint8_t*)MC_VerInfo.Mode);
+					SendData(ID_MC_BC, MODE_REPORT, 0x1720, (uint8_t*)Firmware_Special);
 					break;
 				}
 				case 0x1300://²éѯ×Ô¶¨Òå×Ö·û´®1

+ 549 - 29
User/Src/motor_control.c

@@ -175,7 +175,7 @@ MC_AssistRunMode_Struct_t MC_JudgeAsistRunMode_Process(MC_SupportFlag_Struct_t G
 				else 
 				{
 					//进入踏频模式
-					if(((GearSt & 0xF0) != 0) && (GearSt != MC_GearSt_SMART))
+					if((GearSt & 0xF0) == 0x10)
 					{
 						MC_AssistRunMode_Result = MC_AssistRunMode_CADENCE;
 					}
@@ -234,7 +234,7 @@ int16_t SpeedSetReal = 0;	// 
 /*指拨模式相关变量*/
 
 //指拨模式处理
-MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt_Struct_t GearSt)
+MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t GasSensorData, uint16_t TorqueSensorData, MC_GearSt_Struct_t GearSt)
 {
 	int32_t Tmp;
 	int16_t TorQueBySpd = 0;
@@ -298,7 +298,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
 
 	/*电机最高速度,上位机配置参数*/
 	SpeedMax = MC_MotorParam.Rate_Speed;
-	Tmp = SensorData + 50 ;  //加50偏移量,确保能达到最大值2048
+	Tmp = ((GasSensorData < TorqueSensorData) ? TorqueSensorData : GasSensorData) + 50 ;  //加50偏移量,确保能达到最大值2048
 	Tmp = Tmp > 2048 ? 2048 : Tmp; 
 	
 	/*调试用,根据车速限速值,换算指拨对应的设定车速*/
@@ -320,25 +320,25 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
 	switch (GearSt & 0x0F)
 	{
 		case 0x01:
-			accStep = StepCalc(SpeedMax, 1, 6500);
+			accStep = StepCalc(SpeedMax, 1, 2100);
 			break;
 		case 0x02:
-			accStep = StepCalc(SpeedMax, 1, 6000);
+			accStep = StepCalc(SpeedMax, 1, 1500);
 			break;
 		case 0x03:
-			accStep = StepCalc(SpeedMax, 1, 5500);
+			accStep = StepCalc(SpeedMax, 1, 1071);
 			break;
 		case 0x04:
-			accStep = StepCalc(SpeedMax, 1, 5000);
+			accStep = StepCalc(SpeedMax, 1, 765);
 			break;
 		default:
-			/*计算周期1ms, 加减速时间为 5.00s  加减速步进计算*/
-			accStep = StepCalc(SpeedMax, 1, 5000);
+			/*计算周期1ms, 加减速时间为 2.00s  加减速步进计算*/
+			accStep = StepCalc(SpeedMax, 1, 1500);
 			break;
 	}
 	
 	/*减速步进*/
-	decStep = StepCalc(SpeedMax, 1, 1000);
+	decStep = StepCalc(SpeedMax, 1, 2000);
 
 	/* 跟踪启动 */
 	if(MC_CalParam.Foc_Flag  == RESET)			
@@ -623,23 +623,543 @@ MC_CalParam_Struct_t MC_AssistRunMode_Walk_Process(MC_WorkMode_Struct_t p_MC_Wor
 }
 
 //踏频模式处理
-MC_CalParam_Struct_t MC_AssistRunMode_Cadence_Process(MC_GearSt_Struct_t GearSt)
+MC_CalParam_Struct_t MC_AssistRunMode_Cadence_Process(MC_CadenceResult_Struct_t CadenceData, uint16_t SenorData, MC_GearSt_Struct_t GearSt)
 {
   MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0,	0, RESET};
+  uint8_t TorqueAccStep = 0;//力矩上升斜率
+	uint8_t TorqueDecStep = 0;//力矩下降斜率
+	uint16_t TorqueStartData = 0, TorqueStopData = 0;//力矩启动值,力矩停机值
+	int16_t Torque_Temp = 0;
+	int32_t Torque_Ref_Temp = 0;;
+	static uint32_t TorqueStopDelayTimeCnt = 0; //低力矩停机计时
+	uint16_t TorqueStopDelayTime = 0;;
+	static int16_t IqRefByInPower;           //限流计算结果
+  static uint16_t CurrentLimitPresent;     //限流实际值,做升降速处理
+	uint16_t CurrentLimitSet = 0;;           //限流设置值,不同助力档位更新
+	
+	static uint8_t TorqueRefEndUpdateCount = 0;
+	
+	#define SOFT_SATRT 1
+	
+	#if SOFT_SATRT
+	static FlagStatus SoftStartFlag = SET;
+	static uint16_t SoftStartDelayTimeCount = 0;
+	uint16_t SoftStartDelayTime = 0;
+	uint16_t SoftStartAcc = 0;
+	#endif
+	
+	#if 1
+	
+	//踩踏力矩输入
+  MC_TorqueProcess_Param.TorqueApp = SenorData;
+	
+	#else
+	//输入阶跃
+	MC_TorqueProcess_Param.TorqueApp  = 1000;
+	
+	//踏频设为启动
+	CadenceData.Cadence_Dir = MC_Cadence_Forward;
+	CadenceData.IsStopFlag = FALSE;
 	
-  //...插入踏频处理
+	#endif
+	
+	//低力矩停机
+	TorqueStopData = (MC_TorqueCorrectParam.StarData < 300) ? 100 : (MC_TorqueCorrectParam.StarData / 3);
+	if(MC_TorqueProcess_Param.TorqueApp >= (TorqueStopData))
+	{
+	  TorqueStopDelayTimeCnt = HAL_GetTick();
+	}
+	else
+	{
+//		if(MC_RunInfo.MotorSpeed > 200)
+//		{
+//		  TorqueStopDelayTime = 218400 / MC_RunInfo.MotorSpeed; //60s / (电机转速 / 4.55 / 2.4) / 3,曲柄1/3圈
+//		}
+//		else
+//		{
+//		  TorqueStopDelayTime = 1200;
+//		}
+//		TorqueStopDelayTime= (TorqueStopDelayTime < 500) ? 500 : TorqueStopDelayTime;
+		TorqueStopDelayTime = 1500;
+		if((HAL_GetTick() - TorqueStopDelayTimeCnt) > TorqueStopDelayTime)//超时1200ms
+		{
+			MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
+		}
+	}
+	
+	//启动值判断
+	if(MC_RunInfo.BikeSpeed > 60) 
+	{
+		TorqueStartData =  (MC_TorqueCorrectParam.StarData < 200 ? 150 : (MC_TorqueCorrectParam.StarData > 700 ? 525 : ((MC_TorqueCorrectParam.StarData * 3) >> 2)));
+	}
+	else
+	{
+		TorqueStartData =  (MC_TorqueCorrectParam.StarData < 200 ? 150 : (MC_TorqueCorrectParam.StarData > 700 ? 700 : MC_TorqueCorrectParam.StarData));
+	}
+	if(MC_TorqueProcess_Param.TorqueApp >= TorqueStartData)
+	{
+		 MC_TorqueProcess_Param.MotorStopLock_Flag = RESET;
+	}
 	
-	//电机启动
-	MC_MotorStar(&MC_StarFlag);
+	//踏频反向或踏频停止停机
+	if((CadenceData.Cadence_Dir == MC_Cadence_Backward) ||
+		 (CadenceData.IsStopFlag == TRUE)		
+		)
+	{
+		MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
+	}
 	
+	//停机状态,延时处理
+	if(MC_TorqueProcess_Param.MotorStopLock_Flag == SET)
+	{
+	  if(MC_TorqueProcess_Param.TorqueRefEnd <= 7)
+		{
+		  MC_TorqueProcess_Param.TorqueRefEnd = 0;
+			//停机处理
+			MC_MotorStop(&MC_StarFlag);
+			
+			#if SOFT_SATRT
+			//缓启动标志置位
+			SoftStartFlag = SET;
+			SoftStartDelayTimeCount = 0;
+			#endif
+		}
+		else
+		{
+		  MC_TorqueProcess_Param.TorqueRefEnd -= 7;  //这里影响到停止踩踏后的断电时间
+			MC_MotorStar(&MC_StarFlag);
+		}
+	}
+	//力矩给定升降速处理
+	else
+	{
+		/*调节助力比,使用经过踏频信号滤波处理的力矩值*/
+		MC_TorqueProcess_Param.TorqueApp = CadenceData.torqueByCadence;
+		
+		//按照助力档位调节力矩输入值
+		switch(GearSt)
+		{
+			case MC_GearSt_Cadence_ECO:
+			{
+				//控制输入给定加速斜率
+				if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN <= 80)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_ECO.AccCnt - 1;
+				}
+				else if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN >= 120)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_ECO.AccCnt + 1;
+				}
+				else
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_ECO.AccCnt;
+				}
+				TorqueAccStep = (TorqueAccStep <= 0) ? 1 : TorqueAccStep;
+				//控制输入给定减速斜率
+				TorqueDecStep = MC_AssisParam.Gear_ECO.DecCnt;
+				//调节电机输出功率
+				if(CadenceData.Cadence_Data < 50)//输出功率与输入力矩成正比,等效于踏频采用固定值50rpm
+				{
+					Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_ECO.Gain_K >> 1, MC_AssisParam.Gear_ECO.Gain_K, MC_AssisParam.Gear_ECO.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_ECO.Upper_Iq 
+					                                            : Torque_Temp * 120 / (MC_RunInfo.MotorSpeed * 20 / 91);
+				}
+				else if((CadenceData.Cadence_Data >= 50) && (CadenceData.Cadence_Data < 90))//输出功率与输入力矩成正比
+				{
+				  Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_ECO.Gain_K >> 1, MC_AssisParam.Gear_ECO.Gain_K, MC_AssisParam.Gear_ECO.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_ECO.Upper_Iq 
+					                                            : ((MC_RunInfo.MotorSpeed < 983) ? Torque_Temp * 216 / (MC_RunInfo.MotorSpeed * 20 / 91) 
+					                                                                             : Torque_Temp * CadenceData.Cadence_Data * 24 / 10 / (MC_RunInfo.MotorSpeed * 20 / 91));
+				}
+				else//全功率输出
+				{
+				  Torque_Temp = MC_AssisParam.Gear_ECO.Upper_Iq;
+				}
+				//根据助力增益调节助力比
+				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_ECO.Assist_K_GAIN / 100;
+				//给定下限
+				Torque_Temp = (Torque_Temp < MC_AssisParam.Gear_ECO.Lower_Iq) ? MC_AssisParam.Gear_ECO.Lower_Iq : Torque_Temp;
+				//给定上限
+				Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_ECO.Upper_Iq) ? MC_AssisParam.Gear_ECO.Upper_Iq : Torque_Temp;
+				//限流参数设置
+				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_ECO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
+				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
+				PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_ECO.Upper_Iq);   //Lower Limit for Output limitation
+				PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
+				PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_ECO.Upper_Iq << 10); // 放大1024
+				PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
+				break;
+			}
+			case MC_GearSt_Cadence_NORM:
+			{
+				//控制输入给定加速斜率
+				if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN <= 80)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_NORM.AccCnt - 1;
+				}
+				else if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN >= 120)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_NORM.AccCnt + 1;
+				}
+				else
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_NORM.AccCnt;
+				}
+				TorqueAccStep = (TorqueAccStep <= 0) ? 1 : TorqueAccStep;
+				//控制输入给定减速斜率
+				TorqueDecStep = MC_AssisParam.Gear_NORM.DecCnt;
+				//调节电机输出功率
+				if(CadenceData.Cadence_Data < 50)//输出功率与输入力矩成正比,等效于踏频采用固定值50rpm
+				{
+					Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_NORM.Gain_K >> 1, MC_AssisParam.Gear_NORM.Gain_K, MC_AssisParam.Gear_NORM.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_NORM.Upper_Iq 
+					                                            : Torque_Temp * 120 / (MC_RunInfo.MotorSpeed * 20 / 91);
+				}
+				else if((CadenceData.Cadence_Data >= 50) && (CadenceData.Cadence_Data < 90))//输出功率与输入力矩成正比
+				{
+				  Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_NORM.Gain_K >> 1, MC_AssisParam.Gear_NORM.Gain_K, MC_AssisParam.Gear_NORM.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_NORM.Upper_Iq 
+					                                            : ((MC_RunInfo.MotorSpeed < 983) ? Torque_Temp * 216 / (MC_RunInfo.MotorSpeed * 20 / 91) 
+					                                                                             : Torque_Temp * CadenceData.Cadence_Data * 24 / 10 / (MC_RunInfo.MotorSpeed * 20 / 91));
+				}
+				else//全功率输出
+				{
+				  Torque_Temp = MC_AssisParam.Gear_NORM.Upper_Iq;
+				}
+				//根据助力增益调节助力比
+				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_NORM.Assist_K_GAIN / 100;
+				//给定下限
+				Torque_Temp = (Torque_Temp < MC_AssisParam.Gear_NORM.Lower_Iq) ? MC_AssisParam.Gear_NORM.Lower_Iq : Torque_Temp;
+				//给定上限
+				Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_NORM.Upper_Iq) ? MC_AssisParam.Gear_NORM.Upper_Iq : Torque_Temp;
+				
+				//限流参数设置
+				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
+				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
+				PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_NORM.Upper_Iq);   //Lower Limit for Output limitation
+				PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
+				PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_NORM.Upper_Iq << 10); // 放大1024
+				PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
+				break;
+			}
+			case MC_GearSt_Cadence_SPORT:
+			{
+				//控制输入给定加速斜率
+				if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN <= 80)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_SPORT.AccCnt - 1;
+				}
+				else if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN >= 120)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_SPORT.AccCnt + 1;
+				}
+				else
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_SPORT.AccCnt;
+				}
+				TorqueAccStep = (TorqueAccStep <= 0) ? 1 : TorqueAccStep;
+				//控制输入给定减速斜率
+				TorqueDecStep = MC_AssisParam.Gear_SPORT.DecCnt;
+				//调节电机输出功率
+				if(CadenceData.Cadence_Data < 50)//输出功率与输入力矩成正比,等效于踏频采用固定值50rpm
+				{
+					Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_SPORT.Gain_K >> 1, MC_AssisParam.Gear_SPORT.Gain_K, MC_AssisParam.Gear_SPORT.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_SPORT.Upper_Iq 
+					                                            : Torque_Temp * 120 / (MC_RunInfo.MotorSpeed * 20 / 91);
+				}
+				else if((CadenceData.Cadence_Data >= 50) && (CadenceData.Cadence_Data < 90))//输出功率与输入力矩成正比
+				{
+				  Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_SPORT.Gain_K >> 1, MC_AssisParam.Gear_SPORT.Gain_K, MC_AssisParam.Gear_SPORT.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_SPORT.Upper_Iq 
+					                                            : ((MC_RunInfo.MotorSpeed < 983) ? Torque_Temp * 216 / (MC_RunInfo.MotorSpeed * 20 / 91) 
+					                                                                             : Torque_Temp * CadenceData.Cadence_Data * 24 / 10 / (MC_RunInfo.MotorSpeed * 20 / 91));
+				}
+				else//全功率输出
+				{
+				  Torque_Temp = MC_AssisParam.Gear_SPORT.Upper_Iq;
+				}
+				//根据助力增益调节助力比
+				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_SPORT.Assist_K_GAIN / 100;
+				//给定下限
+				Torque_Temp = (Torque_Temp < MC_AssisParam.Gear_SPORT.Lower_Iq) ? MC_AssisParam.Gear_SPORT.Lower_Iq : Torque_Temp;
+				//给定上限
+				Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_SPORT.Upper_Iq) ? MC_AssisParam.Gear_SPORT.Upper_Iq : Torque_Temp;
+				//限流参数设置
+				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SPORT.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
+				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
+				PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_SPORT.Upper_Iq);   //Lower Limit for Output limitation
+				PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
+				PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_SPORT.Upper_Iq << 10); // 放大1024
+				PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
+				break;
+			}
+			case MC_GearSt_Cadence_TURBO:
+			{
+				//控制输入给定加速斜率
+				if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN <= 80)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_TURBO.AccCnt - 1;
+				}
+				else if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN >= 120)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_TURBO.AccCnt + 1;
+				}
+				else
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_TURBO.AccCnt;
+				}
+				TorqueAccStep = (TorqueAccStep <= 0) ? 1 : TorqueAccStep;
+				//控制输入给定减速斜率
+				TorqueDecStep = MC_AssisParam.Gear_TURBO.DecCnt;
+        //调节电机输出功率
+				if(CadenceData.Cadence_Data < 50)//输出功率与输入力矩成正比,等效于踏频采用固定值50rpm
+				{
+					Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_TURBO.Gain_K >> 1, MC_AssisParam.Gear_TURBO.Gain_K, MC_AssisParam.Gear_TURBO.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_TURBO.Upper_Iq 
+					                                            : Torque_Temp * 120 / (MC_RunInfo.MotorSpeed * 20 / 91);
+				}
+				else if((CadenceData.Cadence_Data >= 50) && (CadenceData.Cadence_Data < 90))//输出功率与输入力矩成正比
+				{
+				  Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_TURBO.Gain_K >> 1, MC_AssisParam.Gear_TURBO.Gain_K, MC_AssisParam.Gear_TURBO.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_TURBO.Upper_Iq 
+					                                            : ((MC_RunInfo.MotorSpeed < 983) ? Torque_Temp * 216 / (MC_RunInfo.MotorSpeed * 20 / 91) 
+					                                                                             : Torque_Temp * CadenceData.Cadence_Data * 24 / 10 / (MC_RunInfo.MotorSpeed * 20 / 91));
+				}
+				else//全功率输出
+				{
+				  Torque_Temp = MC_AssisParam.Gear_TURBO.Upper_Iq;
+				}				
+				//根据助力增益调节助力比
+				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_TURBO.Assist_K_GAIN / 100;
+				//给定下限
+				Torque_Temp = (Torque_Temp < MC_AssisParam.Gear_TURBO.Lower_Iq) ? MC_AssisParam.Gear_TURBO.Lower_Iq : Torque_Temp;
+				//给定上限
+				Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_TURBO.Upper_Iq) ? MC_AssisParam.Gear_TURBO.Upper_Iq : Torque_Temp;
+				//限流参数设置
+				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_TURBO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
+				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
+				PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_TURBO.Upper_Iq);   //Lower Limit for Output limitation
+				PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
+				PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_TURBO.Upper_Iq << 10); // 放大1024
+				PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
+				break;
+			}
+			case MC_GearSt_SMART:
+			{
+				//控制输入给定加速斜率
+				if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN <= 80)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_SMART.AccCnt - 1;
+				}
+				else if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN >= 120)
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_SMART.AccCnt + 1;
+				}
+				else
+				{
+				  TorqueAccStep = MC_AssisParam.Gear_SMART.AccCnt;
+				}
+				TorqueAccStep = (TorqueAccStep <= 0) ? 1 : TorqueAccStep;
+				//控制输入给定减速斜率
+				TorqueDecStep = MC_AssisParam.Gear_SMART.DecCnt;
+				//调节电机输出功率
+				if(CadenceData.Cadence_Data < 50)//输出功率与输入力矩成正比,等效于踏频采用固定值50rpm
+				{
+					Torque_Temp = (uint32_t)(MC_TorqueProcess_Param.TorqueApp * MC_TorqueProcess_Param.TorqueApp) / (MC_AssisParam.Gear_SMART.TorqueApp_TH);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_SMART.Upper_Iq 
+					                                            : Torque_Temp * 120 / (MC_RunInfo.MotorSpeed * 20 / 91);
+				}
+				else if((CadenceData.Cadence_Data >= 50) && (CadenceData.Cadence_Data < 90))//输出功率与输入力矩成正比
+				{
+				  Torque_Temp = (uint32_t)(MC_TorqueProcess_Param.TorqueApp * MC_TorqueProcess_Param.TorqueApp) / (MC_AssisParam.Gear_SMART.TorqueApp_TH);
+				  Torque_Temp = (MC_RunInfo.MotorSpeed < 546) ? MC_AssisParam.Gear_SMART.Upper_Iq 
+					                                            : ((MC_RunInfo.MotorSpeed < 983) ? Torque_Temp * 216 / (MC_RunInfo.MotorSpeed * 20 / 91) 
+					                                                                             : Torque_Temp * CadenceData.Cadence_Data * 24 / 10 / (MC_RunInfo.MotorSpeed * 20 / 91));
+				}
+				else//全功率输出
+				{
+				  Torque_Temp = MC_AssisParam.Gear_SMART.Upper_Iq;
+				}				
+				//根据助力增益调节助力比
+				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_SMART.Assist_K_GAIN / 100;
+				//给定下限
+				Torque_Temp = (Torque_Temp < MC_AssisParam.Gear_SMART.Lower_Iq) ? MC_AssisParam.Gear_SMART.Lower_Iq : Torque_Temp;
+				//给定上限
+				Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_SMART.Upper_Iq) ? MC_AssisParam.Gear_SMART.Upper_Iq : Torque_Temp;
+				//限流参数设置
+				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SMART.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
+				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
+				PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_SMART.Upper_Iq);   //Lower Limit for Output limitation
+				PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
+				PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_SMART.Upper_Iq << 10); // 放大1024
+				PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
+				break;
+			}
+			default: 
+			{
+				TorqueAccStep = 0;
+				TorqueDecStep = 0;
+				Torque_Temp = 0;
+				break;
+			}
+		}
+		
+		//随车速调节助力比
+		Torque_Temp = (uint16_t)((uint32_t)(Torque_Temp * Function_Linear_3Stage(MC_ConfigParam1.SpeedLimit * 10, 0, MC_ConfigParam1.SpeedLimit * 10, 52, MC_SpeedSensorData.Speed_Data)) >> 10);
+			
+    //助力输出		
+		MC_TorqueProcess_Param.TorqueRef = Torque_Temp;
+		if(MC_TorqueProcess_Param.TorqueRef <= 0)
+		{
+			MC_TorqueProcess_Param.TorqueRef = 0;
+		}
+				
+		//升降速曲线计算
+		if( MC_SpeedSensorData.Speed_Data > (MC_ConfigParam1.SpeedLimit * 10) ) //限速处理
+		{
+			if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
+			{
+				MC_TorqueProcess_Param.TorqueRefEnd += 1;
+			}
+			else if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) < (- 1))
+			{
+				MC_TorqueProcess_Param.TorqueRefEnd -= 1; 
+			}
+		}
+		else if( (Bike_Attitude.UpWardSlope_flag == TRUE)&&(MC_SpeedSensorData.Speed_Data < 100))  //上坡处理			  
+		{
+			if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
+			{
+				MC_TorqueProcess_Param.TorqueRefEnd += TorqueAccStep;
+			}
+			else if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) < (- 1))
+			{
+				TorqueRefEndUpdateCount++;			
+				if(TorqueRefEndUpdateCount >=3)
+				{
+					TorqueRefEndUpdateCount = 0;
+					MC_TorqueProcess_Param.TorqueRefEnd -= TorqueDecStep;
+				}
+			}		
+		}	
+		
+    #if SOFT_SATRT		
+    else if(SoftStartFlag == SET)  //启动处理
+		{
+			if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)  //强劲模式,无延迟
+			{
+			  SoftStartDelayTimeCount = 0;
+				SoftStartFlag = RESET;
+			}
+			else
+			{
+				if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)   //柔和模式,延迟300ms
+				{
+					SoftStartDelayTime = 300;      //启动处理延时300ms
+					SoftStartAcc = 30;             //30ms递增0.1倍
+				}
+				else                                                //正常模式,延迟100ms
+				{
+					SoftStartDelayTime = 100;      //启动处理延时100ms
+					SoftStartAcc = 10;             //10ms递增0.1倍
+				}
+				SoftStartDelayTimeCount++;
+				if(SoftStartDelayTimeCount <= SoftStartDelayTime) // 缓启动过程,按照0.1倍率逐步增加加减速斜率
+				{  
+					if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
+					{
+						if((SoftStartDelayTimeCount % (10 - SoftStartDelayTimeCount / SoftStartAcc))  == 0)
+						{
+							MC_TorqueProcess_Param.TorqueRefEnd += TorqueAccStep;
+						}
+					}
+					else if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) < (- 1))
+					{
+						MC_TorqueProcess_Param.TorqueRefEnd -= TorqueDecStep;
+					}
+				}
+				else
+				{
+					SoftStartDelayTimeCount = 0;
+					SoftStartFlag = RESET;
+				}
+			}
+		}	
+    #endif
+		
+		else //正常骑行
+		{
+			if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
+			{
+				MC_TorqueProcess_Param.TorqueRefEnd += TorqueAccStep;
+			}
+			else if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) < (- 1))
+			{
+				MC_TorqueProcess_Param.TorqueRefEnd -= TorqueDecStep;
+			}
+		}
+		MC_TorqueProcess_Param.TorqueRefEnd = (MC_TorqueProcess_Param.TorqueRefEnd < 6) ? 6 : MC_TorqueProcess_Param.TorqueRefEnd;
+		
+		//限速点处理
+		if( MC_SpeedSensorData.Speed_Data > (MC_ConfigParam1.SpeedLimit * 10 + 22) ) //限速值+2.2
+		{
+			MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
+			MC_TorqueProcess_Param.TorqueRefEnd = 0;
+			//停机处理
+			MC_MotorStop(&MC_StarFlag);
+		}
+		#if 0  //低于限速点启动电机
+		else if(MC_RunInfo.BikeSpeed < ((MC_ConfigParam1.SpeedLimit) * 10))
+		{
+		  MC_MotorStar(&MC_StarFlag);
+		}
+		#elif 1  //低于断电点即启动电机
+		else
+		{
+		  MC_MotorStar(&MC_StarFlag);
+		}
+		#endif
+	}
+	
+	#if 1
+	static uint16_t K_ByVoltage_Set_Old = 1024;
+	uint16_t K_ByVoltage_Set;
+	static uint16_t K_ByVoltage_Result;
+	uint16_t K_ByTemperature_Set;
+	static uint16_t K_ByTemperature_Result;
+
+	//根据电压调节输出
+  K_ByVoltage_Set = MC_Cal_K_ByVoltage(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, K_ByVoltage_Set_Old);//根据母线电压计算衰减比例,递减
+	K_ByVoltage_Set_Old = K_ByVoltage_Set;
+  K_ByVoltage_Result = MC_DataSet_Linear_Process(K_ByVoltage_Set, K_ByVoltage_Result, 1, 1); //设定值与给定值线性处理
+	
+	//根据温度调节输出
+	K_ByTemperature_Set = MC_Cal_K_ByTemperature(MC_RunInfo.T_Coil, MC_ConfigParam1.TempTH_Alarm); //根据温度计算衰减比例
+	K_ByTemperature_Result = MC_DataSet_Linear_Process(K_ByTemperature_Set, K_ByTemperature_Result, 1, 1); //设定值与给定值线性处理
+	
+	#else
+	
+	uint16_t K_ByVoltage_Result = 1024;
+	uint16_t K_ByTemperature_Result = 1024;
+	#endif
+	
+  //限流计算
+  IqRefByInPower =  PID_Regulator(CurrentLimitPresent / 100, (MC_RunInfo.BusCurrent >> 7), &PID_IMax);
+	
+	Torque_Ref_Temp = ((int32_t)MC_TorqueProcess_Param.TorqueRefEnd * K_ByVoltage_Result) >> 10;
+	Torque_Ref_Temp = (Torque_Ref_Temp * K_ByTemperature_Result) >> 10;
+	Torque_Ref_Temp = (Torque_Ref_Temp + IqRefByInPower) >> 1;
+	
+	p_MC_CalParam.Ref_Torque = (int16_t)Torque_Ref_Temp;
 	p_MC_CalParam.Foc_Flag = SET;
 	p_MC_CalParam.AssistRunMode = MC_AssistRunMode_CADENCE;
 	
 	return (p_MC_CalParam);
+
 }
 
 //力矩模式处理
-MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_GearSt_Struct_t GearSt, uint16_t SenorDataByCadence)
+MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(MC_CadenceResult_Struct_t CadenceData, uint16_t SenorData, MC_GearSt_Struct_t GearSt)
 {
   MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0,	0, RESET};
   uint8_t TorqueAccStep = 0;//力矩上升斜率
@@ -675,8 +1195,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	MC_TorqueProcess_Param.TorqueApp  = 1000;
 	
 	//踏频设为启动
-	MC_CadenceResult.Cadence_Dir = MC_Cadence_Forward;
-	MC_CadenceResult.IsStopFlag = FALSE;
+	CadenceData.Cadence_Dir = MC_Cadence_Forward;
+	CadenceData.IsStopFlag = FALSE;
 	
 	#elif 1
 	
@@ -691,8 +1211,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	MC_TorqueProcess_Param.TorqueApp = RampWaveGenerate(WaveTime_Zero, 6000, 2100);
 	
 	//踏频设为启动
-	MC_CadenceResult.Cadence_Dir = MC_Cadence_Forward;
-	MC_CadenceResult.IsStopFlag = FALSE;
+	CadenceData.Cadence_Dir = MC_Cadence_Forward;
+	CadenceData.IsStopFlag = FALSE;
 	
 	#elif 1
 	
@@ -707,8 +1227,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	MC_TorqueProcess_Param.TorqueApp  = TriangleWaveGenerate(WaveTime_Zero, 500, 1000 ,1500);
 	
 	//踏频设为启动
-	MC_CadenceResult.Cadence_Dir = MC_Cadence_Forward;
-	MC_CadenceResult.IsStopFlag = FALSE;
+	CadenceData.Cadence_Dir = MC_Cadence_Forward;
+	CadenceData.IsStopFlag = FALSE;
 	
 	#elif 1
 	
@@ -723,8 +1243,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	MC_TorqueProcess_Param.TorqueApp  = SquareWaveGenerate(WaveTime_Zero, 5000, 8000, 1500);
 	
 	//踏频设为启动
-	MC_CadenceResult.Cadence_Dir = MC_Cadence_Forward;
-	MC_CadenceResult.IsStopFlag = FALSE;
+	CadenceData.Cadence_Dir = MC_Cadence_Forward;
+	CadenceData.IsStopFlag = FALSE;
 	
 	#endif
 		
@@ -770,8 +1290,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	}
 	
 	//踏频反向或踏频停止停机
-	if((MC_CadenceResult.Cadence_Dir == MC_Cadence_Backward) ||
-		 (MC_CadenceResult.IsStopFlag == TRUE)		
+	if((CadenceData.Cadence_Dir == MC_Cadence_Backward) ||
+		 (CadenceData.IsStopFlag == TRUE)		
 		)
 	{
 		MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
@@ -802,7 +1322,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	else
 	{
 		/*调节助力比,使用经过踏频信号滤波处理的力矩值*/
-		MC_TorqueProcess_Param.TorqueApp = SenorDataByCadence;
+		MC_TorqueProcess_Param.TorqueApp = CadenceData.torqueByCadence;
 		
 		//按照助力档位调节力矩输入值
 		switch(GearSt)
@@ -1273,7 +1793,7 @@ void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
 		case MC_AssistRunMode_GAS:
 		{
 			//计算FOC控制输入
-			*p_MC_CalParam = MC_AssistRunMode_Gas_Process(p_ADC_SensorData.GasSensor, (MC_GearSt_Struct_t)(GearSt & 0x0F));
+			*p_MC_CalParam = MC_AssistRunMode_Gas_Process(p_ADC_SensorData.GasSensor, MC_CadenceResult.torqueByCadence, (MC_GearSt_Struct_t)(GearSt & 0x0F));
 			//助力模式切换标志复位
 			MC_AssistRunMode_ShiftFlag = RESET;
 			break;
@@ -1296,7 +1816,7 @@ void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
 		case MC_AssistRunMode_CADENCE:
 		{
 			//计算FOC控制输入
-			*p_MC_CalParam = MC_AssistRunMode_Cadence_Process(GearSt);
+			*p_MC_CalParam = MC_AssistRunMode_Cadence_Process(MC_CadenceResult, p_ADC_SensorData.TorqueSensor, GearSt);
 			//助力模式切换标志复位
 			MC_AssistRunMode_ShiftFlag = RESET;
 			break;
@@ -1305,7 +1825,7 @@ void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
 		case MC_AssistRunMode_TORQUE:
 		{
 			//计算FOC控制输入
-			*p_MC_CalParam = MC_AssistRunMode_Torque_Process(p_ADC_SensorData.TorqueSensor, GearSt, MC_CadenceResult.torqueByCadence);
+			*p_MC_CalParam = MC_AssistRunMode_Torque_Process(MC_CadenceResult, p_ADC_SensorData.TorqueSensor, GearSt);
 			//助力模式切换标志复位
 			MC_AssistRunMode_ShiftFlag = RESET;
 			break;

+ 46 - 3
User/Src/protect_check.c

@@ -11,12 +11,54 @@ FlagStatus MC_Protect_OverCurrentTrig_Flag = RESET;
 
 /******************************局部函数定义******************************/
 //低压保护检测
-void MC_Protect_UnderVoltage_Process(uint16_t BusVoltage, uint8_t DesignVoltage, uint16_t UV_TH, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
+void MC_Protect_UnderVoltage_Process(uint16_t BusVoltage, uint8_t DesignVoltage, uint16_t UV_TH, TrueOrFalse_Flag_Struct_t BMS_Com_OK_Flag, uint16_t BMS_RC, BMS_STATUS_Struct_t BMS_Status, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
 {
   static uint32_t uvTimeCnt = 0;
 	static uint32_t uvFaultTimeCnt = 0;
 	uint16_t UV_Voltage = 0;
 	
+	//电池通讯正常时,根据剩余容量提示低电量警告,警告延时10s
+	if(BMS_Com_OK_Flag == TRUE)
+	{
+		static uint32_t uvAlarmTimeCnt = 0;
+		static FlagStatus AlarmFlag = RESET;
+		
+		if(BMS_Status.Status_Bit.Charge == 1)//充电状态,清除标志
+		{
+	  	p_MC_ErrorCode->ERROR_Bit.Protect_UnderVoltage = 0;
+			return;
+		}
+		
+		if(p_MC_ErrorCode->ERROR_Bit.Protect_UnderVoltage == 0)
+		{
+			if(AlarmFlag == RESET) // 只出现一次警告,10s后自动消失
+			{
+				if(BMS_RC < 200)
+				{
+					p_MC_ErrorCode->ERROR_Bit.Protect_UnderVoltage = 1;
+					//记录故障日志
+					MC_ErrorLogSaveInfo.NotesInfo1 = 1;
+					MC_ErrorLogSaveInfo.NotesInfo2 = BMS_RunInfo.RC;
+					MC_ErrorLogSaveInfo.NotesInfo3 = BMS_RunInfo.Voltage;
+					ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
+					IsErrorLogSaveInfoUpdateFlag = TRUE;
+					//存储故障次数
+					MC_RunLog1.UV_ProtectCnt++;
+					RunLogSaveIndex = 1;
+					uvAlarmTimeCnt = HAL_GetTick();
+					AlarmFlag = SET;
+				}			
+			}
+		}
+		else
+		{
+			if((HAL_GetTick() - uvAlarmTimeCnt) > 10000)
+			{
+				p_MC_ErrorCode->ERROR_Bit.Protect_UnderVoltage = 0;
+			}
+		}		
+	}
+	
 	//根据额定电压更新保护阈值
 	switch(DesignVoltage)
 	{
@@ -52,6 +94,7 @@ void MC_Protect_UnderVoltage_Process(uint16_t BusVoltage, uint8_t DesignVoltage,
 		{
 			p_MC_ErrorCode->ERROR_Bit.Protect_UnderVoltage = 1;
 			//记录故障日志
+			MC_ErrorLogSaveInfo.NotesInfo1 = 2;
 			ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
 			IsErrorLogSaveInfoUpdateFlag = TRUE;
 			//存储故障次数
@@ -393,8 +436,8 @@ void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCod
 void MC_Protect_Check_Process(void)
 {
 	//低压保护检测
-	MC_Protect_UnderVoltage_Process(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, ((MC_ConfigParam1.UV_Protect_TH == 0) ? 3100 : MC_ConfigParam1.UV_Protect_TH), &MC_ErrorCode);
-
+	MC_Protect_UnderVoltage_Process(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, ((MC_ConfigParam1.UV_Protect_TH == 0) ? 3100 : MC_ConfigParam1.UV_Protect_TH), IsComOK_BMS.IsOK_Flag, BMS_RunInfo.RC, BMS_RunInfo.Status, &MC_ErrorCode);
+	
 	//过压保护检测
 	MC_Protect_OverVoltage_Process(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, &MC_ErrorCode);
 

+ 2 - 2
User/Src/tim.c

@@ -438,12 +438,12 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
 		  	//꽝옘令�땍
 				switch(MC_CalParam.AssistRunMode)
 				{
-				  case MC_AssistRunMode_TORQUE://제앤친駕
+				  case MC_AssistRunMode_TORQUE: case MC_AssistRunMode_CADENCE: //제앤친駕
 					{
 					  FOC_Model(MC_CalParam.Ref_Torque, MC_RunInfo.MotorSpeed, MC_HallSensorData.SVM_Angle);
 						break;
 					}
-					case MC_AssistRunMode_WALK: case MC_AssistRunMode_CADENCE: case MC_AssistRunMode_GAS://醵똑친駕
+					case MC_AssistRunMode_WALK: case MC_AssistRunMode_GAS://醵똑친駕
 					{
   				  FOC_Model(MC_CalParam.Ref_Speed, MC_RunInfo.MotorSpeed, MC_HallSensorData.SVM_Angle);
 						break;

+ 4 - 2
User/Src/var.c

@@ -3,6 +3,7 @@
 MC_RunInfo_Struct_t MC_RunInfo;                           //MC运行信息
 MC_ErrorCode_Struct_t MC_ErrorCode;                       //MC故障代码
 MC_VerInfo_Struct_t MC_VerInfo;                           //MC版本信息
+char Firmware_Special[32];                                //MC软件版本特性说明
 OnLine_Status_Struct_t DeviceOnLine_Status;               //设备在线检测结果
 BMS_RunInfo_Struct_t BMS_RunInfo;                         //BMS运行信息
 Device_CheckInfo_Struct_t BMS_CheckInfo;                  //BMS授权校验
@@ -228,7 +229,7 @@ const nGearParam_Struct_t GearParam_Default_TURBO_Volans =
 const nGearParam_Struct_t GearParam_Default_SMART_Volans =
 {
   (uint16_t)0,
-	(uint16_t)980,
+	(uint16_t)500,
 	(uint16_t)100,
 	(uint16_t)2100,
 	(uint8_t)4,
@@ -289,7 +290,7 @@ const nGearParam_Struct_t GearParam_Default_TURBO_Volans_Plus =
 const nGearParam_Struct_t GearParam_Default_SMART_Volans_Plus =
 {
   (uint16_t)0,
-	(uint16_t)960,
+	(uint16_t)500,
 	(uint16_t)100,
 	(uint16_t)2100,
 	(uint8_t)4,
@@ -489,6 +490,7 @@ void Var_Init(void)
 	//MC版本信息初始化,Mode和SN从EEPROM读取
   strncpy(MC_VerInfo.HW_Version, (char*)"QD007G.         ", 16);
 	strncpy(MC_VerInfo.FW_Version, (char*)"V2r1r5_20200904.", 16);
+	strncpy(Firmware_Special, (char*)"TC033001A-V1.                   ", 32);
 		
 	//电机型号
 	strncpy(MC_VerInfo.Mode, (char*)"VL6500 & VS7500.", 16);

+ 10 - 1
修改说明.txt

@@ -329,7 +329,16 @@ V2.1.5_20200903
 1、优化开机时刻初始续航里程的计算,根据电池通讯状态计算,解决轮子转5圈后续航跳变的问题;
 2、软件版本:V2r1r5_20200904
 
-
+2.1.5_20200904 TC033001A-V1
+1、指拨信号增加滤波延时,解决松开指拨时电机撞击的声音;
+2、解决踏频模式不计算续航的问题;
+3、增加变量Firmware_Special,用于存储程序版本特性,并通过CAN发出;
+4、增加踏频模式的处理,踏频按照低于50,大于50低于90,大于90分开处理;
+5、指拨模式调整各个档位的加速曲线;
+6、低压保护增加当电池通信正常时,根据RC低于200mAh的警告,延时10s;
+7、踏频模式按照力矩给定;
+8、调整SMART档位的助力参数;
+9、版本号:V2.1.5_20200904 TC033001A-V1