+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Full Member level 4
    Points: 2,290, Level: 11
    Achievements:
    Created Blog entry 7 years registered
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    199
    Helped
    3 / 3
    Points
    2,290
    Level
    11

    MPLINK '.udata' can not fit the section

    Hello guys.
    I learned PIC assembly about 10 years back, when I started with microcontrollers. Back then, I never heard of relocatable programming with assembler. From then, I never used assembler again, because I was programing in C. But now I decided to do a project in assembler, because I like challenge. I want to learn relocatable way of programming with assembler, so I can build a libraries over time and use them across the projects. I got some simple LED blinking program, written in absolute mode, now I am strugling to change it to relocatable. I split the code in two .asm files and I can assembly them separately, but if I want to build a project, the linker gives me the error. I am using MPLABX and here is the whole output:

    CLEAN SUCCESSFUL (total time: 102ms)
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory 'D:/Documents/MPLABX/relocatable_code_example.X'
    make -f nbproject/Makefile-default.mk dist/default/production/relocatable_code_example.X.production.hex
    make[2]: Entering directory 'D:/Documents/MPLABX/relocatable_code_example.X'
    "C:\Program Files (x86)\Microchip\MPLABX\v4.01\mpasmx\mpasmx.exe" -q -p12f675 -l"build/default/production/blinking_led.lst" -e"build/default/production/blinking_led.err" -o"build/default/production/blinking_led.o" "blinking_led.asm"
    Message[302] D:\DOCUMENTS\MPLABX\RELOCATABLE_CODE_EXAMPLE.X\BLI NKING_LED.ASM 52 : Register in operand not in bank 0. Ensure that bank bits are correct.
    Message[302] D:\DOCUMENTS\MPLABX\RELOCATABLE_CODE_EXAMPLE.X\BLI NKING_LED.ASM 55 : Register in operand not in bank 0. Ensure that bank bits are correct.
    Message[312] D:\DOCUMENTS\MPLABX\RELOCATABLE_CODE_EXAMPLE.X\BLI NKING_LED.ASM 73 : Page or Bank selection not needed for this device. No code generated.
    "C:\Program Files (x86)\Microchip\MPLABX\v4.01\mpasmx\mpasmx.exe" -q -p12f675 -l"build/default/production/delay.lst" -e"build/default/production/delay.err" -o"build/default/production/delay.o" "delay.asm"
    "C:\Program Files (x86)\Microchip\MPLABX\v4.01\mpasmx\mplink.exe" -p12f675 -w -m"dist/default/production/relocatable_code_example.X.production.map" -z__MPLAB_BUILD=1 -odist/default/production/relocatable_code_example.X.production.cof build/default/production/blinking_led.o build/default/production/delay.o
    MPLINK 5.08, LINKER
    Device Database Version 1.38
    Copyright (c) 1998-2011 Microchip Technology Inc.
    Error - section '.udata' can not fit the section. Section '.udata' length=0x00000003
    Errors : 1

    nbproject/Makefile-default.mk:140: recipe for target 'dist/default/production/relocatable_code_example.X.production.hex' failed
    make[2]: Leaving directory 'D:/Documents/MPLABX/relocatable_code_example.X'
    nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
    make[1]: Leaving directory 'D:/Documents/MPLABX/relocatable_code_example.X'
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
    make[2]: *** [dist/default/production/relocatable_code_example.X.production.hex] Error 1
    make[1]: *** [.build-conf] Error 2
    make: *** [.build-impl] Error 2

    BUILD FAILED (exit value 2, total time: 1s)
    What am I doing wrong and how can I build a relocatable assembler program in MPLABX? In addition, how can I make a assebly library later, when I have a lot of object files?

    Here is the code:

    MAIN PROGRAM
    Code:
    ; ***********************************************************
    ;
    ; file: blinking_led.asm
    ; target: PIC12f675
    ; author: David Henry
    ; licence: This program is licensed under the terms of the
    ;          MIT licence.  You can get a copy of it at:
    ;     http://www.opensource.org/licenses/mit-license.php
    ;
    ; This program makes blinking alternatively two LEDs (D0
    ; and D1).
    ;
    ; ***********************************************************
    
        ; use PIC 12F675
        list		p=12f675
        #include	<p12f675.inc>
    
        ; set configuration word.
        __CONFIG	_CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
    
    
        extern   count1,count2,wait     
        
        UDATA    
    temp    res	1
    
    reset   CODE    0x0
    	goto    main    
        
        CODE
    main	
        ; -------------------------------------------------------
        ; program's main entry point.
        ; -------------------------------------------------------
    
        ; init wait counters
        movlw	0xff
        banksel	count1    
        movwf	count1
        banksel	count2
        movwf	count2
    
        banksel	GPIO
        clrf	GPIO
        banksel	CMCON
        movlw	0x7
        movwf	CMCON
    
        ; init GPIO
        banksel	ANSEL	; enter bank 1
        clrf	ANSEL
        banksel	TRISIO
        movlw	B'11001110'    
        movwf	TRISIO		; configure I/O
    
        banksel	temp	; enter bank 0
        movlw	B'00010000'	; setup GPIO's output mask
        movwf	temp		; save it to temp
    
    loop
        ; -------------------------------------------------------
        ; program's main loop.
        ; -------------------------------------------------------
    
        movf	temp,w		; load GPIO's output mask
    
        movwf	GPIO
        xorlw	B'00110000'	; light on alternatively LEDs #0 and #1
    
        movwf	temp		; save the modified mask
    
        pagesel	wait
        call	wait		; burn some cycles before switching LEDs
        goto	loop		; repeat forever
    
        end
    DELAY PROGRAM
    Code:
        list		p=12f675
        #include <p12f675.inc>
        
        UDATA
    count1	res 1
    count2	res 1
        GLOBAL count1,count2
        
        CODE
    wait
        GLOBAL wait
        ; -------------------------------------------------------
        ; wait function.  perform a little tempo.
        ; -------------------------------------------------------
    
        nop			; consume one cycle
    
        banksel	count1
        decfsz	count1,f	; decrement first counter
        goto	wait		;  until reaching zero
    
        movlw	0xff		; reload first counter
        banksel	count1
        movwf	count1
    
        banksel	count2
        decfsz	count2,f	; decrement second counter
        goto	wait		;  until reaching zero
    
        movlw	0xff		; reload second counter
        banksel	count2
        movwf	count2
    
        retlw   0
        
        end
    Thank you for your help.
    Regards!

    •   Alt11th October 2017, 16:12

      advertising

        
       

  2. #2
    Advanced Member level 3
    Points: 5,729, Level: 17

    Join Date
    Jan 2015
    Posts
    827
    Helped
    268 / 268
    Points
    5,729
    Level
    17

    Re: MPLINK '.udata' can not fit the section

    Not knowing which are lines 52, 55 and 73, I'd guess that you are missing some BANKSEL lines (or adding one that is not needed for line 73).
    Susan



    •   Alt12th October 2017, 03:08

      advertising

        
       

  3. #3
    Full Member level 4
    Points: 2,290, Level: 11
    Achievements:
    Created Blog entry 7 years registered
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    199
    Helped
    3 / 3
    Points
    2,290
    Level
    11

    Re: MPLINK '.udata' can not fit the section

    These are just warnings, they are not relevant. The linker error is the problem:
    MPLINK 5.08, LINKER
    Device Database Version 1.38
    Copyright (c) 1998-2011 Microchip Technology Inc.
    Error - section '.udata' can not fit the section. Section '.udata' length=0x00000003
    Errors : 1
    Regards!



    •   Alt12th October 2017, 14:11

      advertising

        
       

  4. #4
    Super Moderator
    Points: 68,447, Level: 63
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    11,188
    Helped
    3697 / 3697
    Points
    68,447
    Level
    63

    Re: MPLINK '.udata' can not fit the section

    The udata section should fit without any problems. I suspect your problem lies in these lines:
    Code:
    reset   CODE    0x0
    	goto    main    
        
        CODE
    where you effectively place an 'org 0x0' statement between two CODE directives which ties it to a fixed address and prevents the linker from locating the modules optimally.
    Try removing the address and possibly rearranging the lines so it starts with 'CODE' before the reset label.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  5. #5
    Full Member level 4
    Points: 2,290, Level: 11
    Achievements:
    Created Blog entry 7 years registered
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    199
    Helped
    3 / 3
    Points
    2,290
    Level
    11

    Re: MPLINK '.udata' can not fit the section

    Nope. I tryed it like that:
    Code:
    UDATA    
    temp    res	1    
        
        CODE
    main
    but same error. It deffinetly has something to do with linker and udata section.

    - - - Updated - - -

    Ok, I found a solution. I removed "PROTECTED" label for DATABANK and SHAREBANK and CODEPAGE page in linker script and I had to add .cinit section. Now it compiles, but I don't know, if linker is using general purpose registers for variables and not special function registers. Can someone tell that by .map file?

    MAP file
    MPLINK 5.08, LINKER
    Linker Map File - Created Thu Oct 12 17:49:51 2017

    Section Info
    Section Type Address Location Size(Bytes)
    --------- --------- --------- --------- ---------
    .cinit romdata 0x000000 program 0x000004
    .code code 0x000005 program 0x00004c
    .config_2007_BUILD/DEFAULT/PRODUCTION/BLINKIN code 0x002007 program 0x000002
    .udata udata 0x000000 data 0x000003



    Program Memory Usage
    Start End
    --------- ---------
    0x000000 0x000001
    0x000005 0x00002a
    0x002007 0x002007
    41 out of 1158 program addresses used, program memory utilization is 3%



    Symbols - Sorted by Name
    Name Address Location Storage File
    --------- --------- --------- --------- ---------
    loop 0x000017 program static D:\Documents\MPLABX\relocatable_code_example.X\bli nking_led.asm
    main 0x000005 program static D:\Documents\MPLABX\relocatable_code_example.X\bli nking_led.asm
    wait 0x00001d program extern D:\Documents\MPLABX\relocatable_code_example.X\del ay.asm
    count1 0x000001 data extern D:\Documents\MPLABX\relocatable_code_example.X\del ay.asm
    count2 0x000002 data extern D:\Documents\MPLABX\relocatable_code_example.X\del ay.asm
    temp 0x000000 data static D:\Documents\MPLABX\relocatable_code_example.X\bli nking_led.asm



    Symbols - Sorted by Address
    Name Address Location Storage File
    --------- --------- --------- --------- ---------
    main 0x000005 program static D:\Documents\MPLABX\relocatable_code_example.X\bli nking_led.asm
    loop 0x000017 program static D:\Documents\MPLABX\relocatable_code_example.X\bli nking_led.asm
    wait 0x00001d program extern D:\Documents\MPLABX\relocatable_code_example.X\del ay.asm
    temp 0x000000 data static D:\Documents\MPLABX\relocatable_code_example.X\bli nking_led.asm
    count1 0x000001 data extern D:\Documents\MPLABX\relocatable_code_example.X\del ay.asm
    count2 0x000002 data extern D:\Documents\MPLABX\relocatable_code_example.X\del ay.asm

    Linker script
    // File: 12f675_g.lkr
    // Generic linker script for the PIC12F675 processor

    LIBPATH .

    CODEPAGE NAME=.cinit START=0x0 END=0x4
    CODEPAGE NAME=page START=0x5 END=0x3FE
    CODEPAGE NAME=.oscval START=0x3FF END=0x3FF PROTECTED
    CODEPAGE NAME=.idlocs START=0x2000 END=0x2003 PROTECTED
    CODEPAGE NAME=.devid START=0x2006 END=0x2006 PROTECTED
    CODEPAGE NAME=.config START=0x2007 END=0x2007 PROTECTED
    CODEPAGE NAME=eedata START=0x2100 END=0x217F PROTECTED

    DATABANK NAME=sfr0 START=0x0 END=0x1F
    DATABANK NAME=sfr1 START=0x80 END=0x9F


    SHAREBANK NAME=gpr0 START=0x20 END=0x5F
    SHAREBANK NAME=gpr1 START=0xA0 END=0xDF

    SECTION NAME=PROG ROM=page // ROM code space
    SECTION NAME=OSCVAL ROM=.oscval // Oscillator value
    SECTION NAME=IDLOCS ROM=.idlocs // ID locations
    SECTION NAME=DEEPROM ROM=eedata // Data EEPROM

    SECTION NAME=RAM0 RAM=gpr0
    SECTION NAME=RAM1 RAM=gpr1

    Regards!



    •   Alt12th October 2017, 16:54

      advertising

        
       

  6. #6
    Full Member level 4
    Points: 2,290, Level: 11
    Achievements:
    Created Blog entry 7 years registered
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    199
    Helped
    3 / 3
    Points
    2,290
    Level
    11

    Re: MPLINK '.udata' can not fit the section

    And of course, some strange things were happening, because DATABANK actually means start of RAM and wherever in my program I was manipulating with location 0x2 (PCL), the program ran away (it makes sense). So I changed start location of DATABANK section and removed SHAREBANK. Now it works.
    Regards!



--[[ ]]--