Programming the NXT in C

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
mrblp
Posts: 82
Joined: 02 Oct 2010, 14:33

Re: Programming the NXT in C

Post by mrblp »

Hello Matt,
I don't want JTAG to be required.
You always need a JTAG for in-circuit debugging the code. For just getting the code to the brick use the Bare Metal method - you do not need a in-circuit debugger. But it will be very useful because you start at point zero. No display drivers, no button drivers, no communication to the ATmega48. That one will shut off the power if you do not send the string "Let's samba nxt arm in arm, (c)LEGO System A/S" to it (Bare Metal does this in the init routine).

Why are you going to try this? Are there real limits of the nbc virtual machine for you? Did you ever try any other firmwares (lejos, pbLua)?

I think to start with "Bare Metal" without any microcontroller experience is not the easiest way. There are some simpler robots out there with ATmega16 or the Adurino System to start.

To get really started with a microcontroller you need to know about the peripherals of that one and of course about the circuit where it is built in. I am sure you did take a look to the shematics Lego published on their web site. Did you take a look to the datasheet of the microcontroller (AT91SAM7S256)? Just go to the Atmel page and take a real look in there. If that is your world - fine :-)

To get the peripherals run take a look to the lejos c-source code. They have well checked c routines to get the peripherals work. I checked it - you have to download a GNU tarball when browsing the repository - in the standard source package these sources are left out...

Have fun :-)

Marvin
Bye Marvin

- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Programming the NXT in C

Post by mattallen37 »

So, you're saying that if I want to program with bare metal, you recommend I invest in a JTAG... I'll consider it.

The NBC VM isn't overly restrictive, and whenever I want something new, John almost always adds it sooner or later. So it's not so much about the limits of NBC as it is about the learning process of attempting to program the bare metal.

I do have some uC experience. I have used PICAXE a fair bit, as well as Arduino. Although, I'll admit that neither system is setup for bare metal. The Arduino does let you control the registers though, and I have done that a little (adjusting the timers to send the Power Functions IR messages at timer set-point interrupts).

I know a little about the peripherals of the AT91SAM7S256, and I am very familiar with the NXT circuit. I actually already downloaded the datasheet for the chip, I just haven't spent the time thoroughly wading through it yet (as you hinted, it's a pretty long, advanced datasheet).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mrblp
Posts: 82
Joined: 02 Oct 2010, 14:33

Re: Programming the NXT in C

Post by mrblp »

mattallen37 wrote:So, you're saying that if I want to program with bare metal, you recommend I invest in a JTAG... I'll consider it.
No - as I said you do not need it. It sounded to me you never ever had any contact to a microcontroller so this could be a very frustrating experience ;-)

I think the "Bare Metal" site you cited is a good starting point and as a next step I recommend you the hardware drivers of lejos. They are written in c and give you bare access to the peripherals of the NXT. You find the files here.

Have fun :-)

Bye marvin
Bye Marvin

- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Programming the NXT in C

Post by mattallen37 »

Thanks. I looked through several of those drivers, and they don't seem overly complex.

Now I need to figure out how to compile bare metal programs.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mrblp
Posts: 82
Joined: 02 Oct 2010, 14:33

Re: Programming the NXT in C

Post by mrblp »

mattallen37 wrote:Thanks. I looked through several of those drivers, and they don't seem overly complex.

Now I need to figure out how to compile bare metal programs.
If you can read bash / shell scripts, this may help: http://lejos.svn.sourceforge.net/viewvc ... ision=6356.

Have a nice day,
Bye marvin
Bye Marvin

- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: Programming the NXT in C

Post by tcwan »

mattallen37 wrote:First, I'd like to say that this would certainly not replace NXC for me. It would primarily be used as a learning experience.

I'm not exactly sure what I'm looking for. I want to program at a lower level, with support for pointers etc. but I want to be able to do it through USB (I don't want JTAG to be required).

I've heard about Bare Metal on the NXT. Perhaps that's what I should try.

I have also heard about NXTGCC. Can you tell me a little more about it, and how to get started with it? I would like to use the BCC IDE if possible.
Firstly, JTAG debugging allows you to investigate lower level code (e.g., interrupt routine code), but is quite unwieldy and fragile since you'd need to remove the cover of the NXT to connect to the JTAG pins. For someone dabbling in bare-metal programming, I'd suggest that it is overkill.

There are two options for USB-based (non-JTAG) debugging:
NXTGCC http://nxtgcc.sourceforge.net/ and NIF http://nxt-firmware.ni.fr.eu.org/.

Nicolas Schodet has integrated my ARMDebug GDB Stub code into NIF to enable USB remote debugging.
I guess since I'm the author of ARMDebug I'd recommend using NIF over NXTGCC :D
There is some comments regarding the difference between NIF and NXTGCC http://nxt-firmware.ni.fr.eu.org/faq/
The Remote Debugger server for NIF is python based, which allows you to use your own IDE instead of Eclipse, though Eclispe is my preferred cross-platform IDE for teaching purposes (I find it clunky personally).

Potentially, it is possible to perform Bluetooth Remote Debugging, but I have not managed to get it to work due to issues with the Fantom Driver's handling of raw direct command messages (I can't get any replies to raw messages sent over Bluetooth).


Sivan Toledo's site is the starting point for bare-metal programming of the NXT. However, he only introduces you to how you can bootstrap the Atmel microcontroller, the rest is up to you. There are no device drivers, libraries, or other supporting routines which would be needed for any real NXT project. If you go the bare metal route, you should probably investigate NxOS, more specifically, the fork that I'm maintaining https://github.com/tcwan/nxos-armdebug, which incorporates ARMDebug with NxOS.

There's also nxtOSEK http://lejos-osek.sourceforge.net/, which is another C/C++ based bare-metal OS, but their goal is to support C/C++ development so the driver design is not as clean as NxOS IMHO.
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: Programming the NXT in C

Post by tcwan »

pbenco wrote:hello mattallen37

You can use NXTGCC, which is a GCC compiler, with the enhanced firmware framework. You can develop directly into the arm codebyte.
Eclipse add-on is available, to replace bricxcc as an IDE.
Hope this help
Ben

http://nxtgcc.sourceforge.net/
Hi Ben,

As far as I know, the NXTGCC firmware is based on the stock LEGO firmware. So it won't have many of the Enhanced Firmware features, especially the latest stuff. I'd suggest using NIF http://nxt-firmware.ni.fr.eu.org/ instead. The 1.31 Enhanced firmware code has been merged into NIF.
pbenco
Posts: 71
Joined: 29 Sep 2010, 09:43
Contact:

Re: Programming the NXT in C

Post by pbenco »

Dear tcwan
i beg your pardon, i made a confusion, you're right! :oops:

Dear mattalen37
JTAG clone are easily available in china, got mine for 25$, plug'n play in IAR dev environnement. :twisted:
This one is a refurbished, US located: http://cgi.ebay.fr/IAR-SYSTEMS-A404-J-L ... 256c4a8e58 but more pricy!!!

Not a big experience in it, yet, as i focus more on a MOC, a swarm of two robots, connected through WIFI. First step will be to dev a lib in NXC for the wifiblock: http://www.humarobotics.com/.

Best regards
Ben
pbenco.wordpress.com/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Programming the NXT in C

Post by mattallen37 »

I'm not even sure yet what a bash/shell script is (although I'm open to learning something new today ;) ).

I am totally open to soldering a couple headers to the PCB. I have done internal NXT work before, and it doesn't concern me much.

Sivan Toledo's project actually does include some drivers, it's just a matter of me getting things to compile. I'm still open to other possibilities, but I downloaded the library of drivers, as well as WinAVR. However, I can't seem to get it to compile; probably because I'm extremely new to this type of programming, and I don't know anything about what files I need to include in the project etc.

@pbenco you're saying that any cheap ARM JTAG from china will do what I would need? I don't need to spend $80+?

I don't have experience setting up compilers and IDEs, and I am fairly new to this "project" idea (10-20 various header and source files). I would greatly appreciate a walk through of setting something up (at this point I don't really care which system I go with, but NxOS sounds pretty good). The only thing I have done so far is setup WinARM (in an attempt to get Bare Metal to work), setting path to include the paths necessary (as explained here), and compiling one of the example programs included with WinARM.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
pbenco
Posts: 71
Joined: 29 Sep 2010, 09:43
Contact:

Re: Programming the NXT in C

Post by pbenco »

Dear mattallen37
@pbenco you're saying that any cheap ARM JTAG from china will do what I would need? I don't need to spend $80+?
NO, NO, NO, the J-link (the black box i show you in the ebay auction!) is compatible with IAR, and GCC hardware level debugging feature. Mine is a copycat of the genuine segger/IAR J-link, With the same case, but no marking... Suspect that it's coming from the same factory chain, as it's recognized by IAR IDE as genuine segger J-Link. Haven't investigate further yet...
Best regards
Ben

PS; the link i bookmarked when wandering this topic was : http://www.yagarto.de/howto.html, it's still active, have a look!
P.S2; the nicolas schodet firmware is there : http://nxt-firmware.ni.fr.eu.org/build/gcc/
http://photos.freelug.org/main.php/v/be ... G_0237.jpg
pbenco.wordpress.com/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests