delay_ms not as expected

Haha just found if I use your delay_ms(500); as follows it works:

while(1) {

REG_PIOB_SODR = PIO_PB27; //Enable output

delay_ms(500);

REG_PIOB_CODR = PIO_PB27; //Disable output

delay_ms(500);

}

Very strange behavior!! But it works with inbuilt delay.