Skip to content

Commit

Permalink
Fixed Imports and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
APBashara committed Sep 14, 2024
1 parent 215d4d9 commit 36baf9b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Core/Inc/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief ADC Function Prototypes
***********************************************/

#include "stm32f407xx.h"
#include "stm32f415xx.h"

/**
* @brief Initialize ADC1
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief Prototype Functions for I2C Driver
***********************************************/

#include "stm32f407xx.h"
#include "stm32f415xx.h"

/**
* @brief Initialize I2C1
Expand Down
18 changes: 16 additions & 2 deletions Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ extern "C" {

#include "gpio.h"
#include "can.h"
#include "i2c.h"

/* Macros ------------------------------------------------------------------*/
#define STATUS_LED_PIN 13
#define GPS_ADDR 0x42

/* Data Structures ---------------------------------------------------------*/
typedef struct {
uint16_t RPM; // RPM
Expand Down Expand Up @@ -63,15 +69,23 @@ void Error_Handler(void);
*
* @param argument
*/
void Status_LED(void *argument);
void Status_LED();

/**
* @brief Thread for handling CAN communication
* @note TODO: Implement CAN Task
*
* @param argument
*/
void CAN_Task(void *argument);
void CAN_Task();

/**
* @brief Thread for handling GPS communication
* @note TODO: Implement GPS Task
*
* @param argument
*/
void GPS_Task();

/**
* @brief Main Function to start FreeRTOS and initialize peripherals
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief Prototype Functions for SPI Driver
***********************************************/

#include "stm32f407xx.h"
#include "stm32f415xx.h"

/**
* @brief Initialize SPI2
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/sysclk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief Clock Configuration Prototypes
***********************************************/

#include "stm32f407xx.h"
#include "stm32f415xx.h"

/**
* @brief Configure the System Clock to 168MHz
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief Timer Function Prototypes
***********************************************/

#include "stm32f407xx.h"
#include "stm32f415xx.h"

/**
* @brief Initialize and start Timer 2
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @brief UART Function Prototypes
***********************************************/

#include "stm32f407xx.h"
#include "stm32f415xx.h"

/**
* @brief Initialize USART2
Expand Down
2 changes: 1 addition & 1 deletion Core/Src/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void I2C1_Init() {
GPIOB->AFR[0] |= (0x4 << GPIO_AFRL_AFSEL6_Pos) | (0x4 << GPIO_AFRL_AFSEL7_Pos); // Set PB6 and PB7 to AF4 (I2C)

// Configure I2C1
I2C1->CR1 |= I2C_CR1_ACK; // Enable Acknowledge
I2C1->CR2 = (42u << I2C_CR2_FREQ_Pos); // Set peripheral clock frequency (42 MHz)

// Configure clock control register for 400kHz I2C speed
Expand All @@ -70,6 +69,7 @@ void I2C1_Init() {

// Enable I2C
I2C1->CR1 |= I2C_CR1_PE;
I2C1->CR1 |= I2C_CR1_ACK; // Enable ACK
}

/**
Expand Down
20 changes: 14 additions & 6 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ osThreadId_t StatusLED;
const osThreadAttr_t StatusLED_attr = {
.name = "Status_Task",
.priority = osPriorityBelowNormal,
.stack_size = 128
.stack_size = 128 * 4
};

osThreadId_t CANTask;
const osThreadAttr_t CANTask_attr = {
.name = "CAN_Task",
.priority = osPriorityNormal,
.stack_size = 128
.stack_size = 128 * 4
};

void main() {
Expand All @@ -32,6 +32,7 @@ void main() {
// Initialize Peripherals
Sysclk_168();
LED_Init();
I2C1_Init();
CAN1_Init();
CAN_Filters_Init();
CAN_Start();
Expand All @@ -44,18 +45,25 @@ void main() {
while(1);
}

void Status_LED(void *argument) {
void Status_LED() {
while(1) {
osDelay(100);
Toggle_Pin(GPIOC, 13);
Toggle_Pin(GPIOC, STATUS_LED_PIN);
}
}

void CAN_Task(void *argument) {
volatile CAN_Frame rFrame;
void CAN_Task() {
volatile CAN_Frame rFrame = {
.id = 0x123,
.data = {8, 6, 5, 3, 2, 4, 1, 5},
.dlc = 8,
.rtr = CAN_RTR_Data
};
volatile CAN_Frame tFrame;
volatile CAN_Status Receive;

while(1) {
CAN_Transmit(CAN1, &tFrame);
Receive = CAN_Receive(CAN1, &rFrame);
if (Receive == CAN_OK) {
telemetry.RPM = rFrame.data[0] << 8 | rFrame.data[1];
Expand Down

0 comments on commit 36baf9b

Please sign in to comment.