2014-08-12 03:14 AM
Hello.
I have medium knowledge of C/C++ (it was enough to make certain devices using Atmel AVR microcontorllers). Now I try to understand the Demo example of the STM32F4 Discovery. Is there some description of it?
I watch the program in IAR EWARM.
For example what does __IO mean:
__IO uint32_t DR;
and this (exactly if USART_TypeDef is a pointer why * is placed after the type):
#define USART3 ((USART_TypeDef *) USART3_BASE)
Thanks!
2014-08-12 04:37 AM
__IO is a typedef of volatile, it's used to describe peripheral registers which can change internal outside of program control. This causes the compiler to re-read the value every time it's used/referenced.
The value is an Address, values passed as Addresses use Pointers. In this case a pointer to a structure, permitting access to registers inside by name. ie USART3->DR = 0x55;2014-08-12 06:34 AM
Thank you for the answer, Clive1.
Did I understand correctly:
__IO uint32_t DR;
is the same as:
volatile uint32_t DR;
?
As for the Addresses and Pointers it is not clear for me.
How the following expression can be explained:
((USART_TypeDef *) USART3_BASE)
?
USART3_BASE = 0x40004800, so
((USART_TypeDef *) 0x40004800) .
How can be the following explained:
USART_TypeDef *
Thanks
2014-08-12 07:23 AM
Probably want to re-read the chapters on
http://en.cppreference.com/w/c/language/typedef
, pointers and casting. When you create a variable, the compiler allocates some space, and the linker assigns it an address. uint32_t foo; uint32_t *p; p = &foo; // Address of foo in memory p = (uint32_t *)0x20002000; // Explicit address of memory *p = 0xDEADBEEF; // write value to memory address described by pointer p[0] = 0x12345678; // write to address described by pointer p[1] = 0x876534321; // write to the next address, incremented by size of the element (4 bytes) Also works for structures and unions. The USART structure describes the registers within the peripheral, the casting sets it to an address within the memory space.2014-08-12 07:32 AM
Did I understandcorrectly:
__IO uint32_t DR;
is the same as:
volatile uint32_t DR;
Yes - you should be able to find that easily using the 'Go To Definition' feature of the IDE.
''As for the Addresses andPointers it is not clear for me''
It's pretty basic 'C' stuff:USART_TypeDef *
is a pointer to something of theUSART_TypeDef
type.Just like(int*)
0x40004800
casts the value
0x40004800
to be a pointer to something of type int''
I have medium knowledge of C/C++''
Hmm... I think you may be over-estimating''(it was enough to make certain devices using Atmel AVR microcontorllers)''All this applies equally to AVRs.http://blog.antronics.co.uk/2010/12/12/things-you-shouldve-learned-in-c-class-0-introduction/
2014-08-12 08:07 AM
Clive1, Neil Anderw thank you for the answers and for the reference. This part is clear now. Will continue to scramble through the mess of demo program...