How to program cz mini STM32F103ZET6 board with Cube or keil IDEs?

Hi,

I bought this board years ago:

and during the past couple days, I was trying to know which IDE I should use to program it.

First of all, the board has two usb ports, the normal and the rs-232. All the work should be with the one using rs-232.

Second, connecting this board to the PC should have this usb driver issue:

And the solution is in this YouTube tutorial:

https://www.youtube.com/watch?v=m1RTEAo6jRI

Next, follow this YouTube video to flash the bin file containing stmduino bootloader to use the board in Arduino IDE.

https://www.youtube.com/watch?v=KurLFm-90w8&t=190s

After that follow my setting in Arduino IDE:

  1. Choose the board type as “Generic STM32F103Z series”
  2. In variant option select “STM32F103ZE”
  3. Upload method, select “Serial”
  4. CPU speed "“72MHz”
  5. Optimized “Smallest”
  6. Select the required COM port
  7. Keep boot1 set to GND
  8. Reset the board
  9. Then program blink example

I used this sketch:

#define LED0 PE0
#define LED1 PE2

void setup() {
  pinMode(LED0, OUTPUT);
  pinMode(LED1, OUTPUT);
}

void loop() {
  digitalWrite(LED0, HIGH);
  digitalWrite(LED1, HIGH);
  delay(1000);
  digitalWrite(LED0, LOW);
  digitalWrite(LED1, LOW);
  delay(1000);
}

But this simple code took a lot of RAM and flash memory:

Sketch uses 15072 bytes (2%) of program storage space. Maximum is 524288 bytes.
Global variables use 3152 bytes (4%) of dynamic memory, leaving 62384 bytes for local variables. Maximum is 65536 bytes.

My question now, is there a better way to get more less memory use ?

I don’t know what bootloader exactly is burned inside the CPU, but in the Arduino IDE I program it with Serial and not with STM32duino.

Hello ABDRHMAN,

This is an Mbed forum (not an Arduino one). So my suggestion is to try the new Keil Studio Cloud and build the following program:

#include "mbed.h"

DigitalOut  led0(PE_0);
DigitalOut  led1(PE_2);

int main()
{
    led0 = 1;
    led1 = 1;
    ThisThread::sleep_for(1s);
    led0 = 0;
    led1 = 0;
    ThisThread::sleep_for(1s);
}

for the following custom target:

    "STM32F103VE": {
        "inherits": ["FAMILY_STM32"],
        "supported_form_factors": ["ARDUINO", "MORPHO"],
        "core": "Cortex-M3",
        "extra_labels_add": ["STM32F1", "STM32F103xE"],
        "config": {
            "clock_source": {
                "help": "Mask value : USE_PLL_HSE_XTAL | USE_PLL_HSI (SYSCLK=64 MHz)",
                "value": "USE_PLL_HSE_XTAL",
                "macro_name": "CLOCK_SOURCE"
            }
        },
        "detect_code": ["0700"],
        "device_has_add": [
            "CAN",
            "SERIAL_ASYNCH",
            "FLASH"
        ],
        "device_has_remove": ["LPTICKER"],
        "device_name": "STM32F103VE"
    }
1 Like

I’m sorry I didn’t ask my question correctly.

My concern is the memory usage in Arduino IDE:

  1. Is that usage of memory normal ?
  2. Is this usage of memory I get in Arduino IDE because of the bootloader ?
  3. Is there a better platform to get less memory usage with the same programming method which is with the Serial connection and not with the ST-LINK programmer because I don’t have one ?

I tried to open a new project but I get there errors:

main.cpp

mbed-os-example-blinky-baremetal
‘mbed.h’ file not foundclang(pp_file_not_found)[6, 10]
Unknown type name 'DigitalOut’clang(unknown_typename)[9, 1]
Unknown type name 'LED1’clang(unknown_typename)[9, 17]
Use of undeclared identifier 'MBED_MAJOR_VERSION’clang(undeclared_var_use)[13, 84]
Use of undeclared identifier 'MBED_MINOR_VERSION’clang(undeclared_var_use)[13, 104]
Use of undeclared identifier 'MBED_PATCH_VERSION’clang(undeclared_var_use)[13, 124]
Use of undeclared identifier 'thread_sleep_for’clang(undeclared_var_use)[18, 9]

I think I have to install the whole Keil environment in the computer.

You can also try the old online compiler at Compiler Deprecation | Mbed

I compiled the program offline for the STM32F103VE target using the GCC_ARM toolchain with the following results:

Total Static RAM memory (data + bss): 1376(+1376) bytes
Total Flash memory (text + data): 17368(+17368) bytes

In case you use the online compiler ( see this for more info) or install the ARM Mbed Studio IDE then you’ll build you program with the ARM toolchain which is a more optimised tool and produces a program requiring less RAM and flash memory.

However, mbed does not report correct data.

Read :

1 Like

OK, I get it, so even if the program is small; like, Blinky, it would take a relatively a fair amount of RAM and program space.

Comparing that with what I get in Arduino IDE, there is not much of a difference.

++ I can program the board in Arduino IDE with Serial connection, but I couldn’t find any platform until now that allow me to program the board with the same RS-232 serial connection.

I installed uVision V5, it’s a nice IDE but I think it requires external programmers to program target boards.

Also, the old online compiler didn’t work for me as it directs me to a page of many boards, which I guess that I should have purchased one of them.

But I got back to the https://studio.keil.arm.com/ I found the problem which didn’t allow me to compile the code in the first time, which is because I didn’t choose a correct supported Target hardware.

Then I chose one which didn’t have the exclamation mark the code compiled but I couldn’t get the size of the flash and RAM.

But anyway I’m happy now with Arduino results.

I have another question:
Is there a way to compile a program in keil studio, uVision, CubeMX or any other IDEs other than Arduino IDE, and then after compiling the code. I can get the final file which should be burned in the microcontroller; like, HEX file in Arduino and Microchip platforms. And then upload the file to the chip with Serial flash programmers; like, Flash Loader Demonstrator ?

Each cortex ARM microcontroller is equipped with a bootloader which is built into the chip during the production. So as explained here you can program your chip over a UART port with an USB to TTL UART converter if you like so. An alternative to the ST-LINK utility is the newer STM32CubeProgrammer available also on Mac and Linux. Of course a programmer is a more convenient piece of hardware and usually it enables also to debug your program.

2 Likes

Thanks for the help and support.

I’m trying to connect over STM32CubeProgrammer, and I get this result:

00:30:18 : RTS low
00:30:18 : DTR low
00:30:19 : Serial Port COM4 is successfully opened.
00:30:19 : Port configuration: parity = even, baudrate = 115200, data-bit = 8, stop-bit = 1.0, flow-control = off
00:30:19 : Activating device: OK
00:30:19 : Board : –
00:30:19 : Chip ID: 0x414
00:30:19 : BootLoader protocol version: 2.2
00:30:19 : Device Read Unprotect requested
00:30:21 : Error: GETID command not acknowledged!
00:30:21 : Reemission of GetID command
00:30:22 : Timeout error occured while waiting for acknowledgement.
00:30:22 : Error: GETID command not acknowledged!
00:30:22 : Reemission of GetID command
00:30:23 : Timeout error occured while waiting for acknowledgement.
00:30:23 : Error: GETID command not acknowledged!
00:30:23 : Error: GETID command not acknowledged!
00:30:23 : Reemission of GetID command
00:30:24 : Timeout error occured while waiting for acknowledgement.
00:30:24 : Error: GETID command not acknowledged!
00:30:24 : Reemission of GetID command
00:30:25 : Timeout error occured while waiting for acknowledgement.
00:30:25 : Error: GETID command not acknowledged!
00:30:25 : Warning: Connection to device 0x414 is lost
00:30:25 : Disconnected from device.

What I’m missing here ?

  • Make sure you use the STM32 chip’s UART1 to connect to the boot loader.
  • Start with lower bit rate, e.g. 9600 bits/s.
  • You can get more info in application note AN3155.
1 Like