Skip to content
23 changes: 6 additions & 17 deletions BLINKY/G4ECHO/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ LogomaticConfig logomatic_config = {
.bus = LOGOMATIC_BUS,
};

VCP_Config vcp_config = {.baud_rate = 19200,
VCP_Config vcp_config = {.baud_rate = 115200,
.clock_source = VCP_CLOCK_PCLK,
.gpio_tx_rx_pin_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3,
.bus_port = VCP_Port_A,
Expand All @@ -81,20 +81,8 @@ VCP_Config vcp_config = {.baud_rate = 19200,
.oversampling = VCP_Oversampling_16,
.tx_fifo_threshold = VCP_Threshold_1_8,
.rx_fifo_threshold = VCP_Threshold_1_8,
.usart_instance = USART2};

void USART2_IRQHandler(void)
{
if (LL_USART_IsActiveFlag_ORE(USART2)) {
LL_USART_ClearFlag_ORE(USART2);
}
while (LL_USART_IsEnabledIT_RXNE(USART2) && LL_USART_IsActiveFlag_RXNE(USART2)) {
uint8_t receivedData = LL_USART_ReceiveData8(USART2);
while (!LL_USART_IsActiveFlag_TXE_TXFNF(USART2)) {}
LL_USART_TransmitData8(USART2, receivedData);
LOGOMATIC("Received: %c\n", receivedData);
}
}
.usart_instance = USART2,
.alternate_function = LL_GPIO_AF_7};
/* USER CODE END 0 */

/**
Expand All @@ -103,7 +91,6 @@ void USART2_IRQHandler(void)
*/
int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
Expand Down Expand Up @@ -138,7 +125,9 @@ int main(void)
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
LOGOMATIC("Hello, LOGOMATIC! Great to be here %f\n", 3.14159265);
LOGOMATIC("Hello, LOGOMATIC! Great to be here\n");
VCP_Send((uint8_t *)"Hello, VCP! Great to be here\n", 30);

LL_mDelay(750);
}
/* USER CODE END 3 */
Expand Down
14 changes: 13 additions & 1 deletion BLINKY/G4ECHO/Core/Src/stm32g4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "Logomatic.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -213,5 +214,16 @@ void EXTI15_10_IRQHandler(void)
}

/* USER CODE BEGIN 1 */

void USART2_IRQHandler(void)
{
if (LL_USART_IsActiveFlag_ORE(USART2)) {
LL_USART_ClearFlag_ORE(USART2);
}
while (LL_USART_IsEnabledIT_RXNE(USART2) && LL_USART_IsActiveFlag_RXNE(USART2)) {
uint8_t receivedData = LL_USART_ReceiveData8(USART2);
while (!LL_USART_IsActiveFlag_TXE_TXFNF(USART2)) {}
LOGOMATIC("VCP: %c\n", receivedData);
LL_USART_TransmitData8(USART2, receivedData);
}
}
/* USER CODE END 1 */
2 changes: 1 addition & 1 deletion CANine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ target_sources(
Core/Src/stm32g4xx_hal_msp.c
)

target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE)
target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB)

target_include_directories(${GR_PROJECT_NAME}_USER_CODE INTERFACE Core/Inc)
1 change: 1 addition & 0 deletions CANine/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern "C" {
#include "stm32g4xx_ll_pwr.h"
#include "stm32g4xx_ll_rcc.h"
#include "stm32g4xx_ll_system.h"
#include "stm32g4xx_ll_usart.h"
#include "stm32g4xx_ll_utils.h"

/* Private includes ----------------------------------------------------------*/
Expand Down
54 changes: 34 additions & 20 deletions CANine/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "Logomatic.h"
#include "vcp.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -56,22 +57,32 @@ static void MX_GPIO_Init(void);
/* USER CODE BEGIN 0 */

/* Enable ITM for SWO output */
LogomaticConfig logomatic_config = {
.baud_rate = 115200,
.clock_source = LOGOMATIC_PCLK1,
.data_width = LOGOMATIC_DATAWIDTH_8B,
.gpio_pin_rx_tx_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3,
.gpio_port = LOGOMATIC_GPIOA,
.hardware_flow_control = LOGOMATIC_HWCONTROL_NONE,
.parity = LOGOMATIC_PARITY_NONE,
.prescaler = LOGOMATIC_PRESCALER_DIV1,
.stop_bits = LOGOMATIC_STOPBITS_1,
.transfer_direction = LOGOMATIC_DIRECTION_TX,
.tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8,
.rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8,
.bus = LOGOMATIC_BUS,
};

LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1,
.bus = LOGOMATIC_BUS,
.gpio_port = LOGOMATIC_GPIOA,
.gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10,
.baud_rate = 115200,
.data_width = LOGOMATIC_DATAWIDTH_8B,
.stop_bits = LOGOMATIC_STOPBITS_1,
.parity = LOGOMATIC_PARITY_NONE,
.transfer_direction = LOGOMATIC_DIRECTION_TX,
.hardware_flow_control = LOGOMATIC_HWCONTROL_NONE,
.prescaler = LOGOMATIC_PRESCALER_DIV1,
.tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8,
.rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8};

VCP_Config vcp_config = {.baud_rate = 4000000,
.clock_source = VCP_CLOCK_PCLK,
.gpio_tx_rx_pin_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3,
.bus_port = VCP_Port_A,
.parity = VCP_Parity_None,
.prescaler = VCP_Prescalar_Div1,
.stop_bits = VCP_StopBits_1,
.oversampling = VCP_Oversampling_16,
.tx_fifo_threshold = VCP_Threshold_1_8,
.rx_fifo_threshold = VCP_Threshold_1_8,
.usart_instance = USART2,
.alternate_function = LL_GPIO_AF_7};
/* USER CODE END 0 */

/**
Expand All @@ -93,20 +104,22 @@ int main(void)
HAL_Init();

/* USER CODE BEGIN Init */
Setup_Logomatic(&logomatic_config);

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

Setup_Logomatic(&logomaticConfig);
Setup_VCP(&vcp_config);
/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */

LOGOMATIC("Logomatic initialization complete\n");
VCP_Send((uint8_t *)"VCP initialization complete\n", 29);
/* USER CODE END 2 */

/* Infinite loop */
Expand All @@ -115,7 +128,8 @@ int main(void)
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
LOGOMATIC("Hello, LOGOMATIC! Great to be here %f\n", 3.14159265);
LOGOMATIC("Hello, LOGOMATIC! Great to be here\n");
VCP_Send((uint8_t *)"Hello, VCP! Great to be here\n", 30);

LL_mDelay(750);
}
Expand Down
3 changes: 2 additions & 1 deletion CCU/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ VCP_Config vcp_config = {.baud_rate = 19200,
.oversampling = VCP_Oversampling_16,
.tx_fifo_threshold = VCP_Threshold_1_8,
.rx_fifo_threshold = VCP_Threshold_1_8,
.usart_instance = USART2};
.usart_instance = USART2,
.alternate_function = LL_GPIO_AF_7};
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
Expand Down
2 changes: 2 additions & 0 deletions Lib/Utils/VirtualComPort/Inc/vcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ typedef struct {
VCP_FifoThreshold tx_fifo_threshold;
/* FIFO threshold for RX */
VCP_FifoThreshold rx_fifo_threshold;
/* Alternate function for use on pins */
uint32_t alternate_function;
} VCP_Config;

void VCP_Send(uint8_t *data, uint32_t length);
Expand Down
55 changes: 45 additions & 10 deletions Lib/Utils/VirtualComPort/Src/vcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ void Setup_VCP(VCP_Config *input_config)
}
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);

} else if (vcp_config.usart_instance == LPUART1) {
switch (vcp_config.clock_source) {
case VCP_CLOCK_PCLK:
LL_RCC_SetUSARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1);
break;
case VCP_CLOCK_SYSCLK:
LL_RCC_SetUSARTClockSource(LL_RCC_LPUART1_CLKSOURCE_SYSCLK);
break;
case VCP_CLOCK_HSI:
LL_RCC_SetUSARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI);
break;
case VCP_CLOCK_LSE:
LL_RCC_SetUSARTClockSource(LL_RCC_LPUART1_CLKSOURCE_LSE);
break;
default:
LOGOMATIC("Unsupported clock source for LPUART1 in Setup_VCP\n");
return;
}
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1);
} else {
LOGOMATIC("Unsupported USART instance for Setup_VCP\n");
return;
Expand All @@ -146,7 +165,7 @@ void Setup_VCP(VCP_Config *input_config)
.Speed = LL_GPIO_SPEED_FREQ_LOW,
.OutputType = LL_GPIO_OUTPUT_PUSHPULL,
.Pull = LL_GPIO_PULL_NO,
.Alternate = LL_GPIO_AF_7};
.Alternate = vcp_config.alternate_function};

switch (vcp_config.bus_port) {
case VCP_Port_A:
Expand Down Expand Up @@ -175,15 +194,26 @@ void Setup_VCP(VCP_Config *input_config)
return;
}

LL_USART_InitTypeDef USART_InitStruct = {.PrescalerValue = vcp_config.prescaler,
.BaudRate = vcp_config.baud_rate,
.DataWidth = LL_USART_DATAWIDTH_8B,
.StopBits = vcp_config.stop_bits,
.Parity = vcp_config.parity,
.TransferDirection = LL_USART_DIRECTION_TX_RX,
.HardwareFlowControl = LL_USART_HWCONTROL_NONE,
.OverSampling = vcp_config.oversampling};
LL_USART_Init(vcp_config.usart_instance, &USART_InitStruct);
if (vcp_config.usart_instance == LPUART1) {
LL_LPUART_InitTypeDef LPUART_InitStruct = {.PrescalerValue = vcp_config.prescaler,
.BaudRate = vcp_config.baud_rate,
.DataWidth = LL_LPUART_DATAWIDTH_8B,
.StopBits = vcp_config.stop_bits,
.Parity = vcp_config.parity,
.TransferDirection = LL_LPUART_DIRECTION_TX_RX,
.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE};
LL_LPUART_Init(vcp_config.usart_instance, &LPUART_InitStruct);
} else {
LL_USART_InitTypeDef USART_InitStruct = {.PrescalerValue = vcp_config.prescaler,
.BaudRate = vcp_config.baud_rate,
.DataWidth = LL_USART_DATAWIDTH_8B,
.StopBits = vcp_config.stop_bits,
.Parity = vcp_config.parity,
.TransferDirection = LL_USART_DIRECTION_TX_RX,
.HardwareFlowControl = LL_USART_HWCONTROL_NONE,
.OverSampling = vcp_config.oversampling};
LL_USART_Init(vcp_config.usart_instance, &USART_InitStruct);
}
LL_USART_SetTXFIFOThreshold(vcp_config.usart_instance, vcp_config.tx_fifo_threshold);
LL_USART_SetRXFIFOThreshold(vcp_config.usart_instance, vcp_config.rx_fifo_threshold);
LL_USART_DisableFIFO(vcp_config.usart_instance);
Expand All @@ -199,6 +229,11 @@ void Setup_VCP(VCP_Config *input_config)
LL_USART_EnableIT_RXNE(USART3);
LL_USART_Enable(USART3);
while ((!(LL_USART_IsActiveFlag_TEACK(USART3))) || (!(LL_USART_IsActiveFlag_REACK(USART3)))) {}
} else if (vcp_config.usart_instance == LPUART1) {
NVIC_EnableIRQ(LPUART1_IRQn);
LL_USART_EnableIT_RXNE(LPUART1);
LL_USART_Enable(LPUART1);
while ((!(LL_USART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_USART_IsActiveFlag_REACK(LPUART1)))) {}
} else {
LOGOMATIC("Unsupported USART instance for Setup_VCP\n");
return;
Expand Down
Loading