NUCLEO-F030R8 support for Arduino_Core_STM32

The official STMicroelectronics Arduino core
User avatar
Rick Kimball
Posts: 1037
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

NUCLEO-F030R8 support for Arduino_Core_STM32

Post by Rick Kimball » Mon Jun 12, 2017 5:29 pm

I took a first pass at adding a new variant with the new combined core. The board I'm using is the NUCLEO-F030R8, it has a smaller cortex-m0 chip, that only has 64k of flash and 8k of ram.

You can find the code here:
https://github.com/RickKimball/Arduino_Core_STM32

If you follow the steps I outlined in this post http://www.stm32duino.com/viewtopic.php ... 172#p29377 ( sorry for hijacking the end of your thread @joelcrouch ), you can see how I created the files in the variant/NUCLEO_F030R8 directory.

To get this to compile, I had to hack up stm32/analog.c to avoid all the DAC functions. This could probably be nicer. I just wanted to throw this out here so others might try it.

One change I made because this chip has such a small amount of ram, I limited the variant to one Serial port. You can conditionally include the Serial1 if you add a define to the board.txt file (-DENABLE_SERIAL1). This change cuts down on the ram usage by not adding the usart buffer used by the second Serial1 port. You probably won't use that most of the time anyhow. Serial is connected to the Nucleo board's VCP and connected to cortex-m0 on USART2 (PA2/PA3). See UM1724 for the pin mapping.

I decided to make the default Oscillator the High Speed Internal one clocked at 48MHz using the PLL. I played around with the value of the internal Oscillator trim value and measured it with a scope. A value of 15 yields the most accurate 48MHz clock for me. You might have to adjust this if your clock speed isn't right.

https://github.com/RickKimball/Arduino_ ... t.cpp#L152

You can measure you clock speed by adding this line below to your setup() function. Then measure PA8 with a scope to find out your actual SYSCLK frequency.

Code: Select all

HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
I also tweaked the ld script so that the the userheap and stack size aren't used to compute the amount of RAM data shown at compile time.

https://github.com/RickKimball/Arduino_ ... pt.ld#L167

I discard the ._user_heap_stack section:
/DISCARD/._user_heap_stack :
This seems to not include that section in the .elf when linking. That prevents the IDE from telling you are using RAM of 1.5k of heap and 512 bytes of stack. However, it does seem to fail when linking if you exceed the min_heap+min_stack size. Not including it in the .elf file gives you a more accurate count of how much RAM memory your application is using. Note: If you are using heap then you will have to mentally add those values to the size shown by the Arduino IDE. The Arduino IDE will also complain if you are using more than 70% of the available RAM.

In all cases, with a small RAM chip like this, you have to keep your eye on how much RAM you are using.

If you give this a try let me know. Overall it isn't that bad a process. Although, the jury is still out if the features work. I need to do a lot more testing.
-rick

fpiSTM
Posts: 224
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by fpiSTM » Mon Jun 12, 2017 9:36 pm

Hi Rick,

Thanks for your feedback.
I've done a pull request to fix when DAC is not available:
https://github.com/stm32duino/Arduino_C ... 32/pull/28

I've also create the variant for the Nucleo F030R8:
https://github.com/stm32duino/Arduino_C ... 32/pull/29

One strange things, the mount point of my board is named "NODE_F030R8".

About your variant, in PeripheralPins.c, it is best to keep only one pin definition for the same feature (by commenting):

Code: Select all

    {PA7,   TIM14,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM14, 1, 0)},  // TIM14_CH1
    {PA7,   TIM17,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM17, 1, 0)},  // TIM17_CH1
    {PA7,   TIM1,   STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 1, 1)},  // TIM1_CH1N
    {PA7,   TIM3,   STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 2, 0)},  // TIM3_CH2
it is the first one in the list which will be used. here PA7 with TIM14, other will be ignored.

I removed UART_EMUL_RX/TX as I think it is not needed.

I probably add the switch for Serial1.
I do not check your update for linker script but you probably better know than me ;)

FYI, I've planned to include the script genpinmap in a gui to create the variant skeleton and update files with user entry.
It will still some update to perform manually but it should help, I hope :roll:

User avatar
Rick Kimball
Posts: 1037
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by Rick Kimball » Tue Jun 13, 2017 2:26 pm

fpiSTM wrote:...
One strange things, the mount point of my board is named "NODE_F030R8".
Maybe we should change the massStorageCopy application to try the NODE_XXXX first and if it isn't found then look for NUCLEO?

fpiSTM wrote:...
About your variant, in PeripheralPins.c, it is best to keep only one pin definition for the same feature (by commenting):

Code: Select all

    {PA7,   TIM14,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM14, 1, 0)},  // TIM14_CH1
    {PA7,   TIM17,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM17, 1, 0)},  // TIM17_CH1
    {PA7,   TIM1,   STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1, 1, 1)},  // TIM1_CH1N
    {PA7,   TIM3,   STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 2, 0)},  // TIM3_CH2
it is the first one in the list which will be used. here PA7 with TIM14, other will be ignored.
How do you go about picking the proper timer? It seems fairly arbitrary. I noticed in your version of PeripheralPins.c in the case above you picked the last PA7 entry using TIM3_CH2 and commented out all the others.
fpiSTM wrote:...
FYI, I've planned to include the script genpinmap in a gui to create the variant skeleton and update files with user entry.
It will still some update to perform manually but it should help, I hope :roll:
I'm fine with the command line stuff. I would think most people attempting this activity would also not care. I wouldn't waste time with a gui for it.
-rick

fpiSTM
Posts: 224
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by fpiSTM » Tue Jun 13, 2017 2:36 pm

Rick Kimball wrote: Maybe we should change the massStorageCopy application to try the NODE_XXXX first and if it isn't found then look for NUCLEO?
Too much specific, I think. If one other guy have also a different name. I'm wondering why you do not have the same. Maybe you rename it and you forgot :)
Rick Kimball wrote: How do you go about picking the proper timer? It seems fairly arbitrary. I noticed in your version of PeripheralPins.c in the case above you picked the last PA7 entry using TIM3_CH2 and commented out all the others.
I'm aligned with the mbed one else based on the documentation I try to set it as bestas possible. But it is fairly customizable so...
https://developer.mbed.org/users/mbed_o ... eralPins.c
Rick Kimball wrote: I'm fine with the command line stuff. I would think most people attempting this activity would also not care. I wouldn't waste time with a gui for it.
when I said a gui it was a very "light" one just to get user inmput: variant name, cubemx path, .... and also package the genpinamp script as a standalone binary. (avoid the user to install python)

User avatar
Rick Kimball
Posts: 1037
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by Rick Kimball » Tue Jun 13, 2017 2:57 pm

fpiSTM wrote:
Rick Kimball wrote: Maybe we should change the massStorageCopy application to try the NODE_XXXX first and if it isn't found then look for NUCLEO?
Too much specific, I think. If one other guy have also a different name. I'm wondering why you do not have the same. Maybe you rename it and you forgot :)
Are you running ubuntu 16.04 lts ? Are you using the ubuntu desktop? I actually run lxde. I looked at my disk settings and I have it setup to automount stuff without intervention. It picked the name using the LABEL provided by the mass storage device

If is do an lsusb on the device it shows up strangely:
lsusb -d 0483: -v | head -40 wrote:
Bus 001 Device 077: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2 ?
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x0483 STMicroelectronics
idProduct 0x374b ST-LINK/V2.1 (Nucleo-F103RB)
bcdDevice 1.00
iManufacturer 1 STMicroelectronics
iProduct 2 STM32 STLink
iSerial 3 0675FF534951775087124912
For some reason it thinks it is a F103RB .. and it certainly isn't it is a NUCLEO-F103RB

If I look at the nucleo as a disk its label is "NUCLEO" that is what Ubuntu uses as a mount point name:
gparted_nucleo.png
gparted_nucleo.png (89.66 KiB) Viewed 373 times
I guess it really doesn't matter to me I can change the entry in the boards.txt file. For newbies, it is just going to fail and they aren't going to know why. Even on my VM setup it shows up as NUCELO (Windows 7 hosted on ubuntu 16.04 running virutal box) It just seems strange how your system figures out it is a NUCLEO-030R8 when none of the info available to it give it any hint that it is that.
Last edited by Rick Kimball on Tue Jul 11, 2017 8:08 pm, edited 1 time in total.
-rick

User avatar
Rick Kimball
Posts: 1037
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by Rick Kimball » Tue Jun 13, 2017 3:11 pm

fpiSTM wrote:
Rick Kimball wrote: How do you go about picking the proper timer? It seems fairly arbitrary. I noticed in your version of PeripheralPins.c in the case above you picked the last PA7 entry using TIM3_CH2 and commented out all the others.
I'm aligned with the mbed one else based on the documentation I try to set it as bestas possible. But it is fairly customizable so...
https://developer.mbed.org/users/mbed_o ... eralPins.c
So does UM1724 come into play? It talks about specific timers and channels for specific pins. UM1724 (p. 38) describes PA7 as using TIM17 channel 1:
um1724.png
um1724.png (55.53 KiB) Viewed 370 times
Whereas mbed defines PA7 as TIM3 channel 2

Code: Select all

{PA_7,  PWM_3,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM3,  2, 0)},  // TIM3_CH2
Who uses the documentation in UM1724?
-rick

fpiSTM
Posts: 224
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by fpiSTM » Tue Jun 13, 2017 3:31 pm

Same for lsub:

Code: Select all

$ lsusb -d 0483: -v | head -40 

Bus 004 Device 014: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x0483 STMicroelectronics
  idProduct          0x374b ST-LINK/V2.1 (Nucleo-F103RB)
  bcdDevice            1.00
  iManufacturer           1 STMicroelectronics
  iProduct                2 STM32 STLink
  iSerial                 3 0672FF485550755187054539
  bNumConfigurations      1
For the label I have well "NODE_F030R8" that's why I have it as mount point name. As you have "NUCLEO" it uses "NUCLEO". That is normal what I try to understand is why you have this label.
partition_F030R8.png
partition_F030R8.png (29.26 KiB) Viewed 368 times

fpiSTM
Posts: 224
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by fpiSTM » Tue Jun 13, 2017 3:34 pm

For this case I think it is a user/developer choice. It make sense to follow the UM.
It provide a pins mapping configuration but nothing stops user to use one other timer.

User avatar
Rick Kimball
Posts: 1037
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by Rick Kimball » Tue Jun 13, 2017 4:04 pm

fpiSTM wrote: For the label I have well "NODE_F030R8" that's why I have it as mount point name. As you have "NUCLEO" it uses "NUCLEO". That is normal what I try to understand is why you have this label.
I also try and understand why you have NODE_F030R8 : ) Maybe you a newer version of the board than me? My board is marked "mb1136 c-01". Is your board perhaps "mb1136 c-02" ?

The label comes from the boot sector as provided by the mass storage device. The nucleo firmware providing the boot sector. I don't see anything with the characters 'NODE_F030R8'. I do see "MBED" and "NUCLEO"

Code: Select all

$ od -t x1 -c -A x   </dev/sdd | head -100 
000000  eb  3c  90  4d  53  44  30  53  34  2e  31  00  02  08  01  00
       353   < 220   M   S   D   0   S   4   .   1  \0 002  \b 001  \0
000010  02  20  00  c8  00  f8  03  00  01  00  01  00  00  00  00  00
       002      \0 310  \0 370 003  \0 001  \0 001  \0  \0  \0  \0  \0
000020  00  00  00  00  00  01  29  74  19  02  27  4d  42  45  44  20
        \0  \0  \0  \0  \0 001   )   t 031 002   '   M   B   E   D    
000030  20  20  20  44  4e  44  46  41  54  31  32  20  20  20  00  00
                     D   N   D   F   A   T   1   2              \0  \0
000040  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
        \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
000200  f8  ff  ff  ff  ff  ff  00  00  00  00  00  00  00  00  00  00
       370 377 377 377 377 377  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
000210  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
        \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
000800  f8  ff  ff  ff  ff  ff  00  00  00  00  00  00  00  00  00  00
       370 377 377 377 377 377  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
000810  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
        \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
000e00  4e  55  43  4c  45  4f  20  20  20  20  20  28  00  00  00  00
         N   U   C   L   E   O                       (  \0  \0  \0  \0
000e10  00  00  00  00  00  00  41  8e  bb  32  00  00  00  00  00  00
        \0  \0  \0  \0  \0  \0   A 216 273   2  \0  \0  \0  \0  \0  \0
000e20  44  45  54  41  49  4c  53  20  54  58  54  01  00  00  00  00
         D   E   T   A   I   L   S       T   X   T 001  \0  \0  \0  \0
000e30  21  00  32  bb  00  00  dc  83  bb  30  02  00  2e  00  00  00
         !  \0   2 273  \0  \0 334 203 273   0 002  \0   .  \0  \0  \0
000e40  4d  42  45  44  20  20  20  20  48  54  4d  01  00  00  00  00
         M   B   E   D                   H   T   M 001  \0  \0  \0  \0
000e50  21  00  32  bb  00  00  dc  83  bb  34  03  00  00  02  00  00
         !  \0   2 273  \0  \0 334 203 273   4 003  \0  \0 002  \0  \0
000e60  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
        \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
-rick

User avatar
Rick Kimball
Posts: 1037
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: NUCLEO-F030R8 support for Arduino_Core_STM32

Post by Rick Kimball » Tue Jun 13, 2017 4:09 pm

fpiSTM wrote:For this case I think it is a user/developer choice. It make sense to follow the UM.
It provide a pins mapping configuration but nothing stops user to use one other timer.
So in your board mappings you are following the same as how mbed is configured. And my first pass at the table was just to have it default to the first entry in the list as provided by the genpinmap thing. Yes?

So is it to be um1724 mapping? If that is the case, couldn't we have genpinmap pick the right timer and channel?
-rick

Post Reply