Skip to content

Commit

Permalink
add intive GmbH 2C2L-USB board
Browse files Browse the repository at this point in the history
  • Loading branch information
intive-hubert-denkmair authored and marckleinebudde committed Apr 26, 2024
1 parent 76fef6f commit 26ce0dd
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 12 deletions.
34 changes: 31 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ populate_ldscript(CPU_FAMILY STM32G0B1XK
HEAP_SIZE 1k
)

populate_ldscript(CPU_FAMILY STM32G0B1XB
FLASH_START 0x08000000
FLASH_SIZE 128k
RAM_START 0x20000000
RAM_SIZE 144k
STACK_SIZE 2k
HEAP_SIZE 1k
)

######### commands for adding each target have a lot in common: make helper func.
# Split into two categories, F042-based and F072-based.

Expand Down Expand Up @@ -249,15 +258,26 @@ function(add_f407_target TGTNAME)
target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F407xE STM32_USB_Device_Library_STM32F407xE)
endfunction()

function(add_g0b1_target TGTNAME)
function(add_g0b1xk_target TGTNAME)
add_target_common(${TGTNAME} STM32G0B1XK)
target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32G0)
target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_G0})
target_sources(${TGTNAME}_fw PRIVATE "src/boards/g0b1-${TGTNAME}.c")
target_sources(${TGTNAME}_fw PRIVATE "src/can/m_can.c")
target_sources(${TGTNAME}_fw PRIVATE "src/device/device_g0.c")
target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_G0})
target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32G0B1xK STM32_USB_Device_Library_STM32G0B1xK)
target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32G0B1xx STM32_USB_Device_Library_STM32G0B1xx)
endfunction()

function(add_g0b1xb_target TGTNAME)
add_target_common(${TGTNAME} STM32G0B1XB)
target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32G0)
target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_G0})
target_sources(${TGTNAME}_fw PRIVATE "src/boards/g0b1-${TGTNAME}.c")
target_sources(${TGTNAME}_fw PRIVATE "src/can/m_can.c")
target_sources(${TGTNAME}_fw PRIVATE "src/device/device_g0.c")
target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_G0})
target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32G0B1xx STM32_USB_Device_Library_STM32G0B1xx)
endfunction()

########## generate list of targets.
Expand All @@ -266,6 +286,7 @@ set(TGTF042_LIST "cantact" "canalyze" "canable" "usb2can" "cannette")
set(TGTF072_LIST "candleLight" "CANable_MKS" "CONVERTDEVICE_xCAN" "DSD_TECH_SH_C30A" "FYSETC_UCAN")
set(TGTF407_LIST "STM32F4_DevBoard")
set(TGTG0B1_LIST "budgetcan" "CONVERTDEVICE_xCANFD" "nucleo_g0b1re" "candleLightFD")
set(TGTG0B1XB_LIST "2C2L_USB")

foreach (TGTNAME IN LISTS TGTF042_LIST)
option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON)
Expand All @@ -291,7 +312,14 @@ endforeach()
foreach (TGTNAME IN LISTS TGTG0B1_LIST)
option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON)
if (BUILD_${TGTNAME})
add_g0b1_target(${TGTNAME})
add_g0b1xk_target(${TGTNAME})
endif()
endforeach()

foreach (TGTNAME IN LISTS TGTG0B1XB_LIST)
option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON)
if (BUILD_${TGTNAME})
add_g0b1xb_target(${TGTNAME})
endif()
endforeach()

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

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

#define TIM2_CLOCK_SPEED 64000000

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

#elif defined(BOARD_STM32F4_DevBoard)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "STM32F4VE Dev Board"
#define USBD_MANUFACTURER_STRING (uint8_t*) "misc"
Expand Down
8 changes: 4 additions & 4 deletions libs/STM32_HAL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ add_library(STM32_HAL_STM32F407xE STATIC ${STM32F4_SOURCES})
target_compile_options(STM32_HAL_STM32F407xE PRIVATE ${CPUFLAGS_F4} -Wno-unused-parameter)
target_compile_definitions(STM32_HAL_STM32F407xE PUBLIC STM32F407xx HAL_TARGET_PREFIX=stm32f4xx)

add_library(STM32_HAL_STM32G0B1xK STATIC ${STM32G0_SOURCES})
target_include_directories(STM32_HAL_STM32G0B1xK PUBLIC ${INCLUDE_DIRS} include/stm32g0xx)
target_compile_options(STM32_HAL_STM32G0B1xK PRIVATE ${CPUFLAGS_G0} -Wno-unused-parameter)
target_compile_definitions(STM32_HAL_STM32G0B1xK PUBLIC STM32G0B1xx HAL_TARGET_PREFIX=stm32g0xx)
add_library(STM32_HAL_STM32G0B1xx STATIC ${STM32G0_SOURCES})
target_include_directories(STM32_HAL_STM32G0B1xx PUBLIC ${INCLUDE_DIRS} include/stm32g0xx)
target_compile_options(STM32_HAL_STM32G0B1xx PRIVATE ${CPUFLAGS_G0} -Wno-unused-parameter)
target_compile_definitions(STM32_HAL_STM32G0B1xx PUBLIC STM32G0B1xx HAL_TARGET_PREFIX=stm32g0xx)
8 changes: 4 additions & 4 deletions libs/STM32_USB_Device_Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ add_library(STM32_USB_Device_Library_STM32F407xE STATIC ${SOURCES})
target_compile_options(STM32_USB_Device_Library_STM32F407xE PRIVATE ${CPUFLAGS_F4} -Wno-unused-parameter -DSTM32F4)
target_link_libraries(STM32_USB_Device_Library_STM32F407xE PRIVATE STM32_HAL_STM32F407xE)

add_library(STM32_USB_Device_Library_STM32G0B1xK STATIC ${SOURCES})
target_include_directories(STM32_USB_Device_Library_STM32G0B1xK PUBLIC ${INCLUDE_DIRS})
target_compile_options(STM32_USB_Device_Library_STM32G0B1xK PRIVATE ${CPUFLAGS_G0} -Wno-unused-parameter -DSTM32G0)
target_link_libraries(STM32_USB_Device_Library_STM32G0B1xK PRIVATE STM32_HAL_STM32G0B1xK)
add_library(STM32_USB_Device_Library_STM32G0B1xx STATIC ${SOURCES})
target_include_directories(STM32_USB_Device_Library_STM32G0B1xx PUBLIC ${INCLUDE_DIRS})
target_compile_options(STM32_USB_Device_Library_STM32G0B1xx PRIVATE ${CPUFLAGS_G0} -Wno-unused-parameter -DSTM32G0)
target_link_libraries(STM32_USB_Device_Library_STM32G0B1xx PRIVATE STM32_HAL_STM32G0B1xx)
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_GPIOA_CLK_ENABLE();
__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 transiver 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,
},
},
},
};
2 changes: 1 addition & 1 deletion src/device/device_g0.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void device_sysclock_config(void) {
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
#if defined(BOARD_candleLightFD)
#if defined(BOARD_candleLightFD) || defined(BOARD_2C2L_USB)
/* CandleLightFD has an externel 8MHz crystal */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
Expand Down

0 comments on commit 26ce0dd

Please sign in to comment.