Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post here first, or if you can't find a relevant section!
WanaGo
Posts: 7
Joined: Fri May 28, 2021 7:26 am

Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by WanaGo »

Hi All

Just got myself a Mikroe M4 Clicker board, it has a STM32F415RGT6 on it, and breaks out to one Click socket. It will arrive on Monday.
ITs like this, but with USB-C rather than Mini-USB like this suggests. They havent updated the doco yet it seems.
https://download.mikroe.com/documents/s ... l-v100.pdf

I have installed the STM32 for Arduino (https://github.com/stm32duino/Arduino_Core_STM32) into the board manager, and have selected the STM32F4 series and Generic F415RGTx board from the menus.

I am just wondering about Serial Ports. I know this has 4 USARTs and 2 UART's, but I don't know what the capability is of it in the Arduino IDE.

Does the USB Port function as a UART, so you can print to Terminal for debugging etc, and then the Click Socket has a UART on it too, so that is another one?
Would the USB be 'Serial' or Serial0, and the Click socket be Serial1 ?

Looking at the Datasheet, it looks like UART4 can be on Pins 14/15 (PA0/PA1) or 51/52 (PC10/PC11), and UART5 can be on 53/54 (PC12/PD2).
Looking at the schematic of this board, PC10/PC11 go to the Click socket for RX/TX and PC12/PD2 are not connected to anything at all. PA0/PA1 for UART4 go to the AN pin of the Click socket, and to an LED, so those are not much help. So it looks like PC10/PC11 is the UART for the pins anyway.

But would the USB port also feature as a UART for the likes of Terminal?

In the Arduino IDE menu, it has a dropdown for the USB Support, saying None, "CDC (Generic 'Serial' supersede U(S)ART)", CDC (no generic 'Serial'), and HID (keyboard and Mouse).
Never used a STM32 before, so never seen options quite like this on a board in the Arduino IDE
If I select the 2nd option, "CDC Generic 'Serial' etc" will that then mean it will be a Serial port? I'm not sure what CDC is.

Sorry if the question is dumb or obvious.

I also assume the USARTs could be used as UART's ? But can they be in the Arduino IDE with this board manager addon? It looks like the only USART pins that are valid on this board in particular go to pins 56/57 which is PB6/PB7, which is on an IO header, so those could be used if supported.

Thanks
by fpiSTM » Fri May 28, 2021 8:27 am
Hi @WanaGo

CDC means Communication Device Class. So it is for VCP (Virtual Com Port).
Select it will enable the USB to have a com port. This will define the SerilaUSB instance which will be mapped on Serial.

For U(S)ART, of course they can all be used. By default only one is defined and mapped to Serial instance (if USB is not selected or does not supersed the default U(S)ART instance).

In your case with generic F415RGTx the default pins used for Serial instance are PA1/PA0 using UART4:
https://github.com/stm32duino/Arduino_C ... #L169-L181

To use other you can read the Wiki:
https://github.com/stm32duino/wiki/wiki ... wareserial
Go to full post
Last edited by WanaGo on Fri May 28, 2021 10:04 am, edited 1 time in total.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by fpiSTM »

Hi @WanaGo

CDC means Communication Device Class. So it is for VCP (Virtual Com Port).
Select it will enable the USB to have a com port. This will define the SerilaUSB instance which will be mapped on Serial.

For U(S)ART, of course they can all be used. By default only one is defined and mapped to Serial instance (if USB is not selected or does not supersed the default U(S)ART instance).

In your case with generic F415RGTx the default pins used for Serial instance are PA1/PA0 using UART4:
https://github.com/stm32duino/Arduino_C ... #L169-L181

To use other you can read the Wiki:
https://github.com/stm32duino/wiki/wiki ... wareserial
WanaGo
Posts: 7
Joined: Fri May 28, 2021 7:26 am

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by WanaGo »

Brilliant, that is very helpful.

Code: Select all

//                      RX    TX
HardwareSerial Serial1(PC11, PC10);
HardwareSerial Serial2(PD2,  PC12); 

void setup() 
{
  Serial.begin(115200);   // Serial for USB VCP
  Serial1.begin(200000);  // Serial1 @ 200000 (200K) Baud
  Serial2.begin(115200);  // Serial2 for Testing @ 115200 Baud
So I have selected "CDC (generic Serial supersede U(S)ART)" - so that will be on 'Serial' - correct? The USB port.
What situation do you use the "CDC (no generic serial)" ? Is this for mapping the USB VCP (SerilaUSB) to a different Serialx instead of Serial? such as doing a

Code: Select all

#define Serial3 SerialUSB
or something?

Thanks again
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by fpiSTM »

No. Just if you don't want SerialUSB mapped to generic Serial name.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by fredbox »

What situation do you use the "CDC (no generic serial)" ?
No generic serial on both the CDC and USART is my normal setting.
This way, you are free to rename the serial ports to your liking.

Here is a GPS example adapted from one of mburnette's projects:

Code: Select all

#define console SerialUSB
// GPS module is connected to USART1
HardwareSerial gpsSerial(PA10, PA9);

// here are the rest of the USARTs for a blue pill board
// you can use either the pin names
// or the hardware port name to define the USART
// HardwareSerial Serial1(USART1);
// HardwareSerial Serial2(USART2);
// HardwareSerial Serial3(USART3);

void setup()
{
  // put your setup code here, to run once:
  console.begin(9600);
  gpsSerial.begin(9600);
}

void loop()
{
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    if (ch == '$')
    {
      char nmea[120];
      uint32_t k = 0;
      do
      {
        while (!gpsSerial.available());
        ch = gpsSerial.read();
        nmea[k++] = ch;
      } while ((ch != '*') && (k < 120));

      if (strstr(nmea, "GPRMC"))
      {
        //console.println(nmea);
        char *p = nmea;
        p = strchr(p, ',') + 1;   // time is at 1st comma
        uint32_t time = atoi(p);
        //console.println(time);
        for (uint32_t n = 0; n < 8; n++)  // date is at 8th comma
        {
          p = strchr(p, ',') + 1;
        }
        uint32_t date = atoi(p);
        //console.println(date);
        char buf[32];
        sprintf(buf, "20%02d/%02d/%02d %02d:%02d:%02d",
                date % 100, ((date % 10000) / 100), date / 10000,
                time / 10000, ((time % 10000) / 100), time % 100);
        console.println(buf);
      }
    }
  }
}
Note that this uses two serial ports with custom names.
WanaGo
Posts: 7
Joined: Fri May 28, 2021 7:26 am

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by WanaGo »

fredbox wrote: Fri May 28, 2021 6:46 pm
What situation do you use the "CDC (no generic serial)" ?
No generic serial on both the CDC and USART is my normal setting.
This way, you are free to rename the serial ports to your liking.
Thanks, this all looks good and as I suspected - Thanks very much.
WanaGo
Posts: 7
Joined: Fri May 28, 2021 7:26 am

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by WanaGo »

Next question is, how do you get this thing to program from the Arduino IDE?

When I plug in the USB, it connects and disconnects over and over every few seconds, going in and out of bootloader mode.
When you connect to it using the Mikroe programmer, it stops doing this, waiting for HEX to be loaded. But how do you do it from the Arduino IDE, as no com port shows up.

I cant see anything of note in the Device Manager, I see no Com port etc.

I've selected HID Bootloader 2.2 as the Programmer, but does it need a special HEX to be loaded to this STM32 to make this work?

I have not yet found anything.
WanaGo
Posts: 7
Joined: Fri May 28, 2021 7:26 am

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by WanaGo »

Compiled the HEX in the Arduino IDE, and wrote it to the board with the Mikroe loader over the USB (I presume using their USB Bootloader), and it loads fine, but does nothing. Not even a Blink sketch on LED on PA1 or PA2 works.

Using the C demo HEX from MikroE, that does work, push the button on the board and the LED blinks in various configurations as you push the button etc. But I cannot get anything compiled with the Arduino IDE to load, when programming the HEX.

I must be missing some context. Is this even possible to do without a special STM programmer?
Is there a USB bootloader that is compatible?
Is there a reason why the HEX loaded with the MikroE loader, doesnt work?

Thanks and sorry for these dumb questions
WanaGo
Posts: 7
Joined: Fri May 28, 2021 7:26 am

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by WanaGo »

Attached is the HEX output from the MikroE sample, vs a edited version of Blink from Arduino.

Anyone have any idea?
Demos.zip
(27.97 KiB) Downloaded 200 times
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE with MikroE M4 Clicker Board - Board Manager

Post by fpiSTM »

You should try to mix what Arduino do and the vendor. The vendor seems providing a Bootloader anyway Arduino IDE is not aware of this BL and so when flashing it probably erase it.
The easiest way is to use an STLink or the internal STM32 Bootloader to flash using DFU but seems Boot0 pin are forced to 0 so it is not usable with this board.
Post Reply

Return to “General discussion”