Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x_lib.h"
- #include "stm32f10x_usart.h"
- #include "stm32f10x_gpio.h"
- #include "stm32f10x_map.h"
- #include "stm32f10x_rcc.h"
- #include "bits.h"
- #define STACK_TOP 0x20000800
- #define NVIC_CCR ((volatile unsigned long *)(0xE000ED14))
- void nmi_handler(void);
- void hardfault_handler(void);
- void myDelay(unsigned long delay);
- void out_string(char* str);
- int main(void);
- void Clk_Init (void);
- // Define the vector table
- unsigned int * myvectors[59]
- __attribute__ ((section("vectors")))= {
- (unsigned int *) 0x20000800, // stack pointer
- (unsigned int *) main, // code entry point
- (unsigned int *) nmi_handler, // NMI handler (not really)
- (unsigned int *) hardfault_handler // hard fault handler (let's hope not)
- /*(unsigned int *) 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0,0,0,0,0
- 0,0,0,0,0,0*/
- };
- //Definiton of Structure
- USART_InitTypeDef USART_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- //#define TxBufferSize (countof(TxBuffer))
- //#define countof(a) (sizeof(a) / sizeof(*(a)))
- int main(void)
- {
- //Private Variable
- u8 TxBuffer[] = "Buffer Send from USART2 to USART1 using Flags";
- u8 RxBuffer[45];
- u8 TxCounter = 0, RxCounter = 0;
- *NVIC_CCR = *NVIC_CCR | 0x200; /* Set STKALIGN in NVIC */
- RCC_DeInit();
- RCC_HSEConfig(RCC_HSE_ON);
- Clk_Init;
- //Clock Enable USART2 & GPIOA
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- // Configure PA.0 as output push-pull
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- // Configure PA.12 as output push-pull
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- //Configure TX as Output - Alternate Function Push-Pull
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //Configure RX as Input - Input Floating
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //Configuration of USART2
- USART_InitStructure.USART_BaudRate = 0x2580; /* 9600 Baud */
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART2,&USART_InitStructure);
- USART_Cmd(USART2,ENABLE);
- while(TxCounter <= 45)
- {
- USART_SendData(USART2,TxBuffer[TxCounter++]);
- while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
- {
- }
- }
- while(1)
- {
- }
- }
- void nmi_handler(void)
- {
- return ;
- }
- void hardfault_handler(void)
- {
- return ;
- }
- void myDelay(unsigned long delay)
- {
- while(delay) delay--;
- }
- void Clk_Init (void)
- {
- // 1. Cloking the controller from internal HSI RC (8 MHz)
- RCC_HSICmd(ENABLE);
- // wait until the HSI is ready
- while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
- RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
- // 2. Enable ext. high frequency OSC
- RCC_HSEConfig(RCC_HSE_ON);
- // wait until the HSE is ready
- while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
- // 3. Init PLL
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); // 72MHz
- // RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9); // 72MHz
- RCC_PLLCmd(ENABLE);
- // wait until the PLL is ready
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
- // 4. Set system clock divders
- RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
- RCC_ADCCLKConfig(RCC_PCLK2_Div8);
- RCC_PCLK2Config(RCC_HCLK_Div1);
- RCC_PCLK1Config(RCC_HCLK_Div2);
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
- // Flash 1 wait state
- *(vu32 *)0x40022000 = 0x12;
- // 5. Clock system from PLL
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement