fix(build): update
This commit is contained in:
@@ -4,16 +4,43 @@
|
|||||||
#define configUSE_PREEMPTION 1
|
#define configUSE_PREEMPTION 1
|
||||||
#define configUSE_IDLE_HOOK 0
|
#define configUSE_IDLE_HOOK 0
|
||||||
#define configUSE_TICK_HOOK 0
|
#define configUSE_TICK_HOOK 0
|
||||||
#define configCPU_CLOCK_HZ ((unsigned long)72000000) // 72MHz
|
#define configCPU_CLOCK_HZ ((unsigned long)72000000)
|
||||||
#define configTICK_RATE_HZ ((TickType_t)1000)
|
#define configTICK_RATE_HZ ((TickType_t)1000)
|
||||||
#define configMAX_PRIORITIES (5)
|
#define configMAX_PRIORITIES (5)
|
||||||
#define configMINIMAL_STACK_SIZE ((unsigned short)128)
|
#define configMINIMAL_STACK_SIZE ((unsigned short)128)
|
||||||
#define configTOTAL_HEAP_SIZE ((size_t)(10 * 1024)) // 10KB Heap
|
#define configTOTAL_HEAP_SIZE ((size_t)(10 * 1024))
|
||||||
#define configMAX_TASK_NAME_LEN (16)
|
#define configMAX_TASK_NAME_LEN (16)
|
||||||
#define configUSE_16_BIT_TICKS 0
|
#define configUSE_16_BIT_TICKS 0
|
||||||
#define configIDLE_SHOULD_YIELD 1
|
#define configIDLE_SHOULD_YIELD 1
|
||||||
|
|
||||||
/* Cortex-M3 specific */
|
/* Mutex support - КРИТИЧНО для TinyUSB */
|
||||||
|
#define configUSE_MUTEXES 1
|
||||||
|
#define configUSE_RECURSIVE_MUTEXES 1
|
||||||
|
|
||||||
|
/* Semaphore support */
|
||||||
|
#define configUSE_COUNTING_SEMAPHORES 1
|
||||||
|
|
||||||
|
/* Software timer definitions */
|
||||||
|
#define configUSE_TIMERS 0
|
||||||
|
#define configTIMER_TASK_PRIORITY (2)
|
||||||
|
#define configTIMER_QUEUE_LENGTH 10
|
||||||
|
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2)
|
||||||
|
|
||||||
|
/* Co-routine definitions */
|
||||||
|
#define configUSE_CO_ROUTINES 0
|
||||||
|
#define configMAX_CO_ROUTINE_PRIORITIES (2)
|
||||||
|
|
||||||
|
/* Set the following definitions to 1 to include the API function, or zero to
|
||||||
|
* exclude the API function. */
|
||||||
|
#define INCLUDE_vTaskPrioritySet 1
|
||||||
|
#define INCLUDE_uxTaskPriorityGet 1
|
||||||
|
#define INCLUDE_vTaskDelete 1
|
||||||
|
#define INCLUDE_vTaskCleanUpResources 0
|
||||||
|
#define INCLUDE_vTaskSuspend 1
|
||||||
|
#define INCLUDE_vTaskDelayUntil 1
|
||||||
|
#define INCLUDE_vTaskDelay 1
|
||||||
|
|
||||||
|
/* Cortex-M3 specific definitions */
|
||||||
#define configPRIO_BITS 4
|
#define configPRIO_BITS 4
|
||||||
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
|
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
|
||||||
#define configKERNEL_INTERRUPT_PRIORITY \
|
#define configKERNEL_INTERRUPT_PRIORITY \
|
||||||
@@ -23,9 +50,17 @@
|
|||||||
(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
|
(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
|
||||||
|
|
||||||
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
|
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
|
||||||
* standard names. */
|
* standard names */
|
||||||
#define vPortSVCHandler SVC_Handler
|
#define vPortSVCHandler SVC_Handler
|
||||||
#define xPortPendSVHandler PendSV_Handler
|
#define xPortPendSVHandler PendSV_Handler
|
||||||
#define xPortSysTickHandler SysTick_Handler
|
#define xPortSysTickHandler SysTick_Handler
|
||||||
|
|
||||||
|
/* Normal assert() semantics without relying on the provision of an assert.h
|
||||||
|
* header file. */
|
||||||
|
#define configASSERT(x) \
|
||||||
|
if ((x) == 0) { \
|
||||||
|
taskDISABLE_INTERRUPTS(); \
|
||||||
|
for (;;); \
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* FREERTOS_CONFIG_H */
|
#endif /* FREERTOS_CONFIG_H */
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ extern "C" {
|
|||||||
|
|
||||||
// Выбор MCU и режима
|
// Выбор MCU и режима
|
||||||
#define CFG_TUSB_MCU OPT_MCU_STM32F1
|
#define CFG_TUSB_MCU OPT_MCU_STM32F1
|
||||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
// Специфичная конфигурация для STM32F1 USB FS
|
||||||
|
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
|
||||||
|
|
||||||
// Конфигурация OS (FreeRTOS)
|
// Конфигурация OS (FreeRTOS)
|
||||||
#define CFG_TUSB_OS OPT_OS_FREERTOS
|
#define CFG_TUSB_OS OPT_OS_FREERTOS
|
||||||
@@ -24,6 +25,9 @@ extern "C" {
|
|||||||
// Endpoint буферизация
|
// Endpoint буферизация
|
||||||
#define CFG_TUD_ENDPOINT0_SIZE 64
|
#define CFG_TUD_ENDPOINT0_SIZE 64
|
||||||
|
|
||||||
|
// Отладка
|
||||||
|
#define CFG_TUSB_DEBUG 2
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
408
firmware/App/Src/system_stm32f1xx.c
Normal file
408
firmware/App/Src/system_stm32f1xx.c
Normal file
@@ -0,0 +1,408 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file system_stm32f1xx.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||||
|
*
|
||||||
|
* 1. This file provides two functions and one global variable to be called from
|
||||||
|
* user application:
|
||||||
|
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||||
|
* factors, AHB/APBx prescalers and Flash settings).
|
||||||
|
* This function is called at startup just after reset and
|
||||||
|
* before branch to main program. This call is made inside
|
||||||
|
* the "startup_stm32f1xx_xx.s" file.
|
||||||
|
*
|
||||||
|
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||||
|
* by the user application to setup the SysTick
|
||||||
|
* timer or configure other parameters.
|
||||||
|
*
|
||||||
|
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||||
|
* be called whenever the core clock is changed
|
||||||
|
* during program execution.
|
||||||
|
*
|
||||||
|
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
|
||||||
|
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
|
||||||
|
* configure the system clock before to branch to main program.
|
||||||
|
*
|
||||||
|
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
|
||||||
|
* the product used), refer to "HSE_VALUE".
|
||||||
|
* When HSE is used as system clock source, directly or through PLL, and you
|
||||||
|
* are using different crystal you have to adapt the HSE value to your own
|
||||||
|
* configuration.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017-2021 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup CMSIS
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup stm32f1xx_system
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_Includes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stm32f1xx.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined (HSE_VALUE)
|
||||||
|
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
|
||||||
|
This value can be provided and adapted by the user application. */
|
||||||
|
#endif /* HSE_VALUE */
|
||||||
|
|
||||||
|
#if !defined (HSI_VALUE)
|
||||||
|
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
||||||
|
This value can be provided and adapted by the user application. */
|
||||||
|
#endif /* HSI_VALUE */
|
||||||
|
|
||||||
|
/*!< Uncomment the following line if you need to use external SRAM */
|
||||||
|
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
|
/* #define DATA_IN_ExtSRAM */
|
||||||
|
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||||
|
|
||||||
|
/* Note: Following vector table addresses must be defined in line with linker
|
||||||
|
configuration. */
|
||||||
|
/*!< Uncomment the following line if you need to relocate the vector table
|
||||||
|
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||||
|
remap of boot address selected */
|
||||||
|
/* #define USER_VECT_TAB_ADDRESS */
|
||||||
|
|
||||||
|
#if defined(USER_VECT_TAB_ADDRESS)
|
||||||
|
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||||
|
in Sram else user remap will be done in Flash. */
|
||||||
|
/* #define VECT_TAB_SRAM */
|
||||||
|
#if defined(VECT_TAB_SRAM)
|
||||||
|
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
|
||||||
|
This value must be a multiple of 0x200. */
|
||||||
|
#else
|
||||||
|
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
|
||||||
|
This value must be a multiple of 0x200. */
|
||||||
|
#endif /* VECT_TAB_SRAM */
|
||||||
|
|
||||||
|
#if !defined(VECT_TAB_OFFSET)
|
||||||
|
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table offset field.
|
||||||
|
This value must be a multiple of 0x200. */
|
||||||
|
#endif /* VECT_TAB_OFFSET */
|
||||||
|
|
||||||
|
#endif /* USER_VECT_TAB_ADDRESS */
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This variable is updated in three ways:
|
||||||
|
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||||
|
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||||
|
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||||
|
Note: If you use this function to configure the system clock; then there
|
||||||
|
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||||
|
variable is updated automatically.
|
||||||
|
*/
|
||||||
|
uint32_t SystemCoreClock = 8000000;
|
||||||
|
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||||
|
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
|
#ifdef DATA_IN_ExtSRAM
|
||||||
|
static void SystemInit_ExtMemCtl(void);
|
||||||
|
#endif /* DATA_IN_ExtSRAM */
|
||||||
|
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup STM32F1xx_System_Private_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Setup the microcontroller system
|
||||||
|
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||||
|
* SystemCoreClock variable.
|
||||||
|
* @note This function should be used only after reset.
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemInit (void)
|
||||||
|
{
|
||||||
|
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
|
#ifdef DATA_IN_ExtSRAM
|
||||||
|
SystemInit_ExtMemCtl();
|
||||||
|
#endif /* DATA_IN_ExtSRAM */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Configure the Vector Table location -------------------------------------*/
|
||||||
|
#if defined(USER_VECT_TAB_ADDRESS)
|
||||||
|
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
||||||
|
#endif /* USER_VECT_TAB_ADDRESS */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||||
|
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||||
|
* be used by the user application to setup the SysTick timer or configure
|
||||||
|
* other parameters.
|
||||||
|
*
|
||||||
|
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||||
|
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||||
|
* based on this variable will be incorrect.
|
||||||
|
*
|
||||||
|
* @note - The system frequency computed by this function is not the real
|
||||||
|
* frequency in the chip. It is calculated based on the predefined
|
||||||
|
* constant and the selected clock source:
|
||||||
|
*
|
||||||
|
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||||
|
*
|
||||||
|
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||||
|
*
|
||||||
|
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||||
|
* or HSI_VALUE(*) multiplied by the PLL factors.
|
||||||
|
*
|
||||||
|
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||||
|
* 8 MHz) but the real value may vary depending on the variations
|
||||||
|
* in voltage and temperature.
|
||||||
|
*
|
||||||
|
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||||
|
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
|
||||||
|
* that HSE_VALUE is same as the real frequency of the crystal used.
|
||||||
|
* Otherwise, this function may have wrong result.
|
||||||
|
*
|
||||||
|
* - The result of this function could be not correct when using fractional
|
||||||
|
* value for HSE crystal.
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemCoreClockUpdate (void)
|
||||||
|
{
|
||||||
|
uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
|
||||||
|
|
||||||
|
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||||
|
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
|
||||||
|
#endif /* STM32F105xC */
|
||||||
|
|
||||||
|
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||||
|
uint32_t prediv1factor = 0U;
|
||||||
|
#endif /* STM32F100xB or STM32F100xE */
|
||||||
|
|
||||||
|
/* Get SYSCLK source -------------------------------------------------------*/
|
||||||
|
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||||
|
|
||||||
|
switch (tmp)
|
||||||
|
{
|
||||||
|
case 0x00U: /* HSI used as system clock */
|
||||||
|
SystemCoreClock = HSI_VALUE;
|
||||||
|
break;
|
||||||
|
case 0x04U: /* HSE used as system clock */
|
||||||
|
SystemCoreClock = HSE_VALUE;
|
||||||
|
break;
|
||||||
|
case 0x08U: /* PLL used as system clock */
|
||||||
|
|
||||||
|
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||||
|
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
|
||||||
|
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||||
|
|
||||||
|
#if !defined(STM32F105xC) && !defined(STM32F107xC)
|
||||||
|
pllmull = ( pllmull >> 18U) + 2U;
|
||||||
|
|
||||||
|
if (pllsource == 0x00U)
|
||||||
|
{
|
||||||
|
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||||
|
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||||
|
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||||
|
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||||
|
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||||
|
#else
|
||||||
|
/* HSE selected as PLL clock entry */
|
||||||
|
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
|
||||||
|
{/* HSE oscillator clock divided by 2 */
|
||||||
|
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SystemCoreClock = HSE_VALUE * pllmull;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
pllmull = pllmull >> 18U;
|
||||||
|
|
||||||
|
if (pllmull != 0x0DU)
|
||||||
|
{
|
||||||
|
pllmull += 2U;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||||
|
pllmull = 13U / 2U;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pllsource == 0x00U)
|
||||||
|
{
|
||||||
|
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||||
|
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{/* PREDIV1 selected as PLL clock entry */
|
||||||
|
|
||||||
|
/* Get PREDIV1 clock source and division factor */
|
||||||
|
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||||
|
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||||
|
|
||||||
|
if (prediv1source == 0U)
|
||||||
|
{
|
||||||
|
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||||
|
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{/* PLL2 clock selected as PREDIV1 clock entry */
|
||||||
|
|
||||||
|
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||||
|
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||||
|
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
|
||||||
|
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* STM32F105xC */
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
SystemCoreClock = HSI_VALUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute HCLK clock frequency ----------------*/
|
||||||
|
/* Get HCLK prescaler */
|
||||||
|
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||||
|
/* HCLK clock frequency */
|
||||||
|
SystemCoreClock >>= tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||||
|
/**
|
||||||
|
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
|
||||||
|
* before jump to __main
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#ifdef DATA_IN_ExtSRAM
|
||||||
|
/**
|
||||||
|
* @brief Setup the external memory controller.
|
||||||
|
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
|
||||||
|
* This function configures the external SRAM mounted on STM3210E-EVAL
|
||||||
|
* board (STM32 High density devices). This SRAM will be used as program
|
||||||
|
* data memory (including heap and stack).
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemInit_ExtMemCtl(void)
|
||||||
|
{
|
||||||
|
__IO uint32_t tmpreg;
|
||||||
|
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||||
|
required, then adjust the Register Addresses */
|
||||||
|
|
||||||
|
/* Enable FSMC clock */
|
||||||
|
RCC->AHBENR = 0x00000114U;
|
||||||
|
|
||||||
|
/* Delay after an RCC peripheral clock enabling */
|
||||||
|
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
|
||||||
|
|
||||||
|
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
|
||||||
|
RCC->APB2ENR = 0x000001E0U;
|
||||||
|
|
||||||
|
/* Delay after an RCC peripheral clock enabling */
|
||||||
|
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
|
||||||
|
|
||||||
|
(void)(tmpreg);
|
||||||
|
|
||||||
|
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
||||||
|
/*---------------- SRAM Address lines configuration -------------------------*/
|
||||||
|
/*---------------- NOE and NWE configuration --------------------------------*/
|
||||||
|
/*---------------- NE3 configuration ----------------------------------------*/
|
||||||
|
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
||||||
|
|
||||||
|
GPIOD->CRL = 0x44BB44BBU;
|
||||||
|
GPIOD->CRH = 0xBBBBBBBBU;
|
||||||
|
|
||||||
|
GPIOE->CRL = 0xB44444BBU;
|
||||||
|
GPIOE->CRH = 0xBBBBBBBBU;
|
||||||
|
|
||||||
|
GPIOF->CRL = 0x44BBBBBBU;
|
||||||
|
GPIOF->CRH = 0xBBBB4444U;
|
||||||
|
|
||||||
|
GPIOG->CRL = 0x44BBBBBBU;
|
||||||
|
GPIOG->CRH = 0x444B4B44U;
|
||||||
|
|
||||||
|
/*---------------- FSMC Configuration ---------------------------------------*/
|
||||||
|
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
||||||
|
|
||||||
|
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
||||||
|
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
||||||
|
}
|
||||||
|
#endif /* DATA_IN_ExtSRAM */
|
||||||
|
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
89
firmware/App/Src/usb_descriptors.c
Normal file
89
firmware/App/Src/usb_descriptors.c
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
#include "tusb.h"
|
||||||
|
|
||||||
|
// --- Device Descriptors ---
|
||||||
|
tusb_desc_device_t const desc_device = {
|
||||||
|
.bLength = sizeof(tusb_desc_device_t),
|
||||||
|
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||||
|
.bcdUSB = 0x0200, // USB 2.0
|
||||||
|
.bDeviceClass = TUSB_CLASS_MISC,
|
||||||
|
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||||
|
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||||
|
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||||
|
|
||||||
|
.idVendor = 0xCAFE, // Пример VID
|
||||||
|
.idProduct = 0x4001, // Пример PID
|
||||||
|
.bcdDevice = 0x0100,
|
||||||
|
|
||||||
|
.iManufacturer = 0x01,
|
||||||
|
.iProduct = 0x02,
|
||||||
|
.iSerialNumber = 0x03,
|
||||||
|
|
||||||
|
.bNumConfigurations = 0x01};
|
||||||
|
|
||||||
|
// Invoked when received GET DEVICE DESCRIPTOR
|
||||||
|
uint8_t const* tud_descriptor_device_cb(void) {
|
||||||
|
return (uint8_t const*)&desc_device;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Configuration Descriptor ---
|
||||||
|
enum { ITF_NUM_CDC = 0, ITF_NUM_CDC_DATA, ITF_NUM_TOTAL };
|
||||||
|
|
||||||
|
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
|
||||||
|
|
||||||
|
// Полный конфигурационный дескриптор
|
||||||
|
uint8_t const desc_configuration[] = {
|
||||||
|
// Config number, interface count, string index, total length, attributes,
|
||||||
|
// power in mA
|
||||||
|
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||||
|
|
||||||
|
// Interface number, string index, EP notification address and size, EP data
|
||||||
|
// address (out, in) and size.
|
||||||
|
// EP Notification: 0x81 (In), EP Data Out: 0x02, EP Data In: 0x82 (In)
|
||||||
|
// ВАЖНО: Убедитесь, что номера EP не конфликтуют и поддерживаются железом
|
||||||
|
// F103
|
||||||
|
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, 64)};
|
||||||
|
|
||||||
|
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||||
|
uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
||||||
|
(void)index; // for multiple configurations
|
||||||
|
return desc_configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- String Descriptors ---
|
||||||
|
char const* string_desc_arr[] = {
|
||||||
|
(const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
|
||||||
|
"TinyUSB", // 1: Manufacturer
|
||||||
|
"TinyUSB Device", // 2: Product
|
||||||
|
"123456", // 3: Serials, should use chip ID
|
||||||
|
"TinyUSB CDC", // 4: CDC Interface
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint16_t _desc_str[32];
|
||||||
|
|
||||||
|
// Invoked when received GET STRING DESCRIPTOR request
|
||||||
|
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||||
|
(void)langid;
|
||||||
|
uint8_t chr_count;
|
||||||
|
|
||||||
|
if (index == 0) {
|
||||||
|
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
||||||
|
chr_count = 1;
|
||||||
|
} else {
|
||||||
|
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
const char* str = string_desc_arr[index];
|
||||||
|
|
||||||
|
// Cap at max char
|
||||||
|
chr_count = strlen(str);
|
||||||
|
if (chr_count > 31) chr_count = 31;
|
||||||
|
|
||||||
|
// Convert ASCII string into UTF-16
|
||||||
|
for (uint8_t i = 0; i < chr_count; i++) { _desc_str[1 + i] = str[i]; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// first byte is length (including header), second byte is string type
|
||||||
|
_desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * chr_count + 2);
|
||||||
|
|
||||||
|
return _desc_str;
|
||||||
|
}
|
||||||
@@ -4,7 +4,9 @@ BUILD_DIR = Build
|
|||||||
# --- Исходники ---
|
# --- Исходники ---
|
||||||
# 1. Приложение
|
# 1. Приложение
|
||||||
C_SOURCES = \
|
C_SOURCES = \
|
||||||
App/Src/main.c
|
App/Src/main.c \
|
||||||
|
App/Src/usb_descriptors.c \
|
||||||
|
App/Src/system_stm32f1xx.c \
|
||||||
|
|
||||||
# 2. FreeRTOS
|
# 2. FreeRTOS
|
||||||
C_SOURCES += \
|
C_SOURCES += \
|
||||||
@@ -18,15 +20,12 @@ Middlewares/FreeRTOS/portable/GCC/ARM_CM3/port.c \
|
|||||||
Middlewares/FreeRTOS/portable/MemMang/heap_4.c
|
Middlewares/FreeRTOS/portable/MemMang/heap_4.c
|
||||||
|
|
||||||
# 3. TinyUSB
|
# 3. TinyUSB
|
||||||
# Базовые файлы
|
|
||||||
C_SOURCES += \
|
C_SOURCES += \
|
||||||
Middlewares/TinyUSB/src/tusb.c \
|
Middlewares/TinyUSB/src/tusb.c \
|
||||||
Middlewares/TinyUSB/src/common/tusb_fifo.c \
|
Middlewares/TinyUSB/src/common/tusb_fifo.c \
|
||||||
Middlewares/TinyUSB/src/device/usbd.c \
|
Middlewares/TinyUSB/src/device/usbd.c \
|
||||||
Middlewares/TinyUSB/src/device/usbd_control.c \
|
Middlewares/TinyUSB/src/device/usbd_control.c \
|
||||||
Middlewares/TinyUSB/src/class/cdc/cdc_device.c
|
Middlewares/TinyUSB/src/class/cdc/cdc_device.c \
|
||||||
# Драйвер для STM32 (Portable)
|
|
||||||
C_SOURCES += \
|
|
||||||
Middlewares/TinyUSB/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
|
Middlewares/TinyUSB/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
|
||||||
|
|
||||||
# 4. Startup
|
# 4. Startup
|
||||||
@@ -39,7 +38,7 @@ AS = $(PREFIX)gcc -x assembler-with-cpp
|
|||||||
CP = $(PREFIX)objcopy
|
CP = $(PREFIX)objcopy
|
||||||
SZ = $(PREFIX)size
|
SZ = $(PREFIX)size
|
||||||
|
|
||||||
MCU = -mcpu=cortex-m3 -mthumb -DSTM32F103xB
|
MCU = -mcpu=cortex-m3 -mthumb
|
||||||
|
|
||||||
# Includes
|
# Includes
|
||||||
C_INCLUDES = \
|
C_INCLUDES = \
|
||||||
@@ -50,7 +49,7 @@ C_INCLUDES = \
|
|||||||
-IMiddlewares/FreeRTOS/portable/GCC/ARM_CM3 \
|
-IMiddlewares/FreeRTOS/portable/GCC/ARM_CM3 \
|
||||||
-IMiddlewares/TinyUSB/src
|
-IMiddlewares/TinyUSB/src
|
||||||
|
|
||||||
# TinyUSB config specific defines
|
# Defines
|
||||||
C_DEFS = \
|
C_DEFS = \
|
||||||
-DSTM32F103xB \
|
-DSTM32F103xB \
|
||||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F1
|
-DCFG_TUSB_MCU=OPT_MCU_STM32F1
|
||||||
@@ -62,17 +61,22 @@ LDSCRIPT = stm32f103c8.ld
|
|||||||
LIBS = -lc -lm -lnosys
|
LIBS = -lc -lm -lnosys
|
||||||
LDFLAGS = $(MCU) -T$(LDSCRIPT) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
LDFLAGS = $(MCU) -T$(LDSCRIPT) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||||
|
|
||||||
|
# --- Генерация списка объектов ---
|
||||||
|
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||||
|
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||||
|
|
||||||
|
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
||||||
|
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
||||||
|
|
||||||
# --- Правила сборки ---
|
# --- Правила сборки ---
|
||||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||||
|
|
||||||
# Компиляция C
|
# Компиляция C файлов
|
||||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||||
@mkdir -p $(dir $@)
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
|
||||||
|
|
||||||
# Компиляция ASM
|
# Компиляция ASM файлов
|
||||||
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(AS) -c $(CFLAGS) $< -o $@
|
$(AS) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
# Линковка
|
# Линковка
|
||||||
@@ -80,20 +84,17 @@ $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
|
|||||||
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
||||||
$(SZ) $@
|
$(SZ) $@
|
||||||
|
|
||||||
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/$(TARGET).elf | $(BUILD_DIR)
|
# Генерация HEX
|
||||||
|
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||||
$(CP) -O ihex $< $@
|
$(CP) -O ihex $< $@
|
||||||
|
|
||||||
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/$(TARGET).elf | $(BUILD_DIR)
|
# Генерация BIN
|
||||||
|
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||||
$(CP) -O binary -S $< $@
|
$(CP) -O binary -S $< $@
|
||||||
|
|
||||||
|
# Создание директории Build
|
||||||
$(BUILD_DIR):
|
$(BUILD_DIR):
|
||||||
mkdir $@
|
mkdir -p $@
|
||||||
|
|
||||||
# Генерация списка объектов (автоматически из C_SOURCES)
|
|
||||||
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
|
||||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
|
||||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
|
||||||
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
@@ -101,3 +102,5 @@ clean:
|
|||||||
flash:
|
flash:
|
||||||
st-flash write $(BUILD_DIR)/$(TARGET).bin 0x8000000
|
st-flash write $(BUILD_DIR)/$(TARGET).bin 0x8000000
|
||||||
|
|
||||||
|
.PHONY: all clean flash
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user