-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9ddf81
commit 6c53ee4
Showing
3 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |