******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
+#include "util.h"
#include "main.h"
#include "stm32f1xx_hal.h"
+#include "usb.h"
/* USER CODE BEGIN Includes */
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
+struct usb usb;
/* USER CODE END PV */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
+ usb_init(&usb, &hpcd_USB_FS);
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
+
+ // A hack to let USB host reset us
+ LL_GPIO_InitTypeDef gpio;
+ gpio.Pin = LL_GPIO_PIN_12 | LL_GPIO_PIN_13;
+ gpio.Mode = LL_GPIO_MODE_OUTPUT;
+ gpio.Speed = LL_GPIO_SPEED_FREQ_HIGH;
+ gpio.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
+ LL_GPIO_Init(GPIOA, &gpio);
+ LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_12);
+ LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_13);
+ LL_mDelay(1000);
+
MX_I2C1_Init();
MX_I2C2_Init();
MX_USB_PCD_Init();
/* USER CODE BEGIN 2 */
+ usb_start(&usb);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
+ int cnt = 0;
while (1)
{
LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
- LL_mDelay(1000);
+ LL_mDelay(500);
LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
- LL_mDelay(1000);
+ LL_mDelay(500);
+ debug_printf("Counter = %d\n", cnt++);
/* USER CODE END WHILE */
/* USB init function */
static void MX_USB_PCD_Init(void)
{
-
hpcd_USB_FS.Instance = USB;
hpcd_USB_FS.Init.dev_endpoints = 8;
hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
{
_Error_Handler(__FILE__, __LINE__);
}
-
}
/** Configure pins as
GPIO_InitStruct.Pin = LED_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+ GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
LL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
/**/