Init
This commit is contained in:
commit
a49391b6f4
|
|
@ -0,0 +1,118 @@
|
|||
//
|
||||
// Created by cfif on 17.03.2024.
|
||||
//
|
||||
#include "CanSerialPorts.h"
|
||||
#include "SerialPorts.h"
|
||||
|
||||
//tCanSerialPorts CAN_SERIAL_PORTS;
|
||||
|
||||
void CanHWControlSet(void) {
|
||||
GPIO_InitType GPIO_InitStructure;
|
||||
GPIO_InitStruct(&GPIO_InitStructure);
|
||||
RCC_EnableAPB2PeriphClk( RCC_APB2_PERIPH_GPIOC | RCC_APB2_PERIPH_GPIOD, ENABLE);
|
||||
|
||||
// STB
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitPeripheral(GPIOC, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(GPIOC, GPIO_PIN_2);
|
||||
|
||||
// STB
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitPeripheral(GPIOD, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(GPIOD, GPIO_PIN_9);
|
||||
}
|
||||
|
||||
|
||||
void vCanSerialPorts_InitRCC() {
|
||||
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_CAN1 | RCC_APB1_PERIPH_CAN2, ENABLE);
|
||||
}
|
||||
|
||||
void USB_LP_CAN1_RX0_IRQHandler(void) {
|
||||
CanSerialPortIrqRxProcessing(&SERIAL_PORTS.SerialPortCan1);
|
||||
}
|
||||
|
||||
void vCanSerialPort_InitCAN1(tCanSerialPortNation *env) {
|
||||
GPIO_InitType GPIO_InitStructure;
|
||||
GPIO_InitStruct(&GPIO_InitStructure);
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_GPIOB, ENABLE);
|
||||
|
||||
// Configure CAN1 RX pin
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
|
||||
// Configure CAN1 TX pin
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ConfigPinRemap(GPIO_RMP2_CAN1, ENABLE);
|
||||
|
||||
vCanSerialPortInit(
|
||||
env,
|
||||
CAN1,
|
||||
CAN_BAUD_RATE_250K,
|
||||
0xFF,
|
||||
CAN_STD_ID,
|
||||
0x400,
|
||||
true,
|
||||
0x400,
|
||||
0x00,
|
||||
512,
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void CAN2_RX0_IRQHandler(void) {
|
||||
CanSerialPortIrqRxProcessing(&SERIAL_PORTS.SerialPortCan2);
|
||||
}
|
||||
|
||||
void vCanSerialPort_InitCAN2(tCanSerialPortNation *env) {
|
||||
GPIO_InitType GPIO_InitStructure;
|
||||
GPIO_InitStruct(&GPIO_InitStructure);
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_GPIOD, ENABLE);
|
||||
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_10;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitPeripheral(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitPeripheral(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ConfigPinRemap(GPIO_RMP3_CAN2, ENABLE);
|
||||
|
||||
vCanSerialPortInit(
|
||||
env,
|
||||
CAN2,
|
||||
CAN_BAUD_RATE_250K,
|
||||
0xFF,
|
||||
CAN_STD_ID,
|
||||
0x400,
|
||||
true,
|
||||
0x400,
|
||||
0x00,
|
||||
512,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
void CanSerialPorts_Init() {
|
||||
tCanSerialPorts *env = &CAN_SERIAL_PORTS;
|
||||
|
||||
vCanSerialPorts_InitRCC();
|
||||
CanHWControlSet();
|
||||
|
||||
vCanSerialPort_InitCAN1(&env->can1);
|
||||
env->can1IO = CanPort_GetIo(&env->can1);
|
||||
|
||||
vCanSerialPort_InitCAN2(&env->can2);
|
||||
env->can2IO = CanPort_GetIo(&env->can2);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Created by cfif on 17.03.2024.
|
||||
//
|
||||
#include "n32g45x.h"
|
||||
#include "CanSerialPort.h"
|
||||
|
||||
#ifndef NATION_CAN_TEST_CANSERIALPORTS_H
|
||||
#define NATION_CAN_TEST_CANSERIALPORTS_H
|
||||
|
||||
typedef struct {
|
||||
tCanSerialPortNation can1;
|
||||
tSerialPortIO can1IO;
|
||||
|
||||
tCanSerialPortNation can2;
|
||||
tSerialPortIO can2IO;
|
||||
} tCanSerialPorts;
|
||||
|
||||
void CanSerialPorts_Init();
|
||||
void vCanSerialPort_InitCAN1(tCanSerialPortNation *env);
|
||||
void vCanSerialPort_InitCAN2(tCanSerialPortNation *env);
|
||||
extern tCanSerialPorts CAN_SERIAL_PORTS;
|
||||
void vCanSerialPorts_InitRCC();
|
||||
void CanHWControlSet();
|
||||
#endif //NATION_CAN_TEST_CANSERIALPORTS_H
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"dep": [
|
||||
{
|
||||
"type": "git",
|
||||
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
|
||||
"repo": "CanSerialPort_NATION_N32G45x"
|
||||
}
|
||||
],
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"./"
|
||||
],
|
||||
"srcs": [
|
||||
"*.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue