Added main clock initialization to STM32.
[goodfet] / firmware / lib / stm32f407.c
1 /*! \file stm32f407.h
2   \author Travis Goodspeed
3   \brief STM32F407 port definitions.
4 */
5
6 #include "platform.h"
7
8 #include "stm32f4xx.h"
9 //#include "stm322xg_eval.h"
10 #include <stm32f4xx_gpio.h>
11 #include <stm32f4xx_rcc.h>
12 #include <stm32f4xx_rcc.h>
13 //#include "stm32f4_discovery.h"
14
15
16 void ioinit(){
17   GPIO_InitTypeDef  GPIO_InitStructure;
18   
19   /* GPIOD Periph clock enable */
20   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
21
22   /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
23   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
24   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
25   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
26   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
27   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
28   GPIO_Init(GPIOD, &GPIO_InitStructure);
29 }
30
31
32 void ledon(){
33   //GPIOG->BSRRL=GPIO_Pin_14;
34   GPIO_ResetBits(GPIOD, GPIO_Pin_14);
35 }
36 void ledoff(){
37   //GPIOG->BSRRH=GPIO_Pin_14;
38   GPIO_SetBits(GPIOD, GPIO_Pin_14);
39 }
40
41
42 //! Count the length of a string.
43 uint32_t strlen(const char *s){
44   return 0;
45 }
46
47 //! Initialize the STM32F4xx ports and USB.
48 void stm32f4xx_init(){
49   SystemInit();
50   ioinit();
51   while(1){
52     ledon();
53     delay(0x1000);
54     ledoff();
55     delay(0x1000);
56   }
57 }
58
59 //! Receive a byte.
60 unsigned char serial0_rx(){
61 }
62
63 //! Receive a byte.
64 unsigned char serial1_rx(){
65 }
66
67 //! Transmit a byte.
68 void serial0_tx(unsigned char x){
69 }
70 //! Transmit a byte.
71 void serial_tx_old(unsigned char x){
72 }
73
74 //! Transmit a byte on the second UART.
75 void serial1_tx(unsigned char x){
76
77 }
78
79 //! Set the baud rate.
80 void setbaud0(unsigned char rate){
81   //Ignore this, as we'll be in USB.
82 }
83
84 //! Set the baud rate of the second uart.
85 void setbaud1(unsigned char rate){
86
87 }
88
89
90 //Declarations
91 void nmi_handler(void);
92 void hardfault_handler(void);
93 int main(void);
94
95 //From min.s
96 void Reset_Handler(void);
97
98
99
100 // Define the vector table
101 unsigned int * myvectors[50] 
102    __attribute__ ((section("vectors")))= {
103         (unsigned int *)        0x20000800,             // stack pointer
104         (unsigned int *)        Reset_Handler,                  // code entry point
105         (unsigned int *)        main,           // NMI handler (not really)
106         (unsigned int *)        main,   // hard fault handler (let's hope not)  
107 };