Przeglądaj źródła

Examples ported to STM32CubeMX HAL.
Outdated stuff removed.

Konstantin Oblaukhov 10 lat temu
rodzic
commit
5ac4b043d1

+ 0 - 81
cmsis-3.0/CMakeLists.txt

@@ -1,81 +0,0 @@
-PROJECT(stm32cmsis)
-
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-ENABLE_LANGUAGE(ASM)
-
-IF(NOT CMSIS3_DIR)
-    SET(CMSIS3_DIR "/opt/CMSIS")
-    MESSAGE(STATUS "No CMSIS3_DIR specified, using default: " ${CMSIS3_DIR})
-ENDIF()
-
-IF(${STM32_FAMILY} STREQUAL "F1")
-    IF(NOT STM32F1_StdPeriphLib_DIR)
-        SET(STM32F1_StdPeriphLib_DIR "/opt/STM32F10x_StdPeriph_Lib_V3.5.0")
-        MESSAGE(STATUS "No STM32F1_StdPeriphLib_DIR specified, using default: " ${STM32F1_StdPeriphLib_DIR})
-    ENDIF()
-
-    INCLUDE_DIRECTORIES(
-        ${STM32F1_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/
-    )
-    
-    SET(CMSIS_HEADERS 
-        ${STM32F1_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h
-        ${STM32F1_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h
-        ${CMSIS3_DIR}/CMSIS/Include/core_cm3.h 
-        ${CMSIS3_DIR}/CMSIS/Include/core_cmFunc.h
-        ${CMSIS3_DIR}/CMSIS/Include/core_cmInstr.h
-    )
-    
-    SET(CMSIS_SOURCES 
-        ${STM32F1_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
-    )
-    
-    SET(CMSIS_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/stm32f1_flash.ld.in)
-    SET(STARTUP_PREFIX ${STM32F1_StdPeriphLib_DIR}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_)
-ELSEIF(${STM32_FAMILY} STREQUAL "F4")
-    IF(NOT STM32F4_StdPeriphLib_DIR)
-        SET(STM32F4_StdPeriphLib_DIR "/opt/STM32F4xx_DSP_StdPeriph_Lib_V1.3.0")
-        MESSAGE(STATUS "No STM32F4_StdPeriphLib_DIR specified, using default: " ${STM32F4_StdPeriphLib_DIR})
-    ENDIF()
-
-    INCLUDE_DIRECTORIES(
-        ${STM32F4_StdPeriphLib_DIR}/Libraries/CMSIS/Device/ST/STM32F4xx/Include/
-    )
-        
-    SET(CMSIS_HEADERS 
-        ${STM32F4_StdPeriphLib_DIR}/Libraries/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h
-        ${STM32F4_StdPeriphLib_DIR}/Libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
-        ${CMSIS3_DIR}/CMSIS/Include/core_cm4.h 
-        ${CMSIS3_DIR}/CMSIS/Include/core_cm4_simd.h
-        ${CMSIS3_DIR}/CMSIS/Include/core_cmFunc.h
-        ${CMSIS3_DIR}/CMSIS/Include/core_cmInstr.h
-    )
-    
-    SET(CMSIS_SOURCES 
-        ${STM32F4_StdPeriphLib_DIR}/Libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c
-    )
-    
-    SET(CMSIS_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/stm32f4_flash.ld.in)
-    SET(STARTUP_PREFIX ${STM32F4_StdPeriphLib_DIR}/Libraries/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f)
-ENDIF()
-
-INCLUDE_DIRECTORIES(
-    ${CMSIS3_DIR}/CMSIS/Include/
-    ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-STRING(TOLOWER ${STM32_FAMILY} STM32_FAMILY_LOWER)
-
-FOREACH(CHIP_TYPE ${STM32_CHIP_TYPES})
-    STRING(TOLOWER ${CHIP_TYPE} CHIP_TYPE_LOWER)
-    
-    LIST(APPEND CMSIS_STARTUP_FILES ${STARTUP_PREFIX}${CHIP_TYPE_LOWER}.s)
-    LIST(APPEND CMSIS_LIBRARIES cmsis_${STM32_FAMILY_LOWER}_${CHIP_TYPE_LOWER})
-    ADD_LIBRARY(cmsis_${STM32_FAMILY_LOWER}_${CHIP_TYPE_LOWER} ${CMSIS_SOURCES})
-    STM32_SET_CHIP_DEFINITIONS(cmsis_${STM32_FAMILY_LOWER}_${CHIP_TYPE_LOWER} ${CHIP_TYPE})
-ENDFOREACH()
-
-INSTALL(TARGETS ${CMSIS_LIBRARIES} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
-INSTALL(FILES ${CMSIS_HEADERS} DESTINATION include/stm32${STM32_FAMILY_LOWER})
-INSTALL(FILES ${CMSIS_STARTUP_FILES} ${CMSIS_LINKER_SCRIPT} DESTINATION share/cmsis/)
-INSTALL(FILES ${CMSIS_SOURCES} DESTINATION share/cmsis/)

+ 0 - 141
cmsis-3.0/stm32f1_flash.ld.in

@@ -1,141 +0,0 @@
-/*
-*****************************************************************************
-**
-**  Linker script for STM32F10x devices
-**
-**  Set heap size, stack size and stack location according
-**    to application requirements.
-**
-**  Set memory bank area and size if external memory is used.
-**
-*****************************************************************************
-*/
-
-/* Entry Point */
-ENTRY(Reset_Handler)
-
-/* Highest address of the user mode stack */
-_estack = ${STM32_STACK_ADDRESS};    /* end of RAM */
-
-/* Generate a link error if heap and stack don't fit into RAM */
-_Min_Heap_Size = ${STM32_MIN_HEAP_SIZE};      /* required amount of heap  */
-_Min_Stack_Size = ${STM32_MIN_STACK_SIZE}; /* required amount of stack */
-
-/* Specify the memory areas */
-MEMORY
-{
-  FLASH (rx)      : ORIGIN = ${STM32_FLASH_ORIGIN}, LENGTH = ${STM32_FLASH_SIZE}
-  RAM (xrw)       : ORIGIN = ${STM32_RAM_ORIGIN}, LENGTH = ${STM32_RAM_SIZE}
-}
-
-/* Define output sections */
-SECTIONS
-{
-  /* The startup code goes first into FLASH */
-  .isr_vector :
-  {
-    . = ALIGN(4);
-    KEEP(*(.isr_vector)) /* Startup code */
-    . = ALIGN(4);
-  } >FLASH
-
-  /* The program code and other data goes into FLASH */
-  .text :
-  {
-    . = ALIGN(4);
-    *(.text)           /* .text sections (code) */
-    *(.text*)          /* .text* sections (code) */
-    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
-    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
-    *(.glue_7)         /* glue arm to thumb code */
-    *(.glue_7t)        /* glue thumb to arm code */
-
-    KEEP (*(.init))
-    KEEP (*(.fini))
-
-    . = ALIGN(4);
-    _etext = .;        /* define a global symbols at end of code */
-  } >FLASH
-
-
-   .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
-    .ARM : {
-    __exidx_start = .;
-      *(.ARM.exidx*)
-      __exidx_end = .;
-    } >FLASH
-
-  .ARM.attributes : { *(.ARM.attributes) } > FLASH
-
-  .preinit_array     :
-  {
-    PROVIDE_HIDDEN (__preinit_array_start = .);
-    KEEP (*(.preinit_array*))
-    PROVIDE_HIDDEN (__preinit_array_end = .);
-  } >FLASH
-  .init_array :
-  {
-    PROVIDE_HIDDEN (__init_array_start = .);
-    KEEP (*(SORT(.init_array.*)))
-    KEEP (*(.init_array*))
-    PROVIDE_HIDDEN (__init_array_end = .);
-  } >FLASH
-  .fini_array :
-  {
-    PROVIDE_HIDDEN (__fini_array_start = .);
-    KEEP (*(.fini_array*))
-    KEEP (*(SORT(.fini_array.*)))
-    PROVIDE_HIDDEN (__fini_array_end = .);
-  } >FLASH
-
-  /* used by the startup to initialize data */
-  _sidata = .;
-
-  /* Initialized data sections goes into RAM, load LMA copy after code */
-  .data : AT ( _sidata )
-  {
-    . = ALIGN(4);
-    _sdata = .;        /* create a global symbol at data start */
-    *(.data)           /* .data sections */
-    *(.data*)          /* .data* sections */
-
-    . = ALIGN(4);
-    _edata = .;        /* define a global symbol at data end */
-  } >RAM
-
-  /* Uninitialized data section */
-  . = ALIGN(4);
-  .bss :
-  {
-    /* This is used by the startup in order to initialize the .bss secion */
-    _sbss = .;         /* define a global symbol at bss start */
-    __bss_start__ = _sbss;
-    *(.bss)
-    *(.bss*)
-    *(COMMON)
-
-    . = ALIGN(4);
-    _ebss = .;         /* define a global symbol at bss end */
-    __bss_end__ = _ebss;
-  } >RAM
-
-  PROVIDE ( end = _ebss );
-  PROVIDE ( _end = _ebss );
-
-  /* User_heap_stack section, used to check that there is enough RAM left */
-  ._user_heap_stack :
-  {
-    . = ALIGN(4);
-    . = . + _Min_Heap_Size;
-    . = . + _Min_Stack_Size;
-    . = ALIGN(4);
-  } >RAM
-
-  /* Remove information from the standard libraries */
-  /DISCARD/ :
-  {
-    libc.a ( * )
-    libm.a ( * )
-    libgcc.a ( * )
-  }
-}

+ 0 - 195
cmsis-3.0/stm32f4_flash.ld.in

@@ -1,195 +0,0 @@
-/*
-Default linker script for STM32F4xx_1024K_192K
-*/
-
-/* include the common STM32F4xx  sub-script */
-
-/* Common part of the linker scripts for STM32F devices*/
-
-
-/* default stack sizes. 
-
-These are used by the startup in order to allocate stacks for the different modes.
-*/
-
-__Stack_Size = 1024 ;
-
-PROVIDE ( _Stack_Size = __Stack_Size ) ;
-
-__Stack_Init = _estack  - __Stack_Size ;
-
-/*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/
-PROVIDE ( _Stack_Init = __Stack_Init ) ;
-
-/*
-There will be a link error if there is not this amount of RAM free at the end.
-*/
-_Minimum_Stack_Size = ${STM32_MIN_STACK_SIZE} ;
-
-
-/* include the memory spaces definitions sub-script */
-/*
-Linker subscript for STM32F4xx definitions with 1024 Flash and 192 Onchip SRAM */
-
-/* Memory Spaces Definitions */
-
-MEMORY
-{
-  RAM (xrw) : ORIGIN = ${STM32_RAM_ORIGIN}, LENGTH = ${STM32_RAM_SIZE}
-  CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
-  FLASH (rx) : ORIGIN = ${STM32_FLASH_ORIGIN}, LENGTH = ${STM32_FLASH_SIZE}
-  MEMORY_ARRAY (xrw)  : ORIGIN = 0x20002000, LENGTH = 32
-}
-
-/* higher address of the user mode stack (end of 128K RAM on AHB bus)*/
-_estack = ${STM32_STACK_ADDRESS};
-
-
-
-/* include the sections management sub-script for FLASH mode */
-
-/* Sections Definitions */
-
-SECTIONS
-{
-    /* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH */
-    .isr_vector :
-    {
-	. = ALIGN(4);
-        KEEP(*(.isr_vector))            /* Startup code */
-	. = ALIGN(4);
-    } >FLASH
- 
-    /* for some STRx devices, the beginning of the startup code is stored in the .flashtext section, which goes to FLASH */
-    .flashtext :
-    {
-	. = ALIGN(4);
-        *(.flashtext)            /* Startup code */
-	. = ALIGN(4);
-    } >FLASH
- 
-    
-    /* the program code is stored in the .text section, which goes to Flash */
-    .text :
-    {
-	    . = ALIGN(4);
-	    
-        *(.text)                   /* remaining code */
-        *(.text.*)                 /* remaining code */
-        *(.rodata)                 /* read-only data (constants) */
-        *(.rodata*)
-        *(.glue_7)
-        *(.glue_7t)
-
-	    . = ALIGN(4);
-   	 _etext = .;
-	    /* This is used by the startup in order to initialize the .data secion */
-   	 _sidata = _etext;
-    } >FLASH
-    
-    /* MEMORY_ARRAY */
-    .ROarraySection :
-    {
-            *(.ROarraySection)                          
-    } >MEMORY_ARRAY
-     
-
-    /* This is the initialized data section
-    The program executes knowing that the data is in the RAM
-    but the loader puts the initial values in the FLASH (inidata).
-    It is one task of the startup to copy the initial values from FLASH to RAM. */
-    .data  : AT ( _sidata )
-    {
-	    . = ALIGN(4);
-        /* This is used by the startup in order to initialize the .data secion */
-        _sdata = . ;
-        
-        *(.data)
-        *(.data.*)
-
-	    . = ALIGN(4);
-	    /* This is used by the startup in order to initialize the .data secion */
-   	 _edata = . ;
-    } >RAM
-    
-    
-
-    /* This is the uninitialized data section */
-    .bss :
-    {
-	    . = ALIGN(4);
-        /* This is used by the startup in order to initialize the .bss secion */
-        _sbss = .;
-        
-        *(.bss)
-        *(COMMON)
-        
-	    . = ALIGN(4);
-	    /* This is used by the startup in order to initialize the .bss secion */
-   	 _ebss = . ;
-    } >RAM
-    
-    PROVIDE ( end = _ebss );
-    PROVIDE ( _end = _ebss );
-    
-    /* This is the user stack section 
-    This is just to check that there is enough RAM left for the User mode stack
-    It should generate an error if it's full.
-     */
-    ._usrstack :
-    {
-	    . = ALIGN(4);
-        _susrstack = . ;
-        
-        . = . + _Minimum_Stack_Size ;
-        
-	    . = ALIGN(4);
-        _eusrstack = . ;
-    } >RAM
-    
-    /* after that it's only debugging information. */
-    
-    /* remove the debugging information from the standard libraries */
-    DISCARD :
-    {
-     libc.a ( * )
-     libm.a ( * )
-     libgcc.a ( * )
-     }
-  
-  
-    /* Stabs debugging sections.  */
-    .stab          0 : { *(.stab) }
-    .stabstr       0 : { *(.stabstr) }
-    .stab.excl     0 : { *(.stab.excl) }
-    .stab.exclstr  0 : { *(.stab.exclstr) }
-    .stab.index    0 : { *(.stab.index) }
-    .stab.indexstr 0 : { *(.stab.indexstr) }
-    .comment       0 : { *(.comment) }
-    /* DWARF debug sections.
-       Symbols in the DWARF debugging sections are relative to the beginning
-       of the section so we begin them at 0.  */
-    /* DWARF 1 */
-    .debug          0 : { *(.debug) }
-    .line           0 : { *(.line) }
-    /* GNU DWARF 1 extensions */
-    .debug_srcinfo  0 : { *(.debug_srcinfo) }
-    .debug_sfnames  0 : { *(.debug_sfnames) }
-    /* DWARF 1.1 and DWARF 2 */
-    .debug_aranges  0 : { *(.debug_aranges) }
-    .debug_pubnames 0 : { *(.debug_pubnames) }
-    /* DWARF 2 */
-    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
-    .debug_abbrev   0 : { *(.debug_abbrev) }
-    .debug_line     0 : { *(.debug_line) }
-    .debug_frame    0 : { *(.debug_frame) }
-    .debug_str      0 : { *(.debug_str) }
-    .debug_loc      0 : { *(.debug_loc) }
-    .debug_macinfo  0 : { *(.debug_macinfo) }
-    /* SGI/MIPS DWARF 2 extensions */
-    .debug_weaknames 0 : { *(.debug_weaknames) }
-    .debug_funcnames 0 : { *(.debug_funcnames) }
-    .debug_typenames 0 : { *(.debug_typenames) }
-    .debug_varnames  0 : { *(.debug_varnames) }    
-    
-}

+ 0 - 25
stm32-blinky-sources/CMakeLists.txt

@@ -1,25 +0,0 @@
-PROJECT(stm32-blinky)
-
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
-ENABLE_LANGUAGE(ASM)
-
-FIND_PACKAGE(CMSIS REQUIRED)
-FIND_PACKAGE(StdPeriphLib REQUIRED)
-
-INCLUDE_DIRECTORIES(
-    ${CMAKE_CURRENT_SOURCE_DIR}
-    ${CMSIS_INCLUDE_DIR}
-    ${StdPeriphLib_INCLUDE_DIR}
-)
-
-SET(PROJECT_SOURCES
-    main.c
-)
-
-SET(STM32_LINKER_SCRIPT ${CMSIS_LINKER_SCRIPT})
-
-ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} ${CMSIS_STARTUP_SOURCE} ${CMSIS_SOURCES} ${StdPeriphLib_SOURCES})
-
-STM32_SET_TARGET_PROPERTIES(${CMAKE_PROJECT_NAME})
-STM32_SET_HSE_VALUE(${CMAKE_PROJECT_NAME} 12000000)
-STM32_ADD_HEX_BIN_TARGETS(${CMAKE_PROJECT_NAME})

+ 0 - 80
stm32-blinky-sources/main.c

@@ -1,80 +0,0 @@
-#if defined STM32F1
-# include <stm32f10x.h>
-#elif defined STM32F4
-# include <stm32f4xx.h>
-#endif
-
-void initGPIO()
-{
-    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
-
-    GPIO_InitTypeDef GPIO_Config;
-#if defined STM32F1
-    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
-
-    GPIO_Config.GPIO_Pin =  GPIO_Pin_8;
-    GPIO_Config.GPIO_Mode = GPIO_Mode_AF_PP;
-    GPIO_Config.GPIO_Speed = GPIO_Speed_50MHz;
-
-    GPIO_Init(GPIOC, &GPIO_Config);
-    GPIO_PinRemapConfig( GPIO_FullRemap_TIM3, ENABLE );
-#elif defined STM32F4
-    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
-
-    GPIO_Config.GPIO_Mode = GPIO_Mode_AF;
-    GPIO_Config.GPIO_OType = GPIO_OType_PP;
-    GPIO_Config.GPIO_Pin = GPIO_Pin_6;
-    GPIO_Config.GPIO_PuPd = GPIO_PuPd_NOPULL;
-    GPIO_Config.GPIO_Speed = GPIO_Speed_2MHz;
-
-    GPIO_Init(GPIOA, &GPIO_Config);
-    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_TIM3);
-#endif
-}
-
-void initTimers()
-{
-	SystemCoreClockUpdate();
-
-    TIM_TimeBaseInitTypeDef TIM_BaseConfig;
-    TIM_OCInitTypeDef TIM_OCConfig;
-
-    // 10 kHz timer.
-    TIM_BaseConfig.TIM_Prescaler = (uint16_t)(SystemCoreClock / 10000) - 1;
-    // 10000 / 5000 = 1 Hz blinking.
-    TIM_BaseConfig.TIM_Period = 5000;
-    TIM_BaseConfig.TIM_ClockDivision = 0;
-    TIM_BaseConfig.TIM_CounterMode = TIM_CounterMode_Up;
-
-    TIM_OCConfig.TIM_OCMode = TIM_OCMode_PWM1;
-    TIM_OCConfig.TIM_OutputState = TIM_OutputState_Enable;
-    // 2500 / 5000 = 50% duty cycle.
-    TIM_OCConfig.TIM_Pulse = 2499;
-    TIM_OCConfig.TIM_OCPolarity = TIM_OCPolarity_High;
-
-#if defined STM32F1
-    TIM_OC3Init(TIM3, &TIM_OCConfig);
-#elif defined STM32F4
-    // For STM32F4 timer clock = SystemCoreClock / 2 by default.
-    TIM_BaseConfig.TIM_Prescaler = (uint16_t)(SystemCoreClock / 2 / 10000) - 1;
-    TIM_OC1Init(TIM3, &TIM_OCConfig);
-#endif
-
-    TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
-    TIM_TimeBaseInit(TIM3, &TIM_BaseConfig);
-    TIM_ARRPreloadConfig(TIM3, ENABLE);
-    TIM_Cmd(TIM3, ENABLE);
-}
-
-void initAll(void)
-{
-    initGPIO();
-    initTimers();
-}
-
-int main(void)
-{
-    initAll();
-    for (;;);
-    return 0;
-}

+ 0 - 30
stm32-blinky-sources/stm32f10x_conf.h

@@ -1,30 +0,0 @@
-#ifndef __STM32F10x_CONF_H
-#define __STM32F10x_CONF_H
-
-/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
-
-// #include "stm32f10x_adc.h"
-// #include "stm32f10x_bkp.h"
-// #include "stm32f10x_can.h"
-// #include "stm32f10x_cec.h"
-// #include "stm32f10x_crc.h"
-// #include "stm32f10x_dac.h"
-// #include "stm32f10x_dbgmcu.h"
-// #include "stm32f10x_dma.h"
-// #include "stm32f10x_exti.h"
-// #include "stm32f10x_flash.h"
-// #include "stm32f10x_fsmc.h"
- #include "stm32f10x_gpio.h"
-// #include "stm32f10x_i2c.h"
-// #include "stm32f10x_iwdg.h"
-// #include "stm32f10x_pwr.h"
- #include "stm32f10x_rcc.h"
-// #include "stm32f10x_rtc.h"
-// #include "stm32f10x_sdio.h"
-// #include "stm32f10x_spi.h"
- #include "stm32f10x_tim.h"
-// #include "stm32f10x_usart.h"
-// #include "stm32f10x_wwdg.h"
- #include "stm32f10x_misc.h"
- 
-#endif

+ 0 - 59
stm32-blinky-sources/stm32f4xx_conf.h

@@ -1,59 +0,0 @@
-#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

+ 3 - 4
stm32-newlib/CMakeLists.txt

@@ -4,12 +4,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
 ENABLE_LANGUAGE(ASM)
 
 FIND_PACKAGE(CMSIS REQUIRED)
-FIND_PACKAGE(StdPeriphLib REQUIRED)
+FIND_PACKAGE(STM32HAL REQUIRED)
 
 INCLUDE_DIRECTORIES(
     ${CMAKE_CURRENT_SOURCE_DIR}
     ${CMSIS_INCLUDE_DIR}
-    ${StdPeriphLib_INCLUDE_DIR}
+    ${STM32HAL_INCLUDE_DIR}
 )
 
 SET(PROJECT_SOURCES
@@ -19,8 +19,7 @@ SET(PROJECT_SOURCES
 
 SET(STM32_LINKER_SCRIPT ${CMSIS_LINKER_SCRIPT})
 
-ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} ${CMSIS_STARTUP_SOURCE})
-TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} ${CMSIS_LIBRARIES} ${StdPeriphLib_LIBRARIES})
+ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} ${CMSIS_SOURCES} ${STM32HAL_SOURCES}) 
 
 STM32_SET_TARGET_PROPERTIES(${CMAKE_PROJECT_NAME})
 STM32_ADD_HEX_BIN_TARGETS(${CMAKE_PROJECT_NAME})

+ 126 - 94
stm32-newlib/main.c

@@ -1,136 +1,168 @@
 #if defined STM32F1
-# include <stm32f10x.h>
+# include <stm32f1xx_hal.h>
 #elif defined STM32F4
-# include <stm32f4xx.h>
+# include <stm32f4xx_hal.h>
 #endif
 
-#include "stm32f4xx_conf.h"
-
 #include <stdio.h>
 #include <time.h>
 
-#if defined STM32F4
-extern uint64_t virtualClock;
+UART_HandleTypeDef UART_Handle;
+uint64_t virtualTimer;
+
 void SysTick_Handler(void)
 {
-	virtualClock++;
+    HAL_IncTick();
+    virtualTimer++;
 }
-#endif
-
 
 void initGPIO()
 {
     GPIO_InitTypeDef GPIO_Config;
 #if defined STM32F1
-    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
-
-    /* USART1 Tx */
-    GPIO_Config.GPIO_Pin = GPIO_Pin_9;
-    GPIO_Config.GPIO_Mode = GPIO_Mode_AF_PP;
-    GPIO_Config.GPIO_Speed = GPIO_Speed_50MHz;
-    GPIO_Init(GPIOA, &GPIO_Config);
-
-    /* USART1 Rx */
-    GPIO_Config.GPIO_Pin = GPIO_Pin_10;
-    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);
+    __GPIOA_CLK_ENABLE();
 
-    if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
-    {
-        PWR_BackupAccessCmd(ENABLE);
+    /* USART1 */
+    GPIO_Config.Mode = GPIO_MODE_AF_PP;
+    GPIO_Config.Pin = GPIO_PIN_9;
+    GPIO_Config.Pull = GPIO_NOPULL;
+    GPIO_Config.Speed = GPIO_SPEED_HIGH;
 
-        BKP_DeInit();
-        RCC_LSEConfig(RCC_LSE_ON);
+    HAL_GPIO_Init(GPIOA, &GPIO_Config);
 
-        while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
+    GPIO_Config.Mode = GPIO_MODE_INPUT;
+    GPIO_Config.Pin = GPIO_PIN_10;
 
-        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
+    HAL_GPIO_Init(GPIOA, &GPIO_Config);
+#elif defined STM32F4
+    __GPIOC_CLK_ENABLE();
 
-        RCC_RTCCLKCmd(ENABLE);
-        RTC_WaitForSynchro();
-        RTC_WaitForLastTask();
+    /* USART3 */
+    GPIO_Config.Alternate = GPIO_AF7_USART3;
+    GPIO_Config.Mode = GPIO_MODE_AF_PP;
+    GPIO_Config.Pin = GPIO_PIN_10 | GPIO_PIN_11;
+    GPIO_Config.Pull = GPIO_NOPULL;
+    GPIO_Config.Speed = GPIO_SPEED_FAST;
 
-        RTC_SetPrescaler(32767);
-        RTC_WaitForLastTask();
+    HAL_GPIO_Init(GPIOC, &GPIO_Config);
+#endif
+}
 
-        BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
-        PWR_BackupAccessCmd(DISABLE);
-    }
-    RTC_WaitForSynchro();
-    RTC_WaitForLastTask();
+void initUART()
+{
+#if defined STM32F1
+    __USART1_CLK_ENABLE();
+    UART_Handle.Instance = USART1;
 #elif defined STM32F4
-    SysTick_Config(SystemCoreClock / 8 / 1000);
-    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
+    __USART3_CLK_ENABLE();
+    UART_Handle.Instance = USART3;
 #endif
-}
 
-void initUSART()
+    UART_Handle.Init.BaudRate = 115200;
+    UART_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+    UART_Handle.Init.Mode = UART_MODE_TX_RX;
+    UART_Handle.Init.OverSampling = UART_OVERSAMPLING_16;
+    UART_Handle.Init.Parity = UART_PARITY_NONE;
+    UART_Handle.Init.StopBits = UART_STOPBITS_1;
+    UART_Handle.Init.WordLength = UART_WORDLENGTH_8B;
+
+    HAL_UART_Init(&UART_Handle);
+}
+void initClock(void)
 {
-    USART_InitTypeDef USART_InitStructure;
+    RCC_ClkInitTypeDef RCC_ClkInitStruct;
+    RCC_OscInitTypeDef RCC_OscInitStruct;
 
-    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;
+    __HAL_RCC_PWR_CLK_ENABLE();
 
 #if defined STM32F1
-    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
-    USART_Init(USART1, &USART_InitStructure);
-    USART_Cmd(USART1, ENABLE);
+    uint8_t fLatency;
+
+    RCC_OscInitStruct.OscillatorType  = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE;
+    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+    RCC_OscInitStruct.LSEState = RCC_LSE_ON;
+    RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
+    RCC_OscInitStruct.HSICalibrationValue = 0;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+
+# if (defined STM32F100xB) || (defined STM32F100xE)
+    // 8 MHz * 3 = 24 MHz SYSCLK
+    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL3;
+    fLatency = FLASH_LATENCY_0;
+# elif (defined STM32F101x6) || (defined STM32F101xB) || (defined STM32F101xE) || (defined STM32F101xG)
+    // 8 MHz / 2 * 9 = 36 MHz SYSCLK
+    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV2;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
+    fLatency = FLASH_LATENCY_1;
+# elif (defined STM32F102x6) || (defined STM32F102xB)
+    // 8 MHz * 6 = 48 MHz SYSCLK
+    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
+    fLatency = FLASH_LATENCY_1;
+# elif (defined STM32F103x6) || (defined STM32F103xB) || (defined STM32F103xE) || (defined STM32F103xG)
+    // 8 MHz * 9 = 72 MHz SYSCLK
+    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
+    fLatency = FLASH_LATENCY_2;
+# elif (defined STM32F105xC) || (defined STM32F107xC)
+    // 8 MHz * 9 = 72 MHz SYSCLK
+    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
+    fLatency = FLASH_LATENCY_2;
+# endif
+
+    HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+    RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
+
+    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, fLatency);
+
 #elif defined STM32F4
-    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
-    USART_Init(USART3, &USART_InitStructure);
-    USART_Cmd(USART3, ENABLE);
+    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+    // 8 MHz * 336 / 8 / 2 = 168 MHz SYSCLK
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+    RCC_OscInitStruct.PLL.PLLM = 8;
+    RCC_OscInitStruct.PLL.PLLN = 336;
+    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
+    RCC_OscInitStruct.PLL.PLLQ = 7;
+    HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+    RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
+    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
+    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
+
+    if (HAL_GetREVID() == 0x1001)
+    {
+        __HAL_FLASH_PREFETCH_BUFFER_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
+    virtualTimer = (uint64_t)time * 1000;
 }
 
 void initAll(void)
 {
-    initRTC();
+    HAL_Init();
+
+    initClock();
     initGPIO();
-    initUSART();
-    RCC_ClearFlag();
+    initUART();
 }
 
 int main(void)
@@ -138,7 +170,7 @@ int main(void)
     initAll();
     for (;;)
     {
-        char c;
+        char c = 0;
         time_t t;
         scanf("%c", &c);
         switch (c)

+ 9 - 38
stm32-newlib/newlib.c

@@ -5,26 +5,14 @@
 #include <sys/time.h>
 
 #if defined STM32F1
-# include <stm32f10x.h>
+# include <stm32f1xx_hal.h>
 #elif defined STM32F4
-# include <stm32f4xx.h>
-#endif
-
-#if defined STM32F4
-uint64_t virtualClock = 0;
+# include <stm32f4xx_hal.h>
 #endif
 
 extern uint32_t __get_MSP(void);
-
-#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
+extern UART_HandleTypeDef UART_Handle;
+extern uint64_t virtualTimer;
 
 #undef errno
 extern int errno;
@@ -69,13 +57,8 @@ 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
+    tv->tv_sec = virtualTimer / 1000;
+    tv->tv_usec = (virtualTimer % 1000) * 1000;
     return 0;
 }
 
@@ -138,11 +121,8 @@ int _read(int file, char *ptr, int len)
     switch (file)
     {
     case STDIN_FILENO:
-        while (USART_GetFlagStatus(STDIN_USART, USART_FLAG_RXNE) == RESET);
-        char c = (char)(USART_ReceiveData(STDIN_USART) & (uint16_t) 0x01FF);
-        *ptr++ = c;
+        HAL_UART_Receive(&UART_Handle, (uint8_t *)ptr, 1, HAL_MAX_DELAY);
         return 1;
-        break;
     default:
         errno = EBADF;
         return -1;
@@ -174,22 +154,13 @@ int _wait(int *status)
 
 int _write(int file, char *ptr, int len)
 {
-    int n;
     switch (file)
     {
     case STDOUT_FILENO: /*stdout*/
-        for (n = 0; n < len; n++)
-        {
-            while (USART_GetFlagStatus(STDOUT_USART, USART_FLAG_TC) == RESET);
-            USART_SendData(STDOUT_USART, (uint8_t) * ptr++);
-        }
+        HAL_UART_Transmit(&UART_Handle, (uint8_t*)ptr, len, HAL_MAX_DELAY);
         break;
     case STDERR_FILENO: /* stderr */
-        for (n = 0; n < len; n++)
-        {
-            while (USART_GetFlagStatus(STDERR_USART, USART_FLAG_TC) == RESET);
-            USART_SendData(STDERR_USART, (uint8_t) * ptr++);
-        }
+        HAL_UART_Transmit(&UART_Handle, (uint8_t*)ptr, len, HAL_MAX_DELAY);
         break;
     default:
         errno = EBADF;

+ 0 - 30
stm32-newlib/stm32f10x_conf.h

@@ -1,30 +0,0 @@
-#ifndef __STM32F10x_CONF_H
-#define __STM32F10x_CONF_H
-
-/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
-
-// #include "stm32f10x_adc.h"
- #include "stm32f10x_bkp.h"
-// #include "stm32f10x_can.h"
-// #include "stm32f10x_cec.h"
-// #include "stm32f10x_crc.h"
-// #include "stm32f10x_dac.h"
-// #include "stm32f10x_dbgmcu.h"
-// #include "stm32f10x_dma.h"
-// #include "stm32f10x_exti.h"
-// #include "stm32f10x_flash.h"
-// #include "stm32f10x_fsmc.h"
- #include "stm32f10x_gpio.h"
-// #include "stm32f10x_i2c.h"
-// #include "stm32f10x_iwdg.h"
- #include "stm32f10x_pwr.h"
- #include "stm32f10x_rcc.h"
- #include "stm32f10x_rtc.h"
-// #include "stm32f10x_sdio.h"
-// #include "stm32f10x_spi.h"
-// #include "stm32f10x_tim.h"
- #include "stm32f10x_usart.h"
-// #include "stm32f10x_wwdg.h"
- #include "stm32f10x_misc.h"
- 
-#endif

+ 367 - 0
stm32-newlib/stm32f1xx_hal_conf.h

@@ -0,0 +1,367 @@
+/**
+  ******************************************************************************
+  * @file    stm32f1xx_hal_conf.h
+  * @author  MCD Application Team
+  * @version V1.0.0
+  * @date    15-December-2014
+  * @brief   HAL configuration template file.
+  *          This file should be copied to the application folder and renamed
+  *          to stm32f1xx_hal_conf.h.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F1xx_HAL_CONF_H
+#define __STM32F1xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+/* ########################## Module Selection ############################## */
+/**
+  * @brief This is the list of modules to be used in the HAL driver 
+  */
+#define HAL_MODULE_ENABLED
+// #define HAL_ADC_MODULE_ENABLED
+// #define HAL_CAN_MODULE_ENABLED
+// #define HAL_CEC_MODULE_ENABLED
+#define HAL_CORTEX_MODULE_ENABLED
+// #define HAL_CRC_MODULE_ENABLED
+// #define HAL_DAC_MODULE_ENABLED
+#define HAL_DMA_MODULE_ENABLED
+// #define HAL_ETH_MODULE_ENABLED
+#define HAL_FLASH_MODULE_ENABLED
+#define HAL_GPIO_MODULE_ENABLED
+// #define HAL_HCD_MODULE_ENABLED
+// #define HAL_I2C_MODULE_ENABLED
+// #define HAL_I2S_MODULE_ENABLED
+// #define HAL_IRDA_MODULE_ENABLED
+// #define HAL_IWDG_MODULE_ENABLED
+// #define HAL_NAND_MODULE_ENABLED
+// #define HAL_NOR_MODULE_ENABLED
+// #define HAL_PCCARD_MODULE_ENABLED
+// #define HAL_PCD_MODULE_ENABLED
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+// #define HAL_RTC_MODULE_ENABLED
+// #define HAL_SD_MODULE_ENABLED
+// #define HAL_SMARTCARD_MODULE_ENABLED
+// #define HAL_SPI_MODULE_ENABLED
+// #define HAL_SRAM_MODULE_ENABLED
+// #define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+// #define HAL_USART_MODULE_ENABLED
+// #define HAL_WWDG_MODULE_ENABLED
+
+/* ########################## Oscillator Values adaptation ####################*/
+/**
+  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSE is used as system clock source, directly or through the PLL).  
+  */
+#if !defined  (HSE_VALUE) 
+#if defined(USE_STM3210C_EVAL)
+  #define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
+#else
+  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif
+#endif /* HSE_VALUE */
+
+#if !defined  (HSE_STARTUP_TIMEOUT)
+  #define HSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+  * @brief Internal High Speed oscillator (HSI) value.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSI is used as system clock source, directly or through the PLL). 
+  */
+#if !defined  (HSI_VALUE)
+  #define HSI_VALUE    ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+  * @brief External Low Speed oscillator (LSE) value.
+  *        This value is used by the UART, RTC HAL module to compute the system frequency
+  */
+#if !defined  (LSE_VALUE)
+  #define LSE_VALUE    ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/
+#endif /* LSE_VALUE */
+
+   
+#if !defined  (LSE_STARTUP_TIMEOUT)
+  #define LSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for LSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+   
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+   ===  you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+  * @brief This is the HAL system configuration section
+  */     
+#define  VDD_VALUE                    ((uint32_t)3300) /*!< Value of VDD in mv */           
+#define  TICK_INT_PRIORITY            ((uint32_t)0x000F)    /*!< tick interrupt priority */            
+#define  USE_RTOS                     0     
+#define  PREFETCH_ENABLE              1
+
+/* ########################## Assert Selection ############################## */
+/**
+  * @brief Uncomment the line below to expanse the "assert_param" macro in the 
+  *        HAL drivers code
+  */
+/*#define USE_FULL_ASSERT    1*/ 
+
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0   2
+#define MAC_ADDR1   0
+#define MAC_ADDR2   0
+#define MAC_ADDR3   0
+#define MAC_ADDR4   0
+#define MAC_ADDR5   0
+
+/* Definition of the Ethernet driver buffers size and count */   
+#define ETH_RX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for receive               */
+#define ETH_TX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for transmit              */
+#define ETH_RXBUFNB                    ((uint32_t)8)       /* 4 Rx buffers of size ETH_RX_BUF_SIZE  */
+#define ETH_TXBUFNB                    ((uint32_t)4)       /* 4 Tx buffers of size ETH_TX_BUF_SIZE  */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/ 
+#define DP83848_PHY_ADDRESS             0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 
+#define PHY_RESET_DELAY                 ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY                ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO                     ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO                    ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR                         ((uint16_t)0x00)    /*!< Transceiver Basic Control Register   */
+#define PHY_BSR                         ((uint16_t)0x01)    /*!< Transceiver Basic Status Register    */
+ 
+#define PHY_RESET                       ((uint16_t)0x8000)  /*!< PHY Reset */
+#define PHY_LOOPBACK                    ((uint16_t)0x4000)  /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M             ((uint16_t)0x2100)  /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M             ((uint16_t)0x2000)  /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M              ((uint16_t)0x0100)  /*!< Set the full-duplex mode at 10 Mb/s  */
+#define PHY_HALFDUPLEX_10M              ((uint16_t)0x0000)  /*!< Set the half-duplex mode at 10 Mb/s  */
+#define PHY_AUTONEGOTIATION             ((uint16_t)0x1000)  /*!< Enable auto-negotiation function     */
+#define PHY_RESTART_AUTONEGOTIATION     ((uint16_t)0x0200)  /*!< Restart auto-negotiation function    */
+#define PHY_POWERDOWN                   ((uint16_t)0x0800)  /*!< Select the power down mode           */
+#define PHY_ISOLATE                     ((uint16_t)0x0400)  /*!< Isolate PHY from MII                 */
+
+#define PHY_AUTONEGO_COMPLETE           ((uint16_t)0x0020)  /*!< Auto-Negotiation process completed   */
+#define PHY_LINKED_STATUS               ((uint16_t)0x0004)  /*!< Valid link established               */
+#define PHY_JABBER_DETECTION            ((uint16_t)0x0002)  /*!< Jabber condition detected            */
+  
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR                          ((uint16_t)0x10)    /*!< PHY status register Offset                      */
+#define PHY_MICR                        ((uint16_t)0x11)    /*!< MII Interrupt Control Register                  */
+#define PHY_MISR                        ((uint16_t)0x12)    /*!< MII Interrupt Status and Misc. Control Register */
+ 
+#define PHY_LINK_STATUS                 ((uint16_t)0x0001)  /*!< PHY Link mask                                   */
+#define PHY_SPEED_STATUS                ((uint16_t)0x0002)  /*!< PHY Speed mask                                  */
+#define PHY_DUPLEX_STATUS               ((uint16_t)0x0004)  /*!< PHY Duplex mask                                 */
+
+#define PHY_MICR_INT_EN                 ((uint16_t)0x0002)  /*!< PHY Enable interrupts                           */
+#define PHY_MICR_INT_OE                 ((uint16_t)0x0001)  /*!< PHY Enable output interrupt events              */
+
+#define PHY_MISR_LINK_INT_EN            ((uint16_t)0x0020)  /*!< Enable Interrupt on change of link status       */
+#define PHY_LINK_INTERRUPT              ((uint16_t)0x2000)  /*!< PHY link status interrupt mask                  */
+
+
+
+/* Includes ------------------------------------------------------------------*/
+/**
+  * @brief Include module's header file 
+  */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f1xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f1xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+   
+#ifdef HAL_DMA_MODULE_ENABLED
+  #include "stm32f1xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+   
+#ifdef HAL_ETH_MODULE_ENABLED
+  #include "stm32f1xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */  
+   
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f1xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CEC_MODULE_ENABLED
+ #include "stm32f1xx_hal_cec.h"
+#endif /* HAL_CEC_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f1xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f1xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f1xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f1xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f1xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f1xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f1xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f1xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f1xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f1xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f1xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f1xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f1xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */ 
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f1xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */  
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f1xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */     
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f1xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f1xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f1xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f1xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f1xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f1xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f1xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f1xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f1xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */   
+   
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef  USE_FULL_ASSERT
+/**
+  * @brief  The assert_param macro is used for function's parameters check.
+  * @param  expr: If expr is false, it calls assert_failed function
+  *         which reports the name of the source file and the source
+  *         line number of the call that failed. 
+  *         If expr is true, it returns no value.
+  * @retval None
+  */
+  #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+  void assert_failed(uint8_t* file, uint32_t line);
+#else
+  #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F1xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 59
stm32-newlib/stm32f4xx_conf.h

@@ -1,59 +0,0 @@
-#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

+ 427 - 0
stm32-newlib/stm32f4xx_hal_conf.h

@@ -0,0 +1,427 @@
+/**
+  ******************************************************************************
+  * @file    stm32f4xx_hal_conf_template.h
+  * @author  MCD Application Team
+  * @version V1.3.1
+  * @date    25-March-2015
+  * @brief   HAL configuration template file. 
+  *          This file should be copied to the application folder and renamed
+  *          to stm32f4xx_hal_conf.h.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+/* ########################## Module Selection ############################## */
+/**
+  * @brief This is the list of modules to be used in the HAL driver 
+  */
+#define HAL_MODULE_ENABLED  
+// #define HAL_ADC_MODULE_ENABLED  
+// #define HAL_CAN_MODULE_ENABLED  
+// #define HAL_CRC_MODULE_ENABLED  
+// #define HAL_CEC_MODULE_ENABLED
+// #define HAL_CRYP_MODULE_ENABLED  
+// #define HAL_DAC_MODULE_ENABLED  
+// #define HAL_DCMI_MODULE_ENABLED 
+#define HAL_DMA_MODULE_ENABLED
+// #define HAL_DMA2D_MODULE_ENABLED 
+// #define HAL_ETH_MODULE_ENABLED 
+#define HAL_FLASH_MODULE_ENABLED 
+// #define HAL_NAND_MODULE_ENABLED
+// #define HAL_NOR_MODULE_ENABLED
+// #define HAL_PCCARD_MODULE_ENABLED
+// #define HAL_SRAM_MODULE_ENABLED
+// #define HAL_SDRAM_MODULE_ENABLED
+// #define HAL_HASH_MODULE_ENABLED  
+#define HAL_GPIO_MODULE_ENABLED
+// #define HAL_I2C_MODULE_ENABLED
+// #define HAL_I2S_MODULE_ENABLED   
+// #define HAL_IWDG_MODULE_ENABLED 
+// #define HAL_LTDC_MODULE_ENABLED 
+#define HAL_PWR_MODULE_ENABLED   
+// #define HAL_QSPI_MODULE_ENABLED   
+#define HAL_RCC_MODULE_ENABLED 
+// #define HAL_RNG_MODULE_ENABLED   
+#define HAL_RTC_MODULE_ENABLED
+// #define HAL_SAI_MODULE_ENABLED   
+// #define HAL_SD_MODULE_ENABLED  
+// #define HAL_SPI_MODULE_ENABLED   
+// #define HAL_TIM_MODULE_ENABLED   
+#define HAL_UART_MODULE_ENABLED
+// #define HAL_USART_MODULE_ENABLED
+// #define HAL_IRDA_MODULE_ENABLED 
+// #define HAL_SMARTCARD_MODULE_ENABLED 
+// #define HAL_WWDG_MODULE_ENABLED  
+#define HAL_CORTEX_MODULE_ENABLED
+// #define HAL_PCD_MODULE_ENABLED
+// #define HAL_HCD_MODULE_ENABLED
+// #define HAL_FMPI2C_MODULE_ENABLED
+// #define HAL_SPDIFRX_MODULE_ENABLED
+
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSE is used as system clock source, directly or through the PLL).  
+  */
+#if !defined  (HSE_VALUE) 
+  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined  (HSE_STARTUP_TIMEOUT)
+  #define HSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+  * @brief Internal High Speed oscillator (HSI) value.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSI is used as system clock source, directly or through the PLL). 
+  */
+#if !defined  (HSI_VALUE)
+  #define HSI_VALUE    ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+  * @brief Internal Low Speed oscillator (LSI) value.
+  */
+#if !defined  (LSI_VALUE) 
+ #define LSI_VALUE  ((uint32_t)32000)       /*!< LSI Typical Value in Hz*/
+#endif /* LSI_VALUE */                      /*!< Value of the Internal Low Speed oscillator in Hz
+                                             The real value may vary depending on the variations
+                                             in voltage and temperature.*/
+/**
+  * @brief External Low Speed oscillator (LSE) value.
+  */
+#if !defined  (LSE_VALUE)
+ #define LSE_VALUE  ((uint32_t)32768)    /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+/**
+  * @brief External clock source for I2S peripheral
+  *        This value is used by the I2S HAL module to compute the I2S clock source 
+  *        frequency, this source is inserted directly through I2S_CKIN pad. 
+  */
+#if !defined  (EXTERNAL_CLOCK_VALUE)
+  #define EXTERNAL_CLOCK_VALUE    ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+   ===  you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+  * @brief This is the HAL system configuration section
+  */     
+#define  VDD_VALUE                    ((uint32_t)3300) /*!< Value of VDD in mv */
+#define  TICK_INT_PRIORITY            ((uint32_t)0x0F) /*!< tick interrupt priority */
+#define  USE_RTOS                     0
+#define  PREFETCH_ENABLE              1
+#define  INSTRUCTION_CACHE_ENABLE     1
+#define  DATA_CACHE_ENABLE            1
+
+/* ########################## Assert Selection ############################## */
+/**
+  * @brief Uncomment the line below to expanse the "assert_param" macro in the 
+  *        HAL drivers code
+  */
+/* #define USE_FULL_ASSERT    1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0   2
+#define MAC_ADDR1   0
+#define MAC_ADDR2   0
+#define MAC_ADDR3   0
+#define MAC_ADDR4   0
+#define MAC_ADDR5   0
+
+/* Definition of the Ethernet driver buffers size and count */   
+#define ETH_RX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for receive               */
+#define ETH_TX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for transmit              */
+#define ETH_RXBUFNB                    ((uint32_t)4)       /* 4 Rx buffers of size ETH_RX_BUF_SIZE  */
+#define ETH_TXBUFNB                    ((uint32_t)4)       /* 4 Tx buffers of size ETH_TX_BUF_SIZE  */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/ 
+#define DP83848_PHY_ADDRESS             0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 
+#define PHY_RESET_DELAY                 ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY                ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO                     ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO                    ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR                         ((uint16_t)0x00)    /*!< Transceiver Basic Control Register   */
+#define PHY_BSR                         ((uint16_t)0x01)    /*!< Transceiver Basic Status Register    */
+ 
+#define PHY_RESET                       ((uint16_t)0x8000)  /*!< PHY Reset */
+#define PHY_LOOPBACK                    ((uint16_t)0x4000)  /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M             ((uint16_t)0x2100)  /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M             ((uint16_t)0x2000)  /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M              ((uint16_t)0x0100)  /*!< Set the full-duplex mode at 10 Mb/s  */
+#define PHY_HALFDUPLEX_10M              ((uint16_t)0x0000)  /*!< Set the half-duplex mode at 10 Mb/s  */
+#define PHY_AUTONEGOTIATION             ((uint16_t)0x1000)  /*!< Enable auto-negotiation function     */
+#define PHY_RESTART_AUTONEGOTIATION     ((uint16_t)0x0200)  /*!< Restart auto-negotiation function    */
+#define PHY_POWERDOWN                   ((uint16_t)0x0800)  /*!< Select the power down mode           */
+#define PHY_ISOLATE                     ((uint16_t)0x0400)  /*!< Isolate PHY from MII                 */
+
+#define PHY_AUTONEGO_COMPLETE           ((uint16_t)0x0020)  /*!< Auto-Negotiation process completed   */
+#define PHY_LINKED_STATUS               ((uint16_t)0x0004)  /*!< Valid link established               */
+#define PHY_JABBER_DETECTION            ((uint16_t)0x0002)  /*!< Jabber condition detected            */
+  
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR                          ((uint16_t)0x10)    /*!< PHY status register Offset                      */
+#define PHY_MICR                        ((uint16_t)0x11)    /*!< MII Interrupt Control Register                  */
+#define PHY_MISR                        ((uint16_t)0x12)    /*!< MII Interrupt Status and Misc. Control Register */
+ 
+#define PHY_LINK_STATUS                 ((uint16_t)0x0001)  /*!< PHY Link mask                                   */
+#define PHY_SPEED_STATUS                ((uint16_t)0x0002)  /*!< PHY Speed mask                                  */
+#define PHY_DUPLEX_STATUS               ((uint16_t)0x0004)  /*!< PHY Duplex mask                                 */
+
+#define PHY_MICR_INT_EN                 ((uint16_t)0x0002)  /*!< PHY Enable interrupts                           */
+#define PHY_MICR_INT_OE                 ((uint16_t)0x0001)  /*!< PHY Enable output interrupt events              */
+
+#define PHY_MISR_LINK_INT_EN            ((uint16_t)0x0020)  /*!< Enable Interrupt on change of link status       */
+#define PHY_LINK_INTERRUPT              ((uint16_t)0x2000)  /*!< PHY link status interrupt mask                  */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+  * @brief Include module's header file 
+  */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+  #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+  #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+  #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+   
+#ifdef HAL_CORTEX_MODULE_ENABLED
+  #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+  #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+  #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+  #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+  #include "stm32f4xx_hal_cryp.h" 
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+  #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+  #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+  #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+  #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+  #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+ 
+#ifdef HAL_SRAM_MODULE_ENABLED
+  #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+  #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+  #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+  #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */ 
+  
+#ifdef HAL_SDRAM_MODULE_ENABLED
+  #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */      
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+   
+#ifdef HAL_QSPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_qspi.h"
+#endif /* HAL_QSPI_MODULE_ENABLED */
+
+#ifdef HAL_CEC_MODULE_ENABLED
+ #include "stm32f4xx_hal_cec.h"
+#endif /* HAL_CEC_MODULE_ENABLED */
+
+#ifdef HAL_FMPI2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_fmpi2c.h"
+#endif /* HAL_FMPI2C_MODULE_ENABLED */
+
+#ifdef HAL_SPDIFRX_MODULE_ENABLED
+ #include "stm32f4xx_hal_spdifrx.h"
+#endif /* HAL_SPDIFRX_MODULE_ENABLED */
+   
+/* Exported macro ------------------------------------------------------------*/
+#ifdef  USE_FULL_ASSERT
+/**
+  * @brief  The assert_param macro is used for function's parameters check.
+  * @param  expr: If expr is false, it calls assert_failed function
+  *         which reports the name of the source file and the source
+  *         line number of the call that failed. 
+  *         If expr is true, it returns no value.
+  * @retval None
+  */
+  #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+  void assert_failed(uint8_t* file, uint32_t line);
+#else
+  #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 3 - 2
stm32-template/CMakeLists.txt

@@ -4,10 +4,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
 ENABLE_LANGUAGE(ASM)
 
 FIND_PACKAGE(CMSIS REQUIRED)
+#FIND_PACKAGE(STM32HAL REQUIRED)
 
 INCLUDE_DIRECTORIES(
     ${CMAKE_CURRENT_SOURCE_DIR}
     ${CMSIS_INCLUDE_DIR}
+    #${STM32HAL_INCLUDE_DIR}
 )
 
 SET(PROJECT_SOURCES
@@ -16,8 +18,7 @@ SET(PROJECT_SOURCES
 
 SET(STM32_LINKER_SCRIPT ${CMSIS_LINKER_SCRIPT})
 
-ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} ${CMSIS_STARTUP_SOURCE})
-TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} ${CMSIS_LIBRARIES})
+ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} ${CMSIS_SOURCES}) # ${STM32HAL_SOURCES}
 
 STM32_SET_TARGET_PROPERTIES(${CMAKE_PROJECT_NAME})
 STM32_ADD_HEX_BIN_TARGETS(${CMAKE_PROJECT_NAME})

+ 3 - 3
stm32-template/main.c

@@ -1,6 +1,6 @@
-#ifdef STM32F1
-# include <stm32f10x.h>
-#elifdef STM32F4
+#if defined STM32F1
+# include <stm32f1xx.h>
+#elif defined STM32F4
 # include <stm32f4xx.h>
 #endif