Playing with Weact STM32H562RGT6

Post here first, or if you can't find a relevant section!
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Playing with Weact STM32H562RGT6

Post by ag123 »

Playing with Weact STM32H562RGT6
https://github.com/WeActStudio/WeActStu ... _CoreBoard
this board is a little pricy, I'd guess it is due to the new chip which is a Cortex M33
https://www.aliexpress.com/item/1005007502799023.html

this board works nicely out of the box in Arduino IDE 2.x (I'm using Arduino IDE 2.3.4)
and using stm32duino version 2.9.0 - current version
https://github.com/stm32duino/Arduino_Core_STM32

Weact installed a default sketch in the chip which is basically a blinky. One can backup the flash like the 1st 1MB (actually 64k would do for now after I examined the exported bin) of flash if one wants to keep it.

flashing the sketch using USB DFU works just fine. Initially, it didn't work for me, I originally mistook it to be related to those secure boot stuff (new in these new soc). It turns out incorrect, simply flip the usb c cable over and it works !
updating using dfu-util can be done via
https://dfu-util.sourceforge.net/

Code: Select all

dfu-util -a 0 -s 0x8000000 -D sketch.bin
it may be necessary to compile dfu-util from source if that distributed with the core doesn't work.

the sketch can be exported using Sketch > export compiled binary, and it'd be in the sketch folder in the build directory.
then one can use the usual tools or with STM32Cube programmer that'd be integrated in the ide.
it is necessary to press the boot and reset buttons as usual
- press both boot0 and reset
- hold boot0 release reset
- release boot0 1 secs later

if compiled with -O2 optimizations, this is a pretty fast chip, the Wheatstone benchmark looks like this
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3075.36 millisec
C Converted Single Precision Whetstones:325.17 Mflops
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3075.36 millisec
C Converted Single Precision Whetstones:325.17 Mflops
spec sheets says it is 250 Mhz
https://www.st.com/en/microcontrollers- ... 562rg.html
I think the apparent high floating point speeds > 1 fp per clock is due to vector SIMD computations

This chip has a lot of sram and flash !
I'd guess one can just go ahead and make fat binaries -O2 etc :lol:
it can probably run pretty big RTOS and can use things like malloc() to do memory management, I'd guess.
select usb-cdc-serial for the built
Attachments
sketch.zip
blink and whetstone sketch used to try out the board
(3.68 KiB) Downloaded 159 times
Last edited by ag123 on Sat Jan 04, 2025 7:28 am, edited 2 times in total.
GonzoG
Posts: 503
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

Re: Playing with Weact STM32H562RGT6

Post by GonzoG »

I've played with it few month back. It's a nice little and quite powerful board.
But there's one issue with G4, H5, and probably few more series. ADC initialization is very slow and analogRead() is 2-3 times slower than on F411.
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: Playing with Weact STM32H562RGT6

Post by ag123 »

reading the data sheets
https://www.st.com/resource/en/datashee ... h562rg.pdf
and ref manuals
https://www.st.com/resource/en/referenc ... ronics.pdf

it certainly feel quite different from the 'older' F4 families, this soc like the high dense f4xx and h7xx is cram packed with features and pheriperials.
quite notable is the FMC and the octo-spi psram feature, I'd guess it may be possible to use spi psram with this and that expands memory significantly.

the smaller features are like the Digital temperature sensor that converts the temperature into a square wave, whose
frequency is proportional to the temperature. The plain old analog temperature sensor is there too.

tried playing with the digital temperature sensor

Code: Select all

void setup() {
  // clock the DTS
  __HAL_RCC_DTS_CLK_ENABLE();
  // pclk is running at 250 Mhz, internal freq must be < 1 Mhz for calibration
  // set HSREF_CLK_DIV to 0x7f (127)
  DTS->CFGR1 |= DTS_CFGR1_HSREF_CLK_DIV_Msk;
  // enable digital temperature sensor  
  DTS->CFGR1 |= DTS_CFGR1_TS1_EN;
  // improve accuracy by using 5 periods
  DTS->CFGR1 |= 5 << DTS_CFGR1_TS1_SMP_TIME_Pos;

}

float readtemp() {
  // wait for TS1_RDY
  while(! DTS->SR & DTS_SR_TS1_RDY) delay(1);
  // clear data register
  DTS->DR = 0;
  // start measuremennt
  DTS->CFGR1 |= DTS_CFGR1_TS1_START;
  // wait for TS1_RDY
  while(! DTS->SR & DTS_SR_TS1_RDY) delay(1);
  // read the measurement value
  int32_t ts1_mfreq = DTS->DR & 0xfffful;
  
  /* from ref manual rm0481
  T = T_0 + (( F_PCLK ⁄ TS1_MFREQ ) * TS1_SMP_TIME - 100 * TS1_FMT0 ) / TS1_RAMP_COEFF
  */
  float t0 = 30.0;
  float f_pclk = 250e6;
  int32_t ts1_fmt0 = DTS->T0VALR1 & 0xfffful;
  int32_t ts1_ramp_coeff = DTS->RAMPVALR & 0xfffful;
  int16_t ts1_smp_time = 5;

  Serial.print("ts1_mfreq ");
  Serial.println(ts1_mfreq);

  Serial.print("ts1_fmt0 ");
  Serial.println(ts1_fmt0);

  Serial.print("ts1_ramp_coeff ");
  Serial.println(ts1_ramp_coeff);

  float t = t0 + (( f_pclk / ts1_mfreq) * ts1_smp_time - 100 * ts1_fmt0) / ts1_ramp_coeff;

  return t;
}

void loop() {
	float t = readtemp();
	Serial print("temp: ");
	Serial.println(t);
	delay(10000);
}
the build works just well no errors.
but no luck, I'm getting zeros for all the DTS register reads, (edit: see below)
apparently there are 2 banks of registers secure and non-secure
the DTS symbol points to the non secure bank of DTS registers in the include file stm32h562xx.h.
i'm not too sure if it is due to pclk being too fast as ref manual states that during calibration the internal frequency of the DTS sensor needs to be less than 1 Mhz, pclk = sysclk = 250 Mhz !, so i set the prescaler to 127 which is the largest divisor possible.

other things that I did not check could be that some peripherals are not clocked, oh well, I'd take a break for now :)

footnote: an interesting thing I noted is the APB1,2,3 runs at 250 Mhz ! it is probably among the fastest APB speeds seen vs the 'older' stm32 chips e.g. F103, F4 etc. these speeds are interesting, but that a long enough wire off a pin would literally make that an antenna, this is running at vhf frequencies higher than typical FM radio bands.

---
edit: ok found it

Code: Select all

__HAL_RCC_DTS_CLK_ENABLE();
now it works pretty well !
Loops:10000, Iterations:1, Duration:3078.15 millisec
C Converted Single Precision Whetstones:324.87 Mflops
ts1_mfreq 346
ts1_fmt0 7075
ts1_ramp_coeff 1895
Temp: 37.94
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3078.16 millisec
C Converted Single Precision Whetstones:324.87 Mflops
ts1_mfreq 347
ts1_fmt0 7075
ts1_ramp_coeff 1895
Temp: 36.84
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3078.16 millisec
C Converted Single Precision Whetstones:324.87 Mflops
ts1_mfreq 346
ts1_fmt0 7075
ts1_ramp_coeff 1895
Temp: 37.94
pause
higher temperatures as it is on the die and that after all I'm running a whetstone benchmark

I've attached the updated sketch with DTS codes, enhanced it a little so that you can pause / resume the scrolling by sending any keystrokes in the console. select usb-cdc-serial for the built. Bin file is included in the zip file.
Attachments
sketch1.zip
blink, whetstone and DTS sketch used to try out the board
(33.08 KiB) Downloaded 216 times
lesept
Posts: 5
Joined: Tue May 27, 2025 2:34 pm

Re: Playing with Weact STM32H562RGT6

Post by lesept »

Hi
I'm new to this board but thanks to your posts, I have succeeded in using it.
Image

However, I have a problem with the serial monitor in the Arduino IDE: sometimes it works sometimes not. More precisely, it seems that sometimes the board is connected to a COM port (I'm on Windows 10) sometimes not.

Here is what I do:
- Compile the sketch (Sketch > Export compiled binary) and find the folder with the bin file
- Set the board in DFU mode (connect while pushing B0 middle button)
- Flash the binary using

Code: Select all

dfu-util -a 0 -s 0x8000000 -D sketch.bin
- Disconnect and reconnect the board (or push reset button)

I have seen also that, to have the output displayed in the serial monitor of the IDE, I need to use some compilation options:
- USB support (if available): CDC (generic 'Serial' supersede U(S)ART)
- U(S)ART support: Unabled (Generic 'Serial')

Is this correct?

When I do this with the code @ag123 has provided, then when I reconnect the board after flashing it, it connects to port COM10 automatically, and I can see the output in the serial monitor.

But, when I use another bigger sketch (474784 bytes instead of 47000) then I don't see the COM port. Is it related to the size of the binary? Should I change the upload address?
Thanks for your help
lesept
Posts: 5
Joined: Tue May 27, 2025 2:34 pm

Re: Playing with Weact STM32H562RGT6

Post by lesept »

Some more information.

Here is the output from dfu-util:
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Warning: Invalid DFU suffix signature
A valid DFU suffix will be required in a future dfu-util release
Cannot open DFU device 17e9:6013 found on devnum 3 (LIBUSB_ERROR_NOT_FOUND)
Opening DFU capable USB device...
Device ID 0483:df11
Device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 011a
Device returned transfer size 1024
DfuSe interface name: "Internal Flash "
Downloading element to address = 0x08000000, size = 474784
Erase [=========================] 100% 474784 bytes
Erase done.
Download [=========================] 100% 474784 bytes
Download done.
File downloaded successfully
So the flash seems ok, but the code is not executed. I have added instructions to blink the LED but it's not blinking...
GonzoG
Posts: 503
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

Re: Playing with Weact STM32H562RGT6

Post by GonzoG »

1. You don't need to use dfu-util. You can upload directly from Arduino IDE.
2. You don't need U(S)ART enabled for USB serial.
3. If your sketch takes control of USB pins USB Serial won't work.
lesept
Posts: 5
Joined: Tue May 27, 2025 2:34 pm

Re: Playing with Weact STM32H562RGT6

Post by lesept »

Thanks for your answer, but I didn't install the ST tools. So when I try to program from the IDE I get the following error message:
STM32CubeProgrammer not found (STM32_Programmer_CLI.exe).
Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:
https://www.st.com/en/development-tools ... eprog.html
Aborting!
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: Playing with Weact STM32H562RGT6

Post by ag123 »

if you tried my sketch in the zip file, it blinks the led when you run the whetstone benchmark. did it blink?
and you should see the whetstone benchmark on the serial console when it runs

oh and that sketch can't be 474,784 bytes, the bin file bundled in my zip file is only 44.9 kB.
you only need to install the bin file.

either way a blink sketch looks like

Code: Select all

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

void loop() {
	digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
	sleep(500);
}
if you simply want to blink the led that is it.

and normally to install over DFU, connect the usb cable, this button dance is relevant:
- press both reset and boot0
- hold boot0, release reset
- release boot0 2-3 secs later

That should place it in DFU mode, and you can use dfu-util or any such programmers to program the sketch into the board.
But it seemed this works normally for you.

if not, note that dfu-util on windows has some pre-requisites to use it, e.g. installing a 'libusb.dll' etc. it is part of the instructions of the old libmaple core.
note that that is 32 bits and i'm not sure if it still works the way it does.
https://github.com/rogerclarkmelbourne/ ... stallation

oh and normally, you need to build that sketch.
https://github.com/stm32duino/Arduino_C ... ng-Started

on Windows, if you struggle with dfu-util, install the stm32cube programmer
https://www.st.com/en/development-tools ... eprog.html
this is the 'official' tool to program stm32 and the relevant drivers are shipped and installed with that installer.

oh, you can't normally just take a 'bin' file and install it on the board/chip, unless that bin file is built for the chip and board (has dependency on the external crystal frequency).
Last edited by ag123 on Wed May 28, 2025 2:13 pm, edited 1 time in total.
lesept
Posts: 5
Joined: Tue May 27, 2025 2:34 pm

Re: Playing with Weact STM32H562RGT6

Post by lesept »

Thanks for your answer.
Your sketch worked ok. I can see the LED blink and the results of the whetstone benchmark. Using O3, I get up to 377 MFlops.
I actually tried this benchmark on an ESP32-S3, also with O3 option and got 417 MFlops.

Now I want to upload a more complex sketch: it's an implementation of a LeNet convolutional network to recognize handwritten digits.
It compiles correctly, uploads also, but the board does not connect to a COM port and then I can't execute it on the Arduino IDE.

I tried to test if some libraries or functions are not accepted by the board, such as iostream of malloc related functions. It appears that if I remove iostream and replace it with Serial prints, I reduce considerably the size on the bin file. Which is a good point. malloc seems ok.

But it doesn't solve the problem.
Last edited by lesept on Thu Jun 05, 2025 1:13 pm, edited 1 time in total.
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: Playing with Weact STM32H562RGT6

Post by ag123 »

To build with a com port, select from the menu Tools > USB support > CDC generic supersede U(S)ART.
Then build the sketch.
note that normally the FPU is 32 bits and in usual cases at most 2 x 32 bits FP ops in parallel. This is normally handled by -O2 or -O3.
I'm not too sure if in ESP32 the compiler is able to optimize the ops such that it uses both cores, which could explain the higher benchmark scores.

if you use c++, you can try using new and delete. Note that in the older compilers, there were reports that that can be goofy, e.g. that it takes a huge amount of sram (the whole object is allocated), but in more recent releases shipped with the core the issue may have been resolved.
you can try a code like such to check the 'free' memory, it is fairly accurate, because sbrk(0) is normally top of the heap.

Code: Select all

extern "C" char* sbrk(int incr);
static int FreeStack() {
  char top = 't';
  return &top - reinterpret_cast<char*>(sbrk(0));
}
Post Reply

Return to “General discussion”