August 27, 2018

On-board LED and GPIO alternate function settings

I made myself crazy for a while being unable to control the on-board LED from bare-metal code. Actually I was experimenting with code in U-boot and manipulating the LED seemed to be the simplest way of making sure that I could control GPIO signals.

I wasted a lot of time fretting about whether the GPIO had clock or reset control bits I had to configure (it does not). My problems all arose from a faulty assumption. Each GPIO bit has a two bit field (4 possible settings) in an alternate function control register. I had figured that setting this field to zero would get the "normal" GPIO function. This may be the way it is on other chips I have worked with, but not on the s5p6818.

In the case of GPIO B12 (which controls the on-board LED), the special function field must be set to 0x2 to make it work like a GPIO. And for other GPIO pins the setting may be 0x1 or rarely 0x0. There is no pattern that I can see. The only way I have found to get this information is in chapter 2 of the user manual, which is organized by pad on the chip package rather than by function. So for B12, you go to page 2-29 and with sharp eyes notice that when setting a value of 2 for pad W24 you get the B12 function (the zero setting gives you ALE0, whatever that is). In chapter 16, page 16-19 it states that the reset value of the special function register is zero for all of the GPIO. So aparently in "ALE0" mode this pad is asserted low, turning on the LED and is in no way connected to the GPIO. At some point I will grind through the tables in chapter 2 and make my own table of settings to get various functions.

Lessons Learned

Don't assume that special function setting zero gives you GPIO, because in general it does not. Once you get this straight, manipulating the GPIO is easy and does not require any clock or reset configuration.

Have any comments? Questions? Drop me a line!

Tom's electronics pages /