This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: What is the origin of "SYSCTL" and "->" in a statement like SYSCTL->RCC = (SYSCTL->RCC & 0xF83FFFFF) | 0x800 ;

Part Number: TM4C123GH6PM

I've been Googling for an answer but can't find it.

Where does "SYSCTL" come from. It's not in the data sheet so I'm guessing it's something that's created in a header file or something.

And what's the meaning of "->" in the statement.

I know the RCC register but don't know where the SYSCTL-> comes from.

I bet it's dead simple once someone shows me the light.

Keith.

  • Keith,
    Maybe you can let us know where did you get that from? Which library or example? I don't have plain SYSCTL defined in any of my codes...
    Typically in C, these all caps entries are macros. If you are using CCS, hold CTRL and click on the entry, and CCS will open another tab with the file in which such macro is defined.
    The -> is used in C when you are referring to an element inside a declared structure, but inside a function that is using the variable as a pointer (otherwise you would use the point, not the ->). I can't even make a decent sentence to explain it, and you are likely to find a more detailed explanation of it on C tutorials.
    Regards
    Bruno
  • May I provide an observation - and then make a recommendation - intended to, "Speed, Ease & Enhance" your MCU "learning" (first) - later your mastery.

    Twice now you have seized upon (relatively) minor - and/or obscure - MCU details.    (bit-band arrived earlier)

    Is it not likely - that by questioning "each/every" (new for you) detail - your understanding will be fragmented, delayed, and inefficient?    (that's the belief of my small, reasonably successful, tech firm & others)

    Might an alternative method - which may (more naturally) answer many such "MCU details" - prove better?     Your combined read of the MCU manual, the "User Guide to the Peripheral Drivers" and the (many) vendor supplied, code examples (found @ "peripherals/examples") - all "Open & At the Ready" - WHILE you run the vendor supplied code examples - has proved - by far - the top learning vehicle @ my firm!   (and others)

    It is likely "too early" for you to note the "relative importance" of MCU minutia.     Would it not prove more efficient to (instead) "piggy-back" upon the efforts of this vendor (they ARE the most skilled - and interested in your success) - which are substantially "MCU Peripheral based" - and seek your active participation via "EXAMPLE" code entry - code flow - and code execution?     This vendor's API is extensive, detailed, greatly "tried/true/tested" and the "occurrence" of "new/strange" concepts or descriptions - tend to be noted - and explained.   (i.e. Number of such "new item," (mentions/occurrences) usually will reflect their importance)

    My attempt here is to offer a different (improved) route - yet to your same - successful destination...

  • Hi Keith,
    Can you please tell where you read the statement SYSCTL->RCC = (SYSCTL->RCC & 0xF83FFFFF) | 0x800;
    The SYSCTL will be a macro defined as a pointer to a structure where the RCC is one of the elements.
  • I must "protest" the apparent YANK of my earlier post!

    Amit has long urged against DRM - has gone so far as to note that DRM examples are being eliminated. Post immediately above this one "invites" a new poster into the DRM Swamp!

    Vendor inconsistency does not convey a strong sense of organization - and if not identified & presented here - where better?

    Staff have programmed (other) than a, "wide counter" to capture the "duration" of this post's existence...

  • Hi cb1,
    By no mean my reply to the poster is an endorsement for DRM. I believe I have in the past in other posts discouraging people from using DRM. I was just curious where the poster found such DRM usage and asked for clarity. I can understand there are people who want to learn the nuts and bolts of microcontroller programming. I can guide the poster not to use DRM but his curiosity will just remain unanswered. I'm just trying to help here.
  • Charles,

    Thank you - my earlier post (must) be undergoing, "moderation." (as past, big law-school attendee - I should be versed in "escaping" such requirement.)

    The code poster presents is clearly DRM - thus a very "Slippery Slope" (having little to do (directly) w/the MCU) has been entered - has it not?

    There is a difference between "endorsement and "tacit acceptance" - but that difference is (too often) minor - thus NOT always detected.

    Part of my "flagging this issue" stems from my (long-term) concern for this forum - especially vendor agents - who become tasked w/details too often "outside & beyond" mainstream, MCU usage! This impedes & slows forum response - and "invites" others to "expand" the mainstream...
  • cb1, Charles,
    It seems we are all on the same page here, but looking at it from angles... My first response was exactly "where did you see that?" - only from then on I'd feel like condemning the registers - or not.
    Still, this question seemed to me to be more of a C doubt than MCU related...
    Again: holding CTRL while clicking on variables do wonders for those who never tried it.
    (too tired for serious work this afternoon)
    Bruno
  • Thank you, Bruno - and all 3 of us have invested time/effort.

    Not so sure about, "all on the same page" though.    I see the poster - while clever & motivated - having his learning efficiency "held hostage" to "interesting" - yet not "uber-critical" nor (even) mainstream, MCU issues.    

    As time/effort are finite - time spent (pardon) "off in the weeds" must subtract from that time available for, "serious, focused & progressive" learning.   (does not stem from keywords!)

    Having attended many such college level courses - and having "adjunct instructed a few" - learning via "Keywords" (no matter how enticing) is not famed as an efficient learning mechanism.    Poster of course is free to accept/reject this observation/recommendation - yet the "trend" was well noted - and I cannot believe it serves this poster's (nor others') best interest...    And that - just may - warrant my comment...

  • Keith Scott <mancavedweller23@gmail.com>

    5:39 AM (0 minutes ago)
    to TM4C_forum
    Thanks for the responses.
    I know there is the Tivaware library, yet a few learning resources seem to be using the direct register approach and "SYSCTL->" is something I've came across several times. The example in my opening post came from the book "The Definitive Guide to the ARM Cortex M3" chapter 20. Seems like uvision 3 is the IDE. 
    These youtube tutorials also use this method https://www.youtube.com/channel/UCMOgTxgkrWUZ4HUtc-4JwkA
    There are more places / books where I've came across it but I've got to dash out to work now so can't dig them up at this point.
    Got to admit it is hard for me to NOT take an interest in direct register understanding. I started off with Arduino yet felt like I didn't know what was happening in the micro and was "held back" from understanding what was happening in the AVR. So I changed to programming in "real" C and using a "real" IDE with single step and debugging capabilities. Much harder but much more capable.
    Now I feel like not using (or at least understanding) direct register is going the other direction, but at the same time direct register in the ARM beasty is a lot more complicated than in an AVR lol.
  • Hello all.
    Here may lay a possible answer: www.microdigitaled.com/.../15B_pwm_servo.txt
    John
  • Keith,

    The way I see it: registers are there, and must be comprehended by whoever deals with MCU's. They are a huge collection of switches, turning features on or off - and the features are quite complex and interlocked, raising the need for lots of those "configuration switches".

    BUT there is no need to turn on or off every switch separately in one's code, because vendor provides something that resembles more to English (or to human language, for what is worth), that somehow can execute "ProperlySetAllSwitchedRequiredForTimerAToWork();". That's what driver libraries (TivaWare) is about.

    SYSCTL is indeed a MACRO (a nickname) for another variable in that code... John's example of pwm_servo shows it being used - but not being declared. Someone just had the hard work of slicing one System Control register into lots of little pieces, each piece with a name like RCGCGPIO, RCC and others. But all these things have to be mapped somewhere. If you change the part number, chances are the mapping no longer works for you.

    Tivaware is "closer" to solving that - at least, of course, while you remain using this vendor's family of products - for once you define the PART you are using, the affected registers inside any Tivaware function automagically point to the right place. And they are easier to human eyes to be read. Still, don't dream too much - I wonder if any English teacher will comprehend something like:

    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS); 
    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 1);

    DRM? Try to configure the ADC with registers - your code will become an unreadable havoc, even if it works.

    Cheers


    Bruno

  • Ha ha,

    I think I'm weakening, but at least I found one other person asking a similar question back in 2009 LOL:

    http://www.keil.com/forum/15726/          Apart from that I can find zippo on the matter.

    It is really irritating me, that I cannot find a plain forward explanation for where the heck that SYSCTL is declared, or for that matter all the other macros that precede "->" in the code examples I've seen. But I guess it's time to let it go and give Tivaware more attention.

    Heck, if I still want to punish myself I can always go back to DRM learning after I've got something real happening using Tivaware.

    Thanks for all the input everyone.

    Keith.

  • Hi Keith,
    I'm sure you will come to like the TivaWare once you get a hang of it. TivaWare API is a great way to facilitate your software development. As illustrated by Bruno, with a few API functionsyou can make a working module with its intended configuration which would have taken awful long time otherwise by other means such as DRM. For other TI MCUs, there are also graphical (GUI) tools to configure the intended usage of a module. With a few clicks of buttons the code is generated. Each method has its own strength and weakness. For TM4C, the TivaWare is the way to go.
  • Keith,

    I don't want to get into the debate on direct register writes, but I also don't want to imply that there is anything hidden or secret. The example code from the book you sited was for an older part and used an include file that I do not have. However, I can make a very good guess at what that code was doing.

    SYSCTL was defined as a pointer to a structure with an address equal to the base address of the control registers:

    typedef volatile struct systemBase
    {
        uint32 DID0_R;                 /* 0x0000 */
        ...
    } systemBASE_t;
    
    #define SYSCTL ((systemBASE_t *)0x400FE000)
    

    Then the value "SYSCTL->RCC" would evaluate to the RCC register at address 0x400FE060

    The current TivaWare header files define the register differently:

    #define SYSCTL_RCC_R            (*((volatile uint32_t *)0x400FE060))
    

    The example you saw:

    SYSCTL->RCC = (SYSCTL->RCC & 0xF83FFFFF) | 0x800 ;

    Reads the register RCC at address 0x400FE060, ANDs the value read with 0xF83FFFFF, ORs the result with  0x800 and then writes that result back to the RCC register.

    Perhaps this detailed explanation will make the point even stronger why we encourage using the TivaWare API instead of doing direct register writes. At least I find the following function call much easier to understand even without comments:

        SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    

  • Firm/I have that exact book - and pgs. 315, 316 reveal - almost exactly as Bob notes:    (I'd scan it - yet the background is dark grey - contrast poor)

    SYSCTRL - by itself - is never defined nor referenced.    And - (always) all such "SYSCTRL" operations employ "assignments" (=) never pointers!   (w/in my book)

    #define SYSCTRL_RCC *((volatile unsigned long *)(0x400FE060))
    #define SYSCTRL_RIS *((volatile unsigned long *)(0x400FE050))
    #define SYSCTRL_RCGC1 *((volatile unsigned long *)(0x400FE104))
    #define SYSCTRL_RCGC2 *((volatile unsigned long *)(0x400FE108))

    There then follow 5 operations upon "SYSCTRL_RCC."   Our poster listed one - Bob detailed - the others cause my fingers to stiffen, "fall from the home row."

    Such was the DRM implementation of, "hello.c" - which outputs to the UART as listed w/in Joseph Yiu's, "Definitive Guide to ARM CORTEX-M3."  (2nd edition)

    As vendor's Bob well noted - the API call to SysCtlClockSet() - is SO much more user friendly, understandable and likely to succeed.
    I'm unable to report upon the number of, "leaps from tall buildings, wrist slashings, or single-car fatalities" - resulting from this foray into DRM...   

  • Thanks for the explanation Bob, I've copied and pasted that into a Word file.

    After my last post I went to the Tivaware PDF and had a glance through some of the functions and explanations. Yes I'll definitely be going that route.

    I was also chatting on the AVR forum and found out many other ARM vendors also have high level libraries like Tivaware, so it seems it's a typical approach, no doubt due to the complexity as many of you have told me.

    Appreciate everyone knocking some sense into me LOL.