Skip to content

Commit

Permalink
WIP Add a config for Nucleo G474 on serial HAL
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jul 11, 2023
1 parent 658a3fe commit 56e119c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
1 change: 0 additions & 1 deletion examples/projects/NUCLEO-G474RE/button/lib/Button/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define BUTTON_H

#include "luos_engine.h"
#include "robus_network.h"
/*******************************************************************************
* Definitions
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/NUCLEO-G474RE/button/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ board = nucleo_g474re
framework = stm32cube
lib_deps =
luos_engine@^3.0.0
robus_network
serial_network
Button
debug_tool = stlink
upload_protocol = stlink
Expand Down
4 changes: 2 additions & 2 deletions examples/projects/NUCLEO-G474RE/button/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "luos_engine.h"
#include "robus_network.h"
#include "serial_network.h"
#include "button.h"
/* USER CODE END Includes */

Expand Down Expand Up @@ -89,7 +89,7 @@ int main(void)
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
LUOS_ADD_PACKAGE(Button)
LUOS_ADD_PACKAGE(Robus)
LUOS_ADD_PACKAGE(Serial)
/* USER CODE END 2 */

/* Infinite loop */
Expand Down
9 changes: 4 additions & 5 deletions network/serial_network/HAL/STM32G4/serial_network_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ volatile uint16_t RX_PrevPointerPosition = 0;
void SerialHAL_Init(uint8_t *rx_buffer, uint32_t buffer_size)
{
LUOS_ASSERT(rx_buffer);
rx_buffer_size = buffer_size;
rx_buffer_size = buffer_size;
RX_PrevPointerPosition = 0;

LL_USART_DeInit(SERIAL_COM);
///////////////////////////////
Expand Down Expand Up @@ -75,7 +76,7 @@ void SerialHAL_Init(uint8_t *rx_buffer, uint32_t buffer_size)
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
// USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
while (LL_USART_Init(SERIAL_COM, &USART_InitStruct) != SUCCESS)
;
LL_USART_Enable(SERIAL_COM);
Expand All @@ -86,8 +87,6 @@ void SerialHAL_Init(uint8_t *rx_buffer, uint32_t buffer_size)
HAL_NVIC_EnableIRQ(SERIAL_COM_IRQ);
HAL_NVIC_SetPriority(SERIAL_COM_IRQ, 1, 1);

RX_PrevPointerPosition = 0;

///////////////////////////////
// DMA SERIAL Init
///////////////////////////////
Expand Down Expand Up @@ -204,7 +203,7 @@ void SERIAL_COM_IRQHANDLER()
void SERIAL_TX_DMA_IRQHANDLER()
{
// Check if TX DMA is finished
if (SERIAL_TX_DMA_TC(SERIAL_TX_DMA) != RESET)
if ((SERIAL_TX_DMA_TC(SERIAL_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(SERIAL_TX_DMA, SERIAL_TX_DMA_CHANNEL) != RESET))
{
// Clear the DMA irq flags
SERIAL_TX_DMA_CLEAR_TC(SERIAL_TX_DMA);
Expand Down
36 changes: 36 additions & 0 deletions network/serial_network/HAL/STM32G4/serial_network_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// SERIAL_CONFIG need to be define in your node_config.h if you want to redefine
// SERIAL configuration usart or DMA If you need change something in this configuration
// you must redefine all the configuration in you node_config.h

// Nucleo G431KB configuration
#ifndef SERIAL_CONFIG
#define SERIAL_TX_CLK() __HAL_RCC_GPIOA_CLK_ENABLE();
#define SERIAL_TX_PIN GPIO_PIN_2
Expand Down Expand Up @@ -53,6 +55,40 @@
#define SERIAL_TX_DMA_IRQHANDLER() DMA1_Channel4_IRQHandler()
#endif

// Nucleo G474RE configuration
// #ifndef SERIAL_CONFIG
// #define SERIAL_TX_CLK() __HAL_RCC_GPIOA_CLK_ENABLE();
// #define SERIAL_TX_PIN GPIO_PIN_2
// #define SERIAL_TX_PORT GPIOA
// #define SERIAL_TX_AF GPIO_AF12_LPUART1

// #define SERIAL_RX_CLK() __HAL_RCC_GPIOA_CLK_ENABLE();
// #define SERIAL_RX_PIN GPIO_PIN_3
// #define SERIAL_RX_PORT GPIOA
// #define SERIAL_RX_AF GPIO_AF12_LPUART1

// #define SERIAL_COM_CLOCK_ENABLE() __HAL_RCC_LPUART1_CLK_ENABLE()
// #define SERIAL_COM LPUART1
// #define SERIAL_COM_IRQ LPUART1_IRQn
// #define SERIAL_COM_IRQHANDLER() LPUART1_IRQHandler()

// #define SERIAL_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE();
// #define SERIAL_RX_DMA DMA1
// #define SERIAL_RX_DMA_CHANNEL LL_DMA_CHANNEL_3
// #define SERIAL_RX_DMA_REQUEST LL_DMAMUX_REQ_LPUART1_RX
// #define SERIAL_RX_DMA_TC(SERIAL_RX_DMA) LL_DMA_IsActiveFlag_TC3(SERIAL_RX_DMA)
// #define SERIAL_RX_DMA_CLEAR_TC(SERIAL_RX_DMA) LL_DMA_ClearFlag_TC3(SERIAL_RX_DMA)

// #define SERIAL_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE();
// #define SERIAL_TX_DMA DMA1
// #define SERIAL_TX_DMA_CHANNEL LL_DMA_CHANNEL_4
// #define SERIAL_TX_DMA_REQUEST LL_DMAMUX_REQ_LPUART1_TX
// #define SERIAL_TX_DMA_TC(SERIAL_TX_DMA) LL_DMA_IsActiveFlag_TC4(SERIAL_TX_DMA)
// #define SERIAL_TX_DMA_CLEAR_TC(SERIAL_TX_DMA) LL_DMA_ClearFlag_TC4(SERIAL_TX_DMA)
// #define SERIAL_TX_DMA_IRQ DMA1_Channel4_IRQn
// #define SERIAL_TX_DMA_IRQHANDLER() DMA1_Channel4_IRQHandler()
// #endif

void SerialHAL_Init(uint8_t *rx_buffer, uint32_t buffer_size);
void SerialHAL_Loop(void);
void SerialHAL_Send(uint8_t *data, uint16_t size);
Expand Down

0 comments on commit 56e119c

Please sign in to comment.