Skip to content

Commit

Permalink
boards: add intive GmbH 2C2L-USB
Browse files Browse the repository at this point in the history
  • Loading branch information
intive-hubert-denkmair authored and marckleinebudde committed Jun 5, 2024
1 parent b6b5262 commit a9fba5b
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ set(TGTF407_LIST
"STM32F4_DevBoard"
)
set(TGTG0B1_LIST
"2C2L_USB"
"CONVERTDEVICE_xCANFD"
"budgetcan"
"candleLightFD"
Expand Down
12 changes: 12 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ THE SOFTWARE.

/*************** STM32G0B1 ***************/

#elif defined(BOARD_2C2L_USB)
#define USBD_PRODUCT_STRING_FS "intive 2C2L-USB gs_usb"
#define USBD_MANUFACTURER_STRING "intive"
#define DFU_INTERFACE_STRING_FS "intive 2C2L-USB firmware upgrade interface"

#define HSE_OSC_SPEED 8000000
#define TIM2_CLOCK_SPEED 64000000

#define CAN_CLOCK_SPEED 40000000
#define NUM_CAN_CHANNEL 2
#define CONFIG_CANFD 1

#elif defined(BOARD_CONVERTDEVICE_xCANFD)
#define USBD_PRODUCT_STRING_FS "ConvertDevice xCANFD"
#define USBD_MANUFACTURER_STRING "ConvertDevice"
Expand Down
174 changes: 174 additions & 0 deletions src/boards/g0b1-2C2L_USB.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
The MIT License (MIT)
Copyright (c) 2023 Pengutronix,
Marc Kleine-Budde <[email protected]>
Copyright (c) 2024 intive GmbH,
Hubert Denkmair <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "board.h"
#include "config.h"
#include "device.h"
#include "gpio.h"
#include "usbd_gs_can.h"

/*
LED_RX PB14
LEX_TX PB13
UART_TX PB6
UART_RX PB7
USB_P PA12
USB_N PA11
CAN1_RX PD0
CAN1_TX PD1
CAN1_S PD2
CAN2_RX PB0
CAN2_TX PB1
CAN2_S PB9
*/

#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_14
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_Active_High 1

#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_13
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_Active_High 1

static void intive2c2lusb_setup(USBD_GS_CAN_HandleTypeDef *hcan)
{
GPIO_InitTypeDef GPIO_InitStruct;

UNUSED(hcan);

__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();

/* LEDs */
HAL_GPIO_WritePin(LEDRX_GPIO_Port, LEDRX_Pin, GPIO_INIT_STATE(LEDRX_Active_High));
GPIO_InitStruct.Pin = LEDRX_Pin;
GPIO_InitStruct.Mode = LEDRX_Mode;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LEDRX_GPIO_Port, &GPIO_InitStruct);

HAL_GPIO_WritePin(LEDTX_GPIO_Port, LEDTX_Pin, GPIO_INIT_STATE(LEDTX_Active_High));
GPIO_InitStruct.Pin = LEDTX_Pin;
GPIO_InitStruct.Mode = LEDTX_Mode;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LEDTX_GPIO_Port, &GPIO_InitStruct);

/* Setup transceiver silent pin */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* FDCAN */

RCC_PeriphCLKInitTypeDef PeriphClkInit = {
.PeriphClockSelection = RCC_PERIPHCLK_FDCAN,
.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL,
};

HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
__HAL_RCC_FDCAN_CLK_ENABLE();

/* FDCAN1_RX, FDCAN1_TX */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF3_FDCAN1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

/* FDCAN2_RX, FDCAN2_TX */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF3_FDCAN2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

static void intive2c2lusb_phy_power_set(can_data_t *channel, bool enable)
{
UNUSED(channel);
UNUSED(enable);
}

static void intive2c2lusb_termination_set(can_data_t *channel, enum gs_can_termination_state enable)
{
UNUSED(channel);
UNUSED(enable);
}

const struct BoardConfig config = {
.setup = intive2c2lusb_setup,
.phy_power_set = intive2c2lusb_phy_power_set,
.termination_set = intive2c2lusb_termination_set,
.channels[0] = {
.interface = FDCAN1,
.leds = {
[LED_RX] = {
.port = LEDRX_GPIO_Port,
.pin = LEDRX_Pin,
.active_high = LEDRX_Active_High,
},
[LED_TX] = {
.port = LEDTX_GPIO_Port,
.pin = LEDTX_Pin,
.active_high = LEDTX_Active_High,
},
},
},
.channels[1] = {
.interface = FDCAN2,
.leds = {
[LED_RX] = {
.port = LEDRX_GPIO_Port,
.pin = LEDRX_Pin,
.active_high = LEDRX_Active_High,
},
[LED_TX] = {
.port = LEDTX_GPIO_Port,
.pin = LEDTX_Pin,
.active_high = LEDTX_Active_High,
},
},
},
};

0 comments on commit a9fba5b

Please sign in to comment.