cancel
Showing results for 
Search instead for 
Did you mean: 

UART HAL driver usage

stanzanim
Associate III
Posted on August 06, 2015 at 16:41

Hello

I am using NUCLEO L053R8 (STM32L0) , Keil uVision 5.15 and ST-Link (embedded in the nucleus board). I let CubeFx a FW program using CubeFx with HAL enabled.

All compiles well

I can use the the blocking transmit function

HAL_UART_Transmit(&huart2, (uint8_t*)txx,sizeof(txx),1000);

but the non-blocking, interrupt base

HAL_UART_Transmit_IT(&huart2, (uint8_t*)txx,sizeof(txx));

does not work. How do I setup the NVIC as required at the beginning of *_hal_uart.c?

    (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:

 

        (##) Enable the USARTx interface clock.

 

        (##) UART pins configuration:

 

            (+++) Enable the clock for the UART GPIOs.

 

            (+++) Configure these UART pins as alternate function pull-up.

 

        (##) N

VIC configuration

if you need to use interrupt process (HAL_UART_Transmit_IT()

 

             and HAL_UART_Receive_IT() APIs):

 

            (+++) Configure the USARTx interrupt priority.

 

            (+++) Enable the NVIC USART IRQ handle.

 

It looks like that CubeFX generated a project with no interrupt handling support ... so I have added in the main program the following code

void USART2_IRQHandler(void)

{

  HAL_UART_IRQHandler(&huart2);

}

Since I want to write an fputc based on sending a single character, is it available a dedicated API or should I use the same API above with size=1? I tried some piece of code based on accessing the UART registers but I failed ...

The issue I have when using the vlocking transmit function is that the baud rate is unaccurate so I am thinking about the clock selection may be wrong ...

Is there any example abot using the UART with HAL drivers (the code snippets I find in the STM web site use only MSIS so I am wondering if it is recommended using HAL drivers for simple applications)

sorry fo the basic questions (I am a primer here)

thanks

Below the CubeFx configuration file

#MicroXplorer Configuration settings - do not modify

File.Version=5

KeepUserPlacement=true

Mcu.Family=STM32L0

Mcu.IP0=ADC

Mcu.IP1=CRC

Mcu.IP2=IWDG

Mcu.IP3=NVIC

Mcu.IP4=RCC

Mcu.IP5=SYS

Mcu.IP6=TIM6

Mcu.IP7=USART1

Mcu.IP8=USART2

Mcu.IPNb=9

Mcu.Name=STM32L051K(6-8)Tx

Mcu.Package=LQFP32

Mcu.Pin0=PA0

Mcu.Pin1=PA2

Mcu.Pin2=PA3

Mcu.Pin3=PA9

Mcu.Pin4=PA10

Mcu.Pin5=PA13

Mcu.Pin6=PA14

Mcu.Pin7=VP_CRC_VS_CRC

Mcu.Pin8=VP_IWDG_VS_IWDG

Mcu.Pin9=VP_TIM6_VS_ClockSourceINT

Mcu.PinsNb=10

Mcu.UserConstants=

Mcu.UserName=STM32L051K6Tx

MxCube.Version=4.9.0

MxDb.Version=DB.4.0.90

NVIC.SysTick_IRQn=true\:0\:0\:false

PA0.Mode=IN0

PA0.Signal=ADC_IN0

PA10.Mode=Asynchronous

PA10.Signal=USART1_RX

PA13.Mode=Serial_Wire

PA13.Signal=SYS_SWDIO

PA14.Mode=Serial_Wire

PA14.Signal=SYS_SWCLK

PA2.Mode=Asynchronous

PA2.Signal=USART2_TX

PA3.Mode=Asynchronous

PA3.Signal=USART2_RX

PA9.Mode=Asynchronous

PA9.Signal=USART1_TX

PCC.Checker=false

PCC.Line=STM32L0x1

PCC.MCU=STM32L051K(6-8)Tx

PCC.MXVersion=4.9.0

PCC.PartNumber=STM32L051K6Tx

PCC.Seq0=0

PCC.Series=STM32L0

PCC.Temperature=25

PCC.Vdd=null

ProjectManager.AskForMigrate=true

ProjectManager.BackupPrevious=false

ProjectManager.CompilerOptimize=2

ProjectManager.ComputerToolchain=false

ProjectManager.CoupleFile=false

ProjectManager.DeletePrevious=true

ProjectManager.DeviceId=STM32L051K6Tx

ProjectManager.FirmwarePackage=STM32Cube FW_L0 V1.1.2

ProjectManager.FreePins=false

ProjectManager.HalAssertFull=false

ProjectManager.KeepUserCode=true

ProjectManager.LastFirmware=true

ProjectManager.LibraryCopy=1

ProjectManager.ProjectBuild=false

ProjectManager.ProjectFileName=ECM_BLDC.CTRL.ioc

ProjectManager.ProjectName=ECM_BLDC.CTRL

ProjectManager.TargetToolchain=MDK-ARM V5

ProjectManager.ToolChainLocation=

RCC.AHBFreq_Value=2097000

RCC.APB1Freq_Value=2097000

RCC.APB1TimFreq_Value=2097000

RCC.APB2Freq_Value=2097000

RCC.APB2TimFreq_Value=2097000

RCC.ClockTypeSysClk=RCC_CLOCKTYPE_SYSCLK

RCC.FamilyName=M

RCC.HSI16_VALUE=16000000

RCC.HSI_VALUE=16000000

RCC.I2C1Freq_Value=2097000

RCC.IPParameters=FamilyName,LSE_VALUE,MSI_VALUE,HSI16_VALUE,HSI_VALUE,LSI_VALUE,WatchDogFreq_Value,VCOOutputFreq_Value,PLLCLKFreq_Value,RTCFreq_Value,SYSCLKFreq_VALUE,AHBFreq_Value,TIMFreq_Value,APB1Freq_Value,APB1TimFreq_Value,LPTIMFreq_Value,I2C1Freq_Value,APB2Freq_Value,APB2TimFreq_Value,USART1Freq_Value,PWRFreq_Value,USART2Freq_Value,ClockTypeSysClk

RCC.LPTIMFreq_Value=2097000

RCC.LSE_VALUE=32768

RCC.LSI_VALUE=37000

RCC.MSI_VALUE=2097000

RCC.PLLCLKFreq_Value=24000000

RCC.PWRFreq_Value=2097000

RCC.RTCFreq_Value=37000

RCC.SYSCLKFreq_VALUE=2097000

RCC.TIMFreq_Value=2097000

RCC.USART1Freq_Value=2097000

RCC.USART2Freq_Value=2097000

RCC.VCOOutputFreq_Value=48000000

RCC.WatchDogFreq_Value=37000

VP_CRC_VS_CRC.Mode=CRC_Activate

VP_CRC_VS_CRC.Signal=CRC_VS_CRC

VP_IWDG_VS_IWDG.Mode=IWDG_Activate

VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG

VP_TIM6_VS_ClockSourceINT.Mode=Enable_Timer

VP_TIM6_VS_ClockSourceINT.Signal=TIM6_VS_ClockSourceINT

board=ECM_BLDC.CTRL

1 REPLY 1
Amel NASRI
ST Employee
Posted on August 31, 2015 at 15:53

Hi stanzani.marco,

You can find the example you are looking for under STM32Cube_FW_L0\Projects\STM32L053R8-Nucleo\Examples\UART\UART_TwoBoards_ComIT.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.