Hi all!
I am a noob so i apologize for the infuriation when looking at my code
I am trying to make a piece of code that runs without an os on my raspberry pi 2 model b v1.1. It is supposed to make gpio pin 13 go high.
Here is the code:
/* The base address of the GPIO peripheral (ARM Physical Address) */
#define BASE_ADDR 0x3F200000UL
#define FSEL10 0x04
#define GPSET0 0x1C
volatile unsigned int* gpio;
int main(void)
{
/* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
gpio = (unsigned int*)BASE_ADDR;
/* Set the pin as an output */
gpio[FSEL0] |= (1 << 9);
/* Make the pin high. */
gpio[GPSET0] |= (1 << 12);
/* Never exit as there is no OS to exit to! */
while(1)
{
}
}
In the code i set the pin 13 as an output (i set the first pi of the it's function select register (bits 0,1 and 2 of the fsel10 are for gpio pin 10, bits 3,4 and 5 are for gpio pin 11 and so on, so i left shift 1 nine times to get the 10th bit of fsel10 which is the first bit of gpio pin 13, so it should set it high)). I am trying to follow this tutorial btw https://github.com/BrianSidebotham/arm-tutorial-rpi/tree/master/part-1
When the correct function is set (output) then i get the 13th bit of the gpset0 by left shifting 1 by 12 times (i think that 1 by itself is already gpio pin 1).
The while loop is just there to prevent the main function from returning, because there is nothing to return to.
I compile the code with this command: arm-none-eabi-gcc -O2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles main.c -o main.elf
(main.c is the code)
My arm-none-eabi-gcc version is 8.3.1 20190703 (release) [gcc-8-branch revision 273027].
Then i used this command to get the raw machine code: arm-none-eabi-objcopy main.elf -O binary kernel.img
My arm-none-eabi-objcopy version is GNU objcopy (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 2.32.0.20190703 (yse i did copy the output of arm-none-eabi-objcopy --version directly and same with gcc).
I then put the kernel.img on my micro sd card with start.elf and bootcode.bin and i put it in to my raspberry pi 2 model b v1.1.
Why isn't the gpio 13 pin high? I have checked all the wiring connections.
Thanks in advance!!
(And btw you people are awesome! I have checked out some of the projects you are making/have made)
I am a noob so i apologize for the infuriation when looking at my code
I am trying to make a piece of code that runs without an os on my raspberry pi 2 model b v1.1. It is supposed to make gpio pin 13 go high.
Here is the code:
/* The base address of the GPIO peripheral (ARM Physical Address) */
#define BASE_ADDR 0x3F200000UL
#define FSEL10 0x04
#define GPSET0 0x1C
volatile unsigned int* gpio;
int main(void)
{
/* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
gpio = (unsigned int*)BASE_ADDR;
/* Set the pin as an output */
gpio[FSEL0] |= (1 << 9);
/* Make the pin high. */
gpio[GPSET0] |= (1 << 12);
/* Never exit as there is no OS to exit to! */
while(1)
{
}
}
In the code i set the pin 13 as an output (i set the first pi of the it's function select register (bits 0,1 and 2 of the fsel10 are for gpio pin 10, bits 3,4 and 5 are for gpio pin 11 and so on, so i left shift 1 nine times to get the 10th bit of fsel10 which is the first bit of gpio pin 13, so it should set it high)). I am trying to follow this tutorial btw https://github.com/BrianSidebotham/arm-tutorial-rpi/tree/master/part-1
When the correct function is set (output) then i get the 13th bit of the gpset0 by left shifting 1 by 12 times (i think that 1 by itself is already gpio pin 1).
The while loop is just there to prevent the main function from returning, because there is nothing to return to.
I compile the code with this command: arm-none-eabi-gcc -O2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles main.c -o main.elf
(main.c is the code)
My arm-none-eabi-gcc version is 8.3.1 20190703 (release) [gcc-8-branch revision 273027].
Then i used this command to get the raw machine code: arm-none-eabi-objcopy main.elf -O binary kernel.img
My arm-none-eabi-objcopy version is GNU objcopy (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 2.32.0.20190703 (yse i did copy the output of arm-none-eabi-objcopy --version directly and same with gcc).
I then put the kernel.img on my micro sd card with start.elf and bootcode.bin and i put it in to my raspberry pi 2 model b v1.1.
Why isn't the gpio 13 pin high? I have checked all the wiring connections.
Thanks in advance!!
(And btw you people are awesome! I have checked out some of the projects you are making/have made)