Skip to content

Commit

Permalink
Fix stack corruption issue with latest Tiva-C library.
Browse files Browse the repository at this point in the history
Make the raster return / blank feedrate more sensible when main feedrate is high.
  • Loading branch information
art103 committed Mar 28, 2015
1 parent 0925f3f commit 4ebb176
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
9 changes: 6 additions & 3 deletions .cproject
Expand Up @@ -18,11 +18,11 @@
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.1417397969." name="/" resourcePath="">
<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.cross.exe.debug.881380885" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.debug">
<option id="cdt.managedbuild.option.gnu.cross.prefix.2022057451" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" value="arm-none-eabi-" valueType="string"/>
<option id="cdt.managedbuild.option.gnu.cross.path.72389051" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" value="/opt/CodeSourcery/arm-2013.05/bin" valueType="string"/>
<option id="cdt.managedbuild.option.gnu.cross.path.72389051" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" value="" valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.382435908" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder buildPath="${workspace_loc:/grbl}/Debug" enabledIncrementalBuild="true" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.builder.gnu.cross.1162084420" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="false" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool command="gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cross.c.compiler.1469500298" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.391157319" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.391157319" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.size" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.1677407956" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.510751463" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/grbl}&quot;"/>
Expand Down Expand Up @@ -96,7 +96,7 @@
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.376231133" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder buildPath="${workspace_loc:/grbl}/Debug" enabledIncrementalBuild="true" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.builder.gnu.cross.2101463913" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="false" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool command="gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cross.c.compiler.273067082" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.507597422" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.507597422" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.size" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.1674430573" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.182703025" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/grbl}&quot;"/>
Expand Down Expand Up @@ -129,6 +129,7 @@
<option id="gnu.c.link.option.noshared.204054669" name="No shared libraries (-static)" superClass="gnu.c.link.option.noshared" value="true" valueType="boolean"/>
<option id="gnu.c.link.option.other.659613192" name="Other options (-Xlinker [option])" superClass="gnu.c.link.option.other" valueType="stringList">
<listOptionValue builtIn="false" value="--gc-sections"/>
<listOptionValue builtIn="false" value="-Map=grbl.map"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.690684170" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
Expand Down Expand Up @@ -158,6 +159,7 @@
<configuration configurationName="Release">
<resource resourceType="PROJECT" workspacePath="/grbl"/>
</configuration>
<configuration configurationName="TM4C123G"/>
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/grbl"/>
</configuration>
Expand Down Expand Up @@ -198,4 +200,5 @@
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>
3 changes: 0 additions & 3 deletions LM4F.ld
Expand Up @@ -14,9 +14,6 @@ MEMORY
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}

_estack = 0x20008000; /* Upper stack boundary */
_sstack = (_estack - 1024); /* Lower stack boundary */

SECTIONS {
.isr_vector :
{
Expand Down
5 changes: 2 additions & 3 deletions newlib_stubs.c
Expand Up @@ -177,15 +177,14 @@ caddr_t _sbrk(int incr) {

static char *heap_end;
char *prev_heap_end;
//extern char _estack;
extern char _sstack;
extern char g_pui32Stack;

if (heap_end == NULL) {
heap_end = &_end;
}
prev_heap_end = heap_end;
if((((uint32_t)heap_end) + ((uint32_t)incr))
> ((uint32_t)&_sstack)) // stack protection
> ((uint32_t)&g_pui32Stack)) // stack protection
{
errno = ENOMEM;
return (void*) -1;
Expand Down
17 changes: 9 additions & 8 deletions planner.c
Expand Up @@ -257,6 +257,7 @@ void planner_raster(double x, double y, double z,
raster_t *raster) {
double raster_len = 0;
double head = 0;
double blank_feedrate = max(CONFIG_DEFAULT_RATE, feed_rate);

uint8_t *ptr = raster->buffer;
uint32_t count = raster->length;
Expand Down Expand Up @@ -284,19 +285,19 @@ void planner_raster(double x, double y, double z,
// Move to the starting point. (Assumes we have space before the limits are hit)
if (raster->x_off > 0) {
x += head;
planner_movement(x - raster->x_off, y, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x - raster->x_off, y, z, blank_feedrate, acceleration, 0, 0, NULL);
planner_movement(x, y, z, feed_rate, acceleration, 0, 0, NULL);
} else if (raster->x_off < 0) {
x += head;
planner_movement(x + raster_len - raster->x_off, y, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x + raster_len - raster->x_off, y, z, blank_feedrate, acceleration, 0, 0, NULL);
planner_movement(x + raster_len, y, z, feed_rate, acceleration, 0, 0, NULL);
} else if (raster->y_off > 0) {
y += head;
planner_movement(x, y - raster->y_off, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x, y - raster->y_off, z, blank_feedrate, acceleration, 0, 0, NULL);
planner_movement(x, y, z, feed_rate, acceleration, 0, 0, NULL);
} else if (raster->y_off < 0) {
y += head;
planner_movement(x, y + raster_len - raster->y_off, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x, y + raster_len - raster->y_off, z, blank_feedrate, acceleration, 0, 0, NULL);
planner_movement(x, y + raster_len, z, feed_rate, acceleration, 0, 0, NULL);
}

Expand All @@ -319,17 +320,17 @@ void planner_raster(double x, double y, double z,

if (raster->x_off > 0) {
planner_movement(x + raster_len, y, z, feed_rate, acceleration, 0, 0, raster);
planner_movement(x + raster_len + raster->x_off, y, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x + raster_len + raster->x_off, y, z, blank_feedrate, acceleration, 0, 0, NULL);
} else if (raster->x_off < 0) {
planner_movement(x, y, z, feed_rate, acceleration, 0, 0, raster);
planner_movement(x + raster->x_off, y, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x + raster->x_off, y, z, blank_feedrate, acceleration, 0, 0, NULL);
} else if (raster->y_off > 0) {
planner_movement(x, y + raster_len, z, feed_rate, acceleration, 0, 0, raster);
planner_movement(x, y + raster_len + raster->y_off, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x, y + raster_len + raster->y_off, z, blank_feedrate, acceleration, 0, 0, NULL);
} else if (raster->y_off < 0) {
y += head;
planner_movement(x, y, z, feed_rate, acceleration, 0, 0, raster);
planner_movement(x, y + raster->y_off, z, CONFIG_DEFAULT_RATE, acceleration, 0, 0, NULL);
planner_movement(x, y + raster->y_off, z, blank_feedrate, acceleration, 0, 0, NULL);
}
}

Expand Down
5 changes: 3 additions & 2 deletions startup.c
Expand Up @@ -43,6 +43,7 @@ static void IntDefaultHandler(void);
//*****************************************************************************
extern void USB0DeviceIntHandler(void);


//*****************************************************************************
//
// The entry point for the application.
Expand All @@ -55,7 +56,7 @@ extern int main(void);
// Reserve space for the system stack.
//
//*****************************************************************************
static uint32_t pui32Stack[256];
uint32_t g_pui32Stack[512];

//*****************************************************************************
//
Expand All @@ -66,7 +67,7 @@ static uint32_t pui32Stack[256];
__attribute__ ((section(".isr_vector")))
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)),
(void (*)(void))((uint32_t)g_pui32Stack + sizeof(g_pui32Stack)),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
Expand Down
8 changes: 6 additions & 2 deletions stepper.c
Expand Up @@ -177,10 +177,8 @@ void stepper_init() {
// The stepper interrupt gets started when blocks are being added.
stepper_go_idle();

#ifndef DEBUG_IGNORE_SENSORS
// Go Home
gcode_do_home();
#endif
}


Expand Down Expand Up @@ -215,6 +213,8 @@ void stepper_go_idle() {
// Disable stepper driver interrupt
TimerDisable(STEPPING_TIMER, TIMER_A);
control_laser(0, 0);

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
}

// stop event handling
Expand Down Expand Up @@ -324,6 +324,8 @@ void stepper_isr (void) {
}
#endif

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

// pulse steppers
GPIOPinWrite(STEP_DIR_PORT, STEP_DIR_MASK, out_dir_bits);
GPIOPinWrite(STEP_PORT, STEP_MASK, out_step_bits);
Expand Down Expand Up @@ -680,6 +682,7 @@ static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, bool reverse_dir
}

void stepper_homing_cycle() {
#ifndef DEBUG_IGNORE_SENSORS
stepper_synchronize();
// home the x and y axis

Expand All @@ -690,6 +693,7 @@ void stepper_homing_cycle() {
// Perform a slow (accurate) home.
homing_cycle(true, true, false, false, 1000);
homing_cycle(true, true, false, true, 1000);
#endif
}


Expand Down

0 comments on commit 4ebb176

Please sign in to comment.