Other Parts Discussed in Thread: HALCOGEN
Hello!
I have few questions regarding programming my RM46 microcontroller. This is a bit long post where I am trying to explain what I've done so far and the issues I am not certain of and I would need your help with these.
I have tried to program it without using HALCoGen and hence hit a giant wall that surpasses that of Great Wall of China (go figure, lol).
I want to point out that I do not want to use HALCoGen and I want to write everything down myself. If you are wondering why I will give you two reasons as I fear that the discussion will go 'USE THE HALCOGEN' way and I want to avoid it:
- I am used to writing everything down myself. I have never used software like this nor do I want to start using it (think of me as a granda who doesn't want to modernise and use a mobile phone);
- The biggest problem I have with HALCoGen is that it generates a lot of code that I find unnecessary and I do not want to skim through the generated code just to find what I need. I understand that using HALCoGen is easier than doing what I want to do myself, but it also limits you as you are left with a lot of code you might simply not understand or even care to understand.
So, let's just, for example, speak about me writing my own GPIO. I downloaded the technical reference manual (approx. 2000 page long - the longest one I read so far) to get myself familiar with what I need to write in each register to get the desired result. Let's say I want to turn on the GPIO. I need to use GIOGCR0 register. It says that if I write 1 on bit0 it will enable the GPIO. But what is extremely weird is that I am not getting any error and my program compiles as long as I write GIOGCR0 in .h file (I found this being weird latter). I get the warning, though: 'THIS DECLARATION HAS NO STORAGE CLASS OR TYPE SPECIFIER'. I haven't payed much attention to it at first, since I was working with Eclipse to program Arduino long time ago, and warnings arose with every register name. The fork when I started taking the warning seriously was when I started writing the function that utilises GIODIN. I can't really write that in header file, so I jumped out to write it in .c file whilst writing the function prototype in header file. What got me astonished is that I got two major errors. First one is that Code Composer Studio does not understand the uint32_t nor uint32 type. The second issue was that GIODIN register cannot be found. This got me wondering and so I decided to do the stupidest thing I could think of >> let's remove gio.c and write to GIODIN register in .h file, and so I got even more confusing result. Compilation passed with few warnings only. That is when I realised that compiler cannot find the memory address of the register which should have resulted in error, but it didn't. Weird, no?
Then I've decided to go to Google and try to find the library with defined memory locations of each and every register. There was none since everyone uses HALCoGen... It seems I'm the only weirdo out there and that's why were here. Then I've decided to pick the lengthy technical manual once again, since I have no other option then write my own register file for the first time ever, and I have no clue how to do this, so I need your help. What I firstly found was:
Table 2-3. Module Registers / Memories Memory-Map (continued)
GIO PS[16] 0xFFF7_BC00 0xFFF7_BCFF 256B 256B Reads return zeros, writes have no effect
Let's also say that I have no clue what PS[16] should stand for or the explanation that it is memory select.
From this I realised that GIO port is addressed from 0xFFF7BC00 to 0xFFF7BCFF which is good but I can't do a lot with that information unless I know memory addresses of each register mapped in that location.
Next thing I noticed is, if I want to use GIODIR for PORTB offset 54h is given on table 25-1. of GIO Control Register. What is 'h' in this case of an offset? Does this affect anything?
What I want to know is if the address of that register is 0xFFF7_BC54 and how do I specify that it should only be up untill 0xFFF7_BC58 which is the address where GIODIN register starts? I presume using uint32, since it is the length inbetween two registers, would help with the #define statement but Code Composer Studio still has no clue what uint32 is and that is annoying for a microcontroller based IDE not to know.
So far I haven't had the need to write this down myself, so I am not sure how to do this since I am still getting errors.
Let's say that I have gio_register.h file where I will write down:
#define GIOGCR0 ((uint32_t *) 0xFFF7BC00)
#define GIOINTDET ((volatile uint32_t *) 0xFFF7BC08)
#define GIOPOL ((unti32_t *) 0xFFF7BC0C)
.
.
.
#define GIODIRB ((uint32_t *) 0xFFF7BC54)
#define GIODINB ((volatile uint32_t *) 0xFFF7BC58)
.
.
.
#define GIOPSLB ((uint32_t *) 0xFFF7BC70)
Will this work? Do I need to specify that each register is volatile? I am not exactly sure of that. It looks to me like only registers that change in time like GIODIR need that, but like GIOGCR0 do not, since they are only initialised at the start. What do you think about this? I am not a fan of turning off optimisation if it does not need to be turned off although it won't have any noticeable results in this case since TI has amazing processor. When I was introduced to 'volatile' keyword for first time I was told: 'ADD IT EVERYWHERE JUST IN CASE'... I can't settle with that statement.
Apparently, even if this would work, I am still left with a problem that Code Composer Studio has no clue what uint32 is unlike some other IDEs for microcontrollers. I understand that uint32 is a typedef but why is it not being recognised by Code Composer Studio by default? What's to be done?
Also, I have to ask something else in reference with questions so far.
What I've seen in HALCoGen generated code is: #define gioREG ((gioBASE_t *)0xFFF7BC00U)
Which is later referenced as, for example: gioREG->GCR0 = 1U;
Since GCR0 is a first member of typedef structure it reserves first 32 bits in that structure so it's address is 0xFFFF7BC00 without any doubt. But what is this U appended to address (0xfff7bc00U) and number that is assigned to the GCR0 member of gioREG (1U)? Does it have soemthing to do with that 'h' in offset (56h for example)? Does it mean UNSIGNED? Or what is it?
So, when assigning value to gioREG->GCR0 in case of HALCoGen generated code, are all four the same?
- gioREG->GCR0 = 0b0000'0000'0000'0000'0000'0000'0000'0001;
- gioREG->GCR0 = 0x01;
- gioREG->GCR0 = 1U;
- gioREG->GCR0 = 1.
If not what could be the differences?
And can the U from address be omitted? Are these two the same?
- 0xFFF7BC00U
- 0xFFF7BC00
On contrary to this solution from HALCoGen which seems elegant, I do not want to assign new volatile typedefs or even bit fields. I just want each register to be defined with its exact memory location and directly used, so this: #define GIODIN ((volatile uint32_t *) 0xSOME_ADDRESS) and then latter called like GIODIN = 0x01;
One more thing and I will conclude this, what is rather an essay. Since I know that Eclipse IDE does not support word CLASS, for example, unlike Microsoft Visual Studio for C programming, I am wondering does it support ' or _ for binary / octal / hexadecimal definitions, for example:
GIOGCR0 = 0b0000'0000'0000'0000'0000'0000'0000'0000;
or
#define REG_NAME ((uint8_t *) 0x1234_5678)
Will this pass without any error with Code Composer Studio?
Thank you in advance for reading all this and hopefully helping me with my problems!