CUI32 / UBW32 support?

Dano
Posts: 24
Joined: Mon Jun 20, 2011 9:32 am

CUI32 / UBW32 support?

Post by Dano » Mon Jun 20, 2011 10:14 am

Hi Mark and All,

I'm new here, but I’d love to get your stuff working with the CUI32 and UBW32 (the forum would not let me put direct links to these as a new user, sorry - just search for them on SparkFun) along side your great ChipKIT boards!

I hope the Arduino community accepts your great MPIDE additions for the PIC32 family to integrate them directly into the official Arduino IDE soon, as it is great to have things working nicely across multiple families of ICs!

We’ve been using Microchip’s standard HID bootloader on the CUI32 by default up until now - along with a great OSX/linux bootloader app written by Phil Burgess (again, link was not allowed by the forum here) or just Microchip's own bootloading app for Windows. Neither the CUI32 nor the UBW32 board have an FTDI chip on them, but rely on PIC32s with built-in USB.

One way I could imagine of adding support the CUI32/UBW32 boards would be to incorporate the proper bootloader apps into MPIDE itself (the one mentioned above for OSX/linux and Microchip's host app for Windows), and then if a user selects CUI32/UBW32 from the boards menu it would use this as the proper bootloader tool. What do you think? (this might be a mess supporting all 3 platforms)...

I guess another (better?) way to go would be to write a new PIC32-resident bootloader compatible with avrdude (stk500v2 protocol), that configures the on-chip USB controller to show up as a CDC device (virtual COMport) instead of using the FTDI chip … this would of course require users to push the reset button on the CUI32/UBW32 boards as discussed here: http://chipkit.org/forum/viewtopic.php?f=17&t=98 which is not a big deal.

Finally, a third option would simply be to support the use of a PICKIT3 programmer, and let people go without a bootloader if selecting this option in the MPIDE boards menu.

Is there some work in any of these directions?

All the best,
Dan

Mark
Posts: 116
Joined: Sat May 21, 2011 4:26 pm

Re: CUI32 / UBW32 support?

Post by Mark » Mon Jun 20, 2011 1:07 pm

Dan

I like all of these ideas and we have discussed several of them already. Phil has also been in on some of the discussions. The big issue is having to write and maintain a cross platform program to support one or more of these options. It needs to be a program like avrdude that supports one or more of these other protocols.

This is definitely on the the list of things to look into but nothing has been started yet.

Mark

User avatar
rtestardi
Posts: 79
Joined: Mon Jun 06, 2011 1:16 am
Location: Boulder, CO USA
Contact:

Re: CUI32 / UBW32 support?

Post by rtestardi » Mon Jun 20, 2011 3:19 pm

Hi Dan,

(Good to see you here! I'm guessing that's you! :-)

I think your second option may well be the easiest -- just a new bootloader for the CUI32/UBW32.

Basically, I think I can get the USB/CDC/flash code from the StickOS skeleton project to fit in the 12k bootflash -- the only real challenge is to convert the USB code to run polled without interrupts, but that should be pretty easy. Technically, I think we might be able to steal the last 4k of flash as well, but I don't think that is necessary (heck, we can steal a ton if we just pretend to be an Uno32).

A secondary issue for the CUI32 (and rev 1 of the UBW32) will be that the processor header file for the MX440F512H might not match the MX320F128H or MX795F512L exactly, so some peripheral interactions might not work.

Then I think we can support the chipKIT compatible linker files for the application directly. And the same solution would work for CUI32/UBW32, with no host-side changes needed.

-- Rich
Embedded Systems Made Easy: http://www.cpustick.com .....

Dano
Posts: 24
Joined: Mon Jun 20, 2011 9:32 am

Re: CUI32 / UBW32 support?

Post by Dano » Mon Jun 20, 2011 4:20 pm

Hi RIch,

Yes, it's me! :-)

It would be great to see if we can squeeze a StickOS skeleton-based project into the 12k bootflash!

One thing that'll make this all easier/smoother is that I've got an updated board design for the CUI32 with Markus Gritsch's help, which uses the PIC32MX795 -it's waiting in the wings here for when SparkFun uses up all their existing stock of PIC32MX440s.

I've also been talking a bit with Brian Schmalz on email, and he mentioned there might be a way of doing auto-reset all in firmware (for convenience of not having to physically hit the reset button every time you want to use the bootloader).

Cheers,
Dan

User avatar
rtestardi
Posts: 79
Joined: Mon Jun 06, 2011 1:16 am
Location: Boulder, CO USA
Contact:

Re: CUI32 / UBW32 support?

Post by rtestardi » Mon Jun 20, 2011 5:46 pm

Hi Dan,

Yes, the 795 will help -- is it an H or an L? If it is an H, it might not be as easy. (Your current H *should* map to the H on the Uno32 fairly well, except for the flash size.)

I'm not sure how the auto-reset in firmware will work -- since you're running an arbitrary application that might not even be using USB (or might be using USB for something completely different)... I do the manual resets of my boards and it's not *that* much of a pain... The only hard part is that your application can't actually run for 4-10 seconds after the board resets while the stk500v2 bootloader decides whether there is anyone trying to talk to it or not...

Anyway, if I can free up a couple of evenings here I can take a whack at using the skeleton project to start from -- I'm pretty sure it will all fit once 95% of the code is removed! :-)

-- Rich
Embedded Systems Made Easy: http://www.cpustick.com .....

EmbeddedMan
Posts: 605
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: CUI32 / UBW32 support?

Post by EmbeddedMan » Mon Jun 20, 2011 6:39 pm

Yes, I have been planning on supporting the MPIDE on UBW32 at some point. Too many projects right now that I have to get done, so I haven't spent a whole lot of time on it.

However, I did prove an important piece. I took the Microchip USB stack, and built an application with it. I set it to run in INTERRUPT mode. I also slightly edited the USB stack so that when a handshaking line was toggled, it would perform a CPU reset.

Then, in this application, I wrote a while(1). This simulated a user's sketch having crashed, or gone off in the weeds.

I uploaded this application using the standard HID Bootloader, and then showed that I could reset it at any time by toggling the handshaking line from my terminal emulator. On reset, it dumps you into the HID bootloader, which can easily be modified to wait for a couple seconds before continuing. (Got that done too.)

The only place where this won't work is if the code gets hung while interrupts are disabled. Then you'd need to manually reset the board.

There's no reason this same technique can't be used with any other USB stack - nothing special about Microchip's other than I already have it working on the UBW32.

I also have a cross-platform command line PC application to do the bootloading - I've modified mphidflash and the results are here : schmalzhaus d0t com sLash EBB sLash EBB_BL sLash mphidflash_1_4.zip It needs some work on certain Linux distros, but works great otherwise.

(ARGGG! Why can't we use URLs on this forum!!)

Another way to go, as you've already pointed out, is writing a new bootloader that would talk to AVRDUDE over USB (i.e. include the USB stack). I think this would be a great way to go, but I don't have the necessary smarts to complete that task.

*Brian

User avatar
rtestardi
Posts: 79
Joined: Mon Jun 06, 2011 1:16 am
Location: Boulder, CO USA
Contact:

Re: CUI32 / UBW32 support?

Post by rtestardi » Mon Jun 20, 2011 6:53 pm

Hi Brian,

Good to see you here, too! You'll be able to post URLs shortly -- apparently it's just a spam prevention mechanism... It lasted maybe 3 days for me.

I understand what you did, but doesn't that rely on having your code (and ISR) running in the FW that is downloaded by MPIDE? My understanding is that the HEX file downloaded by MPIDE will cover 0x9d000000 and up, and that the exception table is reprogrammed by the MPIDE in the 0x9d000000 page. So you won't be able to intercept the ISR once you have your first HEX file downloaded from MPIDE...

-- Rich
Embedded Systems Made Easy: http://www.cpustick.com .....

Dano
Posts: 24
Joined: Mon Jun 20, 2011 9:32 am

Re: CUI32 / UBW32 support?

Post by Dano » Mon Jun 20, 2011 9:31 pm

Hi,
Yes, the 795 will help -- is it an H or an L? If it is an H, it might not be as easy. (Your current H *should* map to the H on the Uno32 fairly well, except for the flash size.)
It's an H ... the L is covered by Brian's board extremely well, so I stuck with the smaller pin-count part - I know the registers are annoyingly different, but of course the board is a bit smaller overall.
Anyway, if I can free up a couple of evenings here I can take a whack at using the skeleton project to start from -- I'm pretty sure it will all fit once 95% of the code is removed!
That would be awesome, Rich - if you find time to get it working then we can let StickOS sit on top of this bootloader on the new CUI32 (and UBW32 as well possibly ... not sure if you want this by default Brian, but I definitely do! In my eyes it's a hell of a lot more advanced and functional than the "Firmata" firmware that all Arduinos ship with by default), and then people are free to choose their own adventure | poison | magic ;-) If they want to go back to StickOS after using the Arduino IDE for awhile, they just have to upload StickOS again - I have found in many cases that the interactive nature of StickOS really lends itself to students immediate understanding. But they still want to be able to use Arduino - each has its place!

It would be fun for us to make this work on the current iteration of CUI32 boards right now, but in order to make a clean slate for SparkFun I think I'd hold back on having them ship anything that might incorporate a new bootloader until they also update to the new revised board and retire the current one. Otherwise it'll be more difficult to explain/support questions regarding "which bootloader app do I use?" etc...

Cheers,
Dan

EmbeddedMan
Posts: 605
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: CUI32 / UBW32 support?

Post by EmbeddedMan » Mon Jun 20, 2011 10:29 pm

rtestardi wrote:Hi Brian,
I understand what you did, but doesn't that rely on having your code (and ISR) running in the FW that is downloaded by MPIDE?
-- Rich
Rich, yes, of course. The idea would be to add to the core ChipKIT libraries the functionality to handle this 'behind the scenes' (and hook into the USART send receive as well, so it all 'just works' for sketches). You can link in different things based upon what board you select, so if you selected the UBW32, you'd get this new code compiled in, along with your sketch. So it would all be part of the 'app' - Arduino 'apps' are composed of the code from the sketch, the C/C++ runtime code, and libraries - both the core libraries that give us all of the nice Arduino functions, but also any libraries that you add in (and call).

*Brian

User avatar
rtestardi
Posts: 79
Joined: Mon Jun 06, 2011 1:16 am
Location: Boulder, CO USA
Contact:

Re: CUI32 / UBW32 support?

Post by rtestardi » Tue Jun 21, 2011 12:03 am

Oh, maybe I get it -- it's almost like you're creating a self-propagating bootloader... So as long as the injected code doesn't conflict with the user's code, you'd be good to go. You'd need a new linker file, too

Reminds me of the Reflections on Trusting Trust... :-)

I'm not sure I understand how the whole process would start, though... Are you thinking to keep the UBW32 bootloader around, layer a new CDC/ACM stk500v2 bootloader on top of it, and then re-inject a derivative of the new CDC/ACM stk500v2 bootloader with just the "reset changes" back into every compiled sketch (with a new linker file, of course)?

-- Rich
Embedded Systems Made Easy: http://www.cpustick.com .....

Post Reply