Skip to content

Commit 02dc42f

Browse files
author
mirecta
committed
some fix for STM32
1 parent d302896 commit 02dc42f

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

grbl/planner.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ typedef struct {
6060
// NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values.
6161
uint32_t steps[N_AXIS]; // Step count along each axis
6262
uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block.
63-
uint16_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
63+
64+
#ifdef STM32F103C8
65+
uint16_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
66+
#else
67+
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
68+
#endif
6469

6570
// Block condition data to ensure correct execution depending on states and overrides.
6671
uint8_t condition; // Block bitflag variable defining block run conditions. Copied from pl_line_data.

grbl/spindle_control.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ void spindle_init()
107107

108108
uint8_t spindle_get_state()
109109
{
110-
uint16_t pin = 0;
110+
#if defined (STM32F103C8)
111+
uint16_t pin = 0;
112+
#else
113+
uint8_t pin = 0;
114+
#endif
115+
111116
#ifdef VARIABLE_SPINDLE
112117
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
113118
#ifdef AVRTARGET
@@ -116,7 +121,7 @@ uint8_t spindle_get_state()
116121
#if defined (STM32F103C8)
117122
pin = GPIO_ReadInputData(SPINDLE_ENABLE_PORT);
118123
#endif
119-
// No spindle direction output pin.
124+
// No spindle direction output pin.
120125
#ifdef INVERT_SPINDLE_ENABLE_PIN
121126
if (bit_isfalse(pin,(1<<SPINDLE_ENABLE_BIT))) { return(SPINDLE_STATE_CW); }
122127
#else
@@ -125,7 +130,7 @@ uint8_t spindle_get_state()
125130
#else
126131
#ifdef AVRTARGET
127132
pin = SPINDLE_DIRECTION_PORT;
128-
if (SPINDLE_TCCRA_REGISTER & (1<<SPINDLE_COMB_BIT))
133+
if (SPINDLE_TCCRA_REGISTER & (1<<SPINDLE_COMB_BIT))
129134
#endif
130135
#if defined (STM32F103C8)
131136
pin = GPIO_ReadInputData(SPINDLE_DIRECTION_PORT);
@@ -324,12 +329,12 @@ void spindle_stop()
324329
{
325330
if (sys.abort) { return; } // Block during abort.
326331
if (state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm.
327-
332+
328333
#ifdef VARIABLE_SPINDLE
329334
sys.spindle_speed = 0.0f;
330335
#endif
331336
spindle_stop();
332-
337+
333338
} else {
334339
#ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
335340
if (state == SPINDLE_ENABLE_CW) {
@@ -339,7 +344,7 @@ void spindle_stop()
339344
SetSpindleDirectionBit();
340345
}
341346
#endif
342-
347+
343348
#ifdef VARIABLE_SPINDLE
344349
// NOTE: Assumes all calls to this function is when Grbl is not moving or must remain off.
345350
if (settings.flags & BITFLAG_LASER_MODE) {
@@ -355,15 +360,15 @@ void spindle_stop()
355360
ResetSpindleEnablebit();
356361
#else
357362
SetSpindleEnablebit();
358-
#endif
363+
#endif
359364
#endif
360365
}
361-
366+
362367
sys.report_ovr_counter = 0; // Set to report change immediately
363368
}
364369

365370

366-
// G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails
371+
// G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails
367372
// if an abort or check-mode is active.
368373
#ifdef VARIABLE_SPINDLE
369374
void spindle_sync(uint8_t state, float rpm)

grbl/stepper.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ LONGLONG nTimer0Out = 0;
122122
typedef struct {
123123
uint32_t steps[N_AXIS];
124124
uint32_t step_event_count;
125+
#ifdef STM32F103C8
125126
uint16_t direction_bits;
127+
#else
128+
unit8_t direction_bits;
129+
#endif
126130
#ifdef VARIABLE_SPINDLE
127131
uint8_t is_pwm_rate_adjusted; // Tracks motions that require constant laser power/rate
128132
#endif
@@ -143,7 +147,11 @@ typedef struct {
143147
uint8_t prescaler; // Without AMASS, a prescaler is required to adjust for slow timing.
144148
#endif
145149
#ifdef VARIABLE_SPINDLE
150+
#ifdef STM32F103C8
146151
uint32_t spindle_pwm;
152+
#else
153+
uint8_t spindle_pwm;
154+
#endif
147155
#endif
148156
} segment_t;
149157
static segment_t segment_buffer[SEGMENT_BUFFER_SIZE];
@@ -165,9 +173,14 @@ typedef struct {
165173
#endif
166174

167175
#ifdef STEP_PULSE_DELAY
176+
#ifdef STM32F103C8
177+
uint16_t step_bits;
178+
#else
168179
uint8_t step_bits; // Stores out_bits output to complete the step pulse delay
169180
#endif
170181

182+
#endif
183+
171184
uint8_t execute_step; // Flags step execution for each interrupt.
172185
#ifndef WIN32
173186
uint8_t step_pulse_time; // Step pulse reset time after step rise
@@ -233,7 +246,11 @@ typedef struct {
233246

234247
#ifdef VARIABLE_SPINDLE
235248
float inv_rate; // Used by PWM laser mode to speed up segment calculations.
236-
uint32_t current_spindle_pwm;
249+
#ifdef STM32F103C8
250+
uint32_t current_spindle_pwm;
251+
#else
252+
uint8_t current_spindle_pwm;
253+
#endif
237254
#endif
238255
} st_prep_t;
239256
static st_prep_t prep;
@@ -548,7 +565,7 @@ void Timer1Proc()
548565
#endif
549566

550567
#ifdef VARIABLE_SPINDLE
551-
// Set real-time spindle output as segment is loaded, just prior to the first step. CMMT
568+
// Set real-time spindle output as segment is loaded, just prior to the first step. CMMT
552569
spindle_set_speed(st.exec_segment->spindle_pwm);
553570
#endif
554571

0 commit comments

Comments
 (0)