Port to srm32g031
This commit is contained in:
99
Core/main.cc
99
Core/main.cc
@@ -14,8 +14,9 @@
|
||||
|
||||
using namespace perinet::platform::stm32g0xx;
|
||||
|
||||
Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP);
|
||||
Uart uart(Uart::UartDevice::UART_2, 115200);
|
||||
Gpio green_led(Gpio::Port::PORT_C, 6, Gpio::Mode::MODE_OUTPUT_PP);
|
||||
Uart uart1(Uart::UartDevice::UART_1, 115200);
|
||||
Uart uart2(Uart::UartDevice::UART_2, 115200);
|
||||
|
||||
#ifndef JTAG_DEBUG
|
||||
IndependentWatchdog watchdog(4095, 4095);
|
||||
@@ -44,7 +45,8 @@ int main(void)
|
||||
j = 800;
|
||||
}
|
||||
sprintf(tx_buf, "%u: Hello World\r\n", i++);
|
||||
uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
|
||||
uart1.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
|
||||
uart2.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
|
||||
green_led.toggle();
|
||||
delay_ms(j);
|
||||
|
||||
@@ -52,6 +54,97 @@ int main(void)
|
||||
watchdog.trigger();
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
// 1:
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
//HAL_Init();
|
||||
|
||||
/* Configure Flash prefetch, Instruction cache */
|
||||
/* Default configuration at reset is: */
|
||||
/* - Prefetch disabled */
|
||||
/* - Instruction cache enabled */
|
||||
|
||||
#if (INSTRUCTION_CACHE_ENABLE == 0U)
|
||||
__HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
|
||||
#endif /* INSTRUCTION_CACHE_ENABLE */
|
||||
|
||||
#if (PREFETCH_ENABLE != 0U)
|
||||
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
|
||||
#endif /* PREFETCH_ENABLE */
|
||||
|
||||
/* Use SysTick as time base source and configure 1ms tick (default clock after Reset is HSI) */
|
||||
HAL_InitTick(TICK_INT_PRIORITY);
|
||||
|
||||
PWR_PVDTypeDef sConfigPVD = {0};
|
||||
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
|
||||
/** PVD Configuration*/
|
||||
sConfigPVD.Mode = PWR_PVD_MODE_NORMAL;
|
||||
HAL_PWR_ConfigPVD(&sConfigPVD);
|
||||
/** Enable the PVD Output*/
|
||||
HAL_PWR_EnablePVD();
|
||||
|
||||
// 2:
|
||||
/* Configure the system clock */
|
||||
//SystemClock_Config();
|
||||
|
||||
// 3:
|
||||
/* Initialize all configured peripherals */
|
||||
//MX_GPIO_Init();
|
||||
|
||||
// 4:
|
||||
//MX_DMA_Init();
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
/* DMA1_Channel2_3_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
|
||||
|
||||
// 5:
|
||||
//MX_USART1_UART_Init();
|
||||
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();
|
||||
}
|
||||
|
||||
//6:
|
||||
//uint8_t buf[] = "Hello World\r\n";
|
||||
//HAL_UART_Transmit_DMA(&huart1, buf, strlen((const char *)buf));
|
||||
//HAL_UART_Receive_DMA(&huart1, buf, strlen((const char *)buf));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
Reference in New Issue
Block a user