-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Have platform-dependent code in only one place #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also would be nice to have to code stored on subfolders for each task to identify it better: lexer, parser, runtime... |
I love structures and hierarchies, but then I know that you can go "too much" with it. Lexer and parser is ~1 file each. Having bunch of subdirs means extra work navigating among them. I'm not saying stuff can't be improved, it just should be balanced with practicality. |
The most practical thing is to organize it well. I'm not aware of this "navigation cost". Folders are free, and development IDEs don't care. And just because it is a single file today doesn't mean it will always be a single file. In fact, a single code file for a lexer or parser for any dynamic language sounds VERY overweight at first blush. |
Yeah, but real men don't use finicky "ides", they use cd + vi, right? ;-) |
Well, for that one file cases we can keep going this way, only that in fact Send from my Samsung Galaxy Note II
|
Agree that assembler code should go in a platform-specific folder. |
Just my 2 cents: I am not a huge fan of making platform folders, especially for code that is designed to be portable in the first place. Too much code duplication happens in my experience. Better to try to use a set of #defines and macros first. Even for the assembler, if we can do #defines there and use macros, that would be preferable. For example, the porting of the nlrx64.S to OS X was simply a removal of some unsupported keywords. If we made those into defines we ought to be able to use one file for multiple platforms and not duplicate the majority of the code in different places. |
"Si quieres viajar alrededor del mundo y ser invitado a hablar en un monton |
This is very interesting to me as I want to start porting the code to the STM32F407 but not sure how the code should be structured, but here's an idea, it looks like each driver has two parts, the micropython binding, which is platform independent, I think, and a platform-dependent low-level I/O code, it seems like the first step would be to split each driver into a micropython binding and a target specific implementation of the low level stuff ? take for example the i2c driver, there will be an stm/i2c_pyobj.c file and an stm/STM32F405/i2c_impl.c, this folder will also contain the STM32F405 linker script, so the hierarchy looks something like this:
and so on, now the Makefile would be changed to accept a target on the command line, and based on that it links that target's implementation files, so external calls in the *_pyobj.c would be resolved to the target specific implementation... |
Few comments here:
Given your example, are you seriously thinking that F407 would have different I2C implementation than F405? Can't be that way unless proven otherwise (then STM worth an entry in some "f$#^^ up design" hall-of).
If it's "platform independent", why it's under "stm/" ? All in all, I'd say there's no need to have http://en.wikipedia.org/wiki/Analysis_paralysis , best practice is to start implementing new stuff in such a way as to require minimal changes to existing stuff, and then take further action based on actual experience with that. For example, I'd expect F407 port to require ~zero duplication of code, just adding drivers for new hardware blocks and parametrizing existing code (i.e. #ifdef's) - for example, for case like F407 has 3 I2C blocks, while F405 - 2 (even that's unlikely per my crystal ball). |
I'm not sure, it probably doesn't have a different implementation, but it might have a different pin mapping ? that and the fact that it has a different memory layout, which means there's a different linker script that needs to go somewhere... The micropython binding looks platform independent, someone more familiar with the code might be able to confirm this, if so, then it needs to be separated from the implementation, ok maybe stm/ is a bad example. |
This is how eLua implemented different platforms. |
Looking at the data sheets the 407 is a minum 100 pin device vs the 405's 64 pins. The elua layout is interesting. See https://github.com/elua/elua/blob/master/src/platform/stm32f4/stm32f4xx.h and compare with the adjacent folder for the stm32f2 |
As for the F407, @Neon22 is correct: it's basically the same inside, just has more pins and hence more GPIO and peripherals. The STM library is the same for all F4's, and that's the one I'm using in the stm directory. So there should be almost no change to the code to get it running on an F407. If anything, we just have some I don't want to get bogged down trying to work out a perfect file structure etc for ports. I need to work on the pyboard port and make sure the pyboard works very well and has all the features that it should. |
Speaking of the STM libraries and portability, I think an old version is used, the system_stm32f4xx.c has some code missing, for example in the latest version (V1.3) there are a few conditionals for setting the clock dividers based on the micro:
The one in stm/ doesn't have that..it might be wise to update at some point, same applies to the USB libraries. |
Thanks @iabdalkader for the hint: I've now upgraded the peripheral libraries to V1.3.0. I'm using V2.1.0 for the USB drivers. Is there a newer one? |
No, that's the latest one :) |
Closing because this issue is out of date. The structure of the uPy repo is now more mature and has proven itself (so far), so any issues should be directed at its current state. |
Enable/disable drawing of list
tools/ftpserver.c: Refactoring of ftpserver.c
Have a "platform" folder with subdirs for each platform with their platform dependent code inside (i.e., no asembler code on the core) like PyMite does. This will make more clear where to look and how to port it to another platforms, and also would easier to have a unique central makefile (just define as a param what platform do you want to compile).
The text was updated successfully, but these errors were encountered: