feat: init commit

This commit is contained in:
2025-06-18 18:00:13 +02:00
parent acd96258c1
commit cdd7163db1
25 changed files with 6881 additions and 5873 deletions

68
Software/Core/Inc/can.h Normal file
View File

@ -0,0 +1,68 @@
/*
* can.h
*
* Created on: Jun 12, 2025
* Author: janek
*/
#ifndef INC_CAN_H_
#define INC_CAN_H_
#include "can_halal.h"
#define CAN_ID_TX 0x420
#define CAN_ID_RX_R2D 0x410
#define CAN_ID_RX_AMS 0x00A
typedef union {
struct {
uint8_t ts_inactive : 1;
uint8_t ts_active : 1;
uint8_t ts_precharge : 1;
uint8_t ts_discharge : 1;
uint8_t ts_error : 1;
uint8_t NC1 : 1;
uint8_t NC2 : 1;
uint8_t sdc_closed : 1;
};
uint8_t ams_rx;
} ams_info;
typedef union {
struct {
uint8_t ts_green : 1;
uint8_t imd_error : 1;
uint8_t ams_error : 1;
uint8_t NC1 : 1;
uint8_t NC2 : 1;
uint8_t NC3 : 1;
uint8_t NC4 : 1;
uint8_t NC5 : 1;
};
uint8_t ams_led;
}led_info;
typedef union {
struct {
ams_info ams_status;
led_info led_status;
};
uint16_t ams_bitmask;
} rx_acc;
typedef union{
struct{
uint8_t r2d : 1;
uint8_t tson : 1;
uint8_t racemode : 1;
uint8_t sdc_in : 1;
uint8_t sdc_out : 1;
};
uint8_t dash_send;
}dash_tx_t;
void can_init(CAN_HandleTypeDef* hcan);
void can_send();
void can_rxupdateFrame();
#endif /* INC_CAN_H_ */

View File

@ -0,0 +1,72 @@
#ifndef CAN_HALAL_H
#define CAN_HALAL_H
// Define family macros if none are defined and we recognize a chip macro
#if !defined(STM32F3) && !defined(STM32H7) && !defined(STM32F0)
#if defined(STM32F302x6) || defined(STM32F302x8) || defined(STM32F302xB) || \
defined(STM32F302xC)
#define STM32F3
#endif
#if defined(STM32H7A3xx) || defined(STM32H723xx)
#define STM32H7
#endif
#if defined(STM32F042x6)
#define STM32F0
#endif
#endif
#if defined(STM32F3)
#include "stm32f3xx_hal.h"
#define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13
#elif defined(STM32H7)
#include "stm32h7xx_hal.h"
#define FTCAN_IS_FDCAN
#ifndef FTCAN_NUM_FILTERS
#error "Please configure the number of filters in CubeMX, and then add a compiler define for FTCAN_NUM_FILTERS"
#endif
#elif defined(STM32F0)
#include "stm32f0xx_hal.h"
#define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13
#else
#error "Couldn't detect STM family"
#endif
#if defined(FTCAN_IS_BXCAN)
HAL_StatusTypeDef ftcan_init(CAN_HandleTypeDef *handle);
#elif defined(FTCAN_IS_FDCAN)
HAL_StatusTypeDef ftcan_init(FDCAN_HandleTypeDef *handle);
#else
#error "Unknown CAN peripheral"
#endif
HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data,
size_t datalen);
HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask);
/**
* Define this function to be notified of incoming CAN messages
*/
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
/**
* Read num_bytes bytes from a message (unmarshalled network byte order). The
* msg pointer is advanced by the corresponding number of bytes.
*
* Both methods return a 64-bit integer, but you can safely cast it to a smaller
* integer type.
*/
uint64_t ftcan_unmarshal_unsigned(const uint8_t **data, size_t num_bytes);
int64_t ftcan_unmarshal_signed(const uint8_t **data, size_t num_bytes);
/**
* Write num_bytes to a message (marshalled in network byte order). The pointer
* is advanced by the corresponding number of bytes and returned.
*/
uint8_t *ftcan_marshal_unsigned(uint8_t *data, uint64_t val, size_t num_bytes);
uint8_t *ftcan_marshal_signed(uint8_t *data, int64_t val, size_t num_bytes);
#endif // CAN_HALAL_H

View File

@ -46,7 +46,15 @@ extern "C" {
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
#define R2D_NONE 0x00
#define R2D_TSMS 0x01
#define R2D_TS_ACTIVE 0x02
#define R2D_RESETTING_NODES 0x03
#define R2D_RESETTING_COMMS 0x04
#define R2D_WAITING_INIT 0x05
#define R2D_INIT_STAGE1 0x06
#define R2D_INIT_STAGE2 0x07
#define R2D_INIT_SUCCESS 0x0F
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/

View File

@ -81,7 +81,7 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#define HSE_VALUE ((uint32_t)16000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
/**