Konstantin Oblaukhov 12 лет назад
Родитель
Сommit
7bdf2fe3eb
4 измененных файлов с 199 добавлено и 14 удалено
  1. 59 0
      stm32-blinky/stm32f4xx_conf.h
  2. 56 5
      stm32-newlib/main.c
  3. 25 9
      stm32-newlib/newlib.c
  4. 59 0
      stm32-newlib/stm32f4xx_conf.h

+ 59 - 0
stm32-blinky/stm32f4xx_conf.h

@@ -0,0 +1,59 @@
+#ifndef __STM32F4xx_CONF_H
+#define __STM32F4xx_CONF_H
+
+//#include "stm32f4xx_adc.h"
+//#include "stm32f4xx_crc.h"
+//#include "stm32f4xx_dbgmcu.h"
+//#include "stm32f4xx_dma.h"
+//#include "stm32f4xx_exti.h"
+//#include "stm32f4xx_flash.h"
+#include "stm32f4xx_gpio.h"
+//#include "stm32f4xx_i2c.h"
+//#include "stm32f4xx_iwdg.h"
+//#include "stm32f4xx_pwr.h"
+#include "stm32f4xx_rcc.h"
+//#include "stm32f4xx_rtc.h"
+//#include "stm32f4xx_sdio.h"
+//#include "stm32f4xx_spi.h"
+//#include "stm32f4xx_syscfg.h"
+#include "stm32f4xx_tim.h"
+//#include "stm32f4xx_usart.h"
+//#include "stm32f4xx_wwdg.h"
+#include "stm32f4xx_misc.h"
+
+#if defined (STM32F429_439xx)
+//#include "stm32f4xx_cryp.h"
+//#include "stm32f4xx_hash.h"
+//#include "stm32f4xx_rng.h"
+//#include "stm32f4xx_can.h"
+//#include "stm32f4xx_dac.h"
+//#include "stm32f4xx_dcmi.h"
+//#include "stm32f4xx_dma2d.h"
+//#include "stm32f4xx_fmc.h"
+//#include "stm32f4xx_ltdc.h"
+//#include "stm32f4xx_sai.h"
+#endif
+
+#if defined (STM32F427_437xx)
+//#include "stm32f4xx_cryp.h"
+//#include "stm32f4xx_hash.h"
+//#include "stm32f4xx_rng.h"
+//#include "stm32f4xx_can.h"
+//#include "stm32f4xx_dac.h"
+//#include "stm32f4xx_dcmi.h"
+//#include "stm32f4xx_dma2d.h"
+//#include "stm32f4xx_fmc.h"
+//#include "stm32f4xx_sai.h"
+#endif
+
+#if defined (STM32F40_41xxx)
+//#include "stm32f4xx_cryp.h"
+//#include "stm32f4xx_hash.h"
+//#include "stm32f4xx_rng.h"
+//#include "stm32f4xx_can.h"
+//#include "stm32f4xx_dac.h"
+//#include "stm32f4xx_dcmi.h"
+//#include "stm32f4xx_fsmc.h"
+#endif
+ 
+#endif

+ 56 - 5
stm32-newlib/main.c

@@ -1,11 +1,28 @@
-#include <stm32f10x.h>
+#if defined STM32F1
+# include <stm32f10x.h>
+#elif defined STM32F4
+# include <stm32f4xx.h>
+#endif
+
+#include "stm32f4xx_conf.h"
+
 #include <stdio.h>
 #include <time.h>
 
+#if defined STM32F4
+extern uint64_t virtualClock;
+void SysTick_Handler(void)
+{
+	virtualClock++;
+}
+#endif
+
+
 void initGPIO()
 {
-    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
     GPIO_InitTypeDef GPIO_Config;
+#if defined STM32F1
+    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
 
     /* USART1 Tx */
     GPIO_Config.GPIO_Pin = GPIO_Pin_9;
@@ -18,10 +35,29 @@ void initGPIO()
     GPIO_Config.GPIO_Mode = GPIO_Mode_IN_FLOATING;
     GPIO_Config.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOA, &GPIO_Config);
+#elif defined STM32F4
+    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
+
+    /* USART3 Tx */
+    GPIO_Config.GPIO_Mode = GPIO_Mode_AF;
+    GPIO_Config.GPIO_OType = GPIO_OType_PP;
+    GPIO_Config.GPIO_Pin = GPIO_Pin_10;
+    GPIO_Config.GPIO_PuPd = GPIO_PuPd_UP;
+    GPIO_Config.GPIO_Speed = GPIO_Speed_50MHz;
+    GPIO_Init(GPIOC, &GPIO_Config);
+
+    /* USART3 Rx */
+    GPIO_Config.GPIO_Pin = GPIO_Pin_11;
+    GPIO_Init(GPIOC, &GPIO_Config);
+
+    GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
+    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
+#endif
 }
 
 void initRTC()
 {
+#if defined STM32F1
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
 
     if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
@@ -47,30 +83,46 @@ void initRTC()
     }
     RTC_WaitForSynchro();
     RTC_WaitForLastTask();
+#elif defined STM32F4
+    SysTick_Config(SystemCoreClock / 8 / 1000);
+    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
+#endif
 }
 
 void initUSART()
 {
-    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
     USART_InitTypeDef USART_InitStructure;
+
     USART_InitStructure.USART_BaudRate = 115200;
     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
     USART_InitStructure.USART_StopBits = USART_StopBits_1;
     USART_InitStructure.USART_Parity = USART_Parity_No;
     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
-    USART_Init(USART1, &USART_InitStructure);
 
+#if defined STM32F1
+    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
+    USART_Init(USART1, &USART_InitStructure);
     USART_Cmd(USART1, ENABLE);
+#elif defined STM32F4
+    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
+    USART_Init(USART3, &USART_InitStructure);
+    USART_Cmd(USART3, ENABLE);
+#endif
+
 }
 
 void setTime(uint32_t time)
 {
+#if defined STM32F1
     PWR_BackupAccessCmd(ENABLE);
     RTC_WaitForLastTask();
     RTC_SetCounter(time);
     RTC_WaitForLastTask();
     PWR_BackupAccessCmd(DISABLE);
+#elif defined STM32F4
+    virtualClock = (uint64_t)time * 1000;
+#endif
 }
 
 void initAll(void)
@@ -97,7 +149,6 @@ int main(void)
             printf("Current time changed: %d - %s\r", t, ctime(&t));
             break;
         default:
-            RTC_WaitForLastTask();
             t = time(0);
             printf("Current time: %d - %s\r", t, ctime(&t));
             break;

+ 25 - 9
stm32-newlib/newlib.c

@@ -3,13 +3,28 @@
 #include <sys/times.h>
 #include <sys/unistd.h>
 #include <sys/time.h>
-#include <stm32f10x.h>
+
+#if defined STM32F1
+# include <stm32f10x.h>
+#elif defined STM32F4
+# include <stm32f4xx.h>
+#endif
+
+#if defined STM32F4
+uint64_t virtualClock = 0;
+#endif
 
 extern uint32_t __get_MSP(void);
 
-#define STDOUT_USART USART1
-#define STDERR_USART USART1
-#define STDIN_USART USART1
+#if defined STM32F1
+# define STDOUT_USART USART1
+# define STDERR_USART USART1
+# define STDIN_USART USART1
+#elif defined STM32F4
+# define STDOUT_USART USART3
+# define STDERR_USART USART3
+# define STDIN_USART USART3
+#endif
 
 #undef errno
 extern int errno;
@@ -54,8 +69,13 @@ int _getpid()
 
 int _gettimeofday(struct timeval *tv, struct timezone *tz)
 {
+#if defined STM32F1
     tv->tv_sec = RTC_GetCounter();
     tv->tv_usec = 0;
+#elif defined STM32F4
+    tv->tv_sec = virtualClock / 1000;
+    tv->tv_usec = (virtualClock % 1000) * 1000;
+#endif
     return 0;
 }
 
@@ -94,13 +114,9 @@ int _lseek(int file, int ptr, int dir)
 caddr_t _sbrk(int incr)
 {
     extern char _ebss;
-    static char *heap_end;
+    static char *heap_end= &_ebss;
     char *prev_heap_end;
 
-    if (heap_end == 0)
-    {
-        heap_end = &_ebss;
-    }
     prev_heap_end = heap_end;
 
     char * stack = (char*) __get_MSP();

+ 59 - 0
stm32-newlib/stm32f4xx_conf.h

@@ -0,0 +1,59 @@
+#ifndef __STM32F4xx_CONF_H
+#define __STM32F4xx_CONF_H
+
+//#include "stm32f4xx_adc.h"
+//#include "stm32f4xx_crc.h"
+//#include "stm32f4xx_dbgmcu.h"
+//#include "stm32f4xx_dma.h"
+//#include "stm32f4xx_exti.h"
+//#include "stm32f4xx_flash.h"
+#include "stm32f4xx_gpio.h"
+//#include "stm32f4xx_i2c.h"
+//#include "stm32f4xx_iwdg.h"
+//#include "stm32f4xx_pwr.h"
+#include "stm32f4xx_rcc.h"
+//#include "stm32f4xx_rtc.h"
+//#include "stm32f4xx_sdio.h"
+//#include "stm32f4xx_spi.h"
+//#include "stm32f4xx_syscfg.h"
+//#include "stm32f4xx_tim.h"
+#include "stm32f4xx_usart.h"
+//#include "stm32f4xx_wwdg.h"
+#include "stm32f4xx_misc.h"
+
+#if defined (STM32F429_439xx)
+//#include "stm32f4xx_cryp.h"
+//#include "stm32f4xx_hash.h"
+//#include "stm32f4xx_rng.h"
+//#include "stm32f4xx_can.h"
+//#include "stm32f4xx_dac.h"
+//#include "stm32f4xx_dcmi.h"
+//#include "stm32f4xx_dma2d.h"
+//#include "stm32f4xx_fmc.h"
+//#include "stm32f4xx_ltdc.h"
+//#include "stm32f4xx_sai.h"
+#endif
+
+#if defined (STM32F427_437xx)
+//#include "stm32f4xx_cryp.h"
+//#include "stm32f4xx_hash.h"
+//#include "stm32f4xx_rng.h"
+//#include "stm32f4xx_can.h"
+//#include "stm32f4xx_dac.h"
+//#include "stm32f4xx_dcmi.h"
+//#include "stm32f4xx_dma2d.h"
+//#include "stm32f4xx_fmc.h"
+//#include "stm32f4xx_sai.h"
+#endif
+
+#if defined (STM32F40_41xxx)
+//#include "stm32f4xx_cryp.h"
+//#include "stm32f4xx_hash.h"
+//#include "stm32f4xx_rng.h"
+//#include "stm32f4xx_can.h"
+//#include "stm32f4xx_dac.h"
+//#include "stm32f4xx_dcmi.h"
+//#include "stm32f4xx_fsmc.h"
+#endif
+ 
+#endif