# Semihost\_hardfault in FreeRTOS software timer creation

**URL:** <https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [November 25, 2024, 3:51pm UTC](https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958 "2024-11-25T15:51:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roberth73](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@roberth73](https://forums.freertos.org/u/roberth73)\
**Post date:** [November 25, 2024, 3:51pm UTC](https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958/1 "2024-11-25T15:51:33Z")

</div>

Hi all,  
I have a strange problem. First some dtails:  
Processor: MKV58F1M0xxx24 (NXP Arm Cortex-M7)  
Compiler/IDE: MCUXpresso  
Debugger: J-Link

Here is the relevant code:

```auto

/* Initialization function */
void vInitSupervisoryControlTask(void) {

    printf("In vInitSupervisoryControlTask\n");
    initEventGroups();
    vCreateTimers();
```

The CreateTimers function is as follows:

```auto

void vCreateTimers(void) {

    xTimerShutdownBrake = xTimerCreateStatic(
        "Shutdown & Brake", // Just a text name, not used by the RTOS kernel
        pdMS_TO_TICKS(TIMER_PERIOD_SHUTDOWN_BRAKE * 1000), // Period
        pdFALSE, // Auto-reload
        (void*)0, // ID (a count of the number of times the timer has expired)
        vCallbackShutdownBrake, // Callback function
        &xTimerBufferShutdownBrake // Address of a StaticTimer_t variable
    );
       
   
    xTimer10RPMRotation = xTimerCreateStatic(
        "10 RPM Rotation",
        pdMS_TO_TICKS(TIMER_PERIOD_PERIODIC_ROTATION * 1000),
        pdFALSE, // One-shot timer
        (void*)&xTimer10RPMData, // Pass data for 10 RPM
        vCallbackPeriodicRotation, // Callback function
        &xTimerBuffer10RPMRotation // Static buffer
    );

    xTimer0RPMRotation = xTimerCreateStatic(
        "0 RPM Rotation",
        pdMS_TO_TICKS(TIMER_PERIOD_PERIODIC_ROTATION * 1000),
        pdFALSE, // One-shot timer
        (void*)&xTimer0RPMData, // Pass data for 0 RPM
        vCallbackPeriodicRotation, // Callback function
        &xTimerBuffer0RPMRotation // Static buffer
    );

    // Ensure timers are created successfully
    if (xTimer10RPMRotation == NULL || xTimer0RPMRotation == NULL) {
        // Handle error: Timer creation failed
    }
    else {
        //NOTE: Printing here causes semihost_hardfault
// printf("Timers created\n"); 
 // vTaskDelay(pdMS_TO_TICKS(5000));
    }
}
```

At the moment I have only 4 tasks running but a lot more have been coded (I switch them off by not calling their init functions).

Why could there be a semihost\_hardfault?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 25, 2024, 5:12pm UTC](https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958/2 "2024-11-25T17:12:41Z")

</div>

You can’t normally use semihosting with FreeRTOS as semihosting and the kernel use the same resources, plus semihosting holds up the processor.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [November 25, 2024, 5:39pm UTC](https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958/3 "2024-11-25T17:39:29Z")

</div>

> [@roberth73](#):
>
> Why could there be a semihost\_hardfault?

What are you using semihosting for? Can you share the code for semihost\_hardfault? Can you try removing the prints for testing?

---

<div class="post-metadata">

**Author:** ![roberth73](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@roberth73](https://forums.freertos.org/u/roberth73)\
**Post date:** [November 25, 2024, 8:56pm UTC](https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958/4 "2024-11-25T20:56:19Z")

</div>

Thank you Richard,  
I really appreciate it.

---

<div class="post-metadata">

**Author:** ![roberth73](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@roberth73](https://forums.freertos.org/u/roberth73)\
**Post date:** [November 25, 2024, 9:00pm UTC](https://forums.freertos.org/t/semihost-hardfault-in-freertos-software-timer-creation/21958/5 "2024-11-25T21:00:37Z")

</div>

The semihosting approach is the default approach we use for dev work. But from now on, when developing FreeRTOS applications, I will not use semihosting snymore thanks to Richard’s comment. BTW, the semihosting code is quite large (from MCUXpresso).
