Storage.mod Question

General discussions about working with the Astrobe IDE and programming ARM Cortex-M3, M4 and M7 microcontrollers.

Storage.mod Question

Postby gray » Mon Mar 11, 2019 9:39 am

I am baffled by the following behaviour (Cortex M3, STM32F207 target). Here's a minimal test case, condensed and abstracted from my actual code.

Code: Select all
MODULE testalloc;
  IMPORT Main, Out;

  TYPE
    P = POINTER TO Pdesc;
    Pdesc = RECORD i: INTEGER END;

  VAR
    p: P;

BEGIN
  NEW(p);
  p.i := 13;
  Out.Int(p.i, 0); Out.Ln
END testalloc.

As you'd expect, I get "13" in the terminal. So far, so good. Now I import also 'Storage':

Code: Select all
MODULE testalloc;
  IMPORT Main, Out, Storage;
  (* ... same as above *)

Now I get no output at all, and no rt-error either. Either I miss something, or things go haywire somehow. I don't know how 'p' is represented internally, but if I assume it's an address, I can check if it's within the heap boundaries:

Code: Select all
(* ... as above *)
BEGIN
  NEW(p);
  Out.Hex(SYSTEM.VAL(INTEGER, p), 0); Out.Ln;
  p.i := 13;
  Out.Int(p.i, 0); Out.Ln
END testalloc.

Without 'Storage' imported, I get '20000220H', with 'Storage' I get '20000204H', which both look OK with a heap starting at '20000200H' (assuming 'p' actually represents an address, ofc).
gray
 
Posts: 40
Joined: Tue Feb 12, 2019 2:59 am

Re: Storage.mod Question

Postby cfbsoftware » Mon Mar 11, 2019 11:43 am

I have not been able to reproduce the problem here.

1. Have you modified Storage.Mod?

2. Try running the attached program and compare its output with:

Capture.JPG
Capture.JPG (18.03 KiB) Viewed 321 times


If they do not match check your Configuration file against the default supplied with Astrobe.
Attachments
TestAlloc.zip
(440 Bytes) Downloaded 18 times
cfbsoftware
Site Admin
 
Posts: 387
Joined: Fri Dec 31, 2010 12:30 pm

Re: Storage.mod Question

Postby gray » Mon Mar 11, 2019 1:12 pm

1. No, I have not modified Storage.mod.

2. The config is the stock one, aside from the library search paths.

3. When I run your program with the stock Main.mod, I get the same memory values as you.

4. However, I use a slightly modified Main.mod, as well as a modified Serial.mod (Serial2.mod, allowing the parallel use of both serial ports. Note that the changes to both modules are experimental as of now (or hacks, less euphemistically), and not yet clean implementations, but done with as few as possible changes). With this setup, I get different memory values with your program.

output.png
output.png (4.03 KiB) Viewed 317 times

Observation: Serial2.mod uses NEW(), but 'HeapUsed' reported by Storage is 0H nonetheless.
gray
 
Posts: 40
Joined: Tue Feb 12, 2019 2:59 am

Re: Storage.mod Question

Postby cfbsoftware » Mon Mar 11, 2019 9:11 pm

gray wrote:Observation: Serial2.mod uses NEW(), but 'HeapUsed' reported by Storage is 0H nonetheless.

Thanks for pointing that out. Storage initialises the heap. You need to make sure that it is loaded *before* any calls to NEW. One way to do this is to add it to the IMPORT list in the first module that calls NEW.

P.S. I had to remove your modules.zip attachment as it contained a significant amount of source code which can only be shared with other Astrobe Personal and Professional users. It is OK to republish snippets, or changes that are substantially yours - in this case the following would have been sufficient:
Code: Select all
TYPE
  Serial* = POINTER TO SerialDesc;
  SerialDesc = RECORD
    SR : INTEGER;
    DR : INTEGER;
    CR1: INTEGER;
    CR2: INTEGER;
    CR3: INTEGER;
    BRR: INTEGER
  END;

PROCEDURE SetUsartNo(usartNo: INTEGER): Serial;
  VAR
    s: Serial;
    USARTBase: INTEGER;
BEGIN
  NEW(s);
...

PROCEDURE Open*(usartNo, baudRate: INTEGER): Serial;
  VAR
    s: Serial;
BEGIN
  s := SetUsartNo(usartNo);
...
cfbsoftware
Site Admin
 
Posts: 387
Joined: Fri Dec 31, 2010 12:30 pm

Re: Storage.mod Question

Postby gray » Tue Mar 12, 2019 12:45 am

Thanks.

cfbsoftware wrote:P.S. I had to remove your modules.zip attachment as it contained a significant amount of source code which can only be shared with other Astrobe Personal and Professional users.

Oops. Sorry about that.
gray
 
Posts: 40
Joined: Tue Feb 12, 2019 2:59 am


Return to Astrobe for ARM Cortex-M3, M4 and M7

cron