Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FDCAN to 4MBIT #1397

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion can_bus/quadruna/BMS/BMS_tx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Vitals": {
"msg_id": 100,
"cycle_time": 100,
"cycle_time": 10,
"description": "Vitals message for the BMS.",
"signals": {
"Heartbeat": {
Expand Down
2 changes: 1 addition & 1 deletion can_bus/quadruna/CRIT/CRIT_tx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Vitals": {
"msg_id": 502,
"cycle_time": 100,
"cycle_time": 10,
"description": "CRIT vitals message.",
"signals": {
"Heartbeat": {
Expand Down
2 changes: 1 addition & 1 deletion can_bus/quadruna/FSM/FSM_tx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Vitals": {
"msg_id": 300,
"cycle_time": 100,
"cycle_time": 10,
"description": "FSM vitals message.",
"signals": {
"Heartbeat": {
Expand Down
2 changes: 1 addition & 1 deletion can_bus/quadruna/RSM/RSM_tx.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"Vitals": {
"msg_id": 415,
"cycle_time": 100,
"cycle_time": 10,
"description": "RSM vitals message.",
"signals": {
"Heartbeat": {
Expand Down
2 changes: 1 addition & 1 deletion can_bus/quadruna/VC/VC_tx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Vitals": {
"msg_id": 200,
"cycle_time": 100,
"cycle_time": 10,
"description": "VC vitals message.",
"signals": {
"Heartbeat": {
Expand Down
24 changes: 11 additions & 13 deletions firmware/dev/h7dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ set(ARM_CORE "cm7")
set(IOC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/h7dev.ioc")
set(LINKER_SCRIPT "${LINKER_DIR}/stm32h733vgtx/stm32h733vgtx_app.ld")

file(GLOB_RECURSE EMBEDDED_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
file(GLOB_RECURSE EMBEDDED_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)
list(APPEND EMBEDDED_SRCS
"${SHARED_IO_INCLUDE_DIR}/io_can.c"
"${SHARED_IO_INCLUDE_DIR}/io_canLogging.c"
Expand All @@ -18,23 +21,17 @@ list(APPEND EMBEDDED_SRCS
"${SHARED_IO_INCLUDE_DIR}/io_time.c"
"${SHARED_HW_INCLUDE_DIR}/hw_gpio.c"
)
list(REMOVE_ITEM EMBEDDED_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/cubemx/Src/sysmem.c")

nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS sample.proto)

set(SRCS ${PROTO_SRCS})
set(HDRS ${CMAKE_CURRENT_BINARY_DIR} ${NANOPB_INCLUDE_DIRS})

set(EMBEDDED_INCLUDE_DIRS
"${SHARED_APP_INCLUDE_DIR}"
"${SHARED_IO_INCLUDE_DIR}"
"${SHARED_HW_INCLUDE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/src/io"
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)

# Bootloader files.
file(GLOB_RECURSE BOOT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/boot/*.c")
set(BOOT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/boot/" "${CMAKE_CURRENT_SOURCE_DIR}/boot/cubemx/Inc")
# nanopb nonsense
nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS sample.proto)
set(HDRS ${CMAKE_CURRENT_BINARY_DIR} ${NANOPB_INCLUDE_DIRS})

IF ("${TARGET}" STREQUAL "binary")
generate_stm32cube_code(
Expand Down Expand Up @@ -92,7 +89,7 @@ IF ("${TARGET}" STREQUAL "binary")

embedded_library(
"protobuf_library"
"${SRCS}"
"${PROTO_SRCS}"
"${HDRS}"
"cm7"
TRUE
Expand All @@ -101,6 +98,8 @@ IF ("${TARGET}" STREQUAL "binary")
target_link_libraries("h7dev_app.elf" "h7dev_stm32cube" "protobuf_library" "logfs_cm7")

# Build bootloader.
file(GLOB_RECURSE BOOT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/boot/*.c")
set(BOOT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/boot/" "${CMAKE_CURRENT_SOURCE_DIR}/boot/cubemx/Inc")
stm32h7_boot_binary(
"h7dev_boot"
"${BOOT_SRCS}"
Expand All @@ -118,5 +117,4 @@ IF ("${TARGET}" STREQUAL "binary")
"h7dev_boot.hex"
"${CMAKE_CURRENT_BINARY_DIR}/h7dev_boot.hex"
)

ENDIF ()
147 changes: 50 additions & 97 deletions firmware/dev/h7dev/src/cubemx/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "pb_encode.h"
#include "pb_decode.h"
#include "sample.pb.h"
#include "string.h"
#include "string.h"
#include <string.h>
#include "tasks.h"

#include "hw_hardFaultHandler.h"
#include "hw_can.h"
#include "hw_sd.h"
#include "hw_bootup.h"
#include "hw_uart.h"
#include "io_can.h"
#include "io_canLogging.h"
#include "io_fileSystem.h"
#include "hw_gpio.h"
#include "io_log.h"
#include "hw_utils.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -101,26 +97,23 @@ const osThreadAttr_t canRxTask_attributes = {
.priority = (osPriority_t)osPriorityBelowNormal,
};
/* USER CODE BEGIN PV */

int write_num = 0;
int read_num = 0;
int overflow_num = 0;
static void callback(uint32_t i)
static void overflow_callback(uint32_t i)
{
overflow_num++;
// BREAK_IF_DEBUGGER_CONNECTED();
}

static CanConfig can_config = {
.rx_msg_filter = NULL,
.tx_overflow_callback = callback,
.rx_overflow_callback = callback,
.tx_overflow_callback = overflow_callback,
.rx_overflow_callback = overflow_callback,
};

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_FDCAN2_Init(void);
static void MX_SDMMC1_SD_Init(void);
Expand Down Expand Up @@ -175,6 +168,9 @@ int main(void)
/* Configure the system clock */
SystemClock_Config();

/* Configure the peripherals common clocks */
PeriphCommonClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */
Expand All @@ -186,22 +182,19 @@ int main(void)
MX_FDCAN1_Init();
MX_UART9_Init();
/* USER CODE BEGIN 2 */
// __HAL_DBGMCU_FREEZE_IWDG();
tasks_init();

io_can_init(&can_config);
// __HAL_DBGMCU_FREEZE_IWDG();
hw_hardFaultHandler_init();
io_can_init(&can_config);
hw_can_init(&can);

if (sd_inited)
{
sd.hsd = &hsd1;
sd.timeout = osWaitForever;
int err = io_fileSystem_init();
io_canLogging_init(&can_config);
}

SEGGER_SYSVIEW_Conf();
LOG_INFO("h7dev reset!");
/* USER CODE END 2 */

/* Init scheduler */
Expand Down Expand Up @@ -315,6 +308,32 @@ void SystemClock_Config(void)
}
}

/**
* @brief Peripherals Common Clock Configuration
* @retval None
*/
void PeriphCommonClock_Config(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };

/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_FDCAN;
PeriphClkInitStruct.PLL2.PLL2M = 1;
PeriphClkInitStruct.PLL2.PLL2N = 80;
PeriphClkInitStruct.PLL2.PLL2P = 2;
PeriphClkInitStruct.PLL2.PLL2Q = 8;
PeriphClkInitStruct.PLL2.PLL2R = 2;
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
}

/**
* @brief FDCAN1 Initialization Function
* @param None
Expand Down Expand Up @@ -381,19 +400,19 @@ static void MX_FDCAN2_Init(void)

/* USER CODE END FDCAN2_Init 1 */
hfdcan2.Instance = FDCAN2;
hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan2.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan2.Init.AutoRetransmission = ENABLE;
hfdcan2.Init.TransmitPause = DISABLE;
hfdcan2.Init.ProtocolException = DISABLE;
hfdcan2.Init.NominalPrescaler = 16;
hfdcan2.Init.NominalSyncJumpWidth = 4;
hfdcan2.Init.NominalTimeSeg1 = 13;
hfdcan2.Init.NominalTimeSeg2 = 2;
hfdcan2.Init.NominalPrescaler = 2;
hfdcan2.Init.NominalSyncJumpWidth = 5;
hfdcan2.Init.NominalTimeSeg1 = 34;
hfdcan2.Init.NominalTimeSeg2 = 5;
hfdcan2.Init.DataPrescaler = 1;
hfdcan2.Init.DataSyncJumpWidth = 1;
hfdcan2.Init.DataTimeSeg1 = 1;
hfdcan2.Init.DataTimeSeg2 = 1;
hfdcan2.Init.DataSyncJumpWidth = 5;
hfdcan2.Init.DataTimeSeg1 = 14;
hfdcan2.Init.DataTimeSeg2 = 5;
hfdcan2.Init.MessageRAMOffset = 0;
hfdcan2.Init.StdFiltersNbr = 1;
hfdcan2.Init.ExtFiltersNbr = 0;
Expand Down Expand Up @@ -561,45 +580,7 @@ static void can_msg_received_callback(CanMsg *rx_msg)
void runDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for (;;)
{
// UART modem_uart = { .handle = &huart9 };
// /* Infinite loop */
// // uint8_t message[7] = { 66, 79, 79, 66, 83, 13, 10 };
// // uint8_t num; // use this if just want numbers
// // uint8_t predicData[3];
// // predicData[1] = 13;
// // predicData[2] = 10;
// uint8_t buffer[128];
// uint8_t message_length;
// bool status;

// // SimpleMessage message = SimpleMessage_init_zero;

// for (;;)
// {
// /* Create a stream that will write to our buffer. */
// TelemMessage message = TelemMessage_init_zero;
// pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));

// /* Fill in the lucky number */
// message.can_id = 53;
// message.data = 23;
// message.time_stamp = 9;

// /* Now we are ready to encode the message! */
// status = pb_encode(&stream, TelemMessage_fields, &message);
// message_length = (uint8_t)stream.bytes_written;
// // message_length = stream.bytes_written;
// if (status)
// {
// hw_uart_transmitPoll(&modem_uart, &message_length, 1, 100);
// hw_uart_transmitPoll(&modem_uart, buffer, sizeof(buffer), 100); // fun string
// }
// osDelay(10);
// }
}
tasks_default();
/* USER CODE END 5 */
}

Expand All @@ -613,20 +594,7 @@ void runDefaultTask(void *argument)
void runCanTxTask(void *argument)
{
/* USER CODE BEGIN runCanTxTask */
/* Infinite loop */

for (unsigned int i = 0; i < 10000; i++)
{
CanMsg msg = { .std_id = i, .dlc = 8, .data = { 0, 1, 2, 3, 4, 5, 6, 7 } };
for (int j = 0; j < 6; j++)
{
read_num++;
// io_canLogging_pushTxMsgToQueue(&msg);
}
osDelay(1);
}

osDelay(osWaitForever);
tasks_canTx();
/* USER CODE END runCanTxTask */
}

Expand All @@ -640,22 +608,7 @@ void runCanTxTask(void *argument)
void runCanRxTask(void *argument)
{
/* USER CODE BEGIN runCanRxTask */
/* Infinite loop */
static uint32_t count = 0;
for (;;)
{
// CanMsg msg;
// io_can_popRxMsgFromQueue(&msg);
io_canLogging_recordMsgFromQueue();
write_num++;
count++;

if (count > 256)
{
io_canLogging_sync();
count = 0;
}
}
tasks_canRx();
/* USER CODE END runCanRxTask */
}

Expand Down
Loading
Loading