Discussion:
[nuttx] sdcard + USB MSC
franck gastel franckgastel@gmail.com [nuttx]
2016-10-03 16:16:21 UTC
Permalink
Hello.


What would be the way to get nuttx act as a usb mass storage and show the
content of a SDcard that is connected to a STM32.
Is there an example somewhere for that ?


So far I activated SDIO in the configuration, but I can't get to see any
/dev/mmc0 what would be the steps ?
spudarnia@yahoo.com [nuttx]
2016-10-03 17:33:33 UTC
Permalink
There are looks of examples that do this. You should check out these configurations:

$ find . -name usbmsc
./hymini-stm32v/usbmsc
./lpcxpresso-lpc1768/usbmsc
./mcu123-lpc214x/usbmsc
./olimex-lpc1766stk/usbmsc
./spark/usbmsc
./stm3210e-eval/usbmsc
./stm32f429i-disco/usbmsc
./teensy-2.0/usbmsc

Configuration settings:

CONFIG_USBMSC=y
...
CONFIG_SYSTEM_USBMSC=y

Some special setting is also required in your board initialization logic. Look at:

$ find . -name *_usbmsc.c
./cloudctrl/src/stm32_usbmsc.c
./ea3131/src/lpc31_usbmsc.c
./ea3152/src/lpc31_usbmsc.c
./fire-stm32v2/src/stm32_usbmsc.c
./freedom-k64f/src/k64_usbmsc.c
./hymini-stm32v/src/stm32_usbmsc.c
./kwikstik-k40/src/k40_usbmsc.c
./lpcxpresso-lpc1768/src/lpc17_usbmsc.c
./mcu123-lpc214x/src/lpc2148_usbmsc.c
./olimex-lpc1766stk/src/lpc17_usbmsc.c
./olimexino-stm32/src/stm32_usbmsc.c
./pic32mx-starterkit/src/pic32mx_usbmsc.c
./pic32mx7mmb/src/pic32_usbmsc.c
./sam3u-ek/src/sam_usbmsc.c
./sam4e-ek/src/sam_usbmsc.c
./sama5d3-xplained/src/sam_usbmsc.c
./sama5d3x-ek/src/sam_usbmsc.c
./sama5d4-ek/src/sam_usbmsc.c
./samv71-xult/src/sam_usbmsc.c
./shenzhou/src/stm32_usbmsc.c
./spark/src/stm32_usbmsc.c
./stm3210e-eval/src/stm32_usbmsc.c
./teensy-2.0/src/at90usb_usbmsc.c
./twr-k60n512/src/k60_usbmsc.c
./u-blox-c027/src/lpc17_usbmsc.c
./viewtool-stm32f107/src/stm32_usbmsc.c
./zkit-arm-1769/src/lpc17_usbmsc.c

I checked stm3210e-eval/src/stm32_usbmsc.c. It is a good example.
franck gastel franckgastel@gmail.com [nuttx]
2016-10-04 14:01:13 UTC
Permalink
well in fact that is exactly what I do.
For some reason the MSC doesn't show up


I'd like to debug it, so I wanted to use USART3 of the stm32 as console.
and I might be doing something wrong here again as when I set it up as
console, I have no nsh prompt. I am sure of my wiring tho because when I
use usb nsh, and I do echo hello > /dev/ttyS1 it shows hello on it. and if
I cat /dev/ttyS1 and I type something on the therm, I can see it appear
there.


I take the example that uses USART2 of stm32, I wonder if USART3 can be
used the same way as console, or if there is something to do in order to
get it to work
There are looks of examples that do this. You should check out these
$ find . -name usbmsc
./hymini-stm32v/usbmsc
./lpcxpresso-lpc1768/usbmsc
./mcu123-lpc214x/usbmsc
./olimex-lpc1766stk/usbmsc
./spark/usbmsc
./stm3210e-eval/usbmsc
./stm32f429i-disco/usbmsc
./teensy-2.0/usbmsc
CONFIG_USBMSC=y
...
CONFIG_SYSTEM_USBMSC=y
Some special setting is also required in your board initialization logic.
$ find . -name *_usbmsc.c
./cloudctrl/src/stm32_usbmsc.c
./ea3131/src/lpc31_usbmsc.c
./ea3152/src/lpc31_usbmsc.c
./fire-stm32v2/src/stm32_usbmsc.c
./freedom-k64f/src/k64_usbmsc.c
./hymini-stm32v/src/stm32_usbmsc.c
./kwikstik-k40/src/k40_usbmsc.c
./lpcxpresso-lpc1768/src/lpc17_usbmsc.c
./mcu123-lpc214x/src/lpc2148_usbmsc.c
./olimex-lpc1766stk/src/lpc17_usbmsc.c
./olimexino-stm32/src/stm32_usbmsc.c
./pic32mx-starterkit/src/pic32mx_usbmsc.c
./pic32mx7mmb/src/pic32_usbmsc.c
./sam3u-ek/src/sam_usbmsc.c
./sam4e-ek/src/sam_usbmsc.c
./sama5d3-xplained/src/sam_usbmsc.c
./sama5d3x-ek/src/sam_usbmsc.c
./sama5d4-ek/src/sam_usbmsc.c
./samv71-xult/src/sam_usbmsc.c
./shenzhou/src/stm32_usbmsc.c
./spark/src/stm32_usbmsc.c
./stm3210e-eval/src/stm32_usbmsc.c
./teensy-2.0/src/at90usb_usbmsc.c
./twr-k60n512/src/k60_usbmsc.c
./u-blox-c027/src/lpc17_usbmsc.c
./viewtool-stm32f107/src/stm32_usbmsc.c
./zkit-arm-1769/src/lpc17_usbmsc.c
I checked stm3210e-eval/src/stm32_usbmsc.c. It is a good example.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-10-04 14:38:04 UTC
Permalink
Hi Frank,

Put some debug inside usbmsc_archinitialize() to confirm it is working.

I don't know if it will help, but I used the usbmsc driver to export
the content of my Flash.
In fact this is a nice way to export a big NuttX Flash filesystem to
get access on host computer side:

https://acassis.wordpress.com/2016/01/03/using-the-nuttxs-usb-mass-storage-to-copy-spi-nor-flash-content/

BR,

Alan
Post by franck gastel ***@gmail.com [nuttx]
well in fact that is exactly what I do.
For some reason the MSC doesn't show up
I'd like to debug it, so I wanted to use USART3 of the stm32 as console.
and I might be doing something wrong here again as when I set it up as
console, I have no nsh prompt. I am sure of my wiring tho because when I
use usb nsh, and I do echo hello > /dev/ttyS1 it shows hello on it. and if
I cat /dev/ttyS1 and I type something on the therm, I can see it appear
there.
I take the example that uses USART2 of stm32, I wonder if USART3 can be
used the same way as console, or if there is something to do in order to
get it to work
There are looks of examples that do this. You should check out these
$ find . -name usbmsc
./hymini-stm32v/usbmsc
./lpcxpresso-lpc1768/usbmsc
./mcu123-lpc214x/usbmsc
./olimex-lpc1766stk/usbmsc
./spark/usbmsc
./stm3210e-eval/usbmsc
./stm32f429i-disco/usbmsc
./teensy-2.0/usbmsc
CONFIG_USBMSC=y
...
CONFIG_SYSTEM_USBMSC=y
Some special setting is also required in your board initialization logic.
$ find . -name *_usbmsc.c
./cloudctrl/src/stm32_usbmsc.c
./ea3131/src/lpc31_usbmsc.c
./ea3152/src/lpc31_usbmsc.c
./fire-stm32v2/src/stm32_usbmsc.c
./freedom-k64f/src/k64_usbmsc.c
./hymini-stm32v/src/stm32_usbmsc.c
./kwikstik-k40/src/k40_usbmsc.c
./lpcxpresso-lpc1768/src/lpc17_usbmsc.c
./mcu123-lpc214x/src/lpc2148_usbmsc.c
./olimex-lpc1766stk/src/lpc17_usbmsc.c
./olimexino-stm32/src/stm32_usbmsc.c
./pic32mx-starterkit/src/pic32mx_usbmsc.c
./pic32mx7mmb/src/pic32_usbmsc.c
./sam3u-ek/src/sam_usbmsc.c
./sam4e-ek/src/sam_usbmsc.c
./sama5d3-xplained/src/sam_usbmsc.c
./sama5d3x-ek/src/sam_usbmsc.c
./sama5d4-ek/src/sam_usbmsc.c
./samv71-xult/src/sam_usbmsc.c
./shenzhou/src/stm32_usbmsc.c
./spark/src/stm32_usbmsc.c
./stm3210e-eval/src/stm32_usbmsc.c
./teensy-2.0/src/at90usb_usbmsc.c
./twr-k60n512/src/k60_usbmsc.c
./u-blox-c027/src/lpc17_usbmsc.c
./viewtool-stm32f107/src/stm32_usbmsc.c
./zkit-arm-1769/src/lpc17_usbmsc.c
I checked stm3210e-eval/src/stm32_usbmsc.c. It is a good example.
spudarnia@yahoo.com [nuttx]
2016-10-04 14:52:05 UTC
Permalink
Just select the following:


CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0



Never edit .config files by hand. That is always a disaster and will cause you endless problems. Always use the configuration tool.
Ramtin Amin keytwo@gmail.com [nuttx]
2016-10-04 14:55:04 UTC
Permalink
hello
that is my setup !
I completely removed OTGFS so far, but still no nsh prompt :( even tho I
know my wiring is correct
Post by ***@yahoo.com [nuttx]
CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0
Never edit .config files by hand. That is always a disaster and will
cause you endless problems. Always use the configuration tool.
Ramtin Amin keytwo@gmail.com [nuttx]
2016-10-04 14:55:28 UTC
Permalink
alan, where do you find: [*] USB Mass Storage Device Commands --->
I don't seem to find it
Post by Ramtin Amin ***@gmail.com [nuttx]
hello
that is my setup !
I completely removed OTGFS so far, but still no nsh prompt :( even tho I
know my wiring is correct
Post by ***@yahoo.com [nuttx]
CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0
Never edit .config files by hand. That is always a disaster and will
cause you endless problems. Always use the configuration tool.
franck gastel franckgastel@gmail.com [nuttx]
2016-10-04 14:56:26 UTC
Permalink
yes, the same here
Post by Ramtin Amin ***@gmail.com [nuttx]
alan, where do you find: [*] USB Mass Storage Device Commands --->
I don't seem to find it
Post by Ramtin Amin ***@gmail.com [nuttx]
hello
that is my setup !
I completely removed OTGFS so far, but still no nsh prompt :( even tho I
know my wiring is correct
Post by ***@yahoo.com [nuttx]
CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0
Never edit .config files by hand. That is always a disaster and will
cause you endless problems. Always use the configuration tool.
spudarnia@yahoo.com [nuttx]
2016-10-04 15:35:16 UTC
Permalink
STM32 serial is *very* well tested. So this is not an OS bug. If the configuration is correct then my guesses would be that either the pin configuration is not set up correctly or the clocking is wrong. You might want to review configs/<board>/include/board.h. That is where those things are defined.
franck gastel franckgastel@gmail.com [nuttx]
2016-10-04 15:37:57 UTC
Permalink
If I take the usbnsh from stm32f4discovery/usbnsh and I add from the config
and I activate the usart6 and add a console to it, should I get 2 consoles
there ? (on usb and on usart6)
Post by ***@yahoo.com [nuttx]
STM32 serial is *very* well tested. So this is not an OS bug. If the
configuration is correct then my guesses would be that either the pin
configuration is not set up correctly or the clocking is wrong. You might
want to review configs/<board>/include/board.h. That is where those
things are defined.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-10-04 15:48:11 UTC
Permalink
No, by default NuttX supports only one console!

If you want to have USB Console and MSC at same time you need to
enable USB Composite.

But I think it is not a good idea for now... ;-)
Post by franck gastel ***@gmail.com [nuttx]
If I take the usbnsh from stm32f4discovery/usbnsh and I add from the config
and I activate the usart6 and add a console to it, should I get 2 consoles
there ? (on usb and on usart6)
Post by ***@yahoo.com [nuttx]
STM32 serial is *very* well tested. So this is not an OS bug. If the
configuration is correct then my guesses would be that either the pin
configuration is not set up correctly or the clocking is wrong. You might
want to review configs/<board>/include/board.h. That is where those
things are defined.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-10-04 15:37:19 UTC
Permalink
Here:

Application Configuration --->
System Libraries and NSH Add-Ons --->
[*] USB Mass Storage Device Commands --->
--- USB Mass Storage Device Commands

BR,

Alan
Post by Ramtin Amin ***@gmail.com [nuttx]
alan, where do you find: [*] USB Mass Storage Device Commands --->
I don't seem to find it
Post by Ramtin Amin ***@gmail.com [nuttx]
hello
that is my setup !
I completely removed OTGFS so far, but still no nsh prompt :( even tho I
know my wiring is correct
Post by ***@yahoo.com [nuttx]
CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0
Never edit .config files by hand. That is always a disaster and will
cause you endless problems. Always use the configuration tool.
Ramtin Amin keytwo@gmail.com [nuttx]
2016-10-04 15:39:21 UTC
Permalink
alan, in fact on the trunk version I don't see this when I do a make
menuconfig. Does it need something else to be present there ?
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-10-04 15:50:38 UTC
Permalink
What version/commit are you using / in?

You need to enable USB Device Peripheral, USB MSC driver enable and
then you should see it.

BR,

Alan
Post by Ramtin Amin ***@gmail.com [nuttx]
alan, in fact on the trunk version I don't see this when I do a make
menuconfig. Does it need something else to be present there ?
spudarnia@yahoo.com [nuttx]
2016-10-04 16:24:27 UTC
Permalink
You are probably missing a dependency.


In 'make mencuconfig' (aka kconfig-mconf), the /, then enter the configuration name. It will show you where it can be found and also what it depends on.
franck gastel franckgastel@gmail.com [nuttx]
2016-10-04 16:31:33 UTC
Permalink
yep the pins are correct
In fact, what I do is that I take stm32f4discovery/usbnsh from where I
remove the USB ACM console. then I add USART6 for the BB board, and set the
serial console to USART6. when I run, I don't see the tty acm, neither does
the console work.
If I remove the console on USART6 and re-enable it on ACM, then it works
and echo hello > /dev/ttyS0 on nsh works.
So for some reason, if the ACM is enabled with no console and usart6 wiht
console, it doesnt work
Post by ***@yahoo.com [nuttx]
You are probably missing a dependency.
In 'make mencuconfig' (aka kconfig-mconf), the /, then enter the
configuration name. It will show you where it can be found and also what
it depends on.
spudarnia@yahoo.com [nuttx]
2016-10-04 16:34:58 UTC
Permalink
Don't use it usbnsh configuration unless you want to change a lot. That is a special configuration that only supports a console on USB. No serial is console is supported at all and cannot be supported without a lot of work.


Try the netnsh configuration. I have used that many, many times with the STM32 F4 Discovery and the BB board. USART6 works great in that configuration.


I understand that there are to versions of the BB board. Only the older is supported. I don't know what the difference between versions is.
franck gastel franckgastel@gmail.com [nuttx]
2016-10-06 08:00:05 UTC
Permalink
Ok, in fact I use the netnsh configuration, remove the network part and
lib, and it works on stm32f4discovery + old BB.
The question now is what is the best way to port it to stm32f405rg ? Could
I take the olimex-stm32-h405 defonfig and make it match the same as my
.config that works on stm32f4discovery ? Any tip ?
Post by ***@yahoo.com [nuttx]
Don't use it usbnsh configuration unless you want to change a lot. That
is a special configuration that only supports a console on USB. No serial
is console is supported at all and cannot be supported without a lot of
work.
Try the netnsh configuration. I have used that many, many times with the
STM32 F4 Discovery and the BB board. USART6 works great in that
configuration.
I understand that there are to versions of the BB board. Only the older
is supported. I don't know what the difference between versions is.
spudarnia@yahoo.com [nuttx]
2016-10-06 13:11:19 UTC
Permalink
If you want to clone a configuration for a different board, then everything should match in the configuration except for processor- and board-specific definitions.


I use the tool at tolls/cmpconfig to compare configurations.

Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-10-04 15:40:44 UTC
Permalink
Keep in mind you don't need to change these commands, I changed it
because I want to use the mass storage with the SPI NOR Flash instead
of SDCard.

BR,

Alan
Post by Alan Carvalho de Assis ***@gmail.com [nuttx]
Application Configuration --->
System Libraries and NSH Add-Ons --->
[*] USB Mass Storage Device Commands --->
--- USB Mass Storage Device Commands
BR,
Alan
Post by Ramtin Amin ***@gmail.com [nuttx]
alan, where do you find: [*] USB Mass Storage Device Commands --->
I don't seem to find it
Post by Ramtin Amin ***@gmail.com [nuttx]
hello
that is my setup !
I completely removed OTGFS so far, but still no nsh prompt :( even tho I
know my wiring is correct
Post by ***@yahoo.com [nuttx]
CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0
Never edit .config files by hand. That is always a disaster and will
cause you endless problems. Always use the configuration tool.
Sebastien Lorquet sebastien@lorquet.fr [nuttx]
2016-10-04 15:33:34 UTC
Permalink
Hello,

Have a look at your board.h and make sure which GPIOs are connected to uart 3.
Usually there are several choices.

Sebastien
Post by Ramtin Amin ***@gmail.com [nuttx]
hello
that is my setup !
I completely removed OTGFS so far, but still no nsh prompt :( even tho I know my
wiring is correct
__
CONFIG_STM32_USART3=y
CONFIG_USART3_SERIAL_CONSOLE=y
CONFIG_USART3_RXBUFSIZE=128
CONFIG_USART3_TXBUFSIZE=128
CONFIG_USART3_BAUD=115200
CONFIG_USART3_BITS=8
CONFIG_USART3_PARITY=0
CONFIG_USART3_2STOP=0
Never edit .config files by hand. That is always a disaster and will cause
you endless problems. Always use the configuration tool.
Loading...