Protected code memory (PIC16F946)

Topics covered here include Microchip PICmicro assemblers, linkers and librarian programs.

Protected code memory (PIC16F946)

Postby melbourne » Sun Oct 24, 2021 11:46 pm

I just ran into a problem rebuilding an old PIC16F946 project. The default linker script (16F946_6.lkr) is a bit unusual:
Code: Select all
CODEPAGE   NAME=page0      START=0x0               END=0x7FF           
CODEPAGE   NAME=page1      START=0x800             END=0xFFF           
CODEPAGE   NAME=page2      START=0x1000            END=0x17FF         

#IFDEF _DEBUG
  CODEPAGE   NAME=page3      START=0x1800            END=0x1DFF         
  CODEPAGE   NAME=debug      START=0x1E00            END=0x1FFF         PROTECTED
#ELSE //no debug
  CODEPAGE   NAME=page3      START=0x1800            END=0x1FFF         
#FI

But the question is, what does that mean? What is it supposed to mean? The affect I am seeing is that I can't have a code segment spanning 01E00. I can have a code segment ending at 1DFF, and another segment starting at 1E00. ( I have a code segment spanning 0x1000)

Language tool versions: MPASMWIN.exe v5.51, mplink.exe v4.49, mplib.exe v4.49

I tried to do a build, and the build failed: I found that I was building in 'debug' mode,
Executing: "C:\..\MPASM Suite\MPASMWIN.exe" /q /p16F946 "myprog.asm" /l"myprog.lst" /e"myprog.err" /d__DEBUG=1 /c- /rDEC

which gave me the error
Error - section '.org_20' can not fit the absolute section. Section '.org_20' start=0x00001800, length=0x000006FA

... and while looking for the problem, I found that the error went away if I started a new section at 1E00:
Code: Select all
         movwf   bcorr
         bcf      status,rp1
         bsf      status,rp0
         movf   numl,0
bg         sublw   0
   org bg+1
         movwf   numl
         movf   numh,0
         btfss   status,c
         incf   numh,0
         sublw   69

This seems an odd meaning for 'protected' ?
melbourne
 
Posts: 2
Joined: Sun Oct 24, 2021 10:54 pm
PIC experience: Professional 5+ years with MCHP products

Re: Protected code memory (PIC16F946)

Postby ric » Sat Oct 30, 2021 12:11 pm

When you are running in debug mode, the tools place a small program (the "debug executive") at the top of code memory to implement the debug interface.
That's why the linker script reserves the memory from 1E00 to 1FFF when you are in debug mode.
I don't know what exactly "protected" does, but your workaround will fail if you actually try to use the debugger.
Presumably that last bit of your code will be overwritten by the debug executive.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 628
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to MPASM, MPLINK, MPLIB

Who is online

Users browsing this forum: No registered users and 1 guest

cron