Skip to content

Commit

Permalink
Improved backlash compensation;
Browse files Browse the repository at this point in the history
Improved TCP server and added wiznet ioLibrary;
Moved most compile time settings to runtime;
Bugfixes;
Code refactoring;

Signed-off-by: Patrick Felixberger <[email protected]>
  • Loading branch information
Schildkroet committed Mar 8, 2024
1 parent 48b6766 commit 43accf7
Show file tree
Hide file tree
Showing 76 changed files with 19,049 additions and 2,688 deletions.
176 changes: 176 additions & 0 deletions ARM/syscalls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/**
******************************************************************************
* @file syscalls.c
* @author Auto-generated by STM32CubeIDE
* @brief STM32CubeIDE Minimal System calls file
*
* For more information about which c-functions
* need which of these lowlevel functions
* please consult the Newlib libc-manual
******************************************************************************
* @attention
*
* Copyright (c) 2020-2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/

/* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>


/* Variables */
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));


char *__env[1] = { 0 };
char **environ = __env;


/* Functions */
void initialise_monitor_handles()
{
}

int _getpid(void)
{
return 1;
}

int _kill(int pid, int sig)
{
(void)pid;
(void)sig;
errno = EINVAL;
return -1;
}

void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}

__attribute__((weak)) int _read(int file, char *ptr, int len)
{
(void)file;
int DataIdx;

for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}

return len;
}

__attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int DataIdx;

for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}

int _close(int file)
{
(void)file;
return -1;
}


int _fstat(int file, struct stat *st)
{
(void)file;
st->st_mode = S_IFCHR;
return 0;
}

int _isatty(int file)
{
(void)file;
return 1;
}

int _lseek(int file, int ptr, int dir)
{
(void)file;
(void)ptr;
(void)dir;
return 0;
}

int _open(char *path, int flags, ...)
{
(void)path;
(void)flags;
/* Pretend like we always fail */
return -1;
}

int _wait(int *status)
{
(void)status;
errno = ECHILD;
return -1;
}

int _unlink(char *name)
{
(void)name;
errno = ENOENT;
return -1;
}

int _times(struct tms *buf)
{
(void)buf;
return -1;
}

/*int _stat(char *file, struct stat *st)
{
(void)file;
//st->st_mode = S_IFCHR;
return 0;
}*/

int _link(char *old, char *new)
{
(void)old;
(void)new;
errno = EMLINK;
return -1;
}

int _fork(void)
{
errno = EAGAIN;
return -1;
}

int _execve(char *name, char **argv, char **env)
{
(void)name;
(void)argv;
(void)env;
errno = ENOMEM;
return -1;
}
14 changes: 7 additions & 7 deletions HAL/FLASH/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ uint8_t EE_ReadByteArray(uint8_t *DataOut, uint16_t VirtAddress, uint16_t size)
*(DataOut++) = data;
}

data = EE_ReadByte(VirtAddress);
if(data == checksum) {
return 1;
}
/*data = EE_ReadByte(VirtAddress);
if(data != checksum) {
return 0;
}*/

return 0;
return 1;
}

void EE_WriteByteArray(uint16_t VirtAddress, uint8_t *DataIn, uint16_t size)
void EE_WriteByteArray(uint16_t VirtAddress, const uint8_t *DataIn, uint16_t size)
{
unsigned char checksum = 0;

Expand All @@ -49,7 +49,7 @@ void EE_WriteByteArray(uint16_t VirtAddress, uint8_t *DataIn, uint16_t size)
EE_WriteByte(VirtAddress++, *(DataIn++));
}

EE_WriteByte(VirtAddress, checksum);
//EE_WriteByte(VirtAddress, checksum);
}

void EE_Program(void)
Expand Down
6 changes: 3 additions & 3 deletions HAL/FLASH/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "stm32f4xx.h"


#ifdef USE_EXT_EEPROM
#define EEPROM_SIZE 1
#if (USE_EXT_EEPROM)
#define EEPROM_SIZE 1
#else
#define EEPROM_SIZE 1024
#endif
Expand All @@ -44,7 +44,7 @@ uint8_t EE_ReadByte(uint16_t VirtAddress);
void EE_WriteByte(uint16_t VirtAddress, uint8_t Data);

uint8_t EE_ReadByteArray(uint8_t *DataOut, uint16_t VirtAddress, uint16_t size);
void EE_WriteByteArray(uint16_t VirtAddress, uint8_t *DataIn, uint16_t size);
void EE_WriteByteArray(uint16_t VirtAddress, const uint8_t *DataIn, uint16_t size);

void EE_Program(void);
void EE_Erase(void);
Expand Down
25 changes: 13 additions & 12 deletions HAL/GPIO/GPIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* D11: SPINDLE_PWM: PA7
* D12: Z_LIMIT_BIT: PA6
* D13: SPINDLE_DIRECTION_BIT: PA5
* D14: SPINDLE_ENABLE_BIT: PB7
* D15: SAFETY_DOOR_ENABLE_BIT: PC2
* ???: SPINDLE_ENABLE_BIT: PB13
* ???: SAFETY_DOOR_ENABLE_BIT: PC2
*
* A0: CONTROL_RESET_BIT: PA0
* A1: CONTROL_FEED_HOLD_BIT: PA1
Expand All @@ -23,6 +23,8 @@
*/
#include "GPIO.h"
#include "Platform.h"
#include "Config.h"
#include "defaults.h"


static void GPIO_InitStepper(void);
Expand Down Expand Up @@ -112,14 +114,12 @@ static void GPIO_InitSpindle(void)
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* GPIO Configuration: */
#if !defined(LATHE_MODE)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#endif

/* GPIO Configuration: PWM */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
Expand All @@ -140,12 +140,13 @@ static void GPIO_InitLimit(void)
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

/* GPIO Configuration: */
#if !defined(LATHE_MODE)
// Y1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#endif
/* GPIO Configuration: */
if (DEFAULT_LATHE_MODE)
{
// Y1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}

// X1 X2 Y2 Z2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_5 | GPIO_Pin_6;
Expand Down Expand Up @@ -176,7 +177,7 @@ static void GPIO_InitSystem(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

#ifdef ETH_IF
#if (USE_ETH_IF)
// W5500 Reset Pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
Expand Down
2 changes: 1 addition & 1 deletion HAL/GPIO/GPIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#define GPIO_SPINDLE_DIR_PORT GPIOA
#define GPIO_SPINDLE_DIR_PIN GPIO_Pin_5
#define GPIO_SPINDLE_ENA_PORT GPIOB
#define GPIO_SPINDLE_ENA_PIN GPIO_Pin_7
#define GPIO_SPINDLE_ENA_PIN GPIO_Pin_13

// Safety door
#define GPIO_DOOR_PORT GPIOC
Expand Down
28 changes: 19 additions & 9 deletions HAL/SPI/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data)
// Loop while DR register is not empty
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);

// Send byte through the SPIx peripheral
// Clear rx register
SPI_I2S_ReceiveData(SPIx);

// Send byte through the SPIx peripheral
SPI_I2S_SendData(SPIx, _data);

while((SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET) && timeout--);
Expand All @@ -182,17 +185,20 @@ uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data)
}


void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len)
void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint16_t _len)
{
uint8_t i = 0;
uint16_t timeout = 0xFFF;
uint16_t i = 0;
uint16_t timeout = 0xFFF;

// Clear rx register
SPI_I2S_ReceiveData(SPIx);

for(i = 0; i < _len; ++i)
for(i = 0; i < _len; ++i)
{
// Loop while DR register is not empty
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);

// Send byte through the SPIx peripheral
// Send byte through the SPIx peripheral
SPI_I2S_SendData(SPIx, 0xFF);

while((SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET) && timeout--);
Expand All @@ -201,18 +207,22 @@ void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len)
}
}

void Spi_WriteDataArray(SPI_TypeDef *SPIx, uint8_t *_data, uint8_t _len)
void Spi_WriteDataArray(SPI_TypeDef *SPIx, uint8_t *_data, uint16_t _len)
{
uint8_t i = 0;
uint16_t i = 0;

for(i = 0; i < _len; ++i)
for(i = 0; i < _len; ++i)
{
// Loop while DR register is not empty
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);

// Send byte through the SPIx peripheral
SPI_I2S_SendData(SPIx, _data[i]);
}
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);

// Clear rx register
SPI_I2S_ReceiveData(SPIx);
}


Expand Down
4 changes: 2 additions & 2 deletions HAL/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void Spi_Init(SPI_TypeDef *SPIx, SPI_Mode mode);
uint8_t Spi_ReadByte(SPI_TypeDef *SPIx);
uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data);

void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len);
void Spi_WriteDataArray(SPI_TypeDef *SPIx, uint8_t *_data, uint8_t _len);
void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint16_t _len);
void Spi_WriteDataArray(SPI_TypeDef *SPIx, uint8_t *_data, uint16_t _len);

void Spi_SetPrescaler(SPI_TypeDef *SPIx, uint16_t prescaler);
void Spi_ChipSelect(SPI_TypeDef *SPIx, bool select);
Expand Down
Loading

0 comments on commit 43accf7

Please sign in to comment.