Skip to content

Commit

Permalink
boards: add CandleLightFD
Browse files Browse the repository at this point in the history
  • Loading branch information
lichtfeind authored and marckleinebudde committed Jun 10, 2024
1 parent c9ddf81 commit 6c53ee4
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ set(TGTF407_LIST
set(TGTG0B1_LIST
"CONVERTDEVICE_xCANFD"
"budgetcan"
"candleLightFD"
"nucleo_g0b1re"
)

Expand Down
12 changes: 12 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ THE SOFTWARE.
#define NUM_CAN_CHANNEL 2
#define CONFIG_CANFD 1

#elif defined(BOARD_candleLightFD)
#define USBD_PRODUCT_STRING_FS "candleLightFD gs_usb"
#define USBD_MANUFACTURER_STRING "candleLightFD"
#define DFU_INTERFACE_STRING_FS "candleLightFD 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_nucleo_g0b1re)
#define USBD_PRODUCT_STRING_FS "NUCLEO-G0B1RE gs_usb"
#define USBD_MANUFACTURER_STRING "STMicroelectronics"
Expand Down
181 changes: 181 additions & 0 deletions src/boards/g0b1-candleLightFD.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 Pengutronix,
* Marc Kleine-Budde <[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 PA3
* LEX_TX PA4
* UART_TX PA9
* UART_RX PA10
* USB_P PA12
* USB_N PA11
* CAN1_RX PD0
* CAN1_TX PD1
* CAN1_S PA15
* CAN2_RX PB0
* CAN2_TX PB1
* CAN2_S PB2
*/

#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_3
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_Active_High 1

#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_4
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_Active_High 1

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

UNUSED(hcan);

__HAL_RCC_GPIOA_CLK_ENABLE();
#if NUM_CAN_CHANNEL == 2
__HAL_RCC_GPIOB_CLK_ENABLE();
#endif
__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(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

#if NUM_CAN_CHANNEL == 2
HAL_GPIO_WritePin(GPIOB, 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(GPIOB, &GPIO_InitStruct);
#endif

/* 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);

#if NUM_CAN_CHANNEL == 2
/* 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);
#endif
}

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

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

const struct BoardConfig config = {
.setup = candlelightfd_setup,
.phy_power_set = candlelightfd_phy_power_set,
.termination_set = candlelightfd_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,
},
},
},
#if NUM_CAN_CHANNEL == 2
.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,
},
},
},
#endif
};

0 comments on commit 6c53ee4

Please sign in to comment.