Skip to content

Commit f8c77f5

Browse files
committed
stm32f1: usb: init usb ios, usb stack, and run usb stack task
Signed-off-by: Rafael Silva <[email protected]>
1 parent 390441e commit f8c77f5

File tree

1 file changed

+41
-0
lines changed
  • src/targets/stm32f1-generic

1 file changed

+41
-0
lines changed

Diff for: src/targets/stm32f1-generic/main.c

+41
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,30 @@
55

66
#include <stm32f1xx.h>
77

8+
#include "platform/stm32f1/dbg.h"
89
#include "platform/stm32f1/flash.h"
10+
#include "platform/stm32f1/gpio.h"
911
#include "platform/stm32f1/rcc.h"
1012
#include "platform/stm32f1/systick.h"
13+
#include "platform/stm32f1/usb.h"
14+
15+
#include "util/data.h"
16+
#include "util/types.h"
17+
18+
#define CFG_TUSB_CONFIG_FILE "targets/stm32f1-generic/tusb_config.h"
19+
#include "tusb.h"
20+
21+
#define OI_MOUSE_REPORT_ID 0x01
22+
23+
struct output_report {
24+
u8 id;
25+
s8 x;
26+
s8 y;
27+
s8 wheel;
28+
u8 button1 : 1;
29+
u8 button2 : 1;
30+
u8 button3 : 1;
31+
} __attribute__((__packed__));
1132

1233
int main()
1334
{
@@ -16,4 +37,24 @@ int main()
1637
rcc_init(EXTERNAL_CLOCK_VALUE);
1738

1839
systick_init();
40+
41+
struct gpio_config_t gpio_config;
42+
struct gpio_pin_t usb_dm_io = {.port = GPIO_PORT_A, .pin = 11};
43+
struct gpio_pin_t usb_dp_io = {.port = GPIO_PORT_A, .pin = 12};
44+
struct gpio_pin_t usb_dp_pu_io = USB_DP_PU_IO;
45+
46+
gpio_init_config(&gpio_config);
47+
48+
gpio_setup_pin(&gpio_config, usb_dm_io, GPIO_MODE_INPUT | GPIO_CNF_INPUT_FLOATING, 0); /* USB DM */
49+
gpio_setup_pin(&gpio_config, usb_dp_io, GPIO_MODE_INPUT | GPIO_CNF_INPUT_FLOATING, 0); /* USB DP */
50+
gpio_setup_pin(
51+
&gpio_config, usb_dp_pu_io, GPIO_MODE_OUTPUT_50MHZ | GPIO_CNF_OUTPUT_GENERAL_PUSH_PULL, 0); /* USB DP PU */
52+
53+
gpio_apply_config(gpio_config);
54+
55+
usb_init();
56+
57+
for (;;) {
58+
tud_task();
59+
}
1960
}

0 commit comments

Comments
 (0)