Skip to content

Commit

Permalink
Added Status LED for testing Mainboard
Browse files Browse the repository at this point in the history
  • Loading branch information
APBashara committed Aug 29, 2024
1 parent 243fc29 commit 557606e
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
#include "stm32f415xx.h"
#include "cmsis_os2.h"

/**
* @brief Set System Clock to 168MHz
* @note HSE Clock is 8MHz, APB1 Clock is 42MHz, APB2 Clock is 84MHz
*/
void SysClock_Config() {
RCC->CR |= RCC_CR_HSEON; // Enable HSE Clock
while (!(RCC->CR & RCC_CR_HSERDY)); // Wait until HSE is ready

RCC->APB1ENR |= RCC_APB1ENR_PWREN; // Enable Power Interface Clock
PWR->CR |= PWR_CR_VOS; // Set Scale 1 mode (max clock frequency)
void Status_LED(void *argument);

RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // Set AHB Prescaler to 1
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; // Set APB1 Prescaler to 4
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; // Set APB2 Prescaler to 2
osThreadId_t StatusLED;
const osThreadAttr_t StatusLED_attr = {
.name = "Status_Task",
.priority = osPriorityNormal,
.stack_size = 128
};

RCC->PLLCFGR = 7 << RCC_PLLCFGR_PLLQ_Pos; // Set PLLQ to 7
RCC->PLLCFGR |= 0 << RCC_PLLCFGR_PLLP_Pos; // Set PLLP to 2
RCC->PLLCFGR |= 336 << RCC_PLLCFGR_PLLN_Pos; // Set PLLN to 336
RCC->PLLCFGR |= 8 << RCC_PLLCFGR_PLLM_Pos; // Set PLLM to 8
RCC->PLLCFGR |= RCC_PLLCFGR_PLLSRC_HSE; // Set PLL Source to HSE

FLASH->ACR |= FLASH_ACR_PRFTEN; // Enable Prefetch Buffer
FLASH->ACR |= FLASH_ACR_ICEN; // Enable Instruction Cache
FLASH->ACR |= FLASH_ACR_DCEN; // Enable Data Cache
FLASH->ACR |= FLASH_ACR_LATENCY_5WS; // Set Flash Latency to 5 Wait States
int main() {
osKernelInitialize(); // Initialize FreeRTOS
StatusLED = osThreadNew(Status_LED, NULL, &StatusLED_attr);

RCC->CR |= RCC_CR_PLLON; // Enable PLL
while (!(RCC->CR & RCC_CR_PLLRDY)); // Wait until PLL is ready
osKernelStart(); // Start FreeRTOS
while(1) {

RCC->CFGR |= RCC_CFGR_SW_PLL; // Set PLL as System Clock
while (!(RCC->CFGR & RCC_CFGR_SWS_PLL)); // Wait until PLL is System Clock

SystemCoreClock = 168000000; // Set System Clock to 168MHz
}
}

int main() {
SysClock_Config();
/**
* @brief Thread for blinking the status led
*
* @param argument
*/
void Status_LED(void *argument) {
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
GPIOC->MODER |= GPIO_MODER_MODE13_0;
GPIOC->OTYPER &= ~GPIO_OTYPER_OT13;
GPIOC->OSPEEDR |= GPIO_OSPEEDR_OSPEED13;

while(1) {

osDelay(1000);
GPIOC->ODR ^= GPIO_ODR_OD13;
}
}

0 comments on commit 557606e

Please sign in to comment.