So I have bought my Nucleo STM32F334xx. I'm beginer in Embedded Systems.
So my first project would be to make led lit.
So my professor gave me this code:
int main(){
//we need THREE STEPS to make the LED be lit:
//1st step: Activate GPIO Port via Advanced Hyper Bus (AHB)
//******************************************************
// Description (pdf p. 22): User LD2 is connected to Pin A.5, so GPIO A is needed
// Datasheet (pdf p. 12): GPIOPORTA is connected to AHB bus
// Ref.Manu. (pdf p. 127): RCC_AHBENR, bit 17 controls IOPAEN, must be set to '1'
//2nd step: configure Pin5 (of GPIO A) to be an push/pull output
//**************************************************************
// Ref.Manu. (pdf p. 145): MODE must be set to '01' to enable GP (general purpose) output
// (since reset value of all other registers is 0, no other changes are neccessary)
// Ref.Manu. (pdf p. 152): GPIOA_MODER, bits 11&10 control the port mode:
// Bit 11 must be set to '0' (i.e. leave unchanged after reset)
// Bit 10 must be set to '1'
// --> together: Mode '01' (i.e. GP OUTput push/pull)
//3rd step: send a '1' to this Pin to make LED be lit
//***************************************************
// Ref.Manu. (pdf p. 144, fig. 13): Output data register contains data that is sent to output pin
// Ref.Manu. (pdf p. 154): GPIOA_ODR, bit 5 corresponds to Pin 5, ('1' means '1'
)
//1st step:
//*********
//Adding
// --- RCC boundary address 0x4002 1000 (Datasheet pdf p. 42)
//to
// --- RCC_AHBENR address offset 0x14 (Ref.Manu. pdf p. 127)
//equals
// --- 0x4002 1014 = address of RCC_AHBENR
//Bit 17 needs to be '1', leave other bits unchanged (as an act of politness
)
//if we want to set a specific bit to '1' we need an OR bitmask
//Bit 'something' OR '0' --> leaves bit 'something' unchanged
//Bit 'something' OR '1' --> sets this bit to '1'
*((unsigned long *) 0x40021014) |= 1<<17;
//now let's try to explain the above line:
// '1<<17' means: take '1' and shift it leftwards 17 times, this equals
// binary 0b00000000000000100000000000000000 (hexadecimal 0x00020000)
// so this is the bitmask, with OR-operator only one bit will be changed: bit 17 --> '1'
//
// '|=' is an operation that says: .read the value on the left .make the OR-Operation .then write it back
//
// now a little pointer arithmetics:
// 0x40021014 is just a number, nothing else
// (unsigned long *) casts it to a 32 bit memory address
// since we don't want to change the ADDRESS but the CONTENT of this address, we need to use...
// '*' eventually
//2nd step:
//*********
// forgive us for not explaining ALL the above mentioned things, all we need is:
//
// --- GPIOA boundary address 0x4800 0000 (Datasheet pdf p. 42)
// --- GPIOA_MODER address offset 0x00 (Ref.Manu. pdf p. 152)
// --- 0x4800 0000 = address of GPIOA_MODER
//Bit 10 must be set to '1'
*((unsigned long *) 0x48000000) |= 1<<10;
//3rd step:
//*********
// the further we go, the easier it becomes, nothing new here:
//
// --- same boundary address
// --- GPIOA_ODR address offset 0x14 (Ref.Manu. pdf p. 154)
// --- 0x4800 0014 = address of GPIOA_MODER
//Bit 5 must be set to '1', the LED is lit
*((unsigned long *) 0x48000014) |= 1<<5;
while(1);
}
So do I need to copy this and build or I need to follow steps in compiler?
So my first project would be to make led lit.
So my professor gave me this code:
int main(){
//we need THREE STEPS to make the LED be lit:
//1st step: Activate GPIO Port via Advanced Hyper Bus (AHB)
//******************************************************
// Description (pdf p. 22): User LD2 is connected to Pin A.5, so GPIO A is needed
// Datasheet (pdf p. 12): GPIOPORTA is connected to AHB bus
// Ref.Manu. (pdf p. 127): RCC_AHBENR, bit 17 controls IOPAEN, must be set to '1'
//2nd step: configure Pin5 (of GPIO A) to be an push/pull output
//**************************************************************
// Ref.Manu. (pdf p. 145): MODE must be set to '01' to enable GP (general purpose) output
// (since reset value of all other registers is 0, no other changes are neccessary)
// Ref.Manu. (pdf p. 152): GPIOA_MODER, bits 11&10 control the port mode:
// Bit 11 must be set to '0' (i.e. leave unchanged after reset)
// Bit 10 must be set to '1'
// --> together: Mode '01' (i.e. GP OUTput push/pull)
//3rd step: send a '1' to this Pin to make LED be lit
//***************************************************
// Ref.Manu. (pdf p. 144, fig. 13): Output data register contains data that is sent to output pin
// Ref.Manu. (pdf p. 154): GPIOA_ODR, bit 5 corresponds to Pin 5, ('1' means '1'
//1st step:
//*********
//Adding
// --- RCC boundary address 0x4002 1000 (Datasheet pdf p. 42)
//to
// --- RCC_AHBENR address offset 0x14 (Ref.Manu. pdf p. 127)
//equals
// --- 0x4002 1014 = address of RCC_AHBENR
//Bit 17 needs to be '1', leave other bits unchanged (as an act of politness
//if we want to set a specific bit to '1' we need an OR bitmask
//Bit 'something' OR '0' --> leaves bit 'something' unchanged
//Bit 'something' OR '1' --> sets this bit to '1'
*((unsigned long *) 0x40021014) |= 1<<17;
//now let's try to explain the above line:
// '1<<17' means: take '1' and shift it leftwards 17 times, this equals
// binary 0b00000000000000100000000000000000 (hexadecimal 0x00020000)
// so this is the bitmask, with OR-operator only one bit will be changed: bit 17 --> '1'
//
// '|=' is an operation that says: .read the value on the left .make the OR-Operation .then write it back
//
// now a little pointer arithmetics:
// 0x40021014 is just a number, nothing else
// (unsigned long *) casts it to a 32 bit memory address
// since we don't want to change the ADDRESS but the CONTENT of this address, we need to use...
// '*' eventually
//2nd step:
//*********
// forgive us for not explaining ALL the above mentioned things, all we need is:
//
// --- GPIOA boundary address 0x4800 0000 (Datasheet pdf p. 42)
// --- GPIOA_MODER address offset 0x00 (Ref.Manu. pdf p. 152)
// --- 0x4800 0000 = address of GPIOA_MODER
//Bit 10 must be set to '1'
*((unsigned long *) 0x48000000) |= 1<<10;
//3rd step:
//*********
// the further we go, the easier it becomes, nothing new here:
//
// --- same boundary address
// --- GPIOA_ODR address offset 0x14 (Ref.Manu. pdf p. 154)
// --- 0x4800 0014 = address of GPIOA_MODER
//Bit 5 must be set to '1', the LED is lit
*((unsigned long *) 0x48000014) |= 1<<5;
while(1);
}
So do I need to copy this and build or I need to follow steps in compiler?