This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help me to use ARM_DRIVER_UART API in Keil ARM MDK5

Hi,
I am new bie in STM32F4 microcontroller. I am studying STM32 with STM32F4 Discovery Board. I want to program communication via 2 UART on chip. I have read Help documents of Keil IDE but I don't understand and how to use API functions of ARM_DRIVER_UART and RTX Keil.
Anyone has a template example or help me some good idea?
Thank you in advance,

PS. sorry for my bad English.

  • Do you have experience with other microcontrollers, and/or other development tools/environments?

  • I have work with UART on 8051 family and Microchip PIC also but they are different from STM32 so much.
    I want to use ARM_DRIVER_UART to program, please don't tell me program Registers of UART peripheral.

  • Hi,

    At first I assume you are working with MDK5. Check if package for STM device is installed. To do so you have to click on Pack Installer button (green, yellow and blue icon). Installed pack must be named something like Keil::STM32Fxxx. When you are sure you have a pack create new project and select device etc... To add UART support to your project click on Manage Runtime Enviornment icon (green icon with black dots in). Navigate through software component tree to Drivers and select UART API, check it. Then Click at the bottom of window Resolve button (it will fix all dependencies etc...) Then close window with press on OK button.

    You will notice that Device, Driver, CMSIS will be included in your project in project explorer. Now in project explorer search for file RTE_Device.h. It's located under Device section. Dbl-click on it and you have two options. You can edit it as a text file or if you switch at the bottom of edit window on Configuration Wizard you will see that file in graphics mode where you will be able to enable UART and configure proper PINS etc.

    Now to access that UART you have to include manually in your main file, file Driver_UART.h.

    eg.

    If you selected UART1 in RTE_Device.h for your UART now in main.c do it as follows:

    // include API header
    #include "Driver_UART.h"
    
    // export symbol
    extern ARM_DRIVER_USART Driver_UART1:
    
    
    void main(void) {
    
      // init
      Driver_UART1.Initialize(...)
      Driver_UART1.PowerControl(...)
      Driver_UART1.Configure (...)
    
      // use it
      Driver_UART1.ReadData(...)
    
    
    }
    

    Hope this helps.

  • Thank you for your support, I know the way add driver to project but don't know how to configure. I will try what you show above.
    Thank you once again.

  • Hi Nixon,

    I am struggling this side as well. Things worked wonderfully before with the STM32 peripheral libraries in MDK 4.

    I am now trying to port things to Keil MDK 5 as the STM32 peripheral library seems to be incompatible with MDK 5 with the new pack installer :(

    I've have tried the following code to use the UART:

    // Header file
    #include "Driver_UART.h"

    // export symbol
    extern ARM_DRIVER_USART Driver_UART1:

    int main(void) {

    Driver_UART1.Initialize(NULL, 0); Driver_UART1.PowerControl(ARM_POWER_FULL); Driver_UART1.Configure(9600, 8, ARM_UART_PARITY_NONE, ARM_UART_STOP_BITS_1, ARM_UART_FLOW_CONTROL_NONE);

    // use it Driver_UART1.WriteData (&ch, 1);

    }

    The debugger shows the program hitting a HardFault Handler. I think it might have something to do with configuring the RCC for the port and UART peripherals, but writing these registers haven't helped either. Busy pulling my hair out because of it. Anyone with ideas?

  • Hi,

    Reasons for hitting FaultHandler can be different. In MDK5 UART depends on RTOS. Check for settings in RTX_Conf_CM.c file. You can edit it manually or via GUI. My current working settings are as follows:

    Thread Configuration
     - Number of concurent running threads 6
     - Default thread stack size 200
     - Main thread stack 200
     - Number of of threads with user.... 0
     - Total stack size [bytes]...... 0
     - Check for stack overflow   ... checked
     - Processor mode.... Privileged mode
    
    RTX Kernel timer Tick configuration
     - Use cortex-m systick.... checked
     - clock (depends on device)
     - timer tick value [us] 1000
    

    Quite common reason can be too small stack size for threads. But this is just one small point for a possible fault. There can be other reasons as well.

    Hope it helps.

  • Thank you so much Nixon! Using your settings there fixed the issue.

    Much appreciated

  • Keil drivers have limited featues and some pheripherals have no keil driver, or some capabilities are missed in MDK5.

    we work with ST driver lib but it is strange that keil will not support such perfect driver and use its buggy and incomplete driver.