Skip to content

Commit edf1c40

Browse files
romainreigniermarckleinebudde
authored andcommitted
boards: add WeActStudio USB2CANFDV1
1 parent cc10270 commit edf1c40

4 files changed

Lines changed: 139 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ set(TGTF407_LIST
448448
set(TGTG0B1_LIST
449449
"2C2L_USB"
450450
"ConvertDevice_xCANFD"
451+
"WeActStudio_USB2CANFDV1"
451452
"budgetcan"
452453
"candleLightFD"
453454
"nucleo_g0b1re"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This is firmware for certain STM32F042x/STM32F072xB-based USB-CAN adapters, nota
1717
- DSD TECH SH-C30A: <https://www.deshide.com/product-details.html?pid=384242&_t=1671089557> (STM32F072xB)
1818
- FYSETC UCAN: <https://www.fysetc.com/products/fysetc-ucan-board-based-on-stm32f072-usb-to-can-adapter-support-with-canable-candlelight-klipper-firmware> (STM32F072xB)
1919
- FalCAN Probe: <https://github.com/AndersBNielsen/FalCAN> (STM32F042C6)
20+
- WeActStudio USB2CANFDV1: https://github.com/WeActStudio/WeActStudio.USB2CANFDV1 (STM32G0B1CBT6)
2021

2122
Of important note is that the common STM32F103 will NOT work with this firmware because its hardware cannot use both USB and CAN simultaneously.
2223
Beware also the smaller packages in the F042 series which map a USB and CAN_TX signal on the same pin and are therefore unusable !

include/config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,18 @@
424424
#define NUM_CAN_CHANNEL 1
425425
#define CONFIG_CANFD 1
426426

427+
#elif defined(BOARD_WeActStudio_USB2CANFDV1)
428+
#define USBD_PRODUCT_STRING_FS "USB2CANFDV1 gs_usb"
429+
#define USBD_MANUFACTURER_STRING "WeActStudio"
430+
#define DFU_INTERFACE_STRING_FS "USB2CANFDV1 firmware upgrade interface"
431+
432+
#define CONFIG_HSE_OSC_SPEED 16000000
433+
#define TIM2_CLOCK_SPEED 64000000
434+
435+
#define CAN_CLOCK_SPEED 40000000
436+
#define NUM_CAN_CHANNEL 1
437+
#define CONFIG_CANFD 1
438+
427439
#elif defined(BOARD_budgetcan)
428440
#define USBD_PRODUCT_STRING_FS "budgetcan gs_usb"
429441
#define USBD_MANUFACTURER_STRING "budgetcan"
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2024,
5+
* Romain Reignier <romain@reignier.sh>
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
#include "board.h"
28+
#include "config.h"
29+
#include "device.h"
30+
#include "gpio.h"
31+
#include "usbd_gs_can.h"
32+
33+
/*
34+
* LED_RX PA0
35+
* LED_TX PA1
36+
* LED_READY PA2
37+
* USB_P PA12
38+
* USB_N PA11
39+
* CAN1_RX PB8
40+
* CAN1_TX PB9
41+
*/
42+
43+
#define LEDRX_GPIO_Port GPIOA
44+
#define LEDRX_Pin GPIO_PIN_0
45+
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
46+
#define LEDRX_Active_High 1
47+
48+
#define LEDTX_GPIO_Port GPIOA
49+
#define LEDTX_Pin GPIO_PIN_1
50+
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
51+
#define LEDTX_Active_High 1
52+
53+
#define LEDREADY_GPIO_Port GPIOA
54+
#define LEDREADY_Pin GPIO_PIN_2
55+
#define LEDREADY_Mode GPIO_MODE_OUTPUT_PP
56+
#define LEDREADY_Active_High 1
57+
58+
static void candlelightfd_setup(USBD_GS_CAN_HandleTypeDef *hcan)
59+
{
60+
GPIO_InitTypeDef GPIO_InitStruct = { };
61+
62+
UNUSED(hcan);
63+
64+
__HAL_RCC_GPIOA_CLK_ENABLE();
65+
__HAL_RCC_GPIOB_CLK_ENABLE();
66+
67+
/* LEDs */
68+
HAL_GPIO_WritePin(LEDRX_GPIO_Port, LEDRX_Pin, GPIO_INIT_STATE(LEDRX_Active_High));
69+
GPIO_InitStruct.Pin = LEDRX_Pin;
70+
GPIO_InitStruct.Mode = LEDRX_Mode;
71+
GPIO_InitStruct.Pull = GPIO_NOPULL;
72+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
73+
HAL_GPIO_Init(LEDRX_GPIO_Port, &GPIO_InitStruct);
74+
75+
HAL_GPIO_WritePin(LEDTX_GPIO_Port, LEDTX_Pin, GPIO_INIT_STATE(LEDTX_Active_High));
76+
GPIO_InitStruct.Pin = LEDTX_Pin;
77+
GPIO_InitStruct.Mode = LEDTX_Mode;
78+
GPIO_InitStruct.Pull = GPIO_NOPULL;
79+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
80+
HAL_GPIO_Init(LEDTX_GPIO_Port, &GPIO_InitStruct);
81+
82+
/* Switch ON the LED READY on start, not driven by the firmware */
83+
HAL_GPIO_WritePin(LEDREADY_GPIO_Port, LEDREADY_Pin, GPIO_INIT_STATE(LEDREADY_Active_High));
84+
GPIO_InitStruct.Pin = LEDREADY_Pin;
85+
GPIO_InitStruct.Mode = LEDREADY_Mode;
86+
GPIO_InitStruct.Pull = GPIO_NOPULL;
87+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
88+
HAL_GPIO_Init(LEDREADY_GPIO_Port, &GPIO_InitStruct);
89+
90+
/* FDCAN */
91+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {
92+
.PeriphClockSelection = RCC_PERIPHCLK_FDCAN,
93+
.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL,
94+
};
95+
96+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
97+
__HAL_RCC_FDCAN_CLK_ENABLE();
98+
99+
/* FDCAN1_RX, FDCAN1_TX */
100+
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
101+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
102+
GPIO_InitStruct.Pull = GPIO_NOPULL;
103+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
104+
GPIO_InitStruct.Alternate = GPIO_AF3_FDCAN1;
105+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
106+
}
107+
108+
const struct board_config config = {
109+
.setup = candlelightfd_setup,
110+
.channel[0] = {
111+
.interface = FDCAN1,
112+
.leds = {
113+
[LED_RX] = {
114+
.port = LEDRX_GPIO_Port,
115+
.pin = LEDRX_Pin,
116+
.active_high = LEDRX_Active_High,
117+
},
118+
[LED_TX] = {
119+
.port = LEDTX_GPIO_Port,
120+
.pin = LEDTX_Pin,
121+
.active_high = LEDTX_Active_High,
122+
},
123+
},
124+
},
125+
};

0 commit comments

Comments
 (0)