I think I found a problem with interrupts. AFIO_EXTICR[1 to 4]
registers are not beeing set correctly. You have to force a 0 on the
bits that are 0 for the mutex to work.
I have attached a patch.
Hope this helps.
Estudiante Ingeniería Civil Electrónica
Universidad Técnica Federico Santa María