use unix line endings

Some files have Windows line endings which is annoying, since pathes
won't apply, diffs looks ugly etc. So do convert the few files which
have Windows line endings to use Unix line endings as well.
This commit is contained in:
Jeroen Hofstee 2019-09-28 15:18:22 +02:00 committed by fenugrec
parent 0434e8eeec
commit cd31acce28
9 changed files with 1826 additions and 1826 deletions

View File

@ -1,33 +1,33 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#pragma once #pragma once
#include "usbd_def.h" #include "usbd_def.h"
extern USBD_DescriptorsTypeDef FS_Desc; extern USBD_DescriptorsTypeDef FS_Desc;
extern uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ]; extern uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ];

View File

@ -1,59 +1,59 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include <usbd_def.h> #include <usbd_def.h>
#include <queue.h> #include <queue.h>
#include <led.h> #include <led.h>
#include <can.h> #include <can.h>
#include <gs_usb.h> #include <gs_usb.h>
/* Define these here so they can be referenced in other files */ /* Define these here so they can be referenced in other files */
#define CAN_DATA_MAX_PACKET_SIZE 32 /* Endpoint IN & OUT Packet size */ #define CAN_DATA_MAX_PACKET_SIZE 32 /* Endpoint IN & OUT Packet size */
#define CAN_CMD_PACKET_SIZE 64 /* Control Endpoint Packet size */ #define CAN_CMD_PACKET_SIZE 64 /* Control Endpoint Packet size */
#define USB_CAN_CONFIG_DESC_SIZ 50 #define USB_CAN_CONFIG_DESC_SIZ 50
#define NUM_CAN_CHANNEL 1 #define NUM_CAN_CHANNEL 1
#define USBD_GS_CAN_VENDOR_CODE 0x20 #define USBD_GS_CAN_VENDOR_CODE 0x20
#define DFU_INTERFACE_NUM 1 #define DFU_INTERFACE_NUM 1
#define DFU_INTERFACE_STR_INDEX 0xE0 #define DFU_INTERFACE_STR_INDEX 0xE0
extern USBD_ClassTypeDef USBD_GS_CAN; extern USBD_ClassTypeDef USBD_GS_CAN;
uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_t *q_from_host, led_data_t *leds); uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_t *q_from_host, led_data_t *leds);
void USBD_GS_CAN_SetChannel(USBD_HandleTypeDef *pdev, uint8_t channel, can_data_t* handle); void USBD_GS_CAN_SetChannel(USBD_HandleTypeDef *pdev, uint8_t channel, can_data_t* handle);
bool USBD_GS_CAN_TxReady(USBD_HandleTypeDef *pdev); bool USBD_GS_CAN_TxReady(USBD_HandleTypeDef *pdev);
uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev); uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev);
bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
bool USBD_GS_CAN_CustomInterfaceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); bool USBD_GS_CAN_CustomInterfaceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev); bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev);
uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *frame); uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *frame);
uint8_t USBD_GS_CAN_Transmit(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len); uint8_t USBD_GS_CAN_Transmit(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len);
uint8_t USBD_GS_CAN_GetProtocolVersion(USBD_HandleTypeDef *pdev); uint8_t USBD_GS_CAN_GetProtocolVersion(USBD_HandleTypeDef *pdev);
uint8_t USBD_GS_CAN_GetPadPacketsToMaxPacketSize(USBD_HandleTypeDef *pdev); uint8_t USBD_GS_CAN_GetPadPacketsToMaxPacketSize(USBD_HandleTypeDef *pdev);

View File

@ -1,318 +1,318 @@
/** /**
****************************************************************************** ******************************************************************************
* @file stm32f0xx_hal_conf.h * @file stm32f0xx_hal_conf.h
* @brief HAL configuration file. * @brief HAL configuration file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors * 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * 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 * 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. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
*/ */
/* Define to prevent recursive inclusion -------------------------------------*/ /* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F0xx_HAL_CONF_H #ifndef __STM32F0xx_HAL_CONF_H
#define __STM32F0xx_HAL_CONF_H #define __STM32F0xx_HAL_CONF_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Exported types ------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */ /* ########################## Module Selection ############################## */
/** /**
* @brief This is the list of modules to be used in the HAL driver * @brief This is the list of modules to be used in the HAL driver
*/ */
#define HAL_MODULE_ENABLED #define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_ADC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_CAN_MODULE_ENABLED #define HAL_CAN_MODULE_ENABLED
/*#define HAL_CEC_MODULE_ENABLED */ /*#define HAL_CEC_MODULE_ENABLED */
/*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_TSC_MODULE_ENABLED */ /*#define HAL_TSC_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */ /*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */ /*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */ /*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_LCD_MODULE_ENABLED */ /*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */ /*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */ /*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */ /*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */ /*#define HAL_TIM_MODULE_ENABLED */
/*#define HAL_UART_MODULE_ENABLED */ /*#define HAL_UART_MODULE_ENABLED */
/*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */ /*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */ /*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_PCD_MODULE_ENABLED #define HAL_PCD_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED #define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED #define HAL_FLASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED #define HAL_GPIO_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED
/* ########################## HSE/HSI Values adaptation ##################### */ /* ########################## HSE/HSI Values adaptation ##################### */
/** /**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application. * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency * This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL). * (when HSE is used as system clock source, directly or through the PLL).
*/ */
#if !defined (HSE_VALUE) #if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */ #endif /* HSE_VALUE */
/** /**
* @brief In the following line adjust the External High Speed oscillator (HSE) Startup * @brief In the following line adjust the External High Speed oscillator (HSE) Startup
* Timeout value * Timeout value
*/ */
#if !defined (HSE_STARTUP_TIMEOUT) #if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */ #endif /* HSE_STARTUP_TIMEOUT */
/** /**
* @brief Internal High Speed oscillator (HSI) value. * @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency * This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL). * (when HSI is used as system clock source, directly or through the PLL).
*/ */
#if !defined (HSI_VALUE) #if !defined (HSI_VALUE)
#define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */ #endif /* HSI_VALUE */
/** /**
* @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup * @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup
* Timeout value * Timeout value
*/ */
#if !defined (HSI_STARTUP_TIMEOUT) #if !defined (HSI_STARTUP_TIMEOUT)
#define HSI_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSI start up */ #define HSI_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSI start up */
#endif /* HSI_STARTUP_TIMEOUT */ #endif /* HSI_STARTUP_TIMEOUT */
/** /**
* @brief Internal High Speed oscillator for ADC (HSI14) value. * @brief Internal High Speed oscillator for ADC (HSI14) value.
*/ */
#if !defined (HSI14_VALUE) #if !defined (HSI14_VALUE)
#define HSI14_VALUE ((uint32_t)14000000) /*!< Value of the Internal High Speed oscillator for ADC in Hz. #define HSI14_VALUE ((uint32_t)14000000) /*!< Value of the Internal High Speed oscillator for ADC in Hz.
The real value may vary depending on the variations The real value may vary depending on the variations
in voltage and temperature. */ in voltage and temperature. */
#endif /* HSI14_VALUE */ #endif /* HSI14_VALUE */
/** /**
* @brief Internal High Speed oscillator for USB (HSI48) value. * @brief Internal High Speed oscillator for USB (HSI48) value.
*/ */
#if !defined (HSI48_VALUE) #if !defined (HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz. #define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz.
The real value may vary depending on the variations The real value may vary depending on the variations
in voltage and temperature. */ in voltage and temperature. */
#endif /* HSI48_VALUE */ #endif /* HSI48_VALUE */
/** /**
* @brief Internal Low Speed oscillator (LSI) value. * @brief Internal Low Speed oscillator (LSI) value.
*/ */
#if !defined (LSI_VALUE) #if !defined (LSI_VALUE)
#define LSI_VALUE ((uint32_t)40000) #define LSI_VALUE ((uint32_t)40000)
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations The real value may vary depending on the variations
in voltage and temperature. */ in voltage and temperature. */
/** /**
* @brief External Low Speed oscillator (LSI) value. * @brief External Low Speed oscillator (LSI) value.
*/ */
#if !defined (LSE_VALUE) #if !defined (LSE_VALUE)
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */ #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */ #endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT) #if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */ #endif /* LSE_STARTUP_TIMEOUT */
/* Tip: To avoid modifying this file each time you need to use different HSE, /* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */ === you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */ /* ########################### System Configuration ######################### */
/** /**
* @brief This is the HAL system configuration section * @brief This is the HAL system configuration section
*/ */
#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ #define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */ #define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */
/* Warning: Must be set to higher priority for HAL_Delay() */ /* Warning: Must be set to higher priority for HAL_Delay() */
/* and HAL_GetTick() usage under interrupt context */ /* and HAL_GetTick() usage under interrupt context */
#define USE_RTOS 0 #define USE_RTOS 0
#define PREFETCH_ENABLE 1 #define PREFETCH_ENABLE 1
#define INSTRUCTION_CACHE_ENABLE 0 #define INSTRUCTION_CACHE_ENABLE 0
#define DATA_CACHE_ENABLE 0 #define DATA_CACHE_ENABLE 0
/* ########################## Assert Selection ############################## */ /* ########################## Assert Selection ############################## */
/** /**
* @brief Uncomment the line below to expanse the "assert_param" macro in the * @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code * HAL drivers code
*/ */
/* #define USE_FULL_ASSERT 1 */ /* #define USE_FULL_ASSERT 1 */
/* ################## SPI peripheral configuration ########################## */ /* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver * Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver * Deactivated: CRC code cleaned from driver
*/ */
#define USE_SPI_CRC 0U #define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
/** /**
* @brief Include module's header file * @brief Include module's header file
*/ */
#ifdef HAL_RCC_MODULE_ENABLED #ifdef HAL_RCC_MODULE_ENABLED
#include "stm32f0xx_hal_rcc.h" #include "stm32f0xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */ #endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED #ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32f0xx_hal_gpio.h" #include "stm32f0xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */ #endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED #ifdef HAL_DMA_MODULE_ENABLED
#include "stm32f0xx_hal_dma.h" #include "stm32f0xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */ #endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED #ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32f0xx_hal_cortex.h" #include "stm32f0xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */ #endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED #ifdef HAL_ADC_MODULE_ENABLED
#include "stm32f0xx_hal_adc.h" #include "stm32f0xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */ #endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CAN_MODULE_ENABLED #ifdef HAL_CAN_MODULE_ENABLED
#include "stm32f0xx_hal_can.h" #include "stm32f0xx_hal_can.h"
#endif /* HAL_CAN_MODULE_ENABLED */ #endif /* HAL_CAN_MODULE_ENABLED */
#ifdef HAL_CEC_MODULE_ENABLED #ifdef HAL_CEC_MODULE_ENABLED
#include "stm32f0xx_hal_cec.h" #include "stm32f0xx_hal_cec.h"
#endif /* HAL_CEC_MODULE_ENABLED */ #endif /* HAL_CEC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED #ifdef HAL_COMP_MODULE_ENABLED
#include "stm32f0xx_hal_comp.h" #include "stm32f0xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */ #endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED #ifdef HAL_CRC_MODULE_ENABLED
#include "stm32f0xx_hal_crc.h" #include "stm32f0xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */ #endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED #ifdef HAL_DAC_MODULE_ENABLED
#include "stm32f0xx_hal_dac.h" #include "stm32f0xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */ #endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED #ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32f0xx_hal_flash.h" #include "stm32f0xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */ #endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED #ifdef HAL_I2C_MODULE_ENABLED
#include "stm32f0xx_hal_i2c.h" #include "stm32f0xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */ #endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED #ifdef HAL_I2S_MODULE_ENABLED
#include "stm32f0xx_hal_i2s.h" #include "stm32f0xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */ #endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED #ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32f0xx_hal_irda.h" #include "stm32f0xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */ #endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED #ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32f0xx_hal_iwdg.h" #include "stm32f0xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */ #endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED #ifdef HAL_PCD_MODULE_ENABLED
#include "stm32f0xx_hal_pcd.h" #include "stm32f0xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */ #endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED #ifdef HAL_PWR_MODULE_ENABLED
#include "stm32f0xx_hal_pwr.h" #include "stm32f0xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */ #endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED #ifdef HAL_RTC_MODULE_ENABLED
#include "stm32f0xx_hal_rtc.h" #include "stm32f0xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */ #endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED #ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32f0xx_hal_smartcard.h" #include "stm32f0xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */ #endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED #ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32f0xx_hal_smbus.h" #include "stm32f0xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */ #endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED #ifdef HAL_SPI_MODULE_ENABLED
#include "stm32f0xx_hal_spi.h" #include "stm32f0xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */ #endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED #ifdef HAL_TIM_MODULE_ENABLED
#include "stm32f0xx_hal_tim.h" #include "stm32f0xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */ #endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_TSC_MODULE_ENABLED #ifdef HAL_TSC_MODULE_ENABLED
#include "stm32f0xx_hal_tsc.h" #include "stm32f0xx_hal_tsc.h"
#endif /* HAL_TSC_MODULE_ENABLED */ #endif /* HAL_TSC_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED #ifdef HAL_UART_MODULE_ENABLED
#include "stm32f0xx_hal_uart.h" #include "stm32f0xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */ #endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED #ifdef HAL_USART_MODULE_ENABLED
#include "stm32f0xx_hal_usart.h" #include "stm32f0xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */ #endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED #ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32f0xx_hal_wwdg.h" #include "stm32f0xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */ #endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT
/** /**
* @brief The assert_param macro is used for function's parameters check. * @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function * @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source * which reports the name of the source file and the source
* line number of the call that failed. * line number of the call that failed.
* If expr is true, it returns no value. * If expr is true, it returns no value.
* @retval None * @retval None
*/ */
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line); void assert_failed(uint8_t* file, uint32_t line);
#else #else
#define assert_param(expr) ((void)0) #define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */ #endif /* USE_FULL_ASSERT */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __STM32F0xx_HAL_CONF_H */ #endif /* __STM32F0xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -1,38 +1,38 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#pragma once #pragma once
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
#define USBD_MAX_NUM_INTERFACES 1 #define USBD_MAX_NUM_INTERFACES 1
#define USBD_MAX_NUM_CONFIGURATION 1 #define USBD_MAX_NUM_CONFIGURATION 1
#define USBD_MAX_STR_DESC_SIZ 512 #define USBD_MAX_STR_DESC_SIZ 512
#define USBD_SUPPORT_USER_STRING 1 #define USBD_SUPPORT_USER_STRING 1
#define USBD_SELF_POWERED 0 #define USBD_SELF_POWERED 0
#define DEVICE_FS 0 #define DEVICE_FS 0
#define USBD_ErrLog(...) #define USBD_ErrLog(...)

View File

@ -1,50 +1,50 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
#include "stm32f0xx.h" #include "stm32f0xx.h"
extern PCD_HandleTypeDef hpcd_USB_FS; extern PCD_HandleTypeDef hpcd_USB_FS;
void NMI_Handler(void) void NMI_Handler(void)
{ {
} }
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
while(42) {} while(42) {}
} }
void SysTick_Handler(void) void SysTick_Handler(void)
{ {
HAL_IncTick(); HAL_IncTick();
HAL_SYSTICK_IRQHandler(); HAL_SYSTICK_IRQHandler();
} }
void USB_IRQHandler(void) void USB_IRQHandler(void)
{ {
HAL_PCD_IRQHandler(&hpcd_USB_FS); HAL_PCD_IRQHandler(&hpcd_USB_FS);
} }

View File

@ -1,244 +1,244 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
#include "usbd_def.h" #include "usbd_def.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_gs_can.h" #include "usbd_gs_can.h"
#include "gpio.h" #include "gpio.h"
#include "queue.h" #include "queue.h"
#include "gs_usb.h" #include "gs_usb.h"
#include "can.h" #include "can.h"
#include "led.h" #include "led.h"
#include "dfu.h" #include "dfu.h"
#include "timer.h" #include "timer.h"
#include "flash.h" #include "flash.h"
void HAL_MspInit(void); void HAL_MspInit(void);
void SystemClock_Config(void); void SystemClock_Config(void);
static bool send_to_host_or_enqueue(struct gs_host_frame *frame); static bool send_to_host_or_enqueue(struct gs_host_frame *frame);
static void send_to_host(); static void send_to_host();
can_data_t hCAN; can_data_t hCAN;
USBD_HandleTypeDef hUSB; USBD_HandleTypeDef hUSB;
led_data_t hLED; led_data_t hLED;
queue_t *q_frame_pool; queue_t *q_frame_pool;
queue_t *q_from_host; queue_t *q_from_host;
queue_t *q_to_host; queue_t *q_to_host;
uint32_t received_count=0; uint32_t received_count=0;
int main(void) int main(void)
{ {
uint32_t last_can_error_status = 0; uint32_t last_can_error_status = 0;
HAL_Init(); HAL_Init();
SystemClock_Config(); SystemClock_Config();
flash_load(); flash_load();
gpio_init(); gpio_init();
led_init(&hLED, LED1_GPIO_Port, LED1_Pin, false, LED2_GPIO_Port, LED2_Pin, false); led_init(&hLED, LED1_GPIO_Port, LED1_Pin, false, LED2_GPIO_Port, LED2_Pin, false);
led_set_mode(&hLED, led_mode_off); led_set_mode(&hLED, led_mode_off);
timer_init(); timer_init();
can_init(&hCAN, CAN); can_init(&hCAN, CAN);
can_disable(&hCAN); can_disable(&hCAN);
q_frame_pool = queue_create(CAN_QUEUE_SIZE); q_frame_pool = queue_create(CAN_QUEUE_SIZE);
q_from_host = queue_create(CAN_QUEUE_SIZE); q_from_host = queue_create(CAN_QUEUE_SIZE);
q_to_host = queue_create(CAN_QUEUE_SIZE); q_to_host = queue_create(CAN_QUEUE_SIZE);
struct gs_host_frame *msgbuf = calloc(CAN_QUEUE_SIZE, sizeof(struct gs_host_frame)); struct gs_host_frame *msgbuf = calloc(CAN_QUEUE_SIZE, sizeof(struct gs_host_frame));
for (unsigned i=0; i<CAN_QUEUE_SIZE; i++) { for (unsigned i=0; i<CAN_QUEUE_SIZE; i++) {
queue_push_back(q_frame_pool, &msgbuf[i]); queue_push_back(q_frame_pool, &msgbuf[i]);
} }
USBD_Init(&hUSB, &FS_Desc, DEVICE_FS); USBD_Init(&hUSB, &FS_Desc, DEVICE_FS);
USBD_RegisterClass(&hUSB, &USBD_GS_CAN); USBD_RegisterClass(&hUSB, &USBD_GS_CAN);
USBD_GS_CAN_Init(&hUSB, q_frame_pool, q_from_host, &hLED); USBD_GS_CAN_Init(&hUSB, q_frame_pool, q_from_host, &hLED);
USBD_GS_CAN_SetChannel(&hUSB, 0, &hCAN); USBD_GS_CAN_SetChannel(&hUSB, 0, &hCAN);
USBD_Start(&hUSB); USBD_Start(&hUSB);
#ifdef CAN_S_GPIO_Port #ifdef CAN_S_GPIO_Port
HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_RESET);
#endif #endif
while (1) { while (1) {
struct gs_host_frame *frame = queue_pop_front(q_from_host); struct gs_host_frame *frame = queue_pop_front(q_from_host);
if (frame != 0) { // send can message from host if (frame != 0) { // send can message from host
if (can_send(&hCAN, frame)) { if (can_send(&hCAN, frame)) {
// Echo sent frame back to host // Echo sent frame back to host
frame->timestamp_us = timer_get(); frame->timestamp_us = timer_get();
send_to_host_or_enqueue(frame); send_to_host_or_enqueue(frame);
led_indicate_trx(&hLED, led_2); led_indicate_trx(&hLED, led_2);
} else { } else {
queue_push_front(q_from_host, frame); // retry later queue_push_front(q_from_host, frame); // retry later
} }
} }
if (USBD_GS_CAN_TxReady(&hUSB)) { if (USBD_GS_CAN_TxReady(&hUSB)) {
send_to_host(); send_to_host();
} }
if (can_is_rx_pending(&hCAN)) { if (can_is_rx_pending(&hCAN)) {
struct gs_host_frame *frame = queue_pop_front(q_frame_pool); struct gs_host_frame *frame = queue_pop_front(q_frame_pool);
if (frame != 0) if (frame != 0)
{ {
if (can_receive(&hCAN, frame)) { if (can_receive(&hCAN, frame)) {
received_count++; received_count++;
frame->timestamp_us = timer_get(); frame->timestamp_us = timer_get();
frame->echo_id = 0xFFFFFFFF; // not a echo frame frame->echo_id = 0xFFFFFFFF; // not a echo frame
frame->channel = 0; frame->channel = 0;
frame->flags = 0; frame->flags = 0;
frame->reserved = 0; frame->reserved = 0;
send_to_host_or_enqueue(frame); send_to_host_or_enqueue(frame);
led_indicate_trx(&hLED, led_1); led_indicate_trx(&hLED, led_1);
} }
else else
{ {
queue_push_back(q_frame_pool, frame); queue_push_back(q_frame_pool, frame);
} }
} }
} }
uint32_t can_err = can_get_error_status(&hCAN); uint32_t can_err = can_get_error_status(&hCAN);
if (can_err != last_can_error_status) { if (can_err != last_can_error_status) {
struct gs_host_frame *frame = queue_pop_front(q_frame_pool); struct gs_host_frame *frame = queue_pop_front(q_frame_pool);
if (frame != 0) { if (frame != 0) {
frame->timestamp_us = timer_get(); frame->timestamp_us = timer_get();
if (can_parse_error_status(can_err, frame)) { if (can_parse_error_status(can_err, frame)) {
send_to_host_or_enqueue(frame); send_to_host_or_enqueue(frame);
last_can_error_status = can_err; last_can_error_status = can_err;
} else { } else {
queue_push_back(q_frame_pool, frame); queue_push_back(q_frame_pool, frame);
} }
} }
} }
led_update(&hLED); led_update(&hLED);
if (USBD_GS_CAN_DfuDetachRequested(&hUSB)) { if (USBD_GS_CAN_DfuDetachRequested(&hUSB)) {
dfu_run_bootloader(); dfu_run_bootloader();
} }
} }
} }
void HAL_MspInit(void) void HAL_MspInit(void)
{ {
__HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_SYSCFG_CLK_ENABLE();
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
} }
void SystemClock_Config(void) void SystemClock_Config(void)
{ {
RCC_OscInitTypeDef RCC_OscInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit; RCC_PeriphCLKInitTypeDef PeriphClkInit;
RCC_CRSInitTypeDef RCC_CRSInitStruct; RCC_CRSInitTypeDef RCC_CRSInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct); HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1; |RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
__HAL_RCC_CRS_CLK_ENABLE(); __HAL_RCC_CRS_CLK_ENABLE();
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000);
RCC_CRSInitStruct.ErrorLimitValue = 34; RCC_CRSInitStruct.ErrorLimitValue = 34;
RCC_CRSInitStruct.HSI48CalibrationValue = 32; RCC_CRSInitStruct.HSI48CalibrationValue = 32;
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */ /* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
} }
bool send_to_host_or_enqueue(struct gs_host_frame *frame) bool send_to_host_or_enqueue(struct gs_host_frame *frame)
{ {
if (USBD_GS_CAN_GetProtocolVersion(&hUSB) == 2) { if (USBD_GS_CAN_GetProtocolVersion(&hUSB) == 2) {
queue_push_back(q_to_host, frame); queue_push_back(q_to_host, frame);
return true; return true;
} else { } else {
bool retval = false; bool retval = false;
if ( USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK ) { if ( USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK ) {
queue_push_back(q_frame_pool, frame); queue_push_back(q_frame_pool, frame);
retval = true; retval = true;
} else { } else {
queue_push_back(q_to_host, frame); queue_push_back(q_to_host, frame);
} }
return retval; return retval;
} }
} }
void send_to_host() void send_to_host()
{ {
struct gs_host_frame *frame = queue_pop_front(q_to_host); struct gs_host_frame *frame = queue_pop_front(q_to_host);
if(!frame) if(!frame)
return; return;
if (USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK) { if (USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK) {
queue_push_back(q_frame_pool, frame); queue_push_back(q_frame_pool, frame);
} else { } else {
queue_push_front(q_to_host, frame); queue_push_front(q_to_host, frame);
} }
} }

View File

@ -1,211 +1,211 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#include <stdbool.h> #include <stdbool.h>
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_gs_can.h" #include "usbd_gs_can.h"
PCD_HandleTypeDef hpcd_USB_FS; PCD_HandleTypeDef hpcd_USB_FS;
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{ {
if(hpcd->Instance==USB) { if(hpcd->Instance==USB) {
__HAL_RCC_USB_CLK_ENABLE(); __HAL_RCC_USB_CLK_ENABLE();
HAL_NVIC_SetPriority(USB_IRQn, 1, 0); HAL_NVIC_SetPriority(USB_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(USB_IRQn); HAL_NVIC_EnableIRQ(USB_IRQn);
} }
} }
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd) void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
{ {
if(hpcd->Instance==USB) { if(hpcd->Instance==USB) {
__HAL_RCC_USB_CLK_DISABLE(); __HAL_RCC_USB_CLK_DISABLE();
HAL_NVIC_DisableIRQ(USB_IRQn); HAL_NVIC_DisableIRQ(USB_IRQn);
} }
} }
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
{ {
USBD_HandleTypeDef *pdev = (USBD_HandleTypeDef*)hpcd->pData; USBD_HandleTypeDef *pdev = (USBD_HandleTypeDef*)hpcd->pData;
USBD_ParseSetupRequest((USBD_SetupReqTypedef*)&pdev->request, (uint8_t*)hpcd->Setup); USBD_ParseSetupRequest((USBD_SetupReqTypedef*)&pdev->request, (uint8_t*)hpcd->Setup);
bool request_was_handled = false; bool request_was_handled = false;
if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_DEVICE ) { // device request if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_DEVICE ) { // device request
request_was_handled = USBD_GS_CAN_CustomDeviceRequest(pdev, &pdev->request); request_was_handled = USBD_GS_CAN_CustomDeviceRequest(pdev, &pdev->request);
} }
if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_INTERFACE ) { // interface request if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_INTERFACE ) { // interface request
request_was_handled = USBD_GS_CAN_CustomInterfaceRequest(pdev, &pdev->request); request_was_handled = USBD_GS_CAN_CustomInterfaceRequest(pdev, &pdev->request);
} }
if (!request_was_handled) { if (!request_was_handled) {
USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup);
} }
} }
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
{ {
USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
} }
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
{ {
USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
} }
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
{ {
USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
} }
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
{ {
USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, USBD_SPEED_FULL); USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, USBD_SPEED_FULL);
USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
} }
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
{ {
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
} }
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
{ {
USBD_LL_Resume((USBD_HandleTypeDef*) hpcd->pData); USBD_LL_Resume((USBD_HandleTypeDef*) hpcd->pData);
} }
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{ {
/* Init USB_IP */ /* Init USB_IP */
/* Link The driver to the stack */ /* Link The driver to the stack */
hpcd_USB_FS.pData = pdev; hpcd_USB_FS.pData = pdev;
pdev->pData = &hpcd_USB_FS; pdev->pData = &hpcd_USB_FS;
hpcd_USB_FS.Instance = USB; hpcd_USB_FS.Instance = USB;
hpcd_USB_FS.Init.dev_endpoints = 5; hpcd_USB_FS.Init.dev_endpoints = 5;
hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_64; hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_64;
hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd_USB_FS.Init.low_power_enable = DISABLE; hpcd_USB_FS.Init.low_power_enable = DISABLE;
hpcd_USB_FS.Init.lpm_enable = DISABLE; hpcd_USB_FS.Init.lpm_enable = DISABLE;
HAL_PCD_Init(&hpcd_USB_FS); HAL_PCD_Init(&hpcd_USB_FS);
/* /*
* PMA layout * PMA layout
* 0x00 - 0x17 (24 bytes) metadata? * 0x00 - 0x17 (24 bytes) metadata?
* 0x18 - 0x57 (64 bytes) EP0 OUT * 0x18 - 0x57 (64 bytes) EP0 OUT
* 0x58 - 0x97 (64 bytes) EP0 IN * 0x58 - 0x97 (64 bytes) EP0 IN
* 0x98 - 0xD7 (64 bytes) EP1 IN * 0x98 - 0xD7 (64 bytes) EP1 IN
* 0xD8 - 0x157 (128 bytes) EP1 OUT (buffer 1) * 0xD8 - 0x157 (128 bytes) EP1 OUT (buffer 1)
* 0x158 - 0x1D7 (128 bytes) EP1 OUT (buffer 2) * 0x158 - 0x1D7 (128 bytes) EP1 OUT (buffer 2)
*/ */
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 24); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 24);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0x98); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0x98);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x02 , PCD_DBL_BUF, 0x00D80158); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x02 , PCD_DBL_BUF, 0x00D80158);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
{ {
HAL_PCD_DeInit((PCD_HandleTypeDef*)pdev->pData); HAL_PCD_DeInit((PCD_HandleTypeDef*)pdev->pData);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
{ {
HAL_PCD_Start((PCD_HandleTypeDef*)pdev->pData); HAL_PCD_Start((PCD_HandleTypeDef*)pdev->pData);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
{ {
HAL_PCD_Stop((PCD_HandleTypeDef*) pdev->pData); HAL_PCD_Stop((PCD_HandleTypeDef*) pdev->pData);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
{ {
HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, ep_addr, ep_mps, ep_type); HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, ep_addr, ep_mps, ep_type);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{ {
HAL_PCD_EP_Close((PCD_HandleTypeDef*) pdev->pData, ep_addr); HAL_PCD_EP_Close((PCD_HandleTypeDef*) pdev->pData, ep_addr);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{ {
HAL_PCD_EP_Flush((PCD_HandleTypeDef*) pdev->pData, ep_addr); HAL_PCD_EP_Flush((PCD_HandleTypeDef*) pdev->pData, ep_addr);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{ {
HAL_PCD_EP_SetStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); HAL_PCD_EP_SetStall((PCD_HandleTypeDef*) pdev->pData, ep_addr);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{ {
HAL_PCD_EP_ClrStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); HAL_PCD_EP_ClrStall((PCD_HandleTypeDef*) pdev->pData, ep_addr);
return USBD_OK; return USBD_OK;
} }
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{ {
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
return ((ep_addr & 0x80) == 0x80) return ((ep_addr & 0x80) == 0x80)
? hpcd->IN_ep[ep_addr & 0x7F].is_stall ? hpcd->IN_ep[ep_addr & 0x7F].is_stall
: hpcd->OUT_ep[ep_addr & 0x7F].is_stall; : hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
} }
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
{ {
HAL_PCD_SetAddress((PCD_HandleTypeDef*) pdev->pData, dev_addr); HAL_PCD_SetAddress((PCD_HandleTypeDef*) pdev->pData, dev_addr);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
{ {
HAL_PCD_EP_Transmit((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); HAL_PCD_EP_Transmit((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size);
return USBD_OK; return USBD_OK;
} }
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
{ {
HAL_PCD_EP_Receive((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); HAL_PCD_EP_Receive((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size);
return USBD_OK; return USBD_OK;
} }
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{ {
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr);
} }

View File

@ -1,141 +1,141 @@
/* /*
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "config.h" #include "config.h"
#include "util.h" #include "util.h"
uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
#ifdef USB_SUPPORT_USER_STRING_DESC #ifdef USB_SUPPORT_USER_STRING_DESC
uint8_t *USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); uint8_t *USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
#endif /* USB_SUPPORT_USER_STRING_DESC */ #endif /* USB_SUPPORT_USER_STRING_DESC */
USBD_DescriptorsTypeDef FS_Desc = { USBD_DescriptorsTypeDef FS_Desc = {
USBD_FS_DeviceDescriptor, USBD_FS_DeviceDescriptor,
USBD_FS_LangIDStrDescriptor, USBD_FS_LangIDStrDescriptor,
USBD_FS_ManufacturerStrDescriptor, USBD_FS_ManufacturerStrDescriptor,
USBD_FS_ProductStrDescriptor, USBD_FS_ProductStrDescriptor,
USBD_FS_SerialStrDescriptor, USBD_FS_SerialStrDescriptor,
USBD_FS_ConfigStrDescriptor, USBD_FS_ConfigStrDescriptor,
USBD_FS_InterfaceStrDescriptor, USBD_FS_InterfaceStrDescriptor,
}; };
/* USB_DeviceDescriptor */ /* USB_DeviceDescriptor */
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
0x12, /* bLength */ 0x12, /* bLength */
USB_DESC_TYPE_DEVICE, /* bDescriptorType */ USB_DESC_TYPE_DEVICE, /* bDescriptorType */
0x00, /* bcdUSB */ 0x00, /* bcdUSB */
0x02, 0x02,
0x00, /* bDeviceClass */ 0x00, /* bDeviceClass */
0x00, /* bDeviceSubClass */ 0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */ 0x00, /* bDeviceProtocol */
USB_MAX_EP0_SIZE, /* bMaxPacketSize */ USB_MAX_EP0_SIZE, /* bMaxPacketSize */
LOBYTE(USBD_VID), /* idVendor */ LOBYTE(USBD_VID), /* idVendor */
HIBYTE(USBD_VID), HIBYTE(USBD_VID),
LOBYTE(USBD_PID_FS), /* idProduct */ LOBYTE(USBD_PID_FS), /* idProduct */
HIBYTE(USBD_PID_FS), HIBYTE(USBD_PID_FS),
0x00, /* bcdDevice rel. 0.00 */ 0x00, /* bcdDevice rel. 0.00 */
0x00, 0x00,
USBD_IDX_MFC_STR, /* Index of manufacturer string */ USBD_IDX_MFC_STR, /* Index of manufacturer string */
USBD_IDX_PRODUCT_STR, /* Index of product string */ USBD_IDX_PRODUCT_STR, /* Index of product string */
USBD_IDX_SERIAL_STR, /* Index of serial number string */ USBD_IDX_SERIAL_STR, /* Index of serial number string */
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */ USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
} ; } ;
/* USB Standard Device Descriptor */ /* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
{ {
USB_LEN_LANGID_STR_DESC, USB_LEN_LANGID_STR_DESC,
USB_DESC_TYPE_STRING, USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING), LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING), HIBYTE(USBD_LANGID_STRING),
}; };
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
UNUSED(speed); UNUSED(speed);
*length = sizeof(USBD_FS_DeviceDesc); *length = sizeof(USBD_FS_DeviceDesc);
return USBD_FS_DeviceDesc; return USBD_FS_DeviceDesc;
} }
uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
UNUSED(speed); UNUSED(speed);
*length = sizeof(USBD_LangIDDesc); *length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc; return USBD_LangIDDesc;
} }
uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
UNUSED(speed); UNUSED(speed);
USBD_GetString(USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); USBD_GetString(USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
return USBD_StrDesc; return USBD_StrDesc;
} }
uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
UNUSED(speed); UNUSED(speed);
USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length); USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc; return USBD_StrDesc;
} }
uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
char buf[25]; char buf[25];
UNUSED(speed); UNUSED(speed);
hex32(buf , *(uint32_t*)(UID_BASE )); hex32(buf , *(uint32_t*)(UID_BASE ));
hex32(buf + 8, *(uint32_t*)(UID_BASE + 4)); hex32(buf + 8, *(uint32_t*)(UID_BASE + 4));
hex32(buf + 16, *(uint32_t*)(UID_BASE + 8)); hex32(buf + 16, *(uint32_t*)(UID_BASE + 8));
USBD_GetString((uint8_t*)buf, USBD_StrDesc, length); USBD_GetString((uint8_t*)buf, USBD_StrDesc, length);
return USBD_StrDesc; return USBD_StrDesc;
} }
uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
UNUSED(speed); UNUSED(speed);
USBD_GetString(USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); USBD_GetString(USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
return USBD_StrDesc; return USBD_StrDesc;
} }
uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{ {
UNUSED(speed); UNUSED(speed);
USBD_GetString(USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); USBD_GetString(USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
return USBD_StrDesc; return USBD_StrDesc;
} }

File diff suppressed because it is too large Load Diff