Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:17 15 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite PlugIn Feature

     Page 2 of 4    
Author Message
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 06:27am 13 Sep 2014
Copy link to clipboard 
Print this post

Hi

I've tried 3 times to flash a PIC32MX170F256B with 4.6\MX170 28-pin.hex and NO MMBasic prompt.

I'm using PIC32PROG.EXE which I have consistently used successfully to flash MMBasic into 170F's.

Just to be sure that PIC32PROG was working OK, I then re-flashed it with 4.5D MX 170 28-pin.hex, and that worked fine.

The main difference that I can see is that with 4.6, DevCFG0 b0=1 means debugger is ENABLED, whereas with 4.5D/C B0=1 means debugger is DISABLED

Now I don't have an ICD.

So, Geoff could you cut us a new .hex please ?

Many thanks

Peter
The only Konstant is Change
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4004
Posted: 06:30am 13 Sep 2014
Copy link to clipboard 
Print this post

Aha - might be that!

I'll patch that bit and try again

V. short of time , may be tomorrow.

John
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 06:32am 13 Sep 2014
Copy link to clipboard 
Print this post

@JohnS

You could try PIC32PROG.EXE, it supports PICKit3 as well - download from http://www.g8jcf.dyndns.org/mmbasic/index.html

I don't think it's your s/w, I tried both my MMProg32RPC and PIC32PROG s/w and neither work for 4.6.

Mick, what was your flashing configuration please ?

73

Peter
The only Konstant is Change
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 06:34am 13 Sep 2014
Copy link to clipboard 
Print this post

I thought of that but then I also have to change the checksum in the .hex file.

Ah well

Peter
The only Konstant is Change
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4004
Posted: 06:41am 13 Sep 2014
Copy link to clipboard 
Print this post

OK, that fixes it.

You can edit the HEX, line before the last line. Swap the FA to FB and checksum 57 to 56.

Gutted that I now don't have time actually to try the new feature with gcc! Have to be tomorrow.

JohnEdited by JohnS 2014-09-14
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3272
Posted: 06:53am 13 Sep 2014
Copy link to clipboard 
Print this post

  G8JCF said  I've tried 3 times to flash a PIC32MX170F256B with 4.6\MX170 28-pin.hex and NO MMBasic prompt.

I'm using PIC32PROG.EXE which I have consistently used successfully to flash MMBasic into 170F's.

Just to be sure that PIC32PROG was working OK, I then re-flashed it with 4.5D MX 170 28-pin.hex, and that worked fine.

The main difference that I can see is that with 4.6, DevCFG0 b0=1 means debugger is ENABLED, whereas with 4.5D/C B0=1 means debugger is DISABLED

Now I don't have an ICD.

So, Geoff could you cut us a new .hex please ?

That is interesting.

Firstly I have the debugger disabled in the configuration code. So what could be turning it on ? (rhetorical)

Secondly I have long been chasing an issue where MPLAB X IPE complains that there is debugging info in the hex file when I load the file. I felt that this was "untidy" so I normally use IPE to remove whatever it is complaining about. But I did not in this case because it was "just a beta".

That could be what is causing your problem. Could you please try the attached file? I have used IPE to "clean" it.
2014-09-13_164906_MX170_28-pin.zip

Geoff
Geoff Graham - http://geoffg.net
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3272
Posted: 06:55am 13 Sep 2014
Copy link to clipboard 
Print this post

  WhiteWizzard said  How are the Plugin Data numbers generated? i.e. once you have written your C code in MPLabX, what do you then do?

At this time you need to laboriously copy and paste them from the disassembly listing into your program.

I have created a macro in my text editor to help automate the process. I copy the whole disassembly listing into my BASIC program and then use the macro to delete all except the hex codes for each line. It also inserts "PlugIn Data" for me.

Peter mentioned that he might modify his program for ByPic Basic to work with the Micromite format. That will automate the whole process.

  WhiteWizzard said  Can only one Plugin be incorporated into MMBasic?

Yes, so if you need to have multiple functions performed by the plugin you should use one of the arguments to specify the required function and then use if statements to select what needs to be done.

Geoff
Geoff Graham - http://geoffg.net
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 06:58am 13 Sep 2014
Copy link to clipboard 
Print this post

Here's the fixed .hex2014-09-13_165737_MX170_28-pin_fixed.zip

Line/record 13633 change FAFFFFF7 to FBFFFFF7 and last 2 characters to 56

73

Peter
The only Konstant is Change
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3272
Posted: 07:12am 13 Sep 2014
Copy link to clipboard 
Print this post

Peter, could you still try the file that I posted above. I'm interested in the result.

Thanks
Geoff Graham - http://geoffg.net
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 07:25am 13 Sep 2014
Copy link to clipboard 
Print this post

Hi Geoff, that works

Now to try the plugin out.

@WW

I'm creating a MMBasic Plugin Maker based on the code I developed for the ByPIC Plugin Maker - see http://www.g8jcf.dyndns.org/bypic/

Should be ready tomorrow evening if all goes well

Thanks Geoff

Peter
The only Konstant is Change
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3272
Posted: 07:41am 13 Sep 2014
Copy link to clipboard 
Print this post

Thanks Peter.

For everyone else - I have uploaded the "cleaned" V4.6 B1 files for both the 28 and 44 pin chips to my website replacing the originals. So, if you are having trouble re download the zip.

Geoff
Geoff Graham - http://geoffg.net
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 07:45am 13 Sep 2014
Copy link to clipboard 
Print this post

@Geoff, thanks for the answer to my questions.
@Peter, An 'MMBasic PlugIn Maker' will be very useful. Will keep my eye out for it.

JohnS/Peter - are you guys successfully using PlugIn C code within MMBasic code other than Geoff's example?

WW
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 11:03am 13 Sep 2014
Copy link to clipboard 
Print this post

Wow this is fantastic... I have been bit-banging my head for several weeks ....

I suggest a PlugIn Library, then @TassyJim may be able to have a /plugin section in mmedit

When authoring a program in his brilliant IDE

Insert PlugIn xyz (choose from an extensible list)


Brilliant



 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 12:12pm 13 Sep 2014
Copy link to clipboard 
Print this post

OK

Here is the MMBasic Plugin Maker. Unzip and run the setup file which should install a G8JCF | MMBasicPluginMaker Start Menu entry.

SetupMMBasicPluginMaker may be downloaded from http://www.g8jcf.dyndns.org/mmbasic (it's too big to attach directly to this post.

Use your MPLab/X or whatever compiler you have to generate a .ELF file. Then in MMBasicPluginMaker select the .ELF so generated. Select ALL the functions, then click Generate Plugin(s). A file with the name main_plugin.bas will be created in the same directory as the .ELF. Open main_plugin.bas, copy and paste its contents into your MMBasic program, download to your uMite and run.

Using Geoff's example, this is what the contents of main_plugin.bas will look like


' main_plugin.bas
' 09-13-2014 22:56:59 MMBasicPluginMaker Ver 1.0.0 by user=Peter
PlugIn Data 27bdfff8 afbe0004 03a0f021 afc40008 8fc20008 24420004 8fc30008 24630004
PlugIn Data 90630000 24630001 306300ff a0430000 8fc20008 24420005 8fc30008 24630005
PlugIn Data 90630000 24630001 306300ff a0430000 03c0e821 8fbe0004 27bd0008 03e00008
PlugIn Data 00000000


This is very much a first release quick off the blocks effort to help get you started with MMBasic plugins, I will tidy up the i/f over the next day or so, and include a more comprehensive tutorial - probably BCD arithmetic :)

I'd be very interested to hear feedback.

Have fun

Peter



The only Konstant is Change
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 12:13pm 13 Sep 2014
Copy link to clipboard 
Print this post

@WW, I'll post an arithmetic plugin in the next hour or so

Peter
The only Konstant is Change
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 12:13pm 13 Sep 2014
Copy link to clipboard 
Print this post

Great work Peter
 
halldave

Senior Member

Joined: 04/05/2014
Location: Australia
Posts: 121
Posted: 12:20pm 13 Sep 2014
Copy link to clipboard 
Print this post

Im interested in some date / time functions as plugins, anyone up for the challenge

Pass a couple of parameters to the one function to return all the following


DATEDIF
DATEVALUE
TIMEVALUE
DAY
DAYS360
NETWORKDAYS.INTL function
NETWORKDAYS
WEEKDAY
WEEKNUM
WORKDAY.INTL function
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 01:03pm 13 Sep 2014
Copy link to clipboard 
Print this post

Peter & Geoff

I have to say that this is outstanding work that you have both created.
Although I am yet to try it I can clearly see that the PlugIn feature along with the PlugIn Maker are going to be a huge hit with a lot of people.

I like the idea of many PlugIn libraries appearing on Dave's MMReference site too.

BRILLIANT work guys

PS: I'm still struggling with 'C' - lost a few more hours this evening getting nowhere! BUT with the new feature on offer I can see a few non-C people taking the plunge!!

WW
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 01:32pm 13 Sep 2014
Copy link to clipboard 
Print this post

Hi

This plugin stuff does work !! Here is an example of a plugin which takes in two unsigned 32 bit integers, adds them and returns the result in another MMBasic variable. The source code for the plugin is tacked on the end of the MMBasic program. So copy and paste that stuff into MPLab/X and compile, then use the MMBasic Plugin Maker to produce the PlugIn Data statements which you can then either cut/paste into your code, or use #include main_plugin.bas (using MCPP) to automatically include the file contents at download time.

@Geoff, I do feel that the 256 words limit is a bit limiting, and also, I don't understand why the plugin code has to loaded at 0x9d002000. The code produced by the compiler is Position Independent, ie -fPIC, and the MMBasicPluginMaker converts all JAL instructions to BAL instructions so that the entire plugin is position independent. It would be really nice if one could say in MMBasic


Dim P(2048) 'Make room for a 2048 32 bit word Plugin
Plugin Data,P words ........
and for MMBasic to load the plugin starting at the address of P(0)

Then to call the plugin one would issue

Plugin P,Arg1,Arg2,Arg3 etc

This way one could have

1) Plugins as big as one needed

2) Multiple plugins within the same program





Here is the example Arithmetic Plugin Code.


' main_plugin.bas
' 09-14-2014 00:55:34 MMBasicPluginMaker Ver 1.0.0 by user=Peter
PlugIn DATA 27bdfff8 afbe0004 03a0f021 afc40008 afc5000c afc60010 8fc20008 8c430000
PlugIn DATA 8fc2000c 8c420000 00621821 8fc20010 ac430000 03c0e821 8fbe0004 27bd0008
PlugIn DATA 03e00008 00000000


'Example MMBasic Program using a Plugin - See end of file for C source code

DIM A, B, C

'Put the value &H 89 ab cd ef into A
LoadInt32("89abcdef",A)

'Put the value &H 12 34 56 78 into B
LoadInt32("12345678",B)

'Make sure C is all 0
ClrInt32 C

'Calculate C = A + B
'&H 9BE0 2467
'2,615,157,863

Plugin A,B,C

PRINT "A=";
PrintInt32 A

PRINT "B=";
PrintInt32 B

PRINT "C=";
PrintInt32 C

END


'Load an INT32 value into a MMBasic numeric variable
'Value is a string in Hex, eg FEDCBA9876432101
'Dest is an MMBasic numeric var
'
SUB LoadInt32(Value$, Dest)
LOCAL A$,B$,B
A$=STRING$(8-LEN(Value$),"0") + Value$
B=0
FOR I=7 TO 1 STEP -2
PRINT "&H" + (MID$(A$,I,2))
POKE VAR Dest,B,VAL("&H" + (MID$(A$,I,2)))
B=B+1
NEXT I

END SUB

'
'Clear a 32 bit unsigned integer
'
SUB ClrInt32(Variable)
LOCAL I
FOR I=0 TO 3
POKE VAR Variable,I,0
NEXT I
END SUB

'
'Print an Int32 variable in Hex
'
SUB PrintInt32(Variable)
PRINT "&H";
FOR I=3 TO 0 STEP -1
PRINT HEX$(PEEK(VAR Variable,I));
NEXT I
PRINT
END SUB


//
// add 2 x 32 bit unsigned numbers
// c=a+b
// c could be a OR b IF desired, ie a=a+b, b=a+b
// Arguments are passed in 3 pointers TO a b, AND the result in c
//
void main(unsigned int*a, unsigned int*b, unsigned int*c) {

*c=*a+*b;
}






73

PeterEdited by G8JCF 2014-09-14
The only Konstant is Change
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2927
Posted: 01:55pm 13 Sep 2014
Copy link to clipboard 
Print this post

Peter - I follow everything apart from the C syntax right near the end of your excellent example.

Please; just for my benefit can you 'translate' the meaning of this C snippet into English/Basic!

d=*a++ + *b++;
*c++ = d % 0x100;

In my brain; if d = *a + *b then what are all the other '+' symbols doing there?
% means what? Is it OR or AND maybe?

Come on; was the person that wrote C drunk when he created it? Perhaps if I have a drink then I may understand it better too? After all, its easier to understand spoken foreign languages when you are drunk so perhaps the same is true for 'foreign' coding languages too

hic . . .
 
     Page 2 of 4    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025