Pycon commit.

This commit is contained in:
cylon 2016-10-28 11:30:47 +02:00
parent 98b1c95a52
commit 3525ba32e7
6 changed files with 290 additions and 13 deletions

79
CMakeLists.txt Normal file
View File

@ -0,0 +1,79 @@
# CMake minimum version
cmake_minimum_required (VERSION {{ cmake.version }})
# Project Infomation
project( {{ cmake.project }} )
enable_language(ASM)
enable_language(C)
# Reset output path
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
# STDLIB
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
# Set include path
{% for inc in cmake.incs %}
include_directories ({{ inc }})
{% endfor %}
# The need build source path and build all files
{% for src in cmake.files %}
set ({{ src.var }} {{ src.path }})
{% endfor %}
{% for as in cmake.ass %}
set_source_files_properties({{ as.path }} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
{% endfor %}
set(CROSS_TARGET_TRIPLET "arm-none-eabi-")
# CC AR LD AS
set(CMAKE_C_COMPILER "${CROSS_TARGET_TRIPLET}gcc")
{%if cmake.cxx == 'true' %}
set(CMAKE_CXX_COMPILER "${CROSS_TARGET_TRIPLET}g++")
{% endif %}
set(CMAKE_ASM_COMPILER "${CROSS_TARGET_TRIPLET}gcc")
# CFLAGS
set (CMAKE_C_FLAGS "{{ cmake.c_flags }}" CACHE INTERNAL "c compiler flags")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} {% for define in cmake.defines %} -D {{ define }} {% endfor %}")
# CXXFLAGS
set (CMAKE_CXX_FLAGS "{{ cmake.cxx_flags }}" CACHE INTERNAL "cxx compiler flags")
# ASMFLAGS
set (CMAKE_ASM_FLAGS "{{ cmake.asm_flags }}" CACHE INTERNAL "asm compiler flags")
# LDFLAGS
set (CMAKE_EXE_LINKER_FLAGS "{{ cmake.linker_flags }}" CACHE INTERNAL "executable linker flags")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${CMAKE_SOURCE_DIR}/{{ cmake.linker_script }} -L {{ cmake.linker_path }}")
{% for lib in cmake.libs %}
# Load the the extern library
set ({{ lib.name }} ${CMAKE_SOURCE_DIR}/{{ lib.path }}/{{ lib.name }}.a)
#add_library ({{ lib.name }} STATIC IMPORTED)
#set_property ({{ lib.name }} PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/{{ lib.path }}/{{ lib.name }}.a)
{% endfor %}
# Generate the target
add_executable (${CMAKE_PROJECT_NAME}.elf {% for src in cmake.files %} {{ '${' }}{{ src.var }}{{ '}' }} {% endfor %})
# Link the library to the target
target_link_libraries (${CMAKE_PROJECT_NAME}.elf {% for lib in cmake.libs %} {{ lib.name }} {% endfor %})
# Generate the binary file
add_custom_target (${CMAKE_PROJECT_NAME}.bin ALL arm-none-eabi-objcopy -Obinary "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.bin" DEPENDS ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf)
# Generate the hex file
add_custom_target (${CMAKE_PROJECT_NAME}.hex ALL arm-none-eabi-objcopy -Oihex "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.hex" DEPENDS ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf)
# Echo the size Infomation
add_custom_target (size ALL arm-none-eabi-size "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf" DEPENDS ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.elf)
# Make flash to the board by st-link
add_custom_target (flash COMMAND st-flash write ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_PROJECT_NAME}.bin 0x8000000)
# Make clean-all
add_custom_target (clean-all COMMAND rm -rf ${CMAKE_BINARY_DIR}/*)

188
STM32FLASH.ld Normal file
View File

@ -0,0 +1,188 @@
/*
*****************************************************************************
**
** File : LinkerScript.ld
**
** Abstract : Linker script for STM32F030R8Tx Device with
** 64KByte FLASH, 8KByte RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
*****************************************************************************
** @attention
**
** <h2><center>&copy; COPYRIGHT(c) 2014 Ac6</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 Ac6 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.
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20002000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = {{ flash }}K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = {{ ram }}K
}
/* 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) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >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 (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = 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 AT> FLASH
/* 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
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@ -1,5 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" CMake generation module
@file
"""
import os import os
import platform import platform
import datetime import datetime
@ -53,6 +57,7 @@ class CMake (object):
i=0 i=0
cmake['files']=[] cmake['files']=[]
cmake['ass']=[]
for file in self.project['srcs']: for file in self.project['srcs']:
if file.endswith('.c') or file.endswith('.h'): if file.endswith('.c') or file.endswith('.h'):
@ -60,6 +65,8 @@ class CMake (object):
i = i+1 i = i+1
for file in self.project['files']: for file in self.project['files']:
print ('Assembly added ' + file)
cmake['ass'].append({'path': file})
cmake['files'].append({'path': file,'var':'SRC_FILE' + str(i)}) cmake['files'].append({'path': file,'var':'SRC_FILE' + str(i)})
i = i+1 i = i+1
@ -69,13 +76,14 @@ class CMake (object):
cmake['cxx_flags'] = '-Wextra -Wshadow -Wredundant-decls -Weffc++ -fno-common -ffunction-sections -fdata-sections -MD -Wall -Wundef -mthumb ' + core + ' ' + fpu cmake['cxx_flags'] = '-Wextra -Wshadow -Wredundant-decls -Weffc++ -fno-common -ffunction-sections -fdata-sections -MD -Wall -Wundef -mthumb ' + core + ' ' + fpu
cmake['asm_flags'] = '-g -mthumb ' + core + ' ' + fpu + ' -x assembler-with-cpp' cmake['asm_flags'] = '-g -mthumb ' + core + ' ' + fpu #+ ' -x assembler-with-cpp'
cmake['linker_flags'] = '-g -Wl,--gc-sections -Wl,-Map=' + cmake['project'] + '.map -mthumb ' + core + ' ' + fpu cmake['linker_flags'] = '-g -Wl,--gc-sections -Wl,-Map=' + cmake['project'] + '.map -mthumb ' + core + ' ' + fpu
cmake['linker_script'] = 'STM32FLASH.ld' cmake['linker_script'] = 'STM32FLASH.ld'
cmake['linker_path'] = '' cmake['linker_path'] = ''
self.linkerScript('STM32FLASH.ld',os.path.join(self.path,'STM32FLASH.ld')) self.linkerScript('STM32FLASH.ld',os.path.join(self.path,'STM32FLASH.ld'))
cmake['oocd_target'] = 'stm32f3x'
cmake['defines'] = [] cmake['defines'] = []
for define in self.project['defs']: for define in self.project['defs']:
cmake['defines'].append(define) cmake['defines'].append(define)
@ -88,7 +96,8 @@ class CMake (object):
print ('Created file CMakeLists.txt') print ('Created file CMakeLists.txt')
def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='../PegasusTemplates'): # def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='../PegasusTemplates'):
def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='.'):
if (pathDst == ''): if (pathDst == ''):
pathDst = pathSrc pathDst = pathSrc
@ -117,7 +126,8 @@ class CMake (object):
# Different OS than Windows or Linux # Different OS than Windows or Linux
pass pass
def linkerScript(self,pathSrc, pathDst='',template_dir='../PegasusTemplates'): def linkerScript(self,pathSrc, pathDst='',template_dir='.'):
# def linkerScript(self,pathSrc, pathDst='',template_dir='.../PegasusTemplates'):
if (pathDst == ''): if (pathDst == ''):
pathDst = pathSrc pathDst = pathSrc

View File

@ -20,7 +20,7 @@ def find_file(path, fileext):
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for file in files: for file in files:
if file.endswith(fileext): if file.endswith(fileext):
file = os.path.join(root, filename) filename = os.path.join(root, file)
return filename return filename
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -60,10 +60,10 @@ class EWPProject(object):
self.project['files'] = [] self.project['files'] = []
i = 0 i = 0
if os.path.exists(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'): if os.path.exists(self.path + '/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc'):
for entry in os.listdir(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'): for entry in os.listdir(self.path + '/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc'):
if entry.endswith('.S') or entry.endswith('.s'): if entry.endswith('.S') or entry.endswith('.s'):
self.project['files'].append(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc/'+entry) self.project['files'].append(self.path + '/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc/'+entry)
def displaySummary(self): def displaySummary(self):
""" Display summary of parsed project settings """ Display summary of parsed project settings

View File

@ -54,10 +54,10 @@ class UVPROJXProject(object):
self.project['files'] = [] self.project['files'] = []
i = 0 i = 0
if os.path.exists(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'): if os.path.exists(self.path + '/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc'):
for entry in os.listdir(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'): for entry in os.listdir(self.path + '/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc'):
if entry.endswith('.S') or entry.endswith('.s'): if entry.endswith('.S') or entry.endswith('.s'):
self.project['files'].append(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc/'+ entry) self.project['files'].append(self.path + '/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc/'+ entry)
def displaySummary(self): def displaySummary(self):
""" Display summary of parsed project settings """ Display summary of parsed project settings