-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
334 changed files
with
132,560 additions
and
11,651 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.74 MB
.metadata/.plugins/org.eclipse.cdt.core/STM32F103_CAN_LOOPBACK.1727071934467.pdom
Binary file not shown.
1 change: 1 addition & 0 deletions
1
.metadata/.plugins/org.eclipse.cdt.core/STM32F103_CAN_LOOPBACK.language.settings.xml
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
+0 Bytes
(100%)
.metadata/.plugins/org.eclipse.cdt.core/STM32F401_TIMER_OC_PWM1.1727002855546.pdom
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
.metadata/.plugins/org.eclipse.cdt.ui/STM32F103_CAN_LOOPBACK.build.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
21:07:07 **** Incremental Build of configuration Debug for project STM32F103_CAN_LOOPBACK **** | ||
make -j8 all | ||
arm-none-eabi-size STM32F103_CAN_LOOPBACK.elf | ||
text data bss dec hex filename | ||
9944 92 2116 12152 2f78 STM32F103_CAN_LOOPBACK.elf | ||
Finished building: default.size.stdout | ||
|
||
|
||
21:07:07 Build Finished. 0 errors, 0 warnings. (took 231ms) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
173 changes: 173 additions & 0 deletions
173
.metadata/.plugins/org.eclipse.core.resources/.history/0/b0a02d49a079001f1aba9cd76fa6de0c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* | ||
* main.c | ||
* | ||
* Created on: Sep 17, 2024 | ||
* Author: Lenovo | ||
*/ | ||
|
||
#include <main_app.h> | ||
#include "string.h" | ||
#include "stdio.h" | ||
|
||
|
||
void SystemClockConfig(uint8_t); | ||
void Error_handler(unint8_t); | ||
void UART1_Init(void); | ||
void CAN1_Init(void); | ||
|
||
UART_HandleTypeDef huart3; | ||
CAN_HandleTypeDef hcan1; | ||
uint8_t msg[100]; | ||
|
||
|
||
|
||
int main(void) | ||
{ | ||
SystemClockConfig(CLOCK_FREQ_64MHz); | ||
|
||
HAL_Init(); | ||
UART1_Init(); | ||
CAN1_Init(); | ||
|
||
|
||
|
||
while(1){ | ||
uint8_t msg[100]; | ||
|
||
memset(msg,0,sizeof(msg)); | ||
sprintf((char *)msg,"SYSHCLK: %ld\r\n", HAL_RCC_GetSysClockFreq()); | ||
HAL_UART_Transmit(&huart3, msg, (uint16_t) strlen((char *)msg), HAL_MAX_DELAY); | ||
memset(msg,0,sizeof(msg)); | ||
sprintf((char *)msg,"HCLK: %ld\r\n", HAL_RCC_GetHCLKFreq()); | ||
HAL_UART_Transmit(&huart3, msg, (uint16_t) strlen((char *)msg), HAL_MAX_DELAY); | ||
memset(msg,0,sizeof(msg)); | ||
sprintf((char *)msg,"PCLK1: %ld\r\n", HAL_RCC_GetPCLK1Freq()); | ||
HAL_UART_Transmit(&huart3, msg, (uint16_t) strlen((char *)msg), HAL_MAX_DELAY); | ||
HAL_Delay(1000); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
void UART1_Init() | ||
{ | ||
huart3.Instance = USART3; | ||
huart3.Init.BaudRate = 115200; | ||
huart3.Init.WordLength = UART_WORDLENGTH_8B; | ||
huart3.Init.StopBits = UART_STOPBITS_1; | ||
huart3.Init.Parity = UART_PARITY_NONE; | ||
huart3.Init.Mode = UART_MODE_TX_RX; | ||
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; | ||
|
||
if(HAL_UART_Init(&huart3) != HAL_OK){ | ||
Error_handler(3); | ||
} | ||
|
||
} | ||
|
||
void Error_handler(uint8_t code) | ||
{ | ||
|
||
while(1){ | ||
sprintf((char *)msg,"error code: %d\r\n", code); | ||
HAL_UART_Transmit(&huart3, msg, (uint16_t) strlen((char *)msg), HAL_MAX_DELAY); | ||
HAL_Delay(1000); | ||
} | ||
|
||
} | ||
|
||
void SystemClockConfig(uint8_t clock_freq) | ||
{ | ||
RCC_OscInitTypeDef osc_init; | ||
RCC_ClkInitTypeDef clk_init; | ||
uint32_t FlashLatency; | ||
|
||
memset(&osc_init,0,sizeof(osc_init)); //there might be garbage values | ||
osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSE; | ||
osc_init.HSEState = RCC_HSE_ON; | ||
osc_init.PLL.PLLState = RCC_PLL_ON; | ||
osc_init.PLL.PLLSource = RCC_PLLSOURCE_HSE; | ||
|
||
switch(clock_freq){ | ||
case CLOCK_FREQ_32MHz: | ||
osc_init.PLL.PLLMUL = RCC_PLL_MUL8; | ||
|
||
clk_init.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | \ | ||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | ||
clk_init.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | ||
clk_init.AHBCLKDivider = RCC_SYSCLK_DIV2; | ||
clk_init.APB1CLKDivider = RCC_HCLK_DIV2; | ||
clk_init.APB2CLKDivider = RCC_HCLK_DIV1; | ||
FlashLatency = FLASH_LATENCY_2; | ||
break; | ||
|
||
case CLOCK_FREQ_64MHz: | ||
|
||
osc_init.PLL.PLLMUL = RCC_PLL_MUL8; | ||
|
||
|
||
clk_init.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | \ | ||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | ||
clk_init.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | ||
clk_init.AHBCLKDivider = RCC_SYSCLK_DIV1; | ||
clk_init.APB1CLKDivider = RCC_HCLK_DIV2; | ||
clk_init.APB2CLKDivider = RCC_HCLK_DIV1; | ||
FlashLatency = FLASH_LATENCY_2; | ||
break; | ||
|
||
|
||
default: | ||
return; | ||
|
||
} | ||
|
||
if(HAL_RCC_OscConfig(&osc_init) != HAL_OK){ | ||
Error_handler(2); | ||
} | ||
|
||
|
||
if(HAL_RCC_ClockConfig(&clk_init, FlashLatency) != HAL_OK){ | ||
Error_handler(2); | ||
} | ||
|
||
__HAL_RCC_HSI_DISABLE(); //Clock powered by HSE, now can disable HSI | ||
|
||
//SysTick Configuration for new clock setup | ||
//Input value is based on HCLK that SysTick would tick every 1 ms. | ||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); // one count period is 1/HCLK so it must count HCLK /1000 to get 1 ms | ||
//Configure clk source as HCLK | ||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | ||
|
||
|
||
} | ||
|
||
void CAN1_Init(void) | ||
{ | ||
hcan1.Instance = CAN1; | ||
hcan1.Init.Mode = CAN_MODE_LOOPBACK; | ||
hcan1.Init.AutoBusOff = DISABLE; | ||
hcan1.Init.AutoRetransmission = ENABLE; | ||
hcan1.Init.AutoWakeUp = DISABLE; | ||
hcan1.Init.ReceiveFifoLocked = DISABLE; | ||
hcan1.Init.TimeTriggeredMode = DISABLE; | ||
hcan1.Init.TransmitFifoPriority = DISABLE; | ||
|
||
//Settings for CAN bit timing | ||
hcan1.Init.Prescaler = 5; | ||
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ; | ||
hcan1.Init.TimeSeg1 = CAN_BS1_8TQ; | ||
hcan1.Init.TimeSeg2 = CAN_BS2_1TQ; | ||
|
||
|
||
if(HAL_CAN_Init(&hcan1) != HAL_OK){ | ||
Error_handler(1); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.