hello,
i am trying to use printf using USART in keil MDK v5:0 using stm32lo53r8t6 nucleo ..
in my source file i have included the retarget and serial .c file and its header file to,but its still not working
i have tryed copying the blink example which was in keil..
below i have posted the code which i have done were i have used two printf statement ..
kindly help me out by telling the issue
/** ****************************************************************************** * File Name : main.c * Description : Main program body ****************************************************************************** * * COPYRIGHT(c) 2016 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */
/* Includes ------------------------------------------------------------------*/ #include <stdio.h> #include "stm32l0xx.h" // Device header #include "stm32l0xx_hal.h" #include "Serial.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
int main(void) {
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init();
/* Configure the system clock */ SystemClock_Config();
/* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC_Init();
SER_Initialize();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
printf ("Hello World 1 \n\r"); /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ printf ("Hello World 2\n\r"); /* USER CODE BEGIN 3 */
} /* USER CODE END 3 */
}
/** System Clock Configuration */ void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.MSIState = RCC_MSI_ON; RCC_OscInitStruct.MSICalibrationValue = 0; RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* ADC init function */ void MX_ADC_Init(void) {
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc.Instance = ADC1; hadc.Init.OversamplingMode = DISABLE; hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV1; hadc.Init.Resolution = ADC_RESOLUTION12b; hadc.Init.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; hadc.Init.ScanDirection = ADC_SCAN_DIRECTION_UPWARD; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ContinuousConvMode = DISABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE; hadc.Init.DMAContinuousRequests = DISABLE; hadc.Init.EOCSelection = EOC_SINGLE_CONV; hadc.Init.Overrun = OVR_DATA_PRESERVED; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerFrequencyMode = DISABLE; hadc.Init.LowPowerAutoOff = DISABLE; HAL_ADC_Init(&hadc);
/**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_0; HAL_ADC_ConfigChannel(&hadc, &sConfig);
/** Pinout Configuration */ void MX_GPIO_Init(void) {
/* GPIO Ports Clock Enable */ __GPIOA_CLK_ENABLE();
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
#ifdef USE_FULL_ASSERT
/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */
#endif
/** * @} */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
I do not read your cobe, but I thing You must make own function fputc() http://www.keil.com/support/man/docs/rlarm/rlarm_fputc.htm
This works with STM32F1 HAL_driver and USART1
int fputc(int ch, FILE *f) { /* Place your implementation of fputc here */ /* e.g. write a character to the USART1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); return ch; }
For clarification. Funciton printf send output to stdout and you must say where it is going.
In other words printf call low level function fputc and function fputc must send character to hardware port, for example USART1 or USART2 or ...
Thanks for the reply
my doubt is in which file should i check in order to understand the printf low level function call..
In my file i could only find out the definition of printf in (stdio.h file) thats the definition..
Hope you reply fast
Regards Austin