Re: Integrating Nuttx to a firmware project.

2020-08-02 Thread Fotis Panagiotopoulos
Thanks everyone for the help.

I managed to have everything set up to my liking.

As a reference for others trying to manage multiple builds, here is what I
did:

I created scripts for every build, using the following format:

# Example contents of DEBUG.sh
kconfig-tweak --enable CONFIG_DEBUG_FEATURES
make oldconfig

The build type is defined as an environment variable in my system (e.g.
BUILD = DEBUG).

The top-level Makefile contains:

ifeq ($(BUILD), DEBUG)
BUILD_DEP = DEBUG.build
BUILD_SCRIPT  = DEBUG.sh
endif
ifeq ($(BUILD), RELEASE)
BUILD_DEP = RELEASE.build
BUILD_SCRIPT  = RELEASE.sh
endif

I changed target all to:
all: $(BUILD_PATH)/$(BUILD_DEP)
@make -C nuttx

and I added the target:

$(BUILD_PATH)/$(BUILD_DEP):
@make clean
@mkdir -p $(BUILD_PATH)
@./boards/config/$(BUILD_SCRIPT)
@touch $(BUILD_PATH)/$(BUILD_DEP)


This way every time I build NuttX, the build configuration is checked by
the Makefile dependency.
If needed (i.e. every time I change the build type), the project is cleaned
and the changes are applied automatically.

Now I can have as many configurations as I like, the changes are applied
automatically, and the tracked files of my repository are not touched.

Στις Κυρ, 26 Ιουλ 2020 στις 1:30 π.μ., ο/η Brennan Ashton <
bash...@brennanashton.com> έγραψε:

> On Sat, Jul 25, 2020 at 4:09 AM Fotis Panagiotopoulos
>  wrote:
> >
> > Perfect! kconfig-tweak is what I was looking for. I will give it a try
> > later today.
> >
> > However at this point I would like to ask. How is a debug build defined
> for
> > NuttX?
> > Surely there are configs that can be changed. But is there any
> system-wide
> > debug option?
> > Is NDEBUG defined in any case?
> >
> > For example I see CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG which is
> > active when CONFIG_DEBUG_SYMBOLS is also active.
> > So, I guess CONFIG_DEBUG_SYMBOLS is our general "debug" macro?
> >
> > My application will most probably need to know whether this is a debug
> > build or not.
>
> Just about all the explicitly debug functionality, it is all behind
> CONFIG_DEBUG_FEATURES
> so if you wanted to indicate if the build had debug functionality
> enabled that would probably be
> the variable to use.  That said there are a few exceptions including
> these which may also be
> of interest to you.
> CONFIG_STACK_COLORATION
> CONFIG_DEBUG_NOOPT
>
> Debug is a very broad word depending on what you are doing, for
> instance I frequently include the nsh when I am developing along with
> things like procfs, but I might not have that enabled in the "final"
> build.
>
> --Brennan
>


Setting MAC address on STM32.

2020-08-02 Thread Fotis Panagiotopoulos
Hi,

I am using an STM32F427 MCU on a project that I am porting to NuttX.
For the moment everything seems to be working, apart from the Ethernet MAC.
I really can't find the correct way to set the MAC address to the Ethernet
driver.

My hardware uses an I2C EEPROM to store the MAC address. I will have to
read the EEPROM, and pass the address to the MAC driver.


Which is the correct function to use to set the MAC address?

When is the correct time during system initialization to do so?


Re: Setting MAC address on STM32.

2020-08-02 Thread Jukka Laitinen

Hi,

I have used in init scripts:

    ifconfig eth0  hw 
    ifup eth0

One suitable place could be in rc.board_defaults, you just need to fetch 
the mac address from the eeprom first with some other program.


Another option surely is to bring it up in board's board_app_initialize 
or such...


Regards,
Jukka

On 2.8.2020 13.59, Fotis Panagiotopoulos wrote:

Hi,

I am using an STM32F427 MCU on a project that I am porting to NuttX.
For the moment everything seems to be working, apart from the Ethernet MAC.
I really can't find the correct way to set the MAC address to the Ethernet
driver.

My hardware uses an I2C EEPROM to store the MAC address. I will have to
read the EEPROM, and pass the address to the MAC driver.


Which is the correct function to use to set the MAC address?

When is the correct time during system initialization to do so?



Re: Setting MAC address on STM32.

2020-08-02 Thread Alan Carvalho de Assis
Hi Fotis,

Please take a look at arm/samv7/same70-xplained/src/sam_ethernet.c

It does exactly what you are planing to do.

BR,

Alan

On 8/2/20, Fotis Panagiotopoulos  wrote:
> Hi,
>
> I am using an STM32F427 MCU on a project that I am porting to NuttX.
> For the moment everything seems to be working, apart from the Ethernet MAC.
> I really can't find the correct way to set the MAC address to the Ethernet
> driver.
>
> My hardware uses an I2C EEPROM to store the MAC address. I will have to
> read the EEPROM, and pass the address to the MAC driver.
>
>
> Which is the correct function to use to set the MAC address?
>
> When is the correct time during system initialization to do so?
>


Re: Setting MAC address on STM32.

2020-08-02 Thread spudaneco

> Another option surely is to bring it up in board's board_app_initialize or 
> such...Like: 
> https://github.com/apache/incubator-nuttx/blob/master/boards/arm/samv7/same70-xplained/src/sam_ethernet.c#L150Sent
>  from Samsung tablet.


Re: Setting MAC address on STM32.

2020-08-02 Thread Fotis Panagiotopoulos
Thank you both. I followed the example of same70-xplained, and essentially
I do the exact same thing.

However, as I get it, the final step would be to call stm32_macaddress() to
set the address to the MAC.
This function takes as an argument a struct stm32_ethmac_s which is private
to the stm32_eth driver.

So I understand that I cannot set the MAC address within the board
initialization.

Is there any other way? Or maybe this function shall be changed to:
void stm32_macaddress(int intf);

Στις Κυρ, 2 Αυγ 2020 στις 4:36 μ.μ., ο/η spudaneco 
έγραψε:

>
> > Another option surely is to bring it up in board's board_app_initialize
> or such...Like:
> https://github.com/apache/incubator-nuttx/blob/master/boards/arm/samv7/same70-xplained/src/sam_ethernet.c#L150Sent
> from Samsung tablet.
>


Re: Setting MAC address on STM32.

2020-08-02 Thread Gregory Nutt




Thank you both. I followed the example of same70-xplained, and essentially
I do the exact same thing.

However, as I get it, the final step would be to call stm32_macaddress() to
set the address to the MAC.
This function takes as an argument a struct stm32_ethmac_s which is private
to the stm32_eth driver.

So I understand that I cannot set the MAC address within the board
initialization.

Is there any other way? Or maybe this function shall be changed to:
void stm32_macaddress(int intf);

You can always set the MAC address in your application at any time after 
booting using 
https://github.com/apache/incubator-nuttx-apps/blob/master/netutils/netlib/netlib_setmacaddr.c 
or similar logic in-line in your applilcation.


Re: Setting MAC address on STM32.

2020-08-02 Thread Fotis Panagiotopoulos
> You can always set the MAC address in your application at any time after
> booting using
>
https://github.com/apache/incubator-nuttx-apps/blob/master/netutils/netlib/netlib_setmacaddr.c

> or similar logic in-line in your applilcation.

Yes I saw this, but it does not seem a very good option to me.
It requires you to set up the hardware in the application, and does not
seem very efficient.

I was expecting to have the hardware/board initialization routines to
properly set-up the hardware and have it ready for usage for the
application.
Usually the board initialization has direct access to the low-level drivers
for this exact reason.

Also, as I see, now the MAC peripheral has essentially to be initialized
twice. Once with no MAC address, and again with the correct address.


Στις Κυρ, 2 Αυγ 2020 στις 6:03 μ.μ., ο/η Gregory Nutt 
έγραψε:

>
> > Thank you both. I followed the example of same70-xplained, and
> essentially
> > I do the exact same thing.
> >
> > However, as I get it, the final step would be to call stm32_macaddress()
> to
> > set the address to the MAC.
> > This function takes as an argument a struct stm32_ethmac_s which is
> private
> > to the stm32_eth driver.
> >
> > So I understand that I cannot set the MAC address within the board
> > initialization.
> >
> > Is there any other way? Or maybe this function shall be changed to:
> > void stm32_macaddress(int intf);
> >
> You can always set the MAC address in your application at any time after
> booting using
>
> https://github.com/apache/incubator-nuttx-apps/blob/master/netutils/netlib/netlib_setmacaddr.c
> or similar logic in-line in your applilcation.
>


Re: Setting MAC address on STM32.

2020-08-02 Thread Gregory Nutt




Yes I saw this, but it does not seem a very good option to me.
It requires you to set up the hardware in the application, and does not
seem very efficient.
Where do you initialize the IP address?  You should use the same socket 
descriptor to call the ioctl to set the MAC address at that location

I was expecting to have the hardware/board initialization routines to
properly set-up the hardware and have it ready for usage for the
application.


The network won't work reliably without the network monitor at 
apps/netuitils/netinit.  If someone unplugs the cable, the network must 
be re-initialized when the cable is plugged back in.


Initialization and re-initialization is something may need to happen 
numerous times.  This is normally done in the appliction space.



Usually the board initialization has direct access to the low-level drivers
for this exact reason.

Also, as I see, now the MAC peripheral has essentially to be initialized
twice. Once with no MAC address, and again with the correct address.


After initialization, the network is still in the DOWN state. Additional 
initialization is required to set the IP address and bring the network up.


I think a PR to bring out the MAC address setup function as was done for 
arch/arm/src/samv7/sam_emac.c would be acceptable too. The MAC address 
should be retained indefinitely after it is set once.






Re: Setting MAC address on STM32.

2020-08-02 Thread Fotis Panagiotopoulos
> Where do you initialize the IP address?  You should use the same socket
> descriptor to call the ioctl to set the MAC address at that location

I am using the NuttX apps package for the moment, and specifically nsh. So
I guess this code handles everything for me.

But still, I believe that the MAC address and the IP address belong to
different layers of the system.
The IP can be handled by the application (as the user may want to do
anything with it).
On the other hand, the MAC address is a hard-wired address, accessed in a
hardware specific way. In my opinion the application shouldn't mess with it
and it is best to be set once during the hardware initialization.

> I think a PR to bring out the MAC address setup function as was done for
> arch/arm/src/samv7/sam_emac.c would be acceptable too. The MAC address
> should be retained indefinitely after it is set once.
I think that this is needed. I am willing to work on this.


Στις Κυρ, 2 Αυγ 2020 στις 6:35 μ.μ., ο/η Gregory Nutt 
έγραψε:

>
> > Yes I saw this, but it does not seem a very good option to me.
> > It requires you to set up the hardware in the application, and does not
> > seem very efficient.
> Where do you initialize the IP address?  You should use the same socket
> descriptor to call the ioctl to set the MAC address at that location
> > I was expecting to have the hardware/board initialization routines to
> > properly set-up the hardware and have it ready for usage for the
> > application.
>
> The network won't work reliably without the network monitor at
> apps/netuitils/netinit.  If someone unplugs the cable, the network must
> be re-initialized when the cable is plugged back in.
>
> Initialization and re-initialization is something may need to happen
> numerous times.  This is normally done in the appliction space.
>
> > Usually the board initialization has direct access to the low-level
> drivers
> > for this exact reason.
> >
> > Also, as I see, now the MAC peripheral has essentially to be initialized
> > twice. Once with no MAC address, and again with the correct address.
>
> After initialization, the network is still in the DOWN state. Additional
> initialization is required to set the IP address and bring the network up.
>
> I think a PR to bring out the MAC address setup function as was done for
> arch/arm/src/samv7/sam_emac.c would be acceptable too. The MAC address
> should be retained indefinitely after it is set once.
>
>
>
>


Re: Setting MAC address on STM32.

2020-08-02 Thread Gregory Nutt




On the other hand, the MAC address is a hard-wired address, accessed in a
hardware specific way. In my opinion the application shouldn't mess with it
and it is best to be set once during the hardware initialization.
The code follows the same model and uses the same IOCTL commands as does 
Linux and BSD.

I think a PR to bring out the MAC address setup function as was done for
arch/arm/src/samv7/sam_emac.c would be acceptable too. The MAC address
should be retained indefinitely after it is set once.

I think that this is needed. I am willing to work on this.


This logic that sets and remembers the MAC does not depend on hardware.  
It simply modifies the common device structure.  You should be able to 
copy past from arch/arm/src/samv7/sam_emac.c with only a few changes.






Re: Setting MAC address on STM32.

2020-08-02 Thread Alan Carvalho de Assis
Hi Fotis,

On 8/2/20, Fotis Panagiotopoulos  wrote:
>> Where do you initialize the IP address?  You should use the same socket
>> descriptor to call the ioctl to set the MAC address at that location
>
> I am using the NuttX apps package for the moment, and specifically nsh. So
> I guess this code handles everything for me.
>
> But still, I believe that the MAC address and the IP address belong to
> different layers of the system.
> The IP can be handled by the application (as the user may want to do
> anything with it).
> On the other hand, the MAC address is a hard-wired address, accessed in a
> hardware specific way. In my opinion the application shouldn't mess with it
> and it is best to be set once during the hardware initialization.
>

The user (i.e. root user on Linux) could be enable to setup a new MAC address.

You can do it using the ifconfig command, ip command or other. So this
same feature should exist on NuttX.

Also as Mr. Greg explained the application needs to setup the MAC
address when the connection was lost and recovered.

BR,

Alan


Re: Setting MAC address on STM32.

2020-08-02 Thread Gregory Nutt




Also as Mr. Greg explained the application needs to setup the MAC
address when the connection was lost and recovered.


I didn't mean to imply that.  It simply has be bring the network down 
and then bring it back up again when the link is again detected by the PHY.


The MAC address is just a global field in the device structure. It 
should persist indefinitely and will not need to be reset.  The MAC will 
automicatically be re-established each time the MAC is brought up again.