Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Assorted fixes:
Browse files Browse the repository at this point in the history
Incomplete iMXRT1062 update affecting some configurations.
Copy/paste error for SAM3X8E spindle PWM/enable pins in some map files.
Rewrite of LPC176x driver to avoid silicon bug(?) in LPC1769: bitband aliasing does not work and cannot be used.
  • Loading branch information
terjeio committed Feb 11, 2021
1 parent bacab4a commit e41177b
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 161 deletions.
7 changes: 3 additions & 4 deletions drivers/IMXRT1062/grblHAL_Teensy4/src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,9 @@ static void StepperDisableMotors (axes_signals_t axes, squaring_mode_t mode)

// Returns limit state as an axes_signals_t variable.
// Each bitfield bit indicates an axis limit, where triggered is 1 and not triggered is 0.
static axes_signals_t limitsGetHomeState()
static limit_signals_t limitsGetHomeState()
{
axes_signals_t signals = {0};
limit_signals_t signals = {0};

if(motors_1.mask) {

Expand Down Expand Up @@ -1013,7 +1013,6 @@ static axes_signals_t limitsGetHomeState()
signals.max.mask ^= settings.limits.invert.mask;
}


return signals;
}

Expand Down Expand Up @@ -2131,7 +2130,7 @@ bool driver_init (void)
options[strlen(options) - 1] = '\0';

hal.info = "iMXRT1062";
hal.driver_version = "210206";
hal.driver_version = "210212";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
#endif
Expand Down
4 changes: 3 additions & 1 deletion drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/tool_change.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void)
if(ok && protocol_buffer_synchronize()) {
sync_position();
block_cycle_start = false;
report_message("Remove any touch plate and press cycle start to continue.", Message_Plain);
report_message(settings.tool_change.mode == ToolChange_Manual_G59_3
? "Press cycle start to continue."
: "Remove any touch plate and press cycle start to continue.", Message_Plain);
}

return ok ? Status_OK : Status_GCodeToolError;
Expand Down
96 changes: 64 additions & 32 deletions drivers/LPC1769/src/btt_skr_1.x.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,47 @@

#include "trinamic/common.h"

#define TRINAMIC_MOSI_BIT (1<<TRINAMIC_MOSI_PIN)
#define TRINAMIC_MISO_BIT (1<<TRINAMIC_MISO_PIN)
#define TRINAMIC_SCK_BIT (1<<TRINAMIC_SCK_PIN)
#define TRINAMIC_CSX_BIT (1<<TRINAMIC_CSX_PIN)
#define TRINAMIC_CSY_BIT (1<<TRINAMIC_CSY_PIN)
#define TRINAMIC_CSZ_BIT (1<<TRINAMIC_CSZ_PIN)
#ifdef A_AXIS
#define TRINAMIC_CSA_BIT (1<<TRINAMIC_CSA_PIN)
#endif
#ifdef B_AXIS
#define TRINAMIC_CSB_BIT (1<<TRINAMIC_CSB_PIN)
#endif

#define spi_get_byte() sw_spi_xfer(0)
#define spi_put_byte(d) sw_spi_xfer(d)

static uint8_t cs_pin[N_AXIS];
static uint32_t cs_bit[N_AXIS];

inline static void delay (void)
{
volatile uint32_t dly = 10;

while(--dly)
__ASM volatile ("nop");
}

static uint8_t sw_spi_xfer (uint8_t byte)
{
uint_fast8_t msk = 0x80, res = 0;

BITBAND_GPIO(TRINAMIC_SCK_PORT->PIN, TRINAMIC_SCK_PIN) = 0;
TRINAMIC_SCK_PORT->CLR = TRINAMIC_SCK_BIT;

do {
BITBAND_GPIO(TRINAMIC_MOSI_PORT->PIN, TRINAMIC_MOSI_PIN) = !!(byte & msk);
DIGITAL_OUT(TRINAMIC_MOSI_PORT, TRINAMIC_MOSI_BIT, byte & msk);
msk >>= 1;
BITBAND_GPIO(TRINAMIC_SCK_PORT->PIN, TRINAMIC_SCK_PIN) = 1;
res = (res << 1) | BITBAND_GPIO(TRINAMIC_MISO_PORT->PIN, TRINAMIC_MISO_PIN);
delay();
res = (res << 1) | DIGITAL_IN(TRINAMIC_MISO_PORT, TRINAMIC_MISO_BIT);
TRINAMIC_SCK_PORT->SET = TRINAMIC_SCK_BIT;
delay();
if(msk)
BITBAND_GPIO(TRINAMIC_SCK_PORT->PIN, TRINAMIC_SCK_PIN) = 0;

TRINAMIC_SCK_PORT->CLR = TRINAMIC_SCK_BIT;
} while (msk);

return (uint8_t)res;
Expand All @@ -57,7 +79,7 @@ TMC_spi_status_t tmc_spi_read (trinamic_motor_t driver, TMC_spi_datagram_t *data
{
TMC_spi_status_t status;

BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, cs_pin[driver.axis]) = 0;
TRINAMIC_CS_PORT->CLR = cs_bit[driver.axis];

datagram->payload.value = 0;

Expand All @@ -68,16 +90,17 @@ TMC_spi_status_t tmc_spi_read (trinamic_motor_t driver, TMC_spi_datagram_t *data
spi_put_byte(0);
spi_put_byte(0);

BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, cs_pin[driver.axis]) = 1;
BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, cs_pin[driver.axis]) = 0;
TRINAMIC_CS_PORT->SET = cs_bit[driver.axis];
delay();
TRINAMIC_CS_PORT->CLR = cs_bit[driver.axis];

status = spi_put_byte(datagram->addr.value);
datagram->payload.data[3] = spi_get_byte();
datagram->payload.data[2] = spi_get_byte();
datagram->payload.data[1] = spi_get_byte();
datagram->payload.data[0] = spi_get_byte();

BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, cs_pin[driver.axis]) = 1;
TRINAMIC_CS_PORT->SET = cs_bit[driver.axis];

return status;
}
Expand All @@ -86,7 +109,7 @@ TMC_spi_status_t tmc_spi_write (trinamic_motor_t driver, TMC_spi_datagram_t *dat
{
TMC_spi_status_t status;

BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, cs_pin[driver.axis]) = 0;
TRINAMIC_CS_PORT->CLR = cs_bit[driver.axis];

datagram->addr.write = 1;
status = spi_put_byte(datagram->addr.value);
Expand All @@ -95,7 +118,7 @@ TMC_spi_status_t tmc_spi_write (trinamic_motor_t driver, TMC_spi_datagram_t *dat
spi_put_byte(datagram->payload.data[1]);
spi_put_byte(datagram->payload.data[0]);

BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, cs_pin[driver.axis]) = 1;
TRINAMIC_CS_PORT->SET = cs_bit[driver.axis];

return status;
}
Expand All @@ -113,33 +136,42 @@ void board_init (void)
Chip_IOCON_PinMux((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSY_PIN, IOCON_MODE_INACT, IOCON_FUNC0);
Chip_IOCON_PinMux((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSZ_PIN, IOCON_MODE_INACT, IOCON_FUNC0);

BITBAND_GPIO(TRINAMIC_MOSI_PORT->DIR, TRINAMIC_MOSI_PIN) = 1;
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_MOSI_PN, TRINAMIC_MOSI_PIN);
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_MISO_PN, TRINAMIC_MOSI_PIN);
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_SCK_PN, TRINAMIC_MOSI_PIN);
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSX_PIN);
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSY_PIN);
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSZ_PIN);

TRINAMIC_MOSI_PORT->DIR |= TRINAMIC_MOSI_BIT;
TRINAMIC_MISO_PORT->DIR &= ~TRINAMIC_MISO_BIT;

BITBAND_GPIO(TRINAMIC_MISO_PORT->DIR, TRINAMIC_MISO_PIN) = 0; // with pullup
TRINAMIC_SCK_PORT->DIR |= TRINAMIC_SCK_BIT;
TRINAMIC_SCK_PORT->SET = TRINAMIC_SCK_BIT;

BITBAND_GPIO(TRINAMIC_SCK_PORT->DIR, TRINAMIC_SCK_PIN) = 1;
BITBAND_GPIO(TRINAMIC_SCK_PORT->PIN, TRINAMIC_SCK_PIN) = 1;
cs_bit[X_AXIS] = TRINAMIC_CSX_BIT;
TRINAMIC_CS_PORT->DIR |= TRINAMIC_CSX_BIT;
TRINAMIC_CS_PORT->SET = TRINAMIC_CSX_BIT;

cs_pin[X_AXIS] = TRINAMIC_CSX_PIN;
BITBAND_GPIO(TRINAMIC_CS_PORT->DIR, TRINAMIC_CSX_PIN) = 1;
BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, TRINAMIC_CSX_PIN) = 1;
cs_bit[Y_AXIS] = TRINAMIC_CSY_BIT;
TRINAMIC_CS_PORT->DIR |= TRINAMIC_CSY_BIT;
TRINAMIC_CS_PORT->SET = TRINAMIC_CSY_BIT;

cs_pin[Y_AXIS] = TRINAMIC_CSY_PIN;
BITBAND_GPIO(TRINAMIC_CS_PORT->DIR, TRINAMIC_CSY_PIN) = 1;
BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, TRINAMIC_CSY_PIN) = 1;
cs_bit[Z_AXIS] = TRINAMIC_CSZ_BIT;
TRINAMIC_CS_PORT->DIR |= TRINAMIC_CSZ_BIT;
TRINAMIC_CS_PORT->SET = TRINAMIC_CSZ_BIT;

cs_pin[Z_AXIS] = TRINAMIC_CSZ_PIN;
BITBAND_GPIO(TRINAMIC_CS_PORT->DIR, TRINAMIC_CSZ_PIN) = 1;
BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, TRINAMIC_CSZ_PIN) = 1;
#ifdef A_AXIS
cs_pin[A_AXIS] = TRINAMIC_CSA_PIN;
BITBAND_GPIO(TRINAMIC_CS_PORT->DIR, TRINAMIC_CSA_PIN) = 1;
BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, TRINAMIC_CSB_PIN) = 1;
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSA_PIN);
cs_bit[A_AXIS] = TRINAMIC_CSA_PIN;
TRINAMIC_CS_PORT->DIR |= TRINAMIC_CSA_BIT;
TRINAMIC_CS_PORT->SET = TRINAMIC_CSA_BIT;
#endif
#ifdef B_AXIS
cs_pin[B_AXIS] = TRINAMIC_CSB_PIN;
BITBAND_GPIO(TRINAMIC_CS_PORT->DIR, TRINAMIC_CSB_PIN) = 1;
BITBAND_GPIO(TRINAMIC_CS_PORT->PIN, TRINAMIC_CSB_PIN) = 1;
Chip_IOCON_DisableOD((LPC_IOCON_T *)LPC_IOCON_BASE, TRINAMIC_CS_PN, TRINAMIC_CSB_PIN);
cs_bit[B_AXIS] = TRINAMIC_CSB_PIN;
TRINAMIC_CS_PORT->DIR |= TRINAMIC_CSB_BIT;
TRINAMIC_CS_PORT->SET = TRINAMIC_CSB_BIT;
#endif

#endif
Expand Down
5 changes: 3 additions & 2 deletions drivers/LPC1769/src/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
#include <stdint.h>
#include <stdbool.h>

#include "ff.h"
#include "diskio.h"
#include "driver.h"

#if SDCARD_ENABLE

#include "ff.h"
#include "diskio.h"

#if SD_SPI_PORT == 0
#define LPC_SD_PORT LPC_SSP0
static const PINMUX_GRP_T sd_pinmux[] = {
Expand Down
Loading

0 comments on commit e41177b

Please sign in to comment.