3 Replies Latest reply on Aug 17, 2020 10:18 PM by DheerajK_81

    How to setup an RTC alarm in Mbed OS 6.2?

    GuGa_1322886

      I'm trying to create an RTC Alarm in Mbed OS 6.2.0 following the PDL documentation, but at compile time I get an error saying that Cy_RTC_Alarm1Interrupt() is already defined, probably at the HAL level. I can't find equivalent functionality in Mbed RTC API. What if you want to wake the device at a specific date and time?, or periodically every day at the same time, for example?

      Is there an alternative API to set an Alarm?

        • 1. Re: How to setup an RTC alarm in Mbed OS 6.2?
          DheerajK_81

          Not sure about how you have implemented it. But I would recommend making use of Cypress HAL APIs for RTC. Mbed APIs do not offer many functionalities (like alarm), you need to make use of Cypress specific APIs. You will be able to set up an alarm in just a few lines of code if you use Cypress HAL. Please find the snippet attached that demonstrates how you can do this.

           

          I ran this on mbed-os version 6.2 and it works correctly. Please let me know if it works for you

           

          Regards,

          Dheeraj

          • 2. Re: How to setup an RTC alarm in Mbed OS 6.2?
            GuGa_1322886

            Thanks DheeraJK_81. That solved the mystery. I was using the wrong API: the Cypress Peripheral Driver Library (PDL) instead of Hardware Abstraction Layer (HAL). The PDL was already part of the sample project and seemed the logical way to go. After loading the HAL library from Github I could create an RTC instance as your sample shows, set the time and program alarms. That was straight forward.

             

            Now, there are more questions:

            Why there are two sets of APIs to access hardware: PDL and HAL?

            How to know when to use one or the other?

            • 3. Re: How to setup an RTC alarm in Mbed OS 6.2?
              DheerajK_81

              I was using the wrong API: the Cypress Peripheral Driver Library (PDL) instead of Hardware Abstraction Layer (HAL). Why there are two sets of APIs to access hardware: PDL and HAL?

              There is nothing wrong with using the PDL. You can use either the PDL or the HAL APIs for interacting with the RTC block. HAL is one layer above the PDL and provides an easy and generic interface to most of the hardware blocks. It uses PDL APIs itself internally.

               

              When using PDL APIs, you need to configure the hardware block using the device configurator. You can do that by clicking the design.modus file present at this path: "<project_directory>\mbed-os\targets\TARGET_Cypress\TARGET_PSOC6\TARGET_<yourBSP>\COMPONENT_BSP_DESIGN_MODUS"

               

              Open this file using the device-configurator tool present in your ModusToolbox installation directory: ModusToolbox\tools_2.1\device-configurator

               

              Enable RTC in the device configurator and then set the required parameters in the Parameters window. When you build your project, the GeneratedSource folder will contain the configs and macros that you can use in your mbed project.

               

              How to know when to use one or the other?

              PDL APIs are lower-level libraries when compared to the HAL. You can make use of both the HAL and PDL in your application as long as you aren't interacting with the same resource. HAL is simple and easy but provides only a subset of functionalities when compared to the PDL. PDL gives you more finer control on the behaviour of the hardware blocks. So the choice is completely upto the developer to see how much control is required. If you can satisfy all your requirements using the HAL APIs, then I recommend using that. If some functionality isn't available through HAL, then make use of PDL.

               

              The HAL and PDL API reference guides must be used to make this choice.

               

              Regards,

              Dheeraj