Skip to content

Commit

Permalink
timer break feature and demo. #173
Browse files Browse the repository at this point in the history
  • Loading branch information
andysworkshop committed Jul 31, 2016
1 parent a54df0f commit 770d531
Show file tree
Hide file tree
Showing 33 changed files with 9,963 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/timer_interrupts/timer_interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TimerInterruptsTest {
_ledState=false;

/*
* Set ourselves up as an observer for interrupts raised by the timer class.
* Set ourselves up as a subscriber for interrupts raised by the timer class.
*/

timer.TimerInterruptEventSender.insertSubscriber(
Expand Down Expand Up @@ -113,7 +113,7 @@ class TimerInterruptsTest {
}

/*
* Observer callback function. This is called when the update interrupt that we've
* Subscriber callback function. This is called when the update interrupt that we've
* enabled is fired.
*/

Expand Down
930 changes: 930 additions & 0 deletions examples/timer_pwm_break/.cproject

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions examples/timer_pwm_break/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
doc/
*~
*.lock
*.DS_Store
*.swp
*.out
*.class
#OS junk files
[Tt]humbs.db

*.a
*.o

#Visual Studio files

*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

# eclipse local settings

.settings/
27 changes: 27 additions & 0 deletions examples/timer_pwm_break/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>stm32plus-examples-timer_pwm_break</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
108 changes: 108 additions & 0 deletions examples/timer_pwm_break/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# SConscript build file for an stm32plus example. Called automatically by the SConstruct
# in the parent directory
#

import os

# import everything exported in SConstruct

Import('*')

# get a copy of the environment

env=env.Clone()

# verify that this example is compatible with the selected MCU

sconscriptFile=(lambda x:x).func_code.co_filename
sconscriptDir=os.path.dirname(sconscriptFile)
compatFile=os.path.join(sconscriptDir,"compat.txt");

supported=True
if os.path.exists(compatFile):
supported=False
for line in open(compatFile,"r"):
line=line.rstrip()
if not line.startswith("#") and line==mcu:
supported=True
break

if supported:

# get all the sources

matches=[]
matches.append(Glob("*.cpp"))
matches.append(Glob("*.c"))
matches.append(Glob("*.asm"))
matches.append("system/LibraryHacks.cpp")

# handle MCU differences

if mcu.startswith("f4"):
matches.append("system/f407_168_8/Startup.asm")
matches.append("system/f407_168_8/System.c")
linkerscript="examples/"+example+"/system/f407_168_8/Linker.ld"

elif mcu=="f1hd":
matches.append("system/f1hd_72_8/Startup.asm")
matches.append("system/f1hd_72_8/System.c")
linkerscript="examples/"+example+"/system/f1hd_72_8/Linker.ld"

elif mcu=="f1cle":
matches.append("system/f107_72_8/Startup.asm")
matches.append("system/f107_72_8/System.c")
linkerscript="examples/"+example+"/system/f107_72_8/Linker.ld"

elif mcu=="f1md":
matches.append("system/f1md/Startup.asm")
matches.append("system/f1md/System.c")
linkerscript="examples/"+example+"/system/f1md/Linker.ld"

elif mcu=="f1mdvl":
matches.append("system/f1mdvl_24_8/Startup.asm")
matches.append("system/f1mdvl_24_8/System.c")
linkerscript="examples/"+example+"/system/f1mdvl_24_8/Linker.ld"

elif mcu=="f042":
matches.append("system/f042_48_8/Startup.asm")
matches.append("system/f042_48_8/System.c")
linkerscript="examples/"+example+"/system/f042_48_8/Linker.ld"

elif mcu=="f051":
matches.append("system/f051_48_8/Startup.asm")
matches.append("system/f051_48_8/System.c")
linkerscript="examples/"+example+"/system/f051_48_8/Linker.ld"

elif mcu=="f030":
matches.append("system/f030_48_8/Startup.asm")
matches.append("system/f030_48_8/System.c")
linkerscript="examples/"+example+"/system/f030_48_8/Linker.ld"

buildoutdir="examples/"+example+"/build/"+systemprefix

# set the additional linker flags

env.Append(LINKFLAGS=["-T"+linkerscript,"-Wl,-wrap,__aeabi_unwind_cpp_pr0","-Wl,-wrap,__aeabi_unwind_cpp_pr1","-Wl,-wrap,__aeabi_unwind_cpp_pr2"])

# additional include directory for the graphics

env.Append(ASFLAGS="-Iexamples/"+example)

# unique additions for this example

env.Append(CPPPATH="#examples/"+example)

# trigger a build with the correct library name

elf=env.Program(example+".elf",matches)
hex=env.Command(example+".hex",elf,"arm-none-eabi-objcopy -O ihex "+buildoutdir+"/"+example+".elf "+buildoutdir+"/"+example+".hex")
bin=env.Command(example+".bin",elf,"arm-none-eabi-objcopy -O binary "+buildoutdir+"/"+example+".elf "+buildoutdir+"/"+example+".bin")
lst=env.Command(example+".lst",elf,"arm-none-eabi-objdump -h -S "+buildoutdir+"/"+example+".elf > "+buildoutdir+"/"+example+".lst")
size=env.Command(example+".size",elf,"arm-none-eabi-size --format=berkeley "+buildoutdir+"/"+example+".elf | tee "+buildoutdir+"/"+example+".size")

# install the library if the user gave the install option

EXAMPLEINSTALLDIR=INSTALLDIR+"/examples/"+example+"/"+systemprefix
env.Alias("install",env.Install(EXAMPLEINSTALLDIR,[elf,hex,bin,lst,size]))
95 changes: 95 additions & 0 deletions examples/timer_pwm_break/system/LibraryHacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* LibraryHacks.cpp
*
* Created on: 23 Jan 2011
* Author: Andy
*/

#include <cstdlib>
#include <sys/types.h>


/*
* The default pulls in 70K of garbage
*/

namespace __gnu_cxx {

void __verbose_terminate_handler() {
for(;;);
}
}


/*
* The default pulls in about 12K of garbage
*/

extern "C" void __cxa_pure_virtual() {
for(;;);
}


/*
* Implement C++ new/delete operators using the heap
*/

void *operator new(size_t size) {
return malloc(size);
}

void *operator new(size_t,void *ptr) {
return ptr;
}

void *operator new[](size_t size) {
return malloc(size);
}

void *operator new[](size_t,void *ptr) {
return ptr;
}

void operator delete(void *p) {
free(p);
}

void operator delete[](void *p) {
free(p);
}


/*
* EABI builds can generate reams of stack unwind code for system generated exceptions
* e.g. (divide-by-zero). Since we don't support exceptions we'll wrap out these
* symbols and save a lot of flash space.
*/

extern "C" void __wrap___aeabi_unwind_cpp_pr0() {}
extern "C" void __wrap___aeabi_unwind_cpp_pr1() {}
extern "C" void __wrap___aeabi_unwind_cpp_pr2() {}


/*
* sbrk function for getting space for malloc and friends
*/

extern int _end;

extern "C" {
caddr_t _sbrk ( int incr ) {

static unsigned char *heap = NULL;
unsigned char *prev_heap;

if (heap == NULL) {
heap = (unsigned char *)&_end;
}
prev_heap = heap;
/* check removed to show basic approach */

heap += incr;

return (caddr_t) prev_heap;
}
}

0 comments on commit 770d531

Please sign in to comment.