user49013: I'm working on code that will control micro servo. I use generic servo and built-in library for controling servo. Microcontroller is generic STM32.
Controlling servo Works as expected. But I don't want next behavior - attach() function sets servo to 180°(maybe 0°, not sure).
In my project I want next:

Servo stays at angle before going off/reboot
Servo goes to 90° after turning on/reboot

I googled about this problem and tried with write(90); before attach() in setup() function. Servo goes to 90° but after like 50ms attach() stops write(90) function and it goes back to 180°. So this didn't solve my problem.
Next I've open Servo.cpp and found that attach() function contains next code:
    bool Servo::attach(uint8 pin,
                   uint16 minPW,
                   uint16 maxPW,
                   int16 minAngle,
                   int16 maxAngle) {
    timer_dev *tdev = PIN_MAP[pin].timer_device;

    if (tdev == NULL) {
        // don't reset any fields or ASSERT(0), to keep driving any
        // previously attach()ed servo.
        return false;
    }

    if (this->attached()) {
        this->detach();
    }

    this->pin = pin;
    this->minPW = minPW;
    this->maxPW = maxPW;
    this->minAngle = minAngle;
    this->maxAngle = maxAngle;

    pinMode(pin, PWM);

    timer_pause(tdev);
    timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
    timer_set_reload(tdev, SERVO_OVERFLOW);
    timer_generate_update(tdev);
    timer_resume(tdev);

    return true;
}

What should I do to fix this problem? Servo will adjust angle of PCB which holds LEDs. PCB will be in case and angle of 90° is default angle. 0°/180° will either destory servo or brake case/PCB/something else.

user51102: You can avoid using the attach(); method by programming without the servo library.
  for(x=0; x<150; x=x+1)
  {
    digitalWrite(Servomotor, HIGH);
    delayMicroseconds(2350); //Change the delay here to change the angle it goes to
    digitalWrite(Servomotor, LOW);
    delayMicroseconds(18550);
  }

This is an example code for how it worked for me. It sends a pulse to the servo which makes it turn a bit until it reaches a "barrier". 

49013: <p>I'm working on code that will control micro servo. I use generic servo and built-in library for controling servo. Microcontroller is generic STM32.
Controlling servo Works as expected. But I don't want next behavior - <code>attach()</code> function sets servo to 180°(maybe 0°, not sure).
In my project I want next:</p>

<ul>
<li>Servo stays at angle before going off/reboot</li>
<li>Servo goes to 90° after turning on/reboot</li>
</ul>

<p>I googled about this problem and tried with <code>write(90);</code> before <code>attach()</code> in <code>setup()</code> function. Servo goes to 90° but after like 50ms <code>attach()</code> stops <code>write(90)</code> function and it goes back to 180°. So this didn't solve my problem.
Next I've open <code>Servo.cpp</code> and found that <code>attach()</code> function contains next code:</p>

<pre><code>    bool Servo::attach(uint8 pin,
                   uint16 minPW,
                   uint16 maxPW,
                   int16 minAngle,
                   int16 maxAngle) {
    timer_dev *tdev = PIN_MAP[pin].timer_device;

    if (tdev == NULL) {
        // don't reset any fields or ASSERT(0), to keep driving any
        // previously attach()ed servo.
        return false;
    }

    if (this-&gt;attached()) {
        this-&gt;detach();
    }

    this-&gt;pin = pin;
    this-&gt;minPW = minPW;
    this-&gt;maxPW = maxPW;
    this-&gt;minAngle = minAngle;
    this-&gt;maxAngle = maxAngle;

    pinMode(pin, PWM);

    timer_pause(tdev);
    timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
    timer_set_reload(tdev, SERVO_OVERFLOW);
    timer_generate_update(tdev);
    timer_resume(tdev);

    return true;
}
</code></pre>

<p>What should I do to fix this problem? Servo will adjust angle of PCB which holds LEDs. PCB will be in case and angle of 90° is default angle. 0°/180° will either destory servo or brake case/PCB/something else.</p>
 51102: <p>You can avoid using the <code>attach();</code> method by programming without the servo library.</p>

<pre><code>  for(x=0; x&lt;150; x=x+1)
  {
    digitalWrite(Servomotor, HIGH);
    delayMicroseconds(2350); //Change the delay here to change the angle it goes to
    digitalWrite(Servomotor, LOW);
    delayMicroseconds(18550);
  }
</code></pre>

<p>This is an example code for how it worked for me. It sends a pulse to the servo which makes it turn a bit until it reaches a "barrier". </p>
