Teensy 3.1 code updates

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
User avatar
dhylands
Posts: 3213
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Teensy 3.1 code updates

Post by dhylands » Fri May 29, 2015 6:39 pm

lbattraw wrote:@dhylands - re: recent code changes

Yep, I have pushed several times recently, which might be part of the problem ;-) Things are changing rapidly as I keep finding new things I'm doing wrong, and there's always something new to fix...

I've been looking at your HAL code for Teensy as I realized I didn't have a way to output strings via the USB VCP, and am wondering some more about where to split up such code and the existing Teensy Arduino libraries (Which I wanted to reference instead of duplicating sections). Ideally I'd like to build on all that existing, tested code to avoid reinventing things (Or copying things that might later be changed in the original code base), with just some glue code to make it work with MicroPython. It might also make it a little less difficult for future ports since if they can use the Arduino API they may be able reuse glue code as well. That's the idea anyway. Any thoughts on this, creating/copying code vs. using Arduino interfaces?

-Larry
So the "first" port (the outdated one) was trying to get teensy stuff running, so I wound up using lots of the arduino shim code.

In the more recent port, I'm trying to use as little of the arduino shims as possible and coding directly to the registers. The timer.c file is an example of this. The Pin code is actually common enough that I was able to use the stmhal version.

The arduino shims are fundamentally too limiting, in that you only get as much functionality as they expose, and it adds an extra layer of redirection (i.e. arduino pin numbers don't necessarily map nicely to CPU pins, etc). It also reduces the code size quite a bit.

I expect that I'll keep the USB serial stuff, but for UART, I would probably just code directly to the registers, since the UART is pretty straight forward as far as peripherals are concerned.

So I would probably take stmhal's uart.c, keep all, or most of the functions, and rewrite the contents of each function.

User avatar
dhylands
Posts: 3213
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Teensy 3.1 code updates

Post by dhylands » Fri May 29, 2015 7:08 pm

lbattraw wrote:@dhylands - re: recent code changes

Yep, I have pushed several times recently, which might be part of the problem ;-) Things are changing rapidly as I keep finding new things I'm doing wrong, and there's always something new to fix...

I've been looking at your HAL code for Teensy as I realized I didn't have a way to output strings via the USB VCP, and am wondering some more about where to split up such code and the existing Teensy Arduino libraries (Which I wanted to reference instead of duplicating sections). Ideally I'd like to build on all that existing, tested code to avoid reinventing things (Or copying things that might later be changed in the original code base), with just some glue code to make it work with MicroPython. It might also make it a little less difficult for future ports since if they can use the Arduino API they may be able reuse glue code as well. That's the idea anyway. Any thoughts on this, creating/copying code vs. using Arduino interfaces?

-Larry
About USB VCP output. Right the pyb.USB_VCP class hasn't been ported.

However, stdout winds up going through stmhal/pybstdio.c which calls mp_hal_xxx functions to do the output.

The teensy port has teensy_hal.c which implements the mp_hal_xxx functions and either calls to a uart function (this path has probably never been tested) or it winds up calling some usb_vcp_xxx functions from teensy/usb.c. These in turn call into the usb_serial code which came from the arduino shims.

From C code, if you call printf then it should wind up going through the mp_hal_xxx code path which means that the data should show up on the REPL.

lbattraw
Posts: 21
Joined: Sun May 10, 2015 11:35 am

Re: Teensy 3.1 code updates

Post by lbattraw » Thu Jun 11, 2015 2:25 am

Hi Dave, I've been looking at the existing stmhal code and it definitely looks like a better bet for current porting needs, so I think I will end up copying that and re-working it instead now that I've had a chance to get my feet wet. I did have one question about one of your posts:
I expect that I'll keep the USB serial stuff, but for UART, I would probably just code directly to the registers, since the UART is pretty straight forward as far as peripherals are concerned.

So I would probably take stmhal's uart.c, keep all, or most of the functions, and rewrite the contents of each function.
Just to be clear, you're saying what you would do if you were working on Teensy porting, not that you have new/unreleased code you're working on, right? Anyway, I definitely agree that the stmhal code is the way to go, so hopefully I'll be able to come up with something based on that.

-Larry

User avatar
dhylands
Posts: 3213
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Teensy 3.1 code updates

Post by dhylands » Thu Jun 11, 2015 4:58 am

I don't have any new unreleased code. I see I typed I'll but I meant I'd.

I did the timer module (FTM), Pin, and GPIO stuff the "new" way (direct to registers - not using the arduino style code).

Post Reply