Skip to content

Commit e6fef78

Browse files
fpistmfpr
authored andcommitted
Fist port USB CDC
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 3c7d906 commit e6fef78

File tree

18 files changed

+1403
-95
lines changed

18 files changed

+1403
-95
lines changed

boards.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ Disco.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2
349349
Nucleo_144.menu.USB_interface.enable_USB=None
350350
Nucleo_144.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
351351
Nucleo_144.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
352-
#Nucleo_144.menu.USB_interface.enable_CDC=CDC (if available)
353-
#Nucleo_144.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
352+
Nucleo_144.menu.USB_interface.enable_CDC=CDC (if available)
353+
Nucleo_144.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
354354

355355
Nucleo_64.menu.USB_interface.enable_USB=None
356356
Nucleo_64.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)

cores/arduino/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern void loop( void ) ;
6868
#include "WMath.h"
6969
#include "HardwareSerial.h"
7070
#include "wiring_pulse.h"
71+
#include "usb_serial.h"
7172
#endif // __cplusplus
7273

7374

cores/arduino/stm32/timer.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ uint32_t getTimerIrq(TIM_TypeDef* tim)
563563
*/
564564
void TimerHandleDeinit(stimer_t *obj)
565565
{
566-
HAL_TIM_Base_DeInit(&(obj->handle));
567566
HAL_TIM_Base_Stop_IT(&(obj->handle));
567+
HAL_TIM_Base_DeInit(&(obj->handle));
568568
}
569569

570570
/**
@@ -1024,6 +1024,17 @@ void attachIntHandle(stimer_t *obj, void (*irqHandle)(stimer_t *))
10241024
obj->irqHandle = irqHandle;
10251025
}
10261026

1027+
/**
1028+
* @brief Attached an interrupt handler
1029+
* @param htim : TIM handle
1030+
* @param irqHandle : interrupt handler
1031+
* @retval none
1032+
*/
1033+
void timer_attach_interrupt_handle(TIM_HandleTypeDef *htim, void (*irqHandle)(stimer_t *))
1034+
{
1035+
stimer_t *obj = get_timer_obj(htim);
1036+
obj->irqHandle = irqHandle;
1037+
}
10271038

10281039
/******************************************************************************/
10291040
/* TIMx IRQ HANDLER */

cores/arduino/stm32/timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct timer_s{
157157

158158
void timer_enable_clock(TIM_HandleTypeDef *htim);
159159
void timer_disable_clock(TIM_HandleTypeDef *htim);
160+
void timer_attach_interrupt_handle(TIM_HandleTypeDef *htim, void (*irqHandle)(stimer_t *));
160161

161162
void TimerHandleInit(stimer_t *obj, uint16_t period, uint16_t prescaler);
162163
void TimerHandleDeinit(stimer_t *obj);

cores/arduino/stm32/usb_device_cdc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* <Description>
3+
*
4+
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
5+
* Author: YOUR NAME <> for STMicroelectronics.
6+
*
7+
* License type: GPLv2
8+
*
9+
* This program is free software; you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License version 2 as published by
11+
* the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful, but
14+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE.
16+
* See the GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License along with
19+
* this program. If not, see
20+
* <http://www.gnu.org/licenses/>.
21+
*/
22+
#ifdef USBCON
23+
24+
#ifdef USBD_USE_CDC
25+
#include "usbd_cdc.c"
26+
#endif // USBD_USE_CDC
27+
28+
#endif //USBCON

cores/arduino/stm32/usb_interface.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
#ifdef USBD_USE_HID_COMPOSITE
9696
static USBD_HandleTypeDef hUSBD_Device_HID;
9797
#endif //USBD_USE_HID_COMPOSITE
98+
#ifdef USBD_USE_CDC
99+
volatile USBD_HandleTypeDef hUSBD_Device_CDC;
100+
#endif //USBD_USE_CDC
101+
98102
/**
99103
* @}
100104
*/
@@ -118,16 +122,36 @@ static USBD_HandleTypeDef hUSBD_Device_HID;
118122
*/
119123
void usbd_interface_init(void)
120124
{
125+
#if defined(USBD_USE_HID_COMPOSITE) && defined(USBD_USE_CDC)
126+
#error "Only one of USBD_USE_HID_COMPOSITE or USBD_USE_CDC could be defined!"
127+
#endif
121128
#ifdef USBD_USE_HID_COMPOSITE
122129
/* Init Device Library */
123-
USBD_Init(&hUSBD_Device_HID, &HID_Desc, 0);
130+
USBD_Init(&hUSBD_Device_HID, &HID_Desc, DEVICE_FS);
124131

125132
/* Add Supported Class */
126133
USBD_RegisterClass(&hUSBD_Device_HID, USBD_COMPOSITE_HID_CLASS);
127134

128135
/* Start Device Process */
129136
USBD_Start(&hUSBD_Device_HID);
130137
#endif // USBD_USE_HID_COMPOSITE
138+
#ifdef USBD_USE_CDC
139+
/* Init Device Library */
140+
if (USBD_Init(&hUSBD_Device_CDC, &CDC_Desc, DEVICE_FS) == USBD_OK) {
141+
142+
/* Add Supported Class */
143+
if (USBD_RegisterClass(&hUSBD_Device_CDC, USBD_CDC_CLASS) == USBD_OK) {
144+
145+
/* Add CDC Interface Class */
146+
if (USBD_CDC_RegisterInterface(&hUSBD_Device_CDC, &USBD_Interface_fops_FS) == USBD_OK) {
147+
148+
/* Start Device Process */
149+
USBD_Start(&hUSBD_Device_CDC);
150+
}
151+
}
152+
}
153+
#endif //USBD_USE_CDC
154+
131155
}
132156

133157
/**
@@ -139,6 +163,9 @@ void usbd_interface_mouse_sendReport(uint8_t *report, uint16_t len)
139163
{
140164
#ifdef USBD_USE_HID_COMPOSITE
141165
USBD_HID_MOUSE_SendReport(&hUSBD_Device_HID, report, len);
166+
#else
167+
UNUSED(report);
168+
UNUSED(len);
142169
#endif // USBD_USE_HID_COMPOSITE
143170
}
144171

@@ -151,6 +178,9 @@ void usbd_interface_keyboard_sendReport(uint8_t *report, uint16_t len)
151178
{
152179
#ifdef USBD_USE_HID_COMPOSITE
153180
USBD_HID_KEYBOARD_SendReport(&hUSBD_Device_HID, report, len);
181+
#else
182+
UNUSED(report);
183+
UNUSED(len);
154184
#endif // USBD_USE_HID_COMPOSITE
155185
}
156186

cores/arduino/stm32/usb_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#endif
5454
#endif
5555
#include "usbd_hid_composite.h"
56+
#include "usbd_cdc_if.h"
5657

5758
#ifdef __cplusplus
5859
extern "C" {

0 commit comments

Comments
 (0)