STM32 core support for Arduino

lsmod
Sat Jan 19, 2019 3:30 pm
Moderator note: moved from “General” to STM Core

Today is the first time i have the time to continue with my STM32 stuff.
That’s the reason why i am impatient with the results of doing something. ;)

I could not answer in the last thread viewtopic.php?f=45&t=4301&start=50#p52463 because it is locked now ! :shock:
This is a strange forum! :?
My relevant thread post was left unanswered viewtopic.php?f=45&t=4301&start=50#p52402.
So there will be no solution for the problem of the thread …

Currently i try to follow the tips for the future use of Arduino with this core https://github.com/stm32duino/Arduino_Core_STM32.
So this will the theme of this thread and i hope it will not be locked too!

All the other approaches for the development eat up to much time for me.
For example i cannot understand why there are only complicate examples for libopencm3 featuring dot-matrix displays, but when i want to use an stupid standard 16×2 LCD i have to convert or write my own library first. :(

Or the posted example https://medium.com/coinmonks/juggling-s … f6820dc808, which use complicate multitasking for easy sensor readings.
In my eyes this are really special cases – i see the standard case for an µC doing linear things like reading an sensor and pushing the data to an interface or data medium.
That’s the reason i want an easy access to libraries for using an LCD-display or writing with FAT to an SD-card.

When I want to do really complex things i will use an Orange-Pi running Linux for $15, or for $25 with an quad core 64 bit machine – then i don’t need an desktop PC any more. ;)
So i don’t have to think or master the multitasking – it’s already perfect with Linux!

That’s the way i am thinking about using the hardware …

Is this the right forum place here to discuss this “Arduino core” https://github.com/stm32duino/Arduino_Core_STM32 ?


lsmod
Sat Jan 19, 2019 4:11 pm
The installation works as descripted in https://github.com/stm32duino/wiki/wiki/Getting-Started. :)
(This will install 896,2 MB stuff.)

Fine. Trying my first steps again with the new core:

Compiling my LCD-example viewtopic.php?f=28&t=4500#p52248 only works after commenting out
enableDebugPorts();


lsmod
Sat Jan 19, 2019 4:30 pm
Besides – manually flashing the blink program with 10576 Bytes is working too.

Now back again to the question of using USB and to get an 8 bit GPIO port access …

Have a look at the 8 bit GPIO first.
mrburnette’s hint https://github.com/rust-embedded/discov … rs/rtrm.md shows no answer,
so i searched for the HAL GPIO definitions and found this nice document https://simonmartin.ch/resources/stm32/ … eRTOS).pdf,
but it seems not to describe the correct HAL. :(

So i tried this example with more success https://www.microcontroller-project.com … oller.html
I connected 4 blue LED’s with PB4 – PB7 over 470 ohm to +5V.

Then i compiled and flashed this Arduino source:
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7, GPIO_PIN_RESET);

/*Configure GPIO pins : Pin1_Pin Pin2_Pin */
GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

void setup() {
MX_GPIO_Init();
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
#define WAIT 250

GPIOB->ODR = ~0x0010; //Write to port-b
HAL_Delay(WAIT);
GPIOB->ODR = ~0x0020; //Write to port-b
HAL_Delay(WAIT);
GPIOB->ODR = ~0x0040; //Write to port-b
HAL_Delay(WAIT);
GPIOB->ODR = ~0x0080; //Write to port-b
HAL_Delay(WAIT);
GPIOB->ODR = ~0x0000; //Write to port-b
HAL_Delay(WAIT);

digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}


lsmod
Sat Jan 19, 2019 6:44 pm
In ../arduino15/packages/STM32/hardware/stm32/1.4.0/cores/arduino/stm32/PinAF_STM32F1.h i found

static inline void pinF1_DisconnectDebug(PinName pin)
{
/** Enable this flag gives the possibility to use debug pins without any risk
* to lose traces
*/
#ifndef STM32F1_LOCK_DEBUG
// Enable AFIO clock
__HAL_RCC_AFIO_CLK_ENABLE();

// Disconnect JTAG-DP + SW-DP signals.
// Warning: Need to reconnect under reset
if ((pin == PA_13) || (pin == PA_14)) {
__HAL_AFIO_REMAP_SWJ_DISABLE(); // JTAG-DP Disabled and SW-DP Disabled
}
if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
__HAL_AFIO_REMAP_SWJ_NOJTAG(); // JTAG-DP Disabled and SW-DP enabled
}
#else
UNUSED(pin);
#endif /* STM32F1_FORCE_DEBUG */
}


lsmod
Sat Jan 19, 2019 7:14 pm
Up to now i see no way to use the USB interface as usb serial.

None of the includes are working :(
//#include <USBComposite.h>
#include <usbd_hid_composite.h>

USBCompositeSerial CompositeSerial;
uint32_t counter = 0;

void setup()
{
CompositeSerial.registerComponent();
USBComposite.begin();
delay(2000);
}

void loop()
{
CompositeSerial.print("Counter: ");
CompositeSerial.print(counter);
CompositeSerial.println(" - Hello World!");
counter++;
delay(500);
}


BennehBoy
Sat Jan 19, 2019 11:48 pm
For CDC you’ll need to get the github dev version, 1.40 release doesn’t include it.

mrburnette
Sun Jan 20, 2019 2:45 am
[BennehBoy – Sat Jan 19, 2019 11:48 pm] –
For CDC you’ll need to get the github dev version, 1.40 release doesn’t include it.

Ray’s comments:
As noted by many members, I am vocal about making the move from Roger’s (LeafLab’s abandoned Maple core) to the official STM32 core. This is my long-term proposition… but I realize that this will not be painless for Blue Pill or Maple Mini users as the current (19-01-2019) master git branch is missing some serious serial-USB code.

IMO, the official core will work best with official SBC hardware: Discovery boards or Nucleo boards. The Official Core also works best with the ST-Link tool. Obviously, those members that are only into the $2 Blue Pills are not going to be happy. Sorry, you have been living on borrowed time for a while… recently there have been reports of Blue Pills with relabled uC (10K SRAM, 32K flash) … therefore, I suspect the glut (suplus) of STM32F103C8T6 is drying-up.

Back many years ago in the Arduino.cc forum, I preached about purchasing one (1) Official board: UNO, Nano, etc. Having that official board helps to diagnose potential clone board h/w issues. Being able to self-test your code on your own official board is critical to continued mental health. The same is true of Arduino on the STM core… one Official board is critically important as a test platform. Deploy on cheap, clone hardware if you want but purchase a Discovery or Nucleo board – you will be glad you did… it is an investment just like a good DVM.

Ray


lsmod
Sun Jan 20, 2019 9:16 am
[BennehBoy – Sat Jan 19, 2019 11:48 pm] –
For CDC you’ll need to get the github dev version, 1.40 release doesn’t include it.

Thank’s for the tip – but how do i get it?

I have the problem to be confused by the mass of different solutions, dependent on different cores and MCU / boards.
Of course it is no problem to get familiar with this when you work with this stuff every day or after years.
But when you have some experience and less time it is really hard to understand what you are writing or what you mean.
So first i had to google what the meaning of CDC is …

[mrburnette – Sun Jan 20, 2019 2:45 am] –
… current (19-01-2019) master git branch is missing some serious serial-USB code.

IMO, the official core will work best with official SBC hardware: Discovery boards or Nucleo boards.
The Official Core also works best with the ST-Link tool.
Obviously, those members that are only into the $2 Blue Pills are not going to be happy.

Back many years ago in the Arduino.cc forum, I preached about purchasing one (1) Official board: UNO, Nano, etc.

It is still not clear what is included in a core for which type of MCU ?

The Nucleo board seems to be selled with different MCU’s:

Discovery board -> STM32F407VG
Nucoleo board -> STM32F030R8 or STM32F103RB https://www.st.com/en/ecosystems/stm32- … tId=SC2003

So when Nucleo boards are supported and STM32F103RB is on this boards, i don’t understand why an STM32F103C8T6 is not supported?

I am owner of an ST-Link but did not work with it so far, because i am doing basic tests.
I want to know if the UART can be used – so why i should not flash over it?
Another new hardware will cause new problems – then my patience will be stressed aditionally. ;)
On the other hand you have seen that i am on the way to solve the problem with the serial upload. 8-)

Yes – it is always a good idea to buy things in a good quality.
But there is really a big difference in price and so it is acceptable to buy direct 3 instead of 1 – so when the hardware is suspect i just change it.
Besides – the Nucleo boards are big and not so handy.


BennehBoy
Sun Jan 20, 2019 10:07 am
https://github.com/stm32duino/wiki/wiki … repository

BennehBoy
Sun Jan 20, 2019 10:44 am
[mrburnette – Sun Jan 20, 2019 2:45 am] –
but I realize that this will not be painless for Blue Pill or Maple Mini users as the current (19-01-2019) master git branch is missing some serious serial-USB code.

CDC is in the base github version as of about a week ago. So it’s moving along nicely, Frederic is mulling over how best to incorporate a DFU upload and there are PR’s in that make this possible already – just a case of deciding which bootloader would be best… there’s a very wide gamut of boards & ARM cores to cover so perhaps this will start off with the already available ones, ie BL2 & HID…

[mrburnette – Sun Jan 20, 2019 2:45 am] –
As noted by many members, I am vocal about making the move from Roger’s (LeafLab’s abandoned Maple core) to the official STM32 core.

I think it’s a good stance, the more people switch to that core, the bigger the snowball becomes, and the faster the pace of development via contributors.

For F4, it’s really nice right now with a strong base of peripheral support – mainly basic support for core Arduino, but open to development from other with more exotic use cases and wanting to expose the more capable hardware. It would be great to get some of the regulars here along on the ride, there’s some incredible talent that can be brought to bear and given that it’s LL & HAL I guess not impossible to breath life into some great functionality.

As it stands I’m continuing my learning journey to make the jump from a tinkerer making projects that run on the core, to someone who can help move the core along, a slow but enjoyable process.


lsmod
Sun Jan 20, 2019 12:20 pm
[BennehBoy – Sun Jan 20, 2019 10:44 am] –
CDC is in the base github version as of about a week ago.

Then this feature is brand new!
It’s not surprising that it is not running, when it is only in the development path.

There was a stupid configuration error for serial upload. :oops:
It must be /dev/ttyUSB0 and not /dev/ttyS0.
So this feature is working correct with /dev/ttyUSB0.
stmflash32 could be a newer version in the repository.

The UART1 as serial is working within the code. :D

But i could not find a workaround to activate PB4 as GPIO port. :(
I have no idea which function must be called to deactivate JTRST ?

Is there any stuff to work with the RTClock?
#include <RTClock.h> is failing to compile and i don’t find any file with rtclock in the STM32 subfolders …
There is a description with naming some examples:
* https://www.st.com/content/ccc/resource … 025071.pdf
* https://www.st.com/content/ccc/resource … 207941.pdf
Is there any place where the examples can be downloaded?

I could find ../.arduino15/packages/STM32/hardware/stm32/1.4.0/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c


BennehBoy
Sun Jan 20, 2019 1:28 pm
RTC library

https://github.com/stm32duino/STM32RTC

What are you trying to do with PB4? It is GPIO by default on STM core for bluepill.

Default SPI for bluepill on STM core is PA7 MOSI, PA6 MISO, PA5 SCLK (wrote this since PB4 is alternate pin for MISO)


lsmod
Sun Jan 20, 2019 1:45 pm
[BennehBoy – Sun Jan 20, 2019 1:28 pm] –
https://github.com/stm32duino/STM32RTC

What are you trying to do with PB4? It is GPIO by default on STM core for bluepill.

Thanks – i will try to make an example for using RTC.

I mention the direct port access viewtopic.php?f=48&t=4521#p52582
It is working except PB4.
But now i have an workaround when i make an explicit pinmode before – then it is working.
void setup() {
pinMode(PB4, OUTPUT);

MX_GPIO_Init();
pinMode(LED_BUILTIN, OUTPUT);
}


BennehBoy
Sun Jan 20, 2019 1:48 pm
Good to know.

Perhaps look into the pinmode handling in the core to see exactly what it does – might be less overhead.


lsmod
Sun Jan 20, 2019 1:53 pm
[BennehBoy – Sun Jan 20, 2019 1:28 pm] –
https://github.com/stm32duino/STM32RTC

Later i will have a closer look

RTC_Tests:15:22: error: STM32RTC.h: No such file or directory
#include <STM32RTC.h>
^
compilation terminated.
exit status 1
STM32RTC.h: No such file or directory


BennehBoy
Sun Jan 20, 2019 2:18 pm
You need to download that library and put it in your user libraries folder…

lsmod
Sun Jan 20, 2019 5:27 pm
[BennehBoy – Sun Jan 20, 2019 2:18 pm] –
You need to download that library and put it in your user libraries folder…

Yes – thanks a lot!
The examples are added to the tree and are compiled without problems.


zoomx
Mon Jan 21, 2019 1:56 pm
[mrburnette – Sun Jan 20, 2019 2:45 am] –
Back many years ago in the Arduino.cc forum, I preached about purchasing one (1) Official board: UNO, Nano, etc. Having that official board helps to diagnose potential clone board h/w issues.

Sometimes having a clone helps to diagnose an official board issue.

The 16u2 mounted as USB-serial adapter has an issue when you open the COM port from a PC without resetting the UNO: depending on baud on PC you get a character that is not sent by the Atmega328.

Using 128000 the character is an F0
Using 256000 the character is a zero
Using 38400 is an FF
Using 9600 you don’t get any character.

This is due to a small pulse that is interpreted as a valid character.

The CH340x that is used on clones doesn’t have this issue so I was able to put my eyes on the 16u2. On the other hand clones sometimes have electrical problems due to the LDO.
If you use the Hoodloader bootloader the issue is not present.


fpiSTM
Mon Jan 21, 2019 7:27 pm
[lsmod – Sat Jan 19, 2019 4:11 pm] –
(This will install 896,2 MB stuff.)

Right, as you install the arm gcc toolchain and also the Arm CMSIS.
395M arm-none-eabi-gcc/
262M CMSIS/

[lsmod – Sat Jan 19, 2019 4:11 pm] –
Compiling my LCD-example viewtopic.php?f=28&t=4500#p52248 only works after commenting out
enableDebugPorts();

lsmod
Tue Jan 22, 2019 9:31 am
[fpiSTM – Mon Jan 21, 2019 7:27 pm] –
Right, as you install the arm gcc toolchain and also the Arm CMSIS.
395M arm-none-eabi-gcc/
262M CMSIS/

There was no possibility to differ this in the board manager.
The mapel core seems to be uninstalled.

I will try out the development version next to test serial USB functionality …

[fpiSTM – Mon Jan 21, 2019 7:27 pm] –
enableDebugPorts();

BennehBoy
Tue Jan 22, 2019 10:18 am
[lsmod – Tue Jan 22, 2019 9:31 am] –
The problem is solved, but it is still not clear what is the correct function name for this core?

There is no function for this, the debug ports are enabled as standard. Roger’s core disables them as standard to prevent people not being able to use them as GPIO, this is because mainly Roger’s core is used on Maple Mini, Bluepill or Blackpill where people are using a bootloader and not SWD.


fpiSTM
Tue Jan 22, 2019 10:30 am
First goal of this core is to be the most close to Arduino API.
I try to extend/provide access to cover the most features in an Arduino style to be as simple as possible.
Now, CMSIS, HAL and LL are fully available and advanced user can do their own implementation to use all capabilities.

Boards manager works the same for other core, you are not warned about what are installed. Readme.md provides those informations. In any case, it remove other cores installed.
https://github.com/stm32duino/Arduino_C … troduction

About function naming, do not try to compare both core, goal is not the same for each core.
About accessing 8 bits, you have all the clue to do it as you already manage to use register access.
About RTC, yes there is much more options. As already said before, goal is to provide simple and close API than Arduino. Still some required feature to add (ex: use backup register to restore time after reset).
configForLowPower(Source_Clock source)


Leave a Reply

Your email address will not be published. Required fields are marked *