Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ this is my fork of usbcnc for STM32F103 specially for board in my chinnese machi

![Board](https://github.com/mirecta/grbl/blob/edge/doc/media/usbmach_pins.jpg?raw=true)

U must remove three capacitors and solder 3 wires, because this would recquire masive sw patches , so better is patch with three wires
NOTE: On my usbmach v2.0 the SWD pin order, left to right as pictured below, is actually VCC,GND,SWDIO,SWCLK Once I figured that out (with the STM32 chip pinout and a multimeter) it programmed just fine with an ST-LINK V2 and STM32CubeProgrammer

Ignore the wire patch lines, that is no longer necessary.

![patch](https://github.com/mirecta/grbl/blob/edge/doc/media/usbmach_patch.jpg?raw=true)

Expand Down
22 changes: 16 additions & 6 deletions grbl/cpu_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,30 @@

#ifdef CPU_MAP_STM32F103

// Define step pulse output pins. NOTE: All step bit pins must be on the same port.
// Define step pulse output pins. NOTE: All step bit pins must be on the same port... Or must they?
// Attempt to split potential pins onto two ports without mucking about with the rest of the code for STM32...
// This could be tricky...
#define H_PORT_OFFSET 16
#define L_PORT_MASK 0xFFFF //Sorry, too tired to bother with deriving one from the other. You get what you pay for.
#define STEP_PORT GPIOB
#define RCC_STEP_PORT RCC_APB2Periph_GPIOB
#define X_STEP_BIT 7
#define Y_STEP_BIT 5
#define H_STEP_PORT GPIOA //We're going to stack the pins on the A controller to the
#define H_RCC_STEP_PORT RCC_APB2Periph_GPIOA //left of the pins on the B controller
#define X_STEP_BIT ( 5 + H_PORT_OFFSET )
#define Y_STEP_BIT ( 7 + H_PORT_OFFSET )
#define Z_STEP_BIT 1
#define A_STEP_BIT 11
#define B_STEP_BIT 14
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)|(1<<A_STEP_BIT)|(1<<B_STEP_BIT)) // All step bits

// Define step direction output pins. NOTE: All direction pins must be on the same port.
#define DIRECTION_PORT GPIOB
// Define direction pulse output pins. NOTE: All direction bit pins must be on the same port... Or must they?
// Attempt to split potential pins onto two ports without mucking about with the rest of the code for STM32...
// This could be tricky...
#define DIRECTION_PORT GPIOB
#define RCC_DIRECTION_PORT RCC_APB2Periph_GPIOB
#define X_DIRECTION_BIT 6
#define H_DIRECTION_PORT GPIOA
#define H_RCC_DIRECTION_PORT RCC_APB2Periph_GPIOA
#define X_DIRECTION_BIT ( 6 + H_PORT_OFFSET )
#define Y_DIRECTION_BIT 0
#define Z_DIRECTION_BIT 10
#define A_DIRECTION_BIT 12
Expand Down
2 changes: 1 addition & 1 deletion grbl/grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void _delay_ms(uint32_t x);
void _delay_us(uint32_t x);
#define false 0
#define true 1
#define PORTPINDEF uint16_t
#define PORTPINDEF uint32_t
typedef int bool;
//#define NOEEPROMSUPPORT
#define printPgmString printString
Expand Down
2 changes: 1 addition & 1 deletion grbl/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct {
uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block.

#ifdef STM32F103C8
uint16_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
uint32_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
#else
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
#endif
Expand Down
32 changes: 22 additions & 10 deletions grbl/stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ typedef struct {
uint32_t steps[N_AXIS];
uint32_t step_event_count;
#ifdef STM32F103C8
uint16_t direction_bits;
uint32_t direction_bits;
#else
unit8_t direction_bits;
#endif
Expand Down Expand Up @@ -174,7 +174,7 @@ typedef struct {

#ifdef STEP_PULSE_DELAY
#ifdef STM32F103C8
uint16_t step_bits;
uint32_t step_bits;
#else
uint8_t step_bits; // Stores out_bits output to complete the step pulse delay
#endif
Expand Down Expand Up @@ -465,7 +465,8 @@ void Timer1Proc()
DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK);
#endif
#ifdef STM32F103C8
GPIO_Write(DIRECTION_PORT, (GPIO_ReadOutputData(DIRECTION_PORT) & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK));
GPIO_Write(DIRECTION_PORT, (GPIO_ReadOutputData(DIRECTION_PORT) & ~(DIRECTION_MASK & L_PORT_MASK) ) | ((st.dir_outbits & DIRECTION_MASK) & L_PORT_MASK) );
GPIO_Write(H_DIRECTION_PORT, (GPIO_ReadOutputData(H_DIRECTION_PORT) & ~(DIRECTION_MASK >> H_PORT_OFFSET) ) | ((st.dir_outbits & DIRECTION_MASK) >> H_PORT_OFFSET ));
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
#endif

Expand All @@ -477,7 +478,8 @@ void Timer1Proc()
STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#endif
#ifdef STM32F103C8
GPIO_Write(STEP_PORT, (GPIO_ReadOutputData(STEP_PORT) & ~STEP_MASK) | st.step_outbits);
GPIO_Write(STEP_PORT, (GPIO_ReadOutputData(STEP_PORT) & ~(STEP_MASK & L_PORT_MASK) ) | (st.step_outbits) & L_PORT_MASK );
GPIO_Write(H_STEP_PORT, (GPIO_ReadOutputData(H_STEP_PORT) & ~(STEP_MASK >> H_PORT_OFFSET) ) | (st.step_outbits >> H_PORT_OFFSET) );
#endif
#endif

Expand Down Expand Up @@ -702,7 +704,8 @@ void Timer0Proc()
TIM3->SR &= ~(1<<0); // clear UIF flag
TIM3->CNT = 0;
NVIC_DisableIRQ(TIM3_IRQn);
GPIO_Write(STEP_PORT, (GPIO_ReadOutputData(STEP_PORT) & ~STEP_MASK) | (step_port_invert_mask & STEP_MASK));
GPIO_Write(STEP_PORT, (GPIO_ReadOutputData(STEP_PORT) & ~(STEP_MASK & L_PORT_MASK) ) | ((step_port_invert_mask & STEP_MASK) & L_PORT_MASK));
GPIO_Write(H_STEP_PORT, (GPIO_ReadOutputData(H_STEP_PORT) & ~(STEP_MASK >> H_PORT_OFFSET) ) | ((step_port_invert_mask & STEP_MASK) >> H_PORT_OFFSET));
}
#endif
#ifdef AVRTARGET
Expand Down Expand Up @@ -765,8 +768,11 @@ void st_reset()
DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | dir_port_invert_mask;
#endif
#ifdef STM32F103C8
GPIO_Write(STEP_PORT, (GPIO_ReadOutputData(STEP_PORT) & ~STEP_MASK) | (step_port_invert_mask & STEP_MASK));
GPIO_Write(DIRECTION_PORT, (GPIO_ReadOutputData(DIRECTION_PORT) & ~DIRECTION_MASK) | (dir_port_invert_mask & DIRECTION_MASK));
GPIO_Write(STEP_PORT, (GPIO_ReadOutputData(STEP_PORT) & ~(STEP_MASK & L_PORT_MASK) ) | ((step_port_invert_mask & STEP_MASK) & L_PORT_MASK));
GPIO_Write(H_STEP_PORT, (GPIO_ReadOutputData(H_STEP_PORT) & ~(STEP_MASK >> H_PORT_OFFSET) ) | ((step_port_invert_mask & STEP_MASK) >> H_PORT_OFFSET));

GPIO_Write(DIRECTION_PORT, (GPIO_ReadOutputData(DIRECTION_PORT) & ~(DIRECTION_MASK & L_PORT_MASK) ) | ((dir_port_invert_mask & DIRECTION_MASK) & L_PORT_MASK));
GPIO_Write(H_DIRECTION_PORT, (GPIO_ReadOutputData(H_DIRECTION_PORT) & ~(DIRECTION_MASK >> H_PORT_OFFSET) ) | ((dir_port_invert_mask & DIRECTION_MASK) >> H_PORT_OFFSET));
#endif
}

Expand Down Expand Up @@ -813,7 +819,7 @@ void Timer0Thread(void *pVoid)
void stepper_init()
{
// Configure step and direction interface pins
#ifdef STM32F103C8
#ifdef STM32F103C8
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_STEPPERS_DISABLE_PORT, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
Expand All @@ -822,12 +828,18 @@ void stepper_init()
GPIO_Init(STEPPERS_DISABLE_PORT, &GPIO_InitStructure);

RCC_APB2PeriphClockCmd(RCC_STEP_PORT, ENABLE);
GPIO_InitStructure.GPIO_Pin = STEP_MASK;
RCC_APB2PeriphClockCmd(H_RCC_STEP_PORT, ENABLE);
GPIO_InitStructure.GPIO_Pin = STEP_MASK & L_PORT_MASK;
GPIO_Init(STEP_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = STEP_MASK >> H_PORT_OFFSET;
GPIO_Init(H_STEP_PORT, &GPIO_InitStructure);

RCC_APB2PeriphClockCmd(RCC_DIRECTION_PORT, ENABLE);
GPIO_InitStructure.GPIO_Pin = DIRECTION_MASK;
RCC_APB2PeriphClockCmd(H_RCC_DIRECTION_PORT, ENABLE);
GPIO_InitStructure.GPIO_Pin = DIRECTION_MASK & L_PORT_MASK;
GPIO_Init(DIRECTION_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = DIRECTION_MASK >> H_PORT_OFFSET;
GPIO_Init(H_DIRECTION_PORT, &GPIO_InitStructure);

RCC->APB1ENR |= RCC_APB1Periph_TIM2;
TIM_Configuration(TIM2, 1, 1, 1);
Expand Down