[SOLVED] MPLINK '.udata' can not fit the section

Status
Not open for further replies.

bmandl

Full Member level 4
Joined
Feb 26, 2010
Messages
207
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Slovenia
Activity points
2,965
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:


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.
 

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
 

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
 

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.
 

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

Linker script
 

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.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…