+add support for 1 channel PCAN FD adapter ( uses same driver as PRO FD but only 1 channel )

This commit is contained in:
moonglow 2021-01-12 13:45:29 +03:00
parent 8395387bb5
commit 813694014d
4 changed files with 45 additions and 33 deletions

View File

@ -58,12 +58,7 @@ Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \ Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \ Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
$(PROTO)
ifeq ($(CANFD), 1)
C_SOURCES += Src/pcanpro_fd_protocol.c
else
C_SOURCES += Src/pcanpro_protocol.c
endif
# ASM sources # ASM sources
ASM_SOURCES = \ ASM_SOURCES = \
@ -113,9 +108,6 @@ AS_DEFS =
C_DEFS = \ C_DEFS = \
-DUSE_HAL_DRIVER \ -DUSE_HAL_DRIVER \
-DSTM32F407xx -DSTM32F407xx
ifeq ($(CANFD), 1)
C_DEFS += -DPCAN_FD=1
endif
# AS includes # AS includes
@ -136,7 +128,7 @@ C_INCLUDES = \
# compile gcc flags # compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -pedantic -fdata-sections -ffunction-sections ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -pedantic -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -std=c11 -Wall -pedantic -fdata-sections -ffunction-sections CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -std=c11 -Wall -pedantic -fdata-sections -ffunction-sections $(BOARD_FLAGS)
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2 CFLAGS += -g -gdwarf-2
@ -159,13 +151,17 @@ LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all # default action: build all
all: pro pro_fd all: pro pro_fd fd
pro: pro:
$(MAKE) BOARD=pro CANFD=0 DEBUG=0 OPT=-Os elf hex bin $(MAKE) BOARD=pro DEBUG=0 OPT=-Os PROTO=Src/pcanpro_protocol.c BOARD_FLAGS='-DPCAN_PRO=1 -DINCLUDE_LIN_INTERFACE=1' elf hex bin
pro_fd: pro_fd:
$(MAKE) BOARD=pro_fd CANFD=1 DEBUG=0 OPT=-Os elf hex bin $(MAKE) BOARD=pro_fd DEBUG=0 OPT=-Os PROTO=Src/pcanpro_fd_protocol.c BOARD_FLAGS='-DPCAN_PRO_FD=1 -DINCLUDE_LIN_INTERFACE=1' elf hex bin
fd:
$(MAKE) BOARD=fd DEBUG=0 OPT=-Os PROTO=Src/pcanpro_fd_protocol.c BOARD_FLAGS='-DPCAN_FD=1 -DINCLUDE_LIN_INTERFACE=0' elf hex bin
####################################### #######################################
# build the application # build the application
@ -213,6 +209,9 @@ hex: $(HEX_TARGET)
clean: clean:
-rm -fR $(BUILD_DIR)* -rm -fR $(BUILD_DIR)*
clean_obj:
-rm -f $(BUILD_DIR)*/*.o $(BUILD_DIR)*/*.d $(BUILD_DIR)*/*.lst
####################################### #######################################
# dependencies # dependencies
####################################### #######################################

View File

@ -5,7 +5,6 @@
#include "usbd_helper.h" #include "usbd_helper.h"
#include "pcanpro_protocol.h" #include "pcanpro_protocol.h"
#include "pcanpro_usbd.h" #include "pcanpro_usbd.h"
#define INCLUDE_LIN_INTERFACE (1)
static struct t_class_data pcanpro_data = { 0 }; static struct t_class_data pcanpro_data = { 0 };
@ -17,8 +16,10 @@ struct t_pcanpro_description
USB_ENDPOINT_DESCRIPTOR ep2_i0; USB_ENDPOINT_DESCRIPTOR ep2_i0;
USB_ENDPOINT_DESCRIPTOR ep3_i0; USB_ENDPOINT_DESCRIPTOR ep3_i0;
USB_ENDPOINT_DESCRIPTOR ep4_i0; USB_ENDPOINT_DESCRIPTOR ep4_i0;
#if ( PCAN_PRO ) || ( PCAN_PRO_FD )
USB_ENDPOINT_DESCRIPTOR ep5_i0; USB_ENDPOINT_DESCRIPTOR ep5_i0;
USB_ENDPOINT_DESCRIPTOR ep6_i0; USB_ENDPOINT_DESCRIPTOR ep6_i0;
#endif
#if INCLUDE_LIN_INTERFACE #if INCLUDE_LIN_INTERFACE
USB_INTERFACE_DESCRIPTOR if1; USB_INTERFACE_DESCRIPTOR if1;
USB_ENDPOINT_DESCRIPTOR ep1_i1; USB_ENDPOINT_DESCRIPTOR ep1_i1;
@ -74,7 +75,11 @@ __ALIGN_BEGIN static struct t_pcanpro_description pcanpro_dev __ALIGN_END =
.bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE, .bDescriptorType = USB_INTERFACE_DESCRIPTOR_TYPE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
#if ( PCAN_PRO ) || ( PCAN_PRO_FD )
.bNumEndpoints = 6, .bNumEndpoints = 6,
#else
.bNumEndpoints = 4,
#endif
.bInterfaceClass = 0, .bInterfaceClass = 0,
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
@ -116,6 +121,7 @@ __ALIGN_BEGIN static struct t_pcanpro_description pcanpro_dev __ALIGN_END =
.wMaxPacketSize = 64,/* FS: 64, HS: 512 */ .wMaxPacketSize = 64,/* FS: 64, HS: 512 */
.bInterval = 0, .bInterval = 0,
}, },
#if ( PCAN_PRO ) || ( PCAN_PRO_FD )
.ep5_i0 = .ep5_i0 =
{ {
.bLength = sizeof( USB_ENDPOINT_DESCRIPTOR ), .bLength = sizeof( USB_ENDPOINT_DESCRIPTOR ),
@ -134,6 +140,7 @@ __ALIGN_BEGIN static struct t_pcanpro_description pcanpro_dev __ALIGN_END =
.wMaxPacketSize = 64,/* FS: 64, HS: 512 */ .wMaxPacketSize = 64,/* FS: 64, HS: 512 */
.bInterval = 0, .bInterval = 0,
}, },
#endif
#if INCLUDE_LIN_INTERFACE #if INCLUDE_LIN_INTERFACE
/* LIN INTERFACE */ /* LIN INTERFACE */
.if1 = .if1 =
@ -396,12 +403,15 @@ static uint8_t *device_get_user_string( USBD_HandleTypeDef *pdev, uint8_t index,
switch( index ) switch( index )
{ {
case 6: case 6:
#if PCAN_FD #if PCAN_PRO_FD
USBD_GetString((uint8_t *)"PCAN-USB Pro FD LIN", USBD_StrDesc, length ); USBD_GetString((uint8_t *)"PCAN-USB Pro FD LIN", USBD_StrDesc, length );
#else
USBD_GetString((uint8_t *)"PCAN-USB-PRO LIN Device", USBD_StrDesc, length );
#endif
break; break;
#elif PCAN_PRO
USBD_GetString((uint8_t *)"PCAN-USB-PRO LIN Device", USBD_StrDesc, length );
break;
#else
/* fallthrough */
#endif
default: default:
USBD_GetString((uint8_t *)"UNHANDLED", USBD_StrDesc, length ); USBD_GetString((uint8_t *)"UNHANDLED", USBD_StrDesc, length );
break; break;

View File

@ -18,12 +18,14 @@
#define PCAN_USB_EP_MSGIN_CH2 0x83 #define PCAN_USB_EP_MSGIN_CH2 0x83
#if PCAN_FD #if ( PCAN_PRO_FD ) || ( PCAN_FD )
#define PCAN_DATA_PACKET_SIZE (256) #define PCAN_DATA_PACKET_SIZE (256)
#define PCAN_CMD_PACKET_SIZE (128) #define PCAN_CMD_PACKET_SIZE (128)
#else #elif ( PCAN_PRO )
#define PCAN_DATA_PACKET_SIZE (64) #define PCAN_DATA_PACKET_SIZE (64)
#define PCAN_CMD_PACKET_SIZE (512) #define PCAN_CMD_PACKET_SIZE (512)
#else
#error Oops
#endif #endif
struct t_class_data struct t_class_data

View File

@ -6,24 +6,25 @@
#define USBD_VID 0x0c72 #define USBD_VID 0x0c72
#define USBD_LANGID_STRING 1033 #define USBD_LANGID_STRING 1033
#define USBD_MANUFACTURER_STRING "PEAK-System Technik GmbH" #define USBD_MANUFACTURER_STRING "PEAK-System Technik GmbH"
#if PCAN_FD #if PCAN_PRO_FD
#define USBD_PID_HS 0x0011 #define USBD_PID_HS 0x0011
#else
#define USBD_PID_HS 0x000d
#endif
#if PCAN_FD
#define USBD_PRODUCT_STRING_HS "PCAN-USB Pro FD" #define USBD_PRODUCT_STRING_HS "PCAN-USB Pro FD"
#else #define USBD_INTERFACE_CAN_STRING_HS "PCAN-USB Pro FD CAN"
#define USBD_INTERFACE_LIN_STRING_HS "PCAN-USB Pro FD LIN"
#elif PCAN_FD
#define USBD_PID_HS 0x0012
#define USBD_PRODUCT_STRING_HS "PCAN-USB FD"
#define USBD_INTERFACE_CAN_STRING_HS "PCAN-USB FD CAN"
#define USBD_INTERFACE_LIN_STRING_HS "PCAN-USB FD LIN"
#elif PCAN_PRO
#define USBD_PID_HS 0x000d
#define USBD_PRODUCT_STRING_HS "PCAN-USB-PRO" #define USBD_PRODUCT_STRING_HS "PCAN-USB-PRO"
#define USBD_INTERFACE_CAN_STRING_HS "PCAN-USB-PRO CAN Device"
#define USBD_INTERFACE_LIN_STRING_HS "PCAN-USB-PRO LIN Device"
#else
#error Oops
#endif #endif
#define USBD_CONFIGURATION_STRING_HS "Config00" #define USBD_CONFIGURATION_STRING_HS "Config00"
#if PCAN_FD
#define USBD_INTERFACE_CAN_STRING_HS "PCAN-USB Pro FD CAN"
#define USBD_INTERFACE_LIN_STRING_HS "PCAN-USB Pro FD LIN"
#else
#define USBD_INTERFACE_CAN_STRING_HS "PCAN-USB-PRO CAN Device"
#define USBD_INTERFACE_LIN_STRING_HS "PCAN-USB-PRO LIN Device"
#endif
#define USB_SIZ_BOS_DESC 0x0C #define USB_SIZ_BOS_DESC 0x0C