Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Driver vs HAL

I am budding Embedded Engineer, currently, I would like to learn how to program nrf52dk. While I am exploring info center, Peripheral examples I have noticed that most of the peripherals has two section: 


1. Driver. 

2. HAL. 

My questions are the following: 

1. What is the difference between these two? and which one to opt 

In future I am interested in implementing RTOS on nrf52. will it make any difference if i learn coding with driver or HAL? 

Thanks in advance, 

Ashok

  • The Hardware Abstraction Layer ensures safe register access to a peripheral, but is often limited in features. A driver sits atop the HAL and expand on its feature set. 

    Whether you want to use the HAL or driver depends on your specific use-case, many drivers ensures reliable operation of the peripherals that might otherwise by tricky to do by writing a driver from scratch. 

    My suggestion is to re-design an existing driver to fit your needs, if it does not do so already. 

  • so you mean to say the following hierarchy 

    1.Driver 

    2.HAL 

    3.Hardware ? 

    Is this how it is existing in nrf52 ? 

  • Yes, you're correct. 

    I suggest you study the RTC driver and RTC HAL API documentation and their code implementation, and compare the two abstraction layers. You should also study the RTC — Real-time counter chapter of the Product specification, and take particular note of the Registers description, it will tell you exactly what each bit in a given register does. If you know what each register does, you will understand how the HAL interfaces with the underlying hardware. As many driver functions results in calls to the HAL api, you'll be able to understand what the driver is actually doing.
    Once you've understood the connection between the driver, HAL, product specification, and register description of the RTC you will be able to debug any HW peripheral in the SDK much more effectively. 

    I believe this abstraction model extends to a great number of embedded systems. 

Related