Skip to content
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

lpc: Add basic micropython port to LPC Cortex-M series microcontrollers #3400

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martinribelotta
Copy link

@martinribelotta martinribelotta commented Oct 30, 2017

LPC port. Initial commit for LPC43xx support over educational board CIAA-NXP.

This PR clean the board initialization code populating board.h interface with common functions for all boards of the port. Additionally, It enable some basic uPy modules like ure, sys, gc, etc.

The next plan is to add support to micromint lpc43xx boards and similars.

prev work: #3354
@ezequielgarcia some comments?
@RockySong The support of lpc541xx/lpc546xx is in my roadmap and in the future, the support of iMX-RT. Some suggestions to integrate your work? what is your rouadmap?

First board introduced is EDU CIAA LPC4337 (educational board),
using LPCOpen library for LPC18xx/43xx v3.01 as external module.

This first commit should introduce some infrastructure for
other boards to be easily supported. For now, let's just
enable a very simple REPL.

Signed-off-by: Ernesto Gigliotti <ernestogigliotti@gmail.com>
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Martin Ribelotta <martinribelotta@gmail.com>
Copy link

@ezequielgarcia ezequielgarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinribelotta Great job reducing the diffstat! It looks really nice. I just had a few style comments here and there.

Also, a question: what's your plan to select between boards? I see that ports/lpc/board.h has some board-specific macros. Perhaps we should include a per-board header instead, and declare those macros there?

On the other side, that can be done on a follow-up pull-request.

@dpgeorge What do you think?

const uint32_t OscRateIn = 12000000;

/* Structure for initial base clock states */
struct CLK_BASE_STATES {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why capital letters for the struct?


/* Structure for initial base clock states */
struct CLK_BASE_STATES {
CHIP_CGU_BASE_CLK_T clk; /* Base clock */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a nitpick: the comment spacing is odd. can we make them all consistent?

CHIP_CGU_CLKIN_T clkin; /* Base clock source, see UM for allowable souorces per base clock */
bool autoblock_enab; /* Set to true to enable autoblocking on frequency change */
bool powerdn; /* Set to true if the base clock is initially powered down */
};

the above snippet has just one space between the semicolong and the beginning of the comment.


void Board_UART_Init(LPC_USART_T *pUART)
{
Chip_SCU_PinMuxSet(0x7, 1, (SCU_MODE_INACT | SCU_MODE_FUNC6)); /* P7.1 : UART2_TXD */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same nitpick comment: a lot of spacing here, vs. no space in the following line.

Chip_UART_Init(CONSOLE_UART);
Chip_UART_SetBaudFDR(CONSOLE_UART, 115200);
Chip_UART_ConfigData(CONSOLE_UART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
/* Enable UART Transmit */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more comment nitpicking ;-) no need to have a comment saying "enable UART", given the line below is quite clearly enabling the UART. Comments should only be used to add relevant information, otherwise they just clutter the code.

/* Setup system level pin muxing */
Chip_SCU_SetPinMuxing(pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
/* Off all leds */
#define X(port, pin) do { \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add an inline static function instead of this X macro. gcc should be smart enough to produce the same code. Plus, a function gives you type detection.

@ezequielgarcia
Copy link

@dpgeorge Don't want this to fall into oblivion. Any feedback?

@martinribelotta
Copy link
Author

@ezequielgarcia Much of the code is from official BSP of NXP. This need a big rework for a good code guidelinges.
I'm reading CODECONVENTIONS.md and try to clean this code with your recomendations in next days.

The real issue with this PR is the need to add anotjer dependency like stm32lib. This is useless code if you compile for unix or win or stm32 port (or any ports). I try to finding a solution of this but my only reliable path is incorporating only needed functions while the port is growing.

@dpgeorge Some sugesstions to this?

@ezequielgarcia
Copy link

The real issue with this PR is the need to add anotjer dependency like stm32lib. This is useless code if you compile for unix or win or stm32 port (or any ports). I try to finding a solution of this but my only reliable path is incorporating only needed functions while the port is growing.

@martinribelotta What do you mean? I think the LPC library will be compiled only if you target LPC. Since micropython is a multiplatform project, I don't think we are gonna get away without having code for multiple platforms. Just like any other multiplatform project: Node.JS, Linux, etc.

@dpgeorge
Copy link
Member

@martinribelotta thanks for persisting with this to get the LPC supported.

Much of the code is from official BSP of NXP

Do you mean there is code here from NXP code base? What are the licensing issues around that code?

The real issue with this PR is the need to add anotjer dependency like stm32lib.

That is ok, having submodules is a way to add ports while keeping the repository relatively lean. But the submodule must be 1) and independent component; 2) not change very often. If your lpc43xxlib submodule is changing too quickly then it won't work because a lot of the commits will just be to update the submodule.

@martinribelotta
Copy link
Author

@dpgeorge I reproduce the relevant part of lpcopen licence below:

Permission to use, copy, modify, and distribute this software and its
documentation is hereby granted, under NXP Semiconductors' and its
licensor's relevant copyrights in the software, without fee, provided that it
is used in conjunction with NXP Semiconductors microcontrollers. This
copyright, permission, and disclaimer notice must appear in all copies of
this code.

This terms are incompatible with GPL/LGPL but compatible with MIT/BSD/Apache licence (and presumible others non-copyleft licences)

The direct response of NXP support is here:
https://community.nxp.com/thread/422347

The lpc43lib is very slowly actualized (The change between 2.x and 3.x required 3 years from NXP).

Only need to do a little change to support more than one family of processor (lpc43, lpc54xxx, etc) and rename this to nxplib. In the next days I do the pertinent changes and re write the pull request.

@ezequielgarcia
Copy link

ezequielgarcia commented Dec 22, 2017

@dpgeorge Almost a month has passed. I wonder if there are any huge blockers preventing this patch from being merged. I think we have addressed all of your comments and concerns, and @martinribelotta has already stated the NXP library repo would be updated very infrequently.

This micropython port for NXP machines (well, actually a fork based on some ancient micropython) is used in Universities [1] and shown in conferences [2] here in Argentina. Moreover, we are aware of at least a company wanting to enable it on their NXP-based platforms.

So, it seems there is enough momentum to justify the adding this support, and enough reasons (in terms of users) to maintain it. Plus, it would make a terrific way of ending 2017 ;-)

[1] http://laboratorios.fi.uba.ar/lse/tesis/LSE-FIUBA-Trabajo-Final-CESE-Ernesto-Gigliotti-2016.pdf
[2] PyconAR 2016 - https://youtu.be/pT-AOUzZBsw

@dc740
Copy link

dc740 commented Apr 22, 2018

Hi. It's been a couple of months without updates and I was wondering what's the current status?

@ezequielgarcia
Copy link

ezequielgarcia commented Oct 29, 2019

Hi. It's been a couple of months without updates and I was wondering what's the current status?

Hello @dc740! On our side, the PR looks good IIRC (it's been 2 years, so I might be forgetting something). @dpgeorge Do you think you are ready to merge this? Having support for more vendors will surely increase the usefulness of micropython. Also, it seems to do so, as it would have zero impact on the other ports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants