Linux core crashes when using inline assembler in freertos

I am trying to use a bitbanging method for led strips and use inline assembler on the little core to create the ones and zeros for the sk6812 protocol on pin A12. The function works perfect and the leds do what I expect but I noticed that the linux core freezes and all network connection stop to respond. Here are the functions I use:

void send_bit_1() {
asm volatile (
“mv t0, %0\n” // Load GPIOA base address
“li t1, (1 << 18)\n” // Load mask for pin 18
“sw t1, 0(t0)\n” // Set pin high
“li t2, 118\n” // Delay for 600 ns
“1: nop\n”
“addi t2, t2, -1\n”
“bnez t2, 1b\n”
“sw zero, 0(t0)\n” // Set pin low
“li t2, 117\n” // Delay for 600 ns
“1: nop\n”
“addi t2, t2, -1\n”
“bnez t2, 1b\n”
:
: “r” (GPIOA_BASE)
: “t0”, “t1”, “t2”, “memory”
);
}

void send_bit_0() {
asm volatile (
“mv t0, %0\n” // Load GPIOA base address
“li t1, (1 << 18)\n” // Load mask for pin 18
“sw t1, 0(t0)\n” // Set pin high
“li t2, 58\n” // Delay for 300 ns
“1: nop\n”
“addi t2, t2, -1\n”
“bnez t2, 1b\n”
“sw zero, 0(t0)\n” // Set pin low
“li t2, 172\n” // Delay for 900 ns
“1: nop\n”
“addi t2, t2, -1\n”
“bnez t2, 1b\n”
:
: “r” (GPIOA_BASE)
: “t0”, “t1”, “t2”, “memory”
);
}

Where is the problem?
Thank you for your help

1 Like

I just found the error. By setting the data bit for the GPIO register I changed ALL other bits to 0 instead of restoring their original values. Now it works perfectly.

1 Like

Happy to hear that! :heart: