整理代码,尝试添加串口中断发送

This commit is contained in:
HEYAHONG 2024-04-08 11:56:02 +08:00
parent a55b96b344
commit 7fd9bf8eff
No known key found for this signature in database
GPG Key ID: 97E3E469FE2C920B
9 changed files with 48 additions and 43 deletions

View File

@ -22,7 +22,7 @@
static ADC_HandleTypeDef adc_config[] =
{
#ifdef BSP_USING_ADC1
{ \
{ \
.Instance = ADC1, \
.Init.ADC_Mode = ADC_Mode_Independent, \
.Init.ADC_ScanConvMode = DISABLE, \
@ -34,7 +34,7 @@ static ADC_HandleTypeDef adc_config[] =
#endif
#ifdef BSP_USING_ADC2
{ \
{ \
.Instance = ADC2, \
.Init.ADC_Mode = ADC_Mode_Independent, \
.Init.ADC_ScanConvMode = DISABLE, \
@ -183,13 +183,13 @@ static rt_err_t air32_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch
}
#endif
/* ADC channel number is up to 17 */
/* ADC channel number is up to 17 */
#if !defined(ADC_CHANNEL_18)
if (channel <= 17)
/* ADC channel number is up to 19 */
/* ADC channel number is up to 19 */
#elif defined(ADC_CHANNEL_19)
if (channel <= 19)
/* ADC channel number is up to 18 */
/* ADC channel number is up to 18 */
#else
if (channel <= 18)
#endif
@ -211,7 +211,7 @@ static rt_err_t air32_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch
ADC_ChanConf.Rank = 1;
ADC_ChanConf.SamplingTime = ADC_SampleTime_239Cycles5;
ADC_RegularChannelConfig(air32_adc_handler->Instance,ADC_ChanConf.Channel , ADC_ChanConf.Rank, ADC_ChanConf.SamplingTime );
ADC_RegularChannelConfig(air32_adc_handler->Instance,ADC_ChanConf.Channel, ADC_ChanConf.Rank, ADC_ChanConf.SamplingTime );
/* start ADC */
ADC_SoftwareStartConvCmd(air32_adc_handler->Instance, ENABLE);

View File

@ -161,7 +161,7 @@ int air32_flash_erase(rt_uint32_t addr, rt_size_t size)
addr += FLASH_PAGE_SIZE;
}
FLASH_Lock();
FLASH_Lock();
__exit:
if(result != RT_EOK)

View File

@ -262,9 +262,9 @@ static rt_err_t air32_pin_attach_irq(struct rt_device *device, rt_base_t pin,
level = rt_hw_interrupt_disable();
if (pin_irq_hdr_tab[irqindex].pin == pin &&
pin_irq_hdr_tab[irqindex].hdr == hdr &&
pin_irq_hdr_tab[irqindex].mode == mode &&
pin_irq_hdr_tab[irqindex].args == args)
pin_irq_hdr_tab[irqindex].hdr == hdr &&
pin_irq_hdr_tab[irqindex].mode == mode &&
pin_irq_hdr_tab[irqindex].args == args)
{
rt_hw_interrupt_enable(level);
return RT_EOK;
@ -321,9 +321,9 @@ static rt_err_t air32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_base_t level;
rt_int32_t irqindex = -1;
rt_uint8_t gpio_port_souce=0;
GPIO_InitTypeDef GPIO_InitStruct={0};
NVIC_InitTypeDef NVIC_InitStructure={0};
EXTI_InitTypeDef EXTI_InitStructure={0};
GPIO_InitTypeDef GPIO_InitStruct= {0};
NVIC_InitTypeDef NVIC_InitStructure= {0};
EXTI_InitTypeDef EXTI_InitStructure= {0};
if (PIN_PORT(pin) >= PIN_AIRPORT_MAX)
{
@ -349,7 +349,7 @@ static rt_err_t air32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
irqmap = &pin_irq_map[irqindex];
/* Configure GPIO_InitStructure */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Configure GPIO_InitStructure */
GPIO_InitStruct.GPIO_Pin = PIN_AIRPIN(pin);

View File

@ -185,12 +185,12 @@ static rt_err_t air32_hwtimer_control(struct rt_hwtimer_device *device, rt_uint3
}
static const struct rt_hwtimer_ops hwtimer_ops =
{
.init = air32_hwtimer_init,
.start = air32_hwtimer_start,
.stop = air32_hwtimer_stop,
.count_get = air32_hwtimer_counter_get,
.control = air32_hwtimer_control,
{
.init = air32_hwtimer_init,
.start = air32_hwtimer_start,
.stop = air32_hwtimer_stop,
.count_get = air32_hwtimer_counter_get,
.control = air32_hwtimer_control,
};
static int rt_hw_hwtimer_init(void)

View File

@ -207,9 +207,9 @@ int rt_sw_i2c_init(void)
air32_i2c_bus_unlock(&soft_i2c_config[i]);
LOG_D("software simulation %s init done, pin scl: %d, pin sda %d",
soft_i2c_config[i].bus_name,
soft_i2c_config[i].scl,
soft_i2c_config[i].sda);
soft_i2c_config[i].bus_name,
soft_i2c_config[i].scl,
soft_i2c_config[i].sda);
}
return RT_EOK;

View File

@ -34,13 +34,15 @@ struct spi_bus_device
static struct spi_bus_device spi_bus_device_list[] = {
#ifdef BSP_USING_SPI1
{.periph = SPI1,
.name = "spi1"},
{ .periph = SPI1,
.name = "spi1"
},
#endif
#ifdef BSP_USING_SPI2
{.periph = SPI2,
.name = "spi2"},
{ .periph = SPI2,
.name = "spi2"
},
#endif
};
@ -290,7 +292,8 @@ static rt_ssize_t air32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mes
static struct rt_spi_ops spi_ops = {
.configure = air32_spi_configure,
.xfer = air32_spi_xfer};
.xfer = air32_spi_xfer
};
int rt_hw_spi_init(void)
{

View File

@ -234,6 +234,7 @@ static rt_err_t air32_control(struct rt_serial_device *serial, int cmd, void *ar
NVIC_Init(&NVIC_InitStruct);
/* disable interrupt */
USART_ITConfig(uart->config->Instance,USART_IT_RXNE,DISABLE);
USART_ITConfig(uart->config->Instance,USART_IT_TC,DISABLE);
break;
@ -245,6 +246,7 @@ static rt_err_t air32_control(struct rt_serial_device *serial, int cmd, void *ar
NVIC_Init(&NVIC_InitStruct);
/* enable interrupt */
USART_ITConfig(uart->config->Instance, USART_IT_RXNE,ENABLE);
USART_ITConfig(uart->config->Instance, USART_IT_TC,ENABLE);
break;
}
@ -293,7 +295,6 @@ static void uart_isr(struct rt_serial_device *serial)
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct air32_uart, serial);
/* UART in mode Receiver -------------------------------------------------*/
if ((USART_GetITStatus(uart->config->Instance, USART_IT_RXNE) != RESET) && (RESET != USART_GetFlagStatus(uart->config->Instance, USART_FLAG_RXNE)))
{
@ -301,6 +302,12 @@ static void uart_isr(struct rt_serial_device *serial)
USART_ClearITPendingBit(uart->config->Instance, USART_IT_RXNE);
USART_ClearFlag(uart->config->Instance, USART_FLAG_RXNE);
}
else if ((USART_GetITStatus(uart->config->Instance, USART_IT_TC) != RESET) && (USART_GetFlagStatus(uart->config->Instance, USART_FLAG_TC) != RESET))
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DONE);
USART_ClearITPendingBit(uart->config->Instance, USART_IT_TC);
USART_ClearFlag(uart->config->Instance, USART_FLAG_TC);
}
else
{
if (USART_GetFlagStatus(uart->config->Instance, USART_FLAG_CTS) != RESET)
@ -312,11 +319,6 @@ static void uart_isr(struct rt_serial_device *serial)
{
USART_ClearFlag(uart->config->Instance, USART_FLAG_LBD);
}
if (USART_GetFlagStatus(uart->config->Instance, USART_FLAG_TC) != RESET)
{
USART_ClearFlag(uart->config->Instance, USART_FLAG_TC);
}
}
}

View File

@ -44,15 +44,15 @@ static rt_err_t air32_wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
IWDG_ReloadCounter();
break;
/* set watchdog timeout */
/* set watchdog timeout */
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
wdt_dev->reload = (*((rt_uint32_t *)arg)) * 40000 / 256;
wdt_dev->reload = (*((rt_uint32_t *)arg)) * 40000 / 256;
if (wdt_dev->reload > 0xFFF)
{
LOG_E("wdg set timeout parameter too large, please less than %ds", 0xFFF * 256 / 40000);
return -RT_EINVAL;
}
if (wdt_dev->reload > 0xFFF)
{
LOG_E("wdg set timeout parameter too large, please less than %ds", 0xFFF * 256 / 40000);
return -RT_EINVAL;
}
if (wdt_dev->is_start)
{
@ -64,7 +64,7 @@ static rt_err_t air32_wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
}
break;
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
(*((rt_uint32_t *)arg)) = wdt_dev->reload * 256 / 40000;
(*((rt_uint32_t *)arg)) = wdt_dev->reload * 256 / 40000;
break;
case RT_DEVICE_CTRL_WDT_START:
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

View File

@ -383,7 +383,7 @@
<Group>
<GroupName>DeviceDrivers</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>