mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-26 01:07:21 +00:00
It is a big patch for stm32f0x, see the fellow :
1. fix heap management for stm32f0xx(SRAM=8k)
2. add USART1, USART2 driver for stm32f051R8
3. fix finsh support for stm32f0x
4. fix board components initial for stm32f0x and open debug msg
5. add led driver(pc9) and test thread for stm32f0discovery board
6. add init thread for stm32f0x do components initial
7. add rcc initial for stm32f0x in rt_hw_board_init()
8. add print rcc freq information function
the console output example is:
SYSCLK_Frequency is 48000000HZ
PCLK_Frequency is 48000000HZ
HCLK_Frequency is 48000000HZ
CECCLK_Frequency is 32786HZ
ADCCLK_Frequency is 14000000HZ
USART1CLK_Frequency is 48000000HZ
I2C1CLK_Frequency is 8000000HZ
SystemCoreClock is 48000000HZ
initialize rti_start:0 done
\ | /
- RT - Thread Operating System
/ | \ 1.2.0 build Nov 15 2013
2006 - 2013 Copyright by rt-thread team
do components intialization.
initialize rti_board_end:0 done
initialize rt_hw_led_init:32768 done
initialize finsh_system_init:0 done
finsh>>
This commit is contained in:
@@ -10,13 +10,18 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-01-05 Bernard first implementation
|
||||
* 2013-11-15 bright add RCC initial and print RCC freq function
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "usart.h"
|
||||
/* RT_USING_COMPONENTS_INIT */
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
#include <components.h>
|
||||
#endif
|
||||
/**
|
||||
* @addtogroup STM32
|
||||
*/
|
||||
@@ -35,6 +40,79 @@ void NVIC_Configuration(void)
|
||||
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts a delay time.
|
||||
* @param nCount: specifies the delay time length.
|
||||
* @retval None
|
||||
*/
|
||||
static void Delay(__IO uint32_t nCount)
|
||||
{
|
||||
/* Decrement nCount value */
|
||||
while (nCount != 0)
|
||||
{
|
||||
nCount--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This RCC initial for system.
|
||||
* use HSI clock source and pll
|
||||
* HSI = 8; sysclk = 8/2 * 12 = 48MHZ
|
||||
* sysclk source is pllclk
|
||||
* AHB prescaler is 1, HCLK = SYSCKL = SystemCoreClock = 48MHZ
|
||||
*/
|
||||
static void RCC_Configuration(void)
|
||||
{
|
||||
RCC_DeInit();
|
||||
/* setup HSI */
|
||||
RCC_HSICmd(ENABLE);
|
||||
/* Configure PLL source is HSI */
|
||||
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_12);
|
||||
RCC_PLLCmd(ENABLE);
|
||||
/* Configure SYSCLK source is PLL */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
|
||||
/* Conigure AHB prescaler value is 1 */
|
||||
RCC_HCLKConfig(RCC_SYSCLK_Div1);
|
||||
/* Delay for RCC setup */
|
||||
Delay(0x3FFFF);
|
||||
/* Update SystemCoreClock value from RCC configure */
|
||||
SystemCoreClockUpdate();
|
||||
}
|
||||
|
||||
#ifdef PRINT_RCC_FREQ_INFO
|
||||
/**
|
||||
* print RCC freq information
|
||||
*
|
||||
* for example:
|
||||
*
|
||||
* SYSCLK_Frequency is 48000000HZ
|
||||
* PCLK_Frequency is 48000000HZ
|
||||
* HCLK_Frequency is 48000000HZ
|
||||
* CECCLK_Frequency is 32786HZ
|
||||
* ADCCLK_Frequency is 14000000HZ
|
||||
* USART1CLK_Frequency is 48000000HZ
|
||||
* I2C1CLK_Frequency is 8000000HZ
|
||||
* SystemCoreClock is 48000000HZ
|
||||
*
|
||||
*/
|
||||
void print_rcc_freq_info(void)
|
||||
{
|
||||
RCC_ClocksTypeDef RCC_ClockFreq;
|
||||
|
||||
RCC_GetClocksFreq(&RCC_ClockFreq);
|
||||
|
||||
rt_kprintf("\nSYSCLK_Frequency is %dHZ", RCC_ClockFreq.SYSCLK_Frequency);
|
||||
rt_kprintf("\nPCLK_Frequency is %dHZ", RCC_ClockFreq.PCLK_Frequency);
|
||||
rt_kprintf("\nHCLK_Frequency is %dHZ", RCC_ClockFreq.HCLK_Frequency);
|
||||
|
||||
rt_kprintf("\nCECCLK_Frequency is %dHZ", RCC_ClockFreq.CECCLK_Frequency);
|
||||
rt_kprintf("\nADCCLK_Frequency is %dHZ", RCC_ClockFreq.ADCCLK_Frequency);
|
||||
rt_kprintf("\nUSART1CLK_Frequency is %dHZ", RCC_ClockFreq.USART1CLK_Frequency);
|
||||
rt_kprintf("\nI2C1CLK_Frequency is %dHZ", RCC_ClockFreq.I2C1CLK_Frequency);
|
||||
rt_kprintf("\nSystemCoreClock is %dHZ\n", SystemCoreClock);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is the timer interrupt service routine.
|
||||
*
|
||||
@@ -49,7 +127,6 @@ void SysTick_Handler(void)
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will initial STM32 board.
|
||||
*/
|
||||
@@ -59,11 +136,21 @@ void rt_hw_board_init()
|
||||
NVIC_Configuration();
|
||||
|
||||
/* Configure the SysTick */
|
||||
RCC_Configuration();
|
||||
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
||||
|
||||
//rt_hw_usart_init();
|
||||
/* Initial usart deriver, and set console device */
|
||||
rt_hw_usart_init();
|
||||
#ifdef RT_USING_CONSOLE
|
||||
rt_console_set_device(CONSOLE_DEVICE);
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
/* Print RCC freq info */
|
||||
#ifdef PRINT_RCC_FREQ_INFO
|
||||
print_rcc_freq_info();
|
||||
#endif
|
||||
/* Call components board initial (use INIT_BOARD_EXPORT()) */
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
rt_components_board_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user