Skip to content

Commit

Permalink
Merge pull request #38 from xrobot-org/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jiu-xiao authored Nov 8, 2023
2 parents 0d8e0e0 + 1f41aac commit 8a579c1
Show file tree
Hide file tree
Showing 84 changed files with 792 additions and 381 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"--enable-config",
"--fallback-style=Google",
"--function-arg-placeholders=false",
"--header-insertion-decorators",
"--header-insertion=iwyu",
"--header-insertion=never",
"--log=verbose",
"--pch-storage=memory",
"--pretty",
Expand Down
22 changes: 22 additions & 0 deletions hw/bsp/atom/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ add_subdirectory(${BOARD_DIR}/drivers)

add_executable(${PROJECT_NAME}.elf ${BOARD_DIR}/main.cpp)

add_executable(${PROJECT_NAME}_with_bl.elf ${BOARD_DIR}/main.cpp)

target_link_libraries(
${PROJECT_NAME}.elf
PUBLIC bsp
PUBLIC system
PUBLIC robot)

target_link_libraries(
${PROJECT_NAME}_with_bl.elf
PUBLIC bsp
PUBLIC system
PUBLIC robot)


target_include_directories(
${PROJECT_NAME}.elf
Expand All @@ -28,6 +36,20 @@ target_include_directories(
PRIVATE $<TARGET_PROPERTY:robot,INTERFACE_INCLUDE_DIRECTORIES>
)

target_include_directories(
${PROJECT_NAME}_with_bl.elf
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE $<TARGET_PROPERTY:bsp,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE $<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE $<TARGET_PROPERTY:robot,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_options(${PROJECT_NAME}_with_bl.elf PRIVATE "-T${BOARD_DIR}/ld/LinkerScripts_with_bl.ld")

create_hex_output(${PROJECT_NAME})
create_bin_output(${PROJECT_NAME})
print_section_sizes(${PROJECT_NAME}.elf)

create_hex_output(${PROJECT_NAME}_with_bl)
create_bin_output(${PROJECT_NAME}_with_bl)
print_section_sizes(${PROJECT_NAME}_with_bl.elf)
2 changes: 1 addition & 1 deletion hw/bsp/atom/drivers/hal/.mxproject

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions hw/bsp/atom/drivers/hal/Core/Inc/stm32g4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void TIM1_BRK_TIM15_IRQHandler(void);
void I2C1_EV_IRQHandler(void);
void SPI1_IRQHandler(void);
void USART2_IRQHandler(void);
void DMA2_Channel1_IRQHandler(void);
void DMA2_Channel2_IRQHandler(void);
/* USER CODE BEGIN EFP */
void HAL_UART_RegisterUserCallback(void (*fn)(UART_HandleTypeDef *huart));
/* USER CODE END EFP */
Expand Down
61 changes: 60 additions & 1 deletion hw/bsp/atom/drivers/hal/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ SPI_HandleTypeDef hspi1;
DMA_HandleTypeDef hdma_spi1_rx;
DMA_HandleTypeDef hdma_spi1_tx;

UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart1_rx;
DMA_HandleTypeDef hdma_usart1_tx;
DMA_HandleTypeDef hdma_usart2_rx;
DMA_HandleTypeDef hdma_usart2_tx;

Expand All @@ -60,6 +63,7 @@ DMA_HandleTypeDef hdma_usart2_tx;

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */
Expand Down Expand Up @@ -251,6 +255,54 @@ void MX_SPI1_Init(void)

}

/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{

/* USER CODE BEGIN USART1_Init 0 */

/* USER CODE END USART1_Init 0 */

/* USER CODE BEGIN USART1_Init 1 */

/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */

/* USER CODE END USART1_Init 2 */

}

/**
* @brief USART2 Initialization Function
* @param None
Expand All @@ -267,7 +319,7 @@ void MX_USART2_UART_Init(void)

/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 460800;
huart2.Init.BaudRate = 1000000;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
Expand Down Expand Up @@ -308,6 +360,7 @@ void MX_DMA_Init(void)
/* DMA controller clock enable */
__HAL_RCC_DMAMUX1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();

/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
Expand All @@ -328,6 +381,12 @@ void MX_DMA_Init(void)
/* DMA1_Channel6_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
/* DMA2_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Channel1_IRQn);
/* DMA2_Channel2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Channel2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Channel2_IRQn);

}

Expand Down
98 changes: 96 additions & 2 deletions hw/bsp/atom/drivers/hal/Core/Src/stm32g4xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extern DMA_HandleTypeDef hdma_spi1_rx;

extern DMA_HandleTypeDef hdma_spi1_tx;

extern DMA_HandleTypeDef hdma_usart1_rx;

extern DMA_HandleTypeDef hdma_usart1_tx;

extern DMA_HandleTypeDef hdma_usart2_rx;

extern DMA_HandleTypeDef hdma_usart2_tx;
Expand Down Expand Up @@ -432,7 +436,76 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(huart->Instance==USART2)
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */

/* USER CODE END USART1_MspInit 0 */

/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}

/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USART1 DMA Init */
/* USART1_RX Init */
hdma_usart1_rx.Instance = DMA2_Channel1;
hdma_usart1_rx.Init.Request = DMA_REQUEST_USART1_RX;
hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart1_rx.Init.Mode = DMA_NORMAL;
hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
{
Error_Handler();
}

__HAL_LINKDMA(huart,hdmarx,hdma_usart1_rx);

/* USART1_TX Init */
hdma_usart1_tx.Instance = DMA2_Channel2;
hdma_usart1_tx.Init.Request = DMA_REQUEST_USART1_TX;
hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart1_tx.Init.Mode = DMA_NORMAL;
hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
{
Error_Handler();
}

__HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx);

/* USER CODE BEGIN USART1_MspInit 1 */

/* USER CODE END USART1_MspInit 1 */
}
else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */

Expand Down Expand Up @@ -515,7 +588,28 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART2)
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspDeInit 0 */

/* USER CODE END USART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART1_CLK_DISABLE();

/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);

/* USART1 DMA DeInit */
HAL_DMA_DeInit(huart->hdmarx);
HAL_DMA_DeInit(huart->hdmatx);
/* USER CODE BEGIN USART1_MspDeInit 1 */

/* USER CODE END USART1_MspDeInit 1 */
}
else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspDeInit 0 */

Expand Down
30 changes: 30 additions & 0 deletions hw/bsp/atom/drivers/hal/Core/Src/stm32g4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ extern I2C_HandleTypeDef hi2c1;
extern DMA_HandleTypeDef hdma_spi1_rx;
extern DMA_HandleTypeDef hdma_spi1_tx;
extern SPI_HandleTypeDef hspi1;
extern DMA_HandleTypeDef hdma_usart1_rx;
extern DMA_HandleTypeDef hdma_usart1_tx;
extern DMA_HandleTypeDef hdma_usart2_rx;
extern DMA_HandleTypeDef hdma_usart2_tx;
extern UART_HandleTypeDef huart2;
Expand Down Expand Up @@ -349,6 +351,34 @@ void USART2_IRQHandler(void)
/* USER CODE END USART2_IRQn 1 */
}

/**
* @brief This function handles DMA2 channel1 global interrupt.
*/
void DMA2_Channel1_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel1_IRQn 0 */

/* USER CODE END DMA2_Channel1_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart1_rx);
/* USER CODE BEGIN DMA2_Channel1_IRQn 1 */

/* USER CODE END DMA2_Channel1_IRQn 1 */
}

/**
* @brief This function handles DMA2 channel2 global interrupt.
*/
void DMA2_Channel2_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel2_IRQn 0 */

/* USER CODE END DMA2_Channel2_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart1_tx);
/* USER CODE BEGIN DMA2_Channel2_IRQn 1 */

/* USER CODE END DMA2_Channel2_IRQn 1 */
}

/* USER CODE BEGIN 1 */
void HAL_UART_RegisterUserCallback(void (*fn)(UART_HandleTypeDef *huart)) {
user_uart_irq_handler = fn;
Expand Down
2 changes: 1 addition & 1 deletion hw/bsp/atom/drivers/hal/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Thu Sep 14 23:13:22 CST 2023]
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Sun Nov 05 11:19:30 CST 2023]
##########################################################################################################################

# ------------------------------------------------
Expand Down
Loading

0 comments on commit 8a579c1

Please sign in to comment.