Want to port a function which is in STM32 API

ujurmsde
Posts: 38
Joined: Tue Jan 19, 2021 6:37 am

Want to port a function which is in STM32 API

Postby ujurmsde » Sat Jan 07, 2023 7:03 am

Hi,
I want to find the idf equvivalant of the following functions.
NoteSetFn(malloc, free, HAL_Delay, HAL_GetTick);
The malloc and free are not an issue. The HAL_delay is the function which which provides minimum delay in the specific API and HAL_GetTick gives the current timestamp.

I have done some basic search but could not find a right functions. Does anyone know and can please tell?

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: Want to port a function which is in STM32 API

Postby mbratch » Sun Jan 08, 2023 3:52 pm

What does the STM32 API documentation say that `NoteSetFn(malloc, free, HAL_Delay, HAL_GetTick);` does? Is it in the STM32 API, or is it a custom function in your project?

ujurmsde
Posts: 38
Joined: Tue Jan 19, 2021 6:37 am

Re: Want to port a function which is in STM32 API

Postby ujurmsde » Mon Jan 09, 2023 4:12 am

It is a custom function which is based on STM32 API's so I need to port it to ESP32.!!

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: Want to port a function which is in STM32 API

Postby mbratch » Mon Jan 09, 2023 10:18 pm

ujurmsde wrote:
Mon Jan 09, 2023 4:12 am
It is a custom function which is based on STM32 API's so I need to port it to ESP32.!!
Ah cool. Perhaps you could show the content of the function (source). Knowing how the parameters are used might indicate how they need to be ported.

Not knowing much more detail, I think the corresponding functions would approximately be `vTaskDelay` and `esp_timer_get_time`. I don't know what the STM32 system you are porting from used as an environment, but ESP-IDF uses FreeRTOS. So delays are done with `vTaskDelay` which accepts ticks. `esp_timer_get_time` gives the number of microseconds since boot. To get the equivalent of the `HAL_GetTick` function, you want milliseconds.

So you'd write some simple wrappers, something like this. You'll need to adjust data types as needed (I don't know the signature of your custom function):

Code: Select all

    uint32_t ticks(void)
    {
        return static_cast<uint32_t>(esp_timer_get_time() / 1000);
    }

Code: Select all

    void delay(uint32_t ms)
    {
        vTaskDelay(pdMS_TO_TICKS(ms));
    }
Note that `millis` above returns milliseconds which, by default, is what `HAL_GetTick` will return because (by default) I think a tick is a millisecond in the STM32 (I may be wrong about that). Anyway, you can use your wrapper to scale as needed.

And then pass these to your ported function.

Code: Select all

NoteSetFn(malloc, free, delay, ticks);

Who is online

Users browsing this forum: Bing [Bot] and 301 guests