Skip to content

Commit

Permalink
Several updates and improvements. Preparations for GrIP. Stepper_Disa…
Browse files Browse the repository at this point in the history
…ble override. Output update.
  • Loading branch information
Schildkroet committed Apr 29, 2019
1 parent e4a414c commit 05d4c30
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 93 deletions.
37 changes: 21 additions & 16 deletions GRBL_Advanced.elay
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<Cursor1 position="1639" topLine="32" />
</Cursor>
</File>
<File name="grbl\Config.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\Config.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="39003" topLine="548" />
<Cursor1 position="36781" topLine="531" />
</Cursor>
</File>
<File name="grbl\CoolantControl.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand All @@ -36,9 +36,9 @@
<Cursor1 position="873" topLine="13" />
</Cursor>
</File>
<File name="grbl\defaults.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\defaults.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2407" topLine="23" />
<Cursor1 position="2407" topLine="10" />
</Cursor>
</File>
<File name="grbl\GCode.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand Down Expand Up @@ -116,12 +116,12 @@
<Cursor1 position="842" topLine="3" />
</Cursor>
</File>
<File name="grbl\Report.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\Report.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="7135" topLine="235" />
</Cursor>
</File>
<File name="grbl\Report.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\Report.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1483" topLine="9" />
</Cursor>
Expand Down Expand Up @@ -156,12 +156,12 @@
<Cursor1 position="875" topLine="0" />
</Cursor>
</File>
<File name="grbl\System.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\System.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="7435" topLine="208" />
</Cursor>
</File>
<File name="grbl\System.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\System.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4260" topLine="53" />
</Cursor>
Expand All @@ -176,9 +176,9 @@
<Cursor1 position="31" topLine="0" />
</Cursor>
</File>
<File name="grbl\util.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="grbl\util.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1079" topLine="16" />
<Cursor1 position="1925" topLine="60" />
</Cursor>
</File>
<File name="HAL\EXTI\EXTI.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand All @@ -201,9 +201,9 @@
<Cursor1 position="1007" topLine="21" />
</Cursor>
</File>
<File name="HAL\GPIO\GPIO.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="HAL\GPIO\GPIO.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3818" topLine="0" />
<Cursor1 position="440" topLine="142" />
</Cursor>
</File>
<File name="HAL\GPIO\GPIO.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand Down Expand Up @@ -296,9 +296,9 @@
<Cursor1 position="781" topLine="12" />
</Cursor>
</File>
<File name="main.c" open="1" top="1" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.c" open="1" top="1" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2887" topLine="53" />
<Cursor1 position="1982" topLine="33" />
</Cursor>
</File>
<File name="SPL\inc\stm32f4xx_cryp.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand Down Expand Up @@ -356,9 +356,14 @@
<Cursor1 position="141" topLine="0" />
</Cursor>
</File>
<File name="Src\Print.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="Src\Platform.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="364" topLine="0" />
<Cursor1 position="530" topLine="0" />
</Cursor>
</File>
<File name="Src\Print.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1109" topLine="57" />
</Cursor>
</File>
<File name="Src\Print.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand Down
10 changes: 7 additions & 3 deletions HAL/SPI/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ uint8_t Spi_ReadByte(SPI_TypeDef *SPIx)

uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data)
{
uint16_t timeout = 0xFFF;

// 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);

while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET);
while((SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET) && timeout--);

// Return the byte read from the SPI bus
return (uint8_t)SPI_I2S_ReceiveData(SPIx);
Expand All @@ -183,6 +185,7 @@ uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data)
void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len)
{
uint8_t i = 0;
uint16_t timeout = 0xFFF;

for(i = 0; i < _len; ++i)
{
Expand All @@ -192,7 +195,7 @@ void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len)
// Send byte through the SPIx peripheral
SPI_I2S_SendData(SPIx, 0xFF);

while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET);
while((SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET) && timeout--);

_buffer[i] = (uint8_t)SPI_I2S_ReceiveData(SPIx);
}
Expand All @@ -217,7 +220,8 @@ void Spi_SetPrescaler(SPI_TypeDef *SPIx, uint16_t prescaler)
{
SPI_Cmd(SPIx, DISABLE);

uint16_t tmpreg = SPIx->CR1;
// Read CR1 and clear baud control
uint16_t tmpreg = SPIx->CR1 & 0xFFC7;

tmpreg |= prescaler;

Expand Down
78 changes: 62 additions & 16 deletions HAL/USART/USART.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,73 @@ void Usart_Init(USART_TypeDef *usart, uint32_t baud)
USART_Cmd(usart, ENABLE);
}

void Usart_Put(USART_TypeDef *usart, char c)
void Usart_Put(USART_TypeDef *usart, bool buffered, char c)
{
if(usart == STDOUT)
FifoUsart_Insert(STDOUT_NUM, USART_DIR_TX, c);

// Enable sending via interrupt
Usart_TxInt(usart, true);
uint8_t num = 0;

if(usart == USART1)
{
num = USART1_NUM;
}
else if(usart == USART2)
{
num = USART2_NUM;
}
else if(usart == USART6)
{
num = USART6_NUM;
}

if(buffered)
{
FifoUsart_Insert(num, USART_DIR_TX, c);

// Enable sending via interrupt
Usart_TxInt(usart, true);
}
else
{
while(USART_GetFlagStatus(usart, USART_FLAG_TC) == RESET);
USART_SendData(usart, c);
}
}

void Usart_Write(USART_TypeDef *usart, uint8_t *data, uint8_t len)
void Usart_Write(USART_TypeDef *usart, bool buffered, char *data, uint8_t len)
{
uint8_t i = 0;

while(len--)
{
if(usart == STDOUT)
FifoUsart_Insert(STDOUT_NUM, USART_DIR_TX, data[i++]);
}

// Enable sending via interrupt
Usart_TxInt(usart, true);
uint8_t num = 0;

if(usart == USART1)
{
num = USART1_NUM;
}
else if(usart == USART2)
{
num = USART2_NUM;
}
else if(usart == USART6)
{
num = USART6_NUM;
}

if(buffered)
{
while(len--)
{
FifoUsart_Insert(num, USART_DIR_TX, data[i++]);
}

// Enable sending via interrupt
Usart_TxInt(usart, true);
}
else
{
while(len--)
{
while(USART_GetFlagStatus(usart, USART_FLAG_TC) == RESET);
USART_SendData(usart, data[i++]);
}
}
}

void Usart_TxInt(USART_TypeDef *usart, bool enable)
Expand Down
4 changes: 2 additions & 2 deletions HAL/USART/USART.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ extern "C" {

void Usart_Init(USART_TypeDef *usart, uint32_t baud);

void Usart_Put(USART_TypeDef *usart, char c);
void Usart_Write(USART_TypeDef *usart, uint8_t *data, uint8_t len);
void Usart_Put(USART_TypeDef *usart, bool buffered, char c);
void Usart_Write(USART_TypeDef *usart, bool buffered, char *data, uint8_t len);

void Usart_TxInt(USART_TypeDef *usart, bool enable);
void Usart_RxInt(USART_TypeDef *usart, bool enable);
Expand Down
46 changes: 46 additions & 0 deletions Src/Platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef PLATFORM_H_INCLUDED
#define PLATFORM_H_INCLUDED


#include "stm32f4xx_conf.h"


//---- I2C ----//
#define EEPROM_I2C I2C1


//---- SPI ----//
#define SPI_W5500 SPI3


//---- USART ----//
// Number of used USARTs on this device
//#define USART_NUM 2

// Numerate available USARTs in ascending order
//#define USART1_NUM 0
//#define USART2_NUM 1
//#define USART6_NUM 2

// USART used for Printf(...)
#define STDOUT USART2
#define STDOUT_NUM USART2_NUM
#define STDOUT_BAUD 230400


//---- Defines ----//

// Direction definitions
#define FIFO_DIR_RX 0
#define FIFO_DIR_TX 1


// Communication interface
// Comment out to use serial interface
//#define ETH_IF

#define ETH_SOCK 0
#define ETH_PORT 30501


#endif /* PLATFORM_H_INCLUDED */
Loading

0 comments on commit 05d4c30

Please sign in to comment.