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.

Toggle Software Tutorial

Other Parts Discussed in Thread: MSP430G2231, MSP430G2211

Im trying to run the msp430G2xx1.asm file as a beginner's tutorial. ; MSP430G2xx1 - Software Toggle P1.0 ; ; Description: Toggle P1.0 by xor'ing P1.0 ; ACLK = n/a, MCLK = SMCLK = default DCO ~800kHz ; ; MSP430G2xx1 ; ----------------- ; /|\| XIN|- ; | | | ; --|RST XOUT|- ; | | ; | P1.0|-->LED ; ; D. Dang ; Texas Instruments Inc. ; October 2010 ; Built with Code Composer Essentials Version: 4.2.0 ;****************************************************************************** .cdecls C,LIST, "msp430g2231.h" ;------------------------------------------------------------------------------ .text ; Progam Start ;------------------------------------------------------------------------------ RESET mov.w #0280h,SP ; Initialize stackpointer StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT SetupP1 bis.b #001h,&P1DIR ; P1.0 output ; Mainloop xor.b #001h,&P1OUT ; Toggle P1.0 Wait mov.w #050000,R15 ; Delay to R15 L1 dec.w R15 ; Decrement R15 jnz L1 ; Delay over? jmp Mainloop ; Again ; ;------------------------------------------------------------------------------ ; Interrupt Vectors ;------------------------------------------------------------------------------ .sect ".reset" ; MSP430 RESET Vector .short RESET ; .end -------------------------------------------------------------------------------- I get the following error: "../lnk_msp430g2231.cmd", line 87: error: placement fails for object ".reset", size 0x4 (page 0). Available ranges: RESET size: 0x2 unused: 0x2 max hole: 0x2 ---------------------------------------------------------------------------------- In the linker command file i find a line that says: [...] .reset 0 00000000 00000004 FAILED TO ALLOCATE [...] I looked online and i found that this is caused by a lack of space and too much code or space used up by sections. (not sure about any of this) But i dont know how to resize my sections, or allocate a bigger space. Also tried the steps advised in the following link: http://processors.wiki.ti.com/index.php?title=CCE_FAQs#What_does_the_CCE_linker_error:_.27placement_fails_for_object_.22xxx.22.27_mean_and_how_to_fix_it.3F I wouldn't post this here if I our professor hadn't said anything at all besides: its not going to work the first time, you must find out why and fix it. I've been at this for about 8 hours total this week and the last, but the lack of proper documentation (or motivation) makes me cringe. So can anyone take the edge off and tell me how can i make my first LED blink a couple of times???
  • Ok, I understand that copy/pasting code here doesn't work as intended. In any case, I think I've narrowed down the problem to the following: It doesn't matter which example code I use, I keep getting the same problem. ********************************************************************************************* "../lnk_msp430g2231.cmd", line 87: error: placement fails for object ".reset",----------------------------------------- size 0x4 (page 0). Available ranges:------------------------------------------------------------------------------------- RESET size: 0x2 unused: 0x2 max hole: 0x2-------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------- undefined first referenced ---------------------------------------------------------------------------------------------------- symbol in file ------------------------------------------------------------------------------------------------------------ --------- ---------------- main C:\Program Files (x86)\Texas Instruments\ccsv4\tools\compiler\msp430\lib\rts430.lib------- ********************************************************************************************* The memory map section that seems relevant is the following:------------------------------------------------------------ ********************************************************************************************* name origin length used --------- unused attr ---------------------------------------------------------- RESET 0000fffe 00000002 00000002 00000000 RWIX--------------------------------------------------------- ********************************************************************************************* I think what this error is trying to tell me is that I haven't configured something correctly, since the ".reset" section size is 0x4 and 'it' is trying to allocate it to a 0x2 memory space. I tried tweaking this around. I changed the whole memory map by substracting the appropriate length for each 'section'. It looked something like this: ********************************************************************************************* name origin length used unused attr ---------------------------------------------------- INT13 0000fff8 00000002 00000000 00000002 RWIX---------------------------------------------------- INT14 0000fffa 00000002 00000000 00000002 RWIX---------------------------------------------------- RESET 0000fffc 00000004 00000002 00000000 RWIX---------------------------------------------------- ********************************************************************************************* I don't think I had too much reasoning to do this. For some reason the code still couldn't be linked but it didn't display the previous error entirely. It only displayed the last part: ********************************************************************************************* undefined first referenced ---------------------------------------------------------------------------------------------------- symbol in file ------------------------------------------------------------------------------------------------------------ main C:\Program Files (x86)\Texas Instruments\ccsv4\tools\compiler\msp430\lib\rts430.lib-------- ********************************************************************************************* Can anyone explain this to me to somehow keep tweaking it in a better way? Much obliged. PS: Can somebody explain why newline isnt registering here? thx...
  • Ok I found the preview option so i think this one will have some sort of better formatting...********************************************************** Continuing. *************************************************************************************************************************** I found this: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/p/18861/72799.asp.********************************** and followed it to the letter and this time there seems to be no problem (as i specified i wanted to make an assembly only project)************************** Now the code is succesfully linked. I get to the debugger view but when i get run i receive the following error:****************************************** -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*** MSP430: Program loaded. Code Size - Text: 28 bytes Data: 2 bytes***************************************************************************** MSP430: AutoRun: Target not run as the symbol "main" is not defined**************************************************************************** MSP430: Can't Run Target CPU: Could not run device (to breakpoint)************************************************************************* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*** So this means what?*********************************************************************************************************************
  • The 'real' input editor apparently was offline for some reason ove rthe last hours. So you probably only got the plain input window (which does not allow any formatting unless you manually type HTML code in)

    The original error you got was about the content of the reset vector being 4 bytes while th ereserved space is only 2 bytes.

    This happens if for some reason teh function to which the reset vector points is placed into the flash above 64k. Yet all interrutp vectors (includign the reset vector) are jsut 16 bit and point to the lower 64k address space.

    This means, your reset function, as well as any interrupt function have to begin in the lower 64k. In assembly language, it may consist of just a jump to the 'real'interrupt function anywhere in the whole flash (at the expense of some additional cycles execution time for the jump).

    When using C, the compiler will automatically take care of this, placing all functions declared as interrupt into th elower text segment specifically. But when using assembly, you'll have to take care of this on your own.

    For the debugger error, the debugger is configured to place an auto breakpoint onto the main function, as this is thestarting point of any C program. You don't have such a function  in your project. So you'll need to define a symbol of this name at the starting location of your project.
    Maybe you can configure the debugger to not 'stop at main' (maybe there is such an option in the project config), so the debugger will not as default try to locate main and stop there.

  • Thank You for reading through that as it was me and it all seemed like a jungle.

    Jens-Michael Gross said:

    For the debugger error, the debugger is configured to place an auto breakpoint onto the main function, as this is thestarting point of any C program. You don't have such a function  in your project. So you'll need to define a symbol of this name at the starting location of your project.
    Maybe you can configure the debugger to not 'stop at main' (maybe there is such an option in the project config), so the debugger will not as default try to locate main and stop there.

    Ok so, i think i found a similar 'solution' that went about defining a global symbol "main" ( .global _main) and substituting _main for the RESET symbol.

    But first I think I need to tackle a more basic problem : what is a symbol? 

    My professor has never mentioned this. I believe it can be thought of as some sort of label... but this is just a rough grasp of numerous lines of code that I've read.

    Also, I took a peed in the .map file and noticed the following: 

    address name

    -----------   -------

    00000200   __text__

    00000200   _main

    00000200   edata

    00000200   end

     

    Is this relevant? From what i can gather the 'end' symbol is in the same place as my '_main' symbol.  Since I don't know what exactly each are, I'm not sure, but it seems to me that they shouldn't have the same address at least...

     

    Thanks Again 

  • Jose Taveras said:
    what is a symbol? [...]I believe it can be thought of as some sort of label.

    The other way round. A label is some sort of a symbol.

    A symbol has a name and a constant value, which is not necessarily known at compile time, but gets known at latest during the link stage. So a constant may be a symbol (if compiler/assembler can substitute the name by the value).
    A variable is no symbol, hovever, the address of a variable is a symbol.
    Or a label.

    Symbols are substituted as soon as their value is known. In case of local labels or variables, the compiler/assembler does it. In this case the symbol is not forwarded to the next stage. Like the precompiler will substitute all texts that are identified as macros, so the compiler will only see the substituted text. If a symbol cannot be substituted because its final value is not known yet (or it never has been declared), the symbol is forwarded to the next pürocessing stage in the hope that it can be resolved there.
    e.g. when calling a function without including the proper header file, the compiler will issue a warning about missing prototype, yet the program will still properly compile. The compile forwards the symbol to the linker and if the linker finds the proper function in any of the linked files, all is well. (the compiler, however, cannot ensure that the parameter lists match, hence the necessity of the warning)

    Just declaring .global main generates a symbol that is located in the global address segment. It is not, however, connected to a specific location, just in front of what follows it (and there follows nothing), so the linker puts it to 0x200.

    Defining a label is basically the same: it defines a symbol and connects its value to 'the final location of what follows', which is usually code. So its final value is the final location of the code after it.
    Once the linker has collected and sorted all code/the variables, all labels should have get their final value and the linker can substitute them.

    btw: using a symbol is implicitely declaring it, even if it is not defined anywhere. In this case, it is there but still undefined and you'll get a linker error. THis happens if you misspell a register name or function name, or forget to include the object file where it is actually defined.

    Jose Taveras said:
    Since I don't know what exactly each are, I'm not sure, but it seems to me that they shouldn't have the same address at least...

    Well, __text_ is assigned to the start of the flash 'text' segment where all code is placed. _main is part of this segment and put there (so same value). edata is the position of the initializer area for global variables and the end of the code part in the flash, and since there was no content before it, it still has the same value. And end, well, it is the flash location of the first byte after the last byte of your program. Since your program contains 0 bytes of code/init data, it still has the same value/points to the same address as the others.

    If you put a 'nop' instruction right behind your declaration of main, you'll likely see edata and end change to 202.

     

  • Ok. I intend to revisit this a couple of times as I seem to understand, but only after I can get this running and can actually start playing with it will I be able to verify anything that I've learned.

     

    Right now I keep receiving no error, just a simple

    MSP430: Can't Run Target CPU: Could not run device (to breakpoint)

    And nothing else.

    This is my code as of today:

    .cdecls C,LIST,"msp430g2231.h" ; Include device header file

    ;-------------------------------------------------------------------------------

    .text

    ; Progam Start

    .global _main

    ;-------------------------------------------------------------------------------

    _main mov.w #300h,SP ; Initialize 'x1121 stackpointer

    StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT

    SetupP1 bis.b #001h,&P1DIR ; P1.0 output ;

    Mainloop xor.b #001h,&P1OUT ; Toggle P1.0 Wait mov.w #050000,R15 ;

    Delay to R15 L1 dec.w R15 ; Decrement R15

    jnz L1 ;Delay over?

    jmp Mainloop ; Again

        ;-------------------------------------------------------------------------------

    ; Interrupt Vectors

    ;-------------------------------------------------------------------------------

    .sect ".reset" ; MSP430 RESET Vector

    .end

    I've arranged the code a little differently here and there but I keep getting the same no error-error. The whole console output is:
    MSP430: Program loaded. Code Size - Text: 28 bytes Data: 0 bytes MSP430: Can't Run Target CPU: Could not run device (to breakpoint)
    Would there be anything else that I can try so that I can actually insert my code into the mcu? Or at least produce some kind of error so that I can identify the problem???
    Thank you for your responses, and your patience :D
  • What does the map file say?

    Does teh reset vector contain anything? You started a section '.reset:', but it does not contain any value. You have to place an address (or a symbol) there that points to the very beginning of your code. Which isn't necessaily main (on C programs it is the startup code that initializes the variables before jumping to main), but in your project it would be main.

    I don't know th e assembler syntax for your assembler (I only worked with MSPGCC), but I think it has to be something like

    .sect ".reset"
    . dw _main // define a word value at this location
    .end

    If the reset vector isn't set, the processor does not know where to start, and the breakpoint in main is never hit. Hence the error.

  • that was a mistake on my part... the actual code goes:

    .cdecls C,LIST, "msp430g2211.h" .global _main ;------------------------------------------------------------------------------ .text ; Progam Start ;------------------------------------------------------------------------------ _main mov.w #0280h,SP ; Initialize stackpointer StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT SetupP1 bis.b #001h,&P1DIR ; P1.0 output ; Mainloop xor.b #001h,&P1OUT ; Toggle P1.0 Wait mov.w #050000,R15 ; Delay to R15 L1 dec.w R15 ; Decrement R15 jnz L1 ; Delay over? jmp Mainloop ; Again ;

    ;------------------------------------------------------------------------------

    ; Interrupt Vectors ;------------------------------------------------------------------------------ .sect ".reset" ; MSP430 RESET Vector .short _main ; .end

    I'm going to try and test the mcu in another computer.  Since I've tested various example codes and keep getting the same error, I'm starting to think the actual code isn't the problem, but instead something pertaining to the CCS setup or installation.  I tried reinstalling the software but keep getting the same error.

    The most frustrating thing is that my first attempt at running a program was successful.  I loaded a .c LED toggle program unto the MCU. It worked fine.  But I tried reproducing the same test under the same conditions (fresh reinstall, fresh workspace) to receive the same frustrating error.

    I have a feeling it's going to work at the University's lab but I'd like to be able play with this in the sanctity of my home computer.

    I'll post results when I can later this weekend. Thanks again.

  • Hi, I'm facing the same problem as you encountered in your original post in trying to get this program to compile and thus get the leds to light up upon pressing the push button.  I was wondering if you ever figured out how to make it work. 

     

    Thanks,

     

    tjk

  • Hi,

    I faced the same problem, my solution has erase the .end at the end of the code and compile the code like that. It worked just fine.

    Afonso

  • Afonso Pereira Bernardino said:
    compile the code like that

    Minor correction: you cannot 'compile' an assembly program. It is processed by the assembler, so it is 'assembled' :)
    For compiling, you'll need a compiler, which is for high-level languages (like the C-Compiler)

    I agree that his isn't helpful for the original problem.

    Unfortunately, each assembler uses its own language and format specifics. And I never used IAR or CCS assembler.

    However, it is possible that the system chokes on a missing line break after the .end or something like that.

**Attention** This is a public forum