• AVR Freaks

Hot!Minibasic for Pic32

Page: < 12345.. > >> Showing page 4 of 11
Author
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 02:10:03 (permalink)
0
ORIGINAL: mimemike

DarioG
I'm thinking of one thing that would be nice, running Basic code straight out of a I2C/SPI EEprom, or a SDcard... it might be useful.

Should be possible to "SAVE" and RUN from  the on-board FLASH.



Hmmm, this is nice as well!
I was considering insert/remove SDcards or 24xx memories off the board, but the above makes sense.

Shall we go incorporating some FAT method for Flash access? Maybe with a #define that lets us decide if 24xx, 25xx, SDcard or Flash is wanted?

Hmmm, there's just a point in the above: since there is never enough RAM (not in PIC8, not in PIC32 I guess) to load the stored Basic program from Flash to RAM, we won't be actually "loading", rather just "choosing" a file from Flash to Run. So, no, not a real FAT... just a "Directory" , grab a pointer to beginning of file, and read on. It's probably a matter of changing the "getNextChar/getNextLine" in the Minibasic Code.
I presume that this was not the case on ARM or other processors... maybe they just run from RAM...

GENOVA :D :D ! GODO
#61
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 04:52:22 (permalink)
0
I updated the page
http://www.pic32.org/minibasic/index.html

with some details.

Suggestions are welcome (of course)


PS the "Splash" thing on PIC18 has been solved - a simple Baud Rate issue only showing on long strings

GENOVA :D :D ! GODO
#62
profdc9
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2007/12/06 18:54:13
  • Location: 0
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 07:43:42 (permalink)
0
The work going on here is impressive and quick.  May I make a few suggestions?

If you need a portable malloc implementation that minimizes fragmentation, look at:

http://g.oswego.edu/dl/html/malloc.html

This is the same malloc implementation used in newlib.

Of course, if you compile with INTONLY, and forget doubles, I'm sure your code size will be much smaller.  You can also remove the editor completely by remove the "-DEDITOR" macro.  You shouldn't need strtod or gcvt if you only use integers.  I have deliberately avoided sprintf/printf or anything that requires I/O functions so that these are not required.  If you use the mystrtol, myitoa, and myitoahex a lot of space is saved.

I use the "-Os" and "-fomit-frame-pointer" options and so the compiler will inline functions that are only used once in the functions that call them.  If your compiler does not automatically do this, you can declare the functions "inline."  This saves quite a bit of space as code to build and tear down stack frames is removed.  In fact, you can use a macro like

#define BINLINE inline

so that you can turn this on and off at will for debugging.  Also declaring functions "static" that are only used in their respective source files also saves space as sometimes the compiler will rearrange the order of functions to take advantage of special branching instructions.  That's why I have "BSTATIC" and "ESTATIC" defintions in the basic.c and editor.c modules.

I have been continuing to make improvements to my version of the code but keeping the core "basic.c" and "editor.c" as portable as possible, defining typedefs for types where I think the size might be changed for smaller word size architectures, minimizing dependence on library routines, and maximizing code reuse.  The biggest change I have made since 0.4e is to rewrite the string handling somewhat so it is 8-bit clean, so that strings can contain arbitrary characters including NULs.  I did this so that perhaps strings could be used as hardware buffers as well as for text (to get data from serial ports or ethernet frames or what not).  It does add a very small amount of additional code, but not much, since I tried to reuse as much existing code as possible.

My future plans for arm-minibasic is to use the ENC29J60 chip and uIP to build in a web server.  That way web pages can be served using BASIC commands to control various input/outputs.  Additional BASIC commands will be added to emit HTML text and get form data.  I am still waiting for my ENC29J60 evaluation board though, but I am going to take the code from the ARM project

http://www.kandi-electronics.com/uCEthernet/Ethernet_7.aspx

which I have got permission to use.  I will attempt to keep my additions as portable as possible.

Dan

#63
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 09:29:51 (permalink)
0
Welcome in here, Dan Smile

Thanks for your suggestions, much appreciated.

The malloc thing will be surely useful: it looks like on PIC32/C32 there are built-in functions for dynamic memory allocation, but we can make comparisons against the page you provide. On C18, on the other hand, as you probably read I borrowed that code from MSD source by Microchip - but it suffers from some limitations. Maybe I can use a better one.

As for your version 0.4 which could not fit on PIC18, actually (as I wrote) the biggest issue was that C18 was crashing with no reason! So I gave up, since my first thought had gone to C18.
Now, I've borrowed some of your newer code and mixed it into the older one, also adding some ideas of mine. I can say that in the future we may re-incorporate your editor and especially the Tokenize part.
For PIC32, there should not be any code-size troubles, if only it is compiled with the proper compiler Smile Thus, I'd leave in the Floating etc. In C18, it is okay for newer parts (19KB on a total of 32), but indeed it may be useful to try a mix with USB on a 18F2550.

Thank you for those STATIC tips, I had not considered them - we'd need to know if they go the same in C18 and C32 as well.

Let's keep in touch.

GENOVA :D :D ! GODO
#64
profdc9
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2007/12/06 18:54:13
  • Location: 0
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 16:35:30 (permalink)
0
Well, my guess as to why the PIC18 is crashing is wordsize issues.  Plus, minibasic uses realloc() which your simplified implementation may not have.  I have attached the malloc from newlib, it is probably a good place to start as it has the options set for a small build.

I have attached the malloc that is included with newlib. 

Dan
#65
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 17:28:38 (permalink)
0
Thank you Dan, I added realloc() in a simplified way (to be completed) to the SRAMalloc module. As I wrote, I plan on using another implementation such as the one you suggest, for that.

But C18 compiler was crashing *before* of that. I'll try recreating the same situation.

BTW: can anyone tell me if (IIRC it is possible) and how, the USART output can be viewed in the Simulator in MPLAB?

GENOVA :D :D ! GODO
#66
lauer
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2003/11/07 12:35:15
  • Status: offline
RE: Minibasic for Pic32 2007/12/07 22:47:26 (permalink)
0
you can simulate serial IO by enabling it in the debugger setting uart tab. it takes the data from a file. the output can be in a file or in a window.
 
if you have the pic32 starterkit you can 'talk' to the pic32 via usb debugger, there are two function inplemented:
 
DPPRINTF() to send messages to the mplab debugger window and
DBGETC() to read from the debugger (creates a input window)
 
regards
 
Peter
#67
profdc9
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2007/12/06 18:54:13
  • Location: 0
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 00:56:39 (permalink)
0
Ok I am up late but I took the malloc and made it work with minibasic-arm.  I configured it to not need MMAP, library routines, etc., and #defined out things that are not needed to save space.  I also modified the memory tables to be very small for small microcontrollers (it supports only 32 linked lists for allocated entries, which should still be plenty).

All you should need to do is implement _sbrk, I think.  I made all of the modified versions dlmalloc, dlfree, dlrealloc, etc. so they wouldn't interfere with other library versions.

sbrk is very simple:

caddr_t _sbrk (int incr)
{
  extern char end asm ("end");  /* Defined by the linker.  */
  static char *heap_end = NULL;
  char *prev_heap_end;

  if (!heap_end)
    heap_end = & end;

  prev_heap_end = heap_end;

  if (heap_end + incr > stack_ptr)
  {
    /* errno = ENOMEM; */
    return (caddr_t) -1;
  }

  heap_end += incr;

  return (caddr_t) prev_heap_end;
}

"end" is the symbol pointing to the end of the .bss segment (uninitialized data).

stack_ptr is the pointer to the lowest address on the stack.

You have to have some way of getting these out of your link script, so that the malloc knows where the heap is.

I attached my modified malloc.c to this message.  I ran a program that creates and frees a lot of strings of many different sizes and no problems so far.

Dan


#68
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 03:22:12 (permalink)
0
ORIGINAL: lauer

if you have the pic32 starterkit you can 'talk' to the pic32 via usb debugger, there are two function inplemented:



Wow, it works! Smile
Thank you Lauer

GENOVA :D :D ! GODO
#69
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 08:05:18 (permalink)
0
Still have to take a look at the new MALLOC file. Thank you Dan for now.

A few updates:
  • Changed SQRT() to SQR(), and ASCII() to ASC() - hope no one minds Smile
  • Added STATUS() as a mean to read hardware errors and clear them (namely, USART OVERRUN etc.)
  • Added ERR() to retrieve latest error code - for future implementation of ON ERROR GOTO
  • Added STOP statement to break in somewhere
  • Added SYS and USR() to call Machine code, maybe useless - just a relic from 6502 times Smile
  • Added TRIM$() function to remove trailing/leading spaces from strings.
  • Moved the Basic Source code into a separate C file
  • Improved handling of End of Program (waits for a keypress or other input and restarts)
  • Did some debugging, for example to PRINT statement and some more (thanks to Serial Output Simulator Window !)
  • Made LET optional (as per Dan code changes)


GENOVA :D :D ! GODO
#70
profdc9
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2007/12/06 18:54:13
  • Location: 0
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 09:27:35 (permalink)
0
Dario,

How do you plan to do your error handling for ON ERROR?

Some of the errors seem rather hard to recover from (e.g. out of memory).  Also, how do you unwind the FOR/NEXT and GOSUB stacks?  Maybe you just reset those stacks and assume that the user will always basically "start over" in the program rather than resuming after the error?

Dan



#71
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 09:58:35 (permalink)
0
Hmmm, I've not considered this yet - and it's been so longe since I used ONERRORGOTO for real Smile

I guess that the way it used to be was to just leave everything as it was, and move the current Line of execution to another part of program: here the code could present a custom error message, or attempt some recover (such as re-try sending data via a stream or else) ... and maybe clear/unroll the FOR/GOSUB stacks and/or clear the variables (thus freeing memory).

But this latest one could be an optional one.

Yes, it would be me more meaningful if the program could be resumed... just start over is not a great option!

GENOVA :D :D ! GODO
#72
profdc9
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2007/12/06 18:54:13
  • Location: 0
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 15:26:48 (permalink)
0
Well, I added ONERROR/ERR() to my version, and fixed a bunch of bugs.  My latest is attached.

Basically, you do

ONERROR <line number>

and it will jump to that line number in case of error and

ERR(0) returns the last error code
ERR(1) returns the line number of the last error

When an error is thrown, another ONERROR must be performed to catch another error.  After an ONERROR, the FOR/NEXT/GOSUB loops are all unwound, and one can GOTO some other point in the program.

BTW, you can do the following in MiniBasic:

DIM LINES(4)=100,200,300,400
PRINT "Choice:";
INPUT CH
GOTO LINES(CH)

as an alternative to ON...GOTO.

This version also has the smaller malloc and 8-bit clean strings.

Dan

#73
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/08 18:43:06 (permalink)
0
Thank you Dan, I'm taking a look at this tomorrow morning. Your work makes sense, though I was considering the matter differently... I will think about this tonight Smile

As per calculated GOTOs, yes, you're right. It came to my mind soon after I considered the ON..GOTO thing. You remember Spectrum vs. Commodore? The former had calculated GOTOs, the latter not... and I was a Commodorian Smile
Indeed ON..GOTO is no longer needed in MiniBasic. But implementing was so cheap...

GENOVA :D :D ! GODO
#74
Alex B._
Super Member
  • Total Posts : 266
  • Reward points : 0
  • Joined: 2006/10/17 15:26:10
  • Location: St-Petersburg, Russia
  • Status: offline
RE: Minibasic for Pic32 2007/12/10 06:07:35 (permalink)
0
By the way, another interesting project is PyMite:
PyMite is a flyweight Python interpreter written from scratch to execute on 8-bit and larger microcontrollers with resources as limited as 64 KiB of program memory (flash) and 4 KiB of RAM

http://pymite.python-hosting.com/
#75
Kiwi Mike AZ
Super Member
  • Total Posts : 2056
  • Reward points : 0
  • Status: offline
RE: Minibasic for Pic32 2007/12/10 11:58:39 (permalink)
0
ORIGINAL: DarioG
Well, I still CAN'T LINK! Same error as always, even with "-g -Os -fsigned-char -mips16" C Build options [:@] Shall I choose any particular MPU?


Hi Dario, Have you managed to get it linked??

Have you registered C32 online?? If you don't, it is 32K Limited.


P.S. I had done a support ticket for the signed char problem as soon as I posted the temporary solution.... apparently it was already in the system so either you or Jason bet me to it.

Mike
#76
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/10 13:11:04 (permalink)
0
Hi Mike, no I have not registered it, I'm afraid...
I did not know about it. I'll let you know.

PS: @Alex, I'm taking a look tomorrow Smile

GENOVA :D :D ! GODO
#77
lauer
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2003/11/07 12:35:15
  • Status: offline
RE: Minibasic for Pic32 2007/12/10 13:13:10 (permalink)
0
I tried to compile Dario's, the linker failed. First it complained about 'script' could not be resolved. I then removed the comments around the script part.
 
this is what the make created:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\basic\d\minibasic.o".
Clean: Deleted file "C:\basic\d\cpu.o".
Clean: Deleted file "C:\basic\d\io.o".
Clean: Deleted file "C:\basic\d\iohw.o".
Clean: Deleted file "C:\basic\d\MiniBasic32.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX320F128L -x c -c "minibasic.c" -o"minibasic.o" -MMD -MF"minibasic.d" -I"C:\basic\d" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\proc" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\peripheral" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include" -g -Os -fsigned-char -mips16
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX320F128L -x c -c "cpu.c" -o"cpu.o" -MMD -MF"cpu.d" -I"C:\basic\d" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\proc" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\peripheral" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include" -g -Os -fsigned-char -mips16
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX320F128L -x c -c "io.c" -o"io.o" -MMD -MF"io.d" -I"C:\basic\d" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\proc" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\peripheral" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include" -g -Os -fsigned-char -mips16
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX320F128L -x c -c "iohw.c" -o"iohw.o" -MMD -MF"iohw.d" -I"C:\basic\d" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\proc" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include\peripheral" -I"C:\Program Files\Microchip\MPLAB C32\pic32mx\include" -g -Os -fsigned-char -mips16
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX320F128L "minibasic.o" "cpu.o" "io.o" "iohw.o" -o"MiniBasic32.elf" -Wl,-L"C:\Program Files\Microchip\MPLAB C32\lib",-L"C:\Program Files\Microchip\MPLAB C32\pic32mx\lib",-Map="MiniBasic32.map"
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: address 0x9d02d830 of MiniBasic32.elf section .text is not within region kseg0_program_mem
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: section .rodata [9d000000 -> 9d00079f] overlaps section .text [9d000000 -> 9d02d82f]
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: section .eh_frame [9d0007a0 -> 9d00080f] overlaps section .text [9d000000 -> 9d02d82f]
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: section .data [9d000810 -> 9d00095b] overlaps section .text [9d000000 -> 9d02d82f]
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: section .sdata [9d00095c -> 9d00095f] overlaps section .text [9d000000 -> 9d02d82f]
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: MiniBasic32.elf: section .text lma 0x9d000000 overlaps previous sections
C:\Program Files\Microchip\MPLAB C32\bin\..\lib\gcc\pic32mx\3.4.4\..\..\..\..\pic32mx\bin\ld.exe: MiniBasic32.elf: section .eh_frame lma 0x9d0007a0 overlaps previous sections
Link step failed.
BUILD FAILED: Mon Dec 10 14:10:07 2007

Peter
#78
lauer
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2003/11/07 12:35:15
  • Status: offline
RE: Minibasic for Pic32 2007/12/10 13:15:00 (permalink)
0
Alex,
what advantage would Python give us over basic on a embedded control?
Peter
#79
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: Minibasic for Pic32 2007/12/10 13:27:07 (permalink)
0
Same as mine Peter. Tomorrow I'll try registering C32.

As for the "script.c" file, could it be that I forgot to add it to the project?
Can you try downloading MiniBasic.zip for C18, and grab the script.c from that one?

GENOVA :D :D ! GODO
#80
Page: < 12345.. > >> Showing page 4 of 11
Jump to:
© 2020 APG vNext Commercial Version 4.5