From e5726f206a1c2d4ff8fbb726740c83c9e122e0ea Mon Sep 17 00:00:00 2001 From: yuneizhilin <94582670@qq.com> Date: Fri, 1 Feb 2019 12:56:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84stm32=5Fadc=5Finit=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_adc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_adc.c b/bsp/stm32/libraries/HAL_Drivers/drv_adc.c index 3bf0c2d8f..124fdab6b 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_adc.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_adc.c @@ -7,6 +7,7 @@ * Date Author Notes * 2018-12-05 zylx first version * 2018-12-12 greedyhao Porting for stm32f7xx + * 2019-02-01 yuneizhilin fix the stm32_adc_init function initialization issue */ #include @@ -206,29 +207,41 @@ static int stm32_adc_init(void) { int result = RT_EOK; /* save adc name */ - char name_buf[6] = {0}; + char name_buf[5] = {'a', 'd', 'c', '0', 0}; int i = 0; for (i = 0; i < sizeof(adc_config) / sizeof(adc_config[0]); i++) { /* ADC init */ + name_buf[3] = '0'; stm32_adc_obj[i].ADC_Handler = adc_config[i]; + if (stm32_adc_obj[i].ADC_Handler.Instance == ADC1) + { + name_buf[3] = '1'; + } + if (stm32_adc_obj[i].ADC_Handler.Instance == ADC2) + { + name_buf[3] = '2'; + } + if (stm32_adc_obj[i].ADC_Handler.Instance == ADC3) + { + name_buf[3] = '3'; + } if (HAL_ADC_Init(&stm32_adc_obj[i].ADC_Handler) != HAL_OK) { - LOG_E("ADC%d init failed", i + 1); + LOG_E("%s init failed", name_buf); result = -RT_ERROR; } else { - rt_sprintf(name_buf, "adc%d", i + 1); /* register ADC device */ if (rt_hw_adc_register(&stm32_adc_obj[i].stm32_adc_device, name_buf, &stm_adc_ops, &stm32_adc_obj[i].ADC_Handler) == RT_EOK) { - LOG_D("ADC%d init success", i + 1); + LOG_D("%s init success", name_buf); } else { - LOG_E("ADC%d register failed", i + 1); + LOG_E("%s register failed", name_buf); result = -RT_ERROR; } } -- GitLab