Use FaSTTUBe CAN Abstraction Layer
This commit is contained in:
parent
533a09e5dd
commit
b47d71cf42
|
@ -0,0 +1,3 @@
|
|||
[submodule "Core/Lib/FT_CAN_AL"]
|
||||
path = Core/Lib/FT_CAN_AL
|
||||
url = ssh://git@git.fasttube.de:313/FaSTTUBe/FT_CAN_AL.git
|
|
@ -0,0 +1 @@
|
|||
Subproject commit dc60f07b4a5f019bb1b44d43ea699b9961f143c6
|
|
@ -304,7 +304,7 @@ static void MX_FDCAN1_Init(void) {
|
|||
hfdcan1.Init.DataTimeSeg1 = 1;
|
||||
hfdcan1.Init.DataTimeSeg2 = 1;
|
||||
hfdcan1.Init.MessageRAMOffset = 0;
|
||||
hfdcan1.Init.StdFiltersNbr = 1;
|
||||
hfdcan1.Init.StdFiltersNbr = 32;
|
||||
hfdcan1.Init.ExtFiltersNbr = 0;
|
||||
hfdcan1.Init.RxFifo0ElmtsNbr = 16;
|
||||
hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
|
||||
|
|
|
@ -1,75 +1,29 @@
|
|||
#include "vehicle.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "ui.h"
|
||||
|
||||
#include "FT_CAN_AL.h"
|
||||
|
||||
#include "stm32h7xx.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_fdcan.h"
|
||||
#include "stm32h7xx_hal_gpio.h"
|
||||
#include "tx_api.h"
|
||||
#include "ui.h"
|
||||
|
||||
FDCAN_HandleTypeDef *hcan;
|
||||
|
||||
void vehicle_thread_entry(ULONG hfdcan_addr) {
|
||||
hcan = (void *)hfdcan_addr;
|
||||
ftcan_init((void *)hfdcan_addr);
|
||||
ftcan_add_filter(0x123, 0x7FF);
|
||||
|
||||
FDCAN_FilterTypeDef filter;
|
||||
filter.IdType = FDCAN_STANDARD_ID;
|
||||
filter.FilterIndex = 0;
|
||||
filter.FilterType = FDCAN_FILTER_MASK;
|
||||
filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
|
||||
filter.FilterID1 = 0x123;
|
||||
filter.FilterID2 = 0x7FF;
|
||||
|
||||
if (HAL_FDCAN_ConfigFilter(hcan, &filter) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
// Reject non-matching messages
|
||||
if (HAL_FDCAN_ConfigGlobalFilter(hcan, FDCAN_REJECT, FDCAN_REJECT,
|
||||
FDCAN_REJECT_REMOTE,
|
||||
FDCAN_REJECT_REMOTE) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_FDCAN_Start(hcan)) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_FDCAN_ActivateNotification(hcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) !=
|
||||
HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
FDCAN_TxHeaderTypeDef tx_header;
|
||||
tx_header.IdType = FDCAN_STANDARD_ID;
|
||||
tx_header.TxFrameType = FDCAN_DATA_FRAME;
|
||||
tx_header.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
|
||||
tx_header.BitRateSwitch = FDCAN_BRS_OFF;
|
||||
tx_header.FDFormat = FDCAN_CLASSIC_CAN;
|
||||
tx_header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
|
||||
tx_header.MessageMarker = 0;
|
||||
while (1) {
|
||||
tx_header.Identifier = 0x456;
|
||||
tx_header.DataLength = FDCAN_DLC_BYTES_2;
|
||||
uint8_t data[] = {0xFF, 0xEE};
|
||||
if (HAL_FDCAN_GetTxFifoFreeLevel(hcan) != 0) {
|
||||
HAL_FDCAN_AddMessageToTxFifoQ(hcan, &tx_header, data);
|
||||
}
|
||||
ftcan_transmit(0x456, data, 2);
|
||||
tx_thread_sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan,
|
||||
uint32_t RxFifo0ITs) {
|
||||
if (hfdcan != hcan || (RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) == RESET) {
|
||||
return;
|
||||
}
|
||||
|
||||
static FDCAN_RxHeaderTypeDef header;
|
||||
static uint8_t data[8];
|
||||
if (HAL_FDCAN_GetRxMessage(hcan, FDCAN_RX_FIFO0, &header, data) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
if (header.IdType != FDCAN_STANDARD_ID || header.Identifier == 0x123) {
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
if (id == 0x123) {
|
||||
HAL_GPIO_TogglePin(STATUS2_GPIO_Port, STATUS2_Pin);
|
||||
}
|
||||
}
|
||||
|
|
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Wed Mar 15 18:54:30 CET 2023]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Thu Mar 16 22:32:27 CET 2023]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
|
|
@ -23,6 +23,8 @@ ldscript: STM32H7A3ZITx_FLASH.ld # linker script
|
|||
cDefinitions:
|
||||
- USE_HAL_DRIVER
|
||||
- STM32H7A3xx
|
||||
- STM32H7
|
||||
- FTCAN_NUM_FILTERS=32
|
||||
|
||||
cxxDefinitions:
|
||||
- USE_HAL_DRIVER
|
||||
|
|
|
@ -37,6 +37,7 @@ BUILD_DIR = build
|
|||
# C sources
|
||||
C_SOURCES = \
|
||||
AZURE_RTOS/App/app_azure_rtos.c \
|
||||
Core/Lib/FT_CAN_AL/FT_CAN_AL.c \
|
||||
Core/Src/app.c \
|
||||
Core/Src/app_threadx.c \
|
||||
Core/Src/hx8357d.c \
|
||||
|
@ -446,6 +447,8 @@ AS_DEFS =
|
|||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DFTCAN_NUM_FILTERS=32 \
|
||||
-DSTM32H7 \
|
||||
-DSTM32H7A3xx \
|
||||
-DTX_INCLUDE_USER_DEFINE_FILE \
|
||||
-DUSE_HAL_DRIVER
|
||||
|
@ -465,6 +468,7 @@ AS_INCLUDES = \
|
|||
C_INCLUDES = \
|
||||
-IAZURE_RTOS/App \
|
||||
-ICore/Inc \
|
||||
-ICore/Lib/FT_CAN_AL \
|
||||
-IDrivers/CMSIS/Device/ST/STM32H7xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/STM32H7xx_HAL_Driver/Inc \
|
||||
|
|
|
@ -15,7 +15,7 @@ FDCAN1.NominalSyncJumpWidth=1
|
|||
FDCAN1.NominalTimeSeg1=63
|
||||
FDCAN1.NominalTimeSeg2=16
|
||||
FDCAN1.RxFifo0ElmtsNbr=16
|
||||
FDCAN1.StdFiltersNbr=1
|
||||
FDCAN1.StdFiltersNbr=32
|
||||
FDCAN1.TxFifoQueueElmtsNbr=1
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Show All
|
||||
|
|
Loading…
Reference in New Issue