ch32v307 Modbus + Web UI firmware - Page 1
Forum section: electronics / general

author: tellurium
author_rank: Frequent Contributor
timestamp: November 27, 2023, 09:43:55 pm
content: This thread is dedicated to the CH32V307 firmware that implements Modbus master and Web UI, built with Mongoose Libary (https://github.com/cesanta/mongoose/)Steps to build & try (on Mac, Windows, Linux):1. Setup build environment:https://mongoose.ws/documentation/tutorials/tools/, most notably - symlink support for git & make2. Install riscv toolchain, e.g. on Mac `brew install riscv-gnu-toolchain`3. clone mongoose repo: git clonehttps://github.com/cesanta/mongoose/4. Go to examples/wch/ch32v307-make-baremetal-builtin, start command prompt/terminal, run "make"5. Attach serial console to USART1: TX pin A9, baud rate 115200. Use serial converter6. Observe logs, look at the obtained IP address (see below for logs example)7. Point your browser at that IP addressExample console output:412 2 net_builtin.c:197:onstatechang READY, IP: 192.168.2.78417 2 net_builtin.c:198:onstatechang GW: 192.168.2.141d 2 net_builtin.c:199:onstatechang MAC: 02:38:9a:a3:39:e3423 2 main.c:107:main Initialising application...429 3 net.c:195:mg_listen 1 0http://0.0.0.042e 2 main.c:110:main Starting event loop7dd 2 main.c:35:timer_fn Ethernet: ready, IP: 192.168.2.78, rx:4, tx:3, dr:0, er:0bc5 2 main.c:35:timer_fn Ethernet: ready, IP: 192.168.2.78, rx:5, tx:3, dr:0, er:0fad 2 main.c:35:timer_fn Ethernet: ready, IP: 192.168.2.78, rx:5, tx:3, dr:0, er:0Current firmware size: ~90k on flash.Screenshot attached.Note: this firmware can be also run on a Windows/Linux/Mac workstation:cd examples/modbus-dashboard && makeThe MQTT functionality is not yet working.Saving configuration persistently on a flash is not yet working either.Feedback is welcome, please let me know what features you'd like to see.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: November 28, 2023, 09:26:37 am
content: thanks tellurium for sharing,But I can not compile the code on win11, I will get these errorsQuote

author: bingo600
author_rank: Super Contributor
timestamp: November 28, 2023, 09:52:45 am
content: Quote from: ali_asadzadeh on November 28, 2023, 09:26:37 amDidn't the answer in the other thread solve it ?https://www.eevblog.com/forum/microcontrollers/ch32v307-risc-v-minicore-with-ethernet/msg5190546/#msg5190546

author: tellurium
author_rank: Frequent Contributor
timestamp: November 28, 2023, 10:32:56 am
content: Quote from: ali_asadzadeh on November 28, 2023, 09:26:37 amYeah, as bingo600 mentioned, try a suggested fix: create a directory c:\temp and set a system-wide environment variable TMP=c:\tempI am attaching .bin and .elf files of the latest firmware to the first post.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: November 28, 2023, 02:27:29 pm
content: I have done it, Still no luck :'(Quote

author: ejeffrey
author_rank: Super Contributor
timestamp: November 28, 2023, 02:43:56 pm
content: Try changing TEMP and TMPDIR as well. Also check at the command line that the variables are set as you expect, windows has both system and user environment variables with the latter overriding the former. Finally check that you can write files in the temp directory chosen.

author: martinribelotta
author_rank: Regular Contributor
timestamp: November 28, 2023, 03:04:55 pm
content: QuoteHo! I see the problem, you don't have administrator permissions and the GCC are trying to write to C:\WINDOWS\TMP.Change TEMP to directory that you can write as a normal user (I think that TMP and TEMP environment vars must be contains the same value)

author: bingo600
author_rank: Super Contributor
timestamp: November 28, 2023, 03:19:25 pm
content: According to the gcc docshttps://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.htmlSetting env var :TMPDIRWould be the one to set for GCCAs already suggested aboveBut i do agree that i would set all the "TMP" env vars to ie. C:\TMP or C:\TEMPNot : C:\WINDOWS\TMP

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: November 28, 2023, 03:31:14 pm
content: Still the same problem

author: martinribelotta
author_rank: Regular Contributor
timestamp: November 28, 2023, 03:35:54 pm
content: QuoteTry to executeCode:echo $TMPDIRecho $TEMPecho $TMPIn MinGW terminal... maybe the /etc/profile has another configuration overwriting the system one.

author: bingo600
author_rank: Super Contributor
timestamp: November 29, 2023, 07:52:33 pm
content: @telluriumJyst FYI ...I tried mongoose today, and was scratching my head a lot ... Using linux mintIt didn't work.I have this board & programmerhttps://www.aliexpress.com/item/1005005021450761.htmlCH32V307 EVT (by SCDZ, close to official W.CH board)I tried a "blinky" ... workedAnd then i discovered that the programmer also registers as /dev/ttyACM0I fired up putty @115200 on ttyACM0When programmed i see thisCode:0 2 main.c:88:main Starting, CPU freq 144 MHz6 2 main.c:102:main MAC: 02:38:32:38:39:e3. Waiting for IP...3f5 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:07dd 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0bc5 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0fad 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:01395 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0177d 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:01b65 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:01f4d 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:02335 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0271d 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:02b05 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:02eed 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:032d5 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:036bd 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:03aa5 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:03e8d 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:04275 2 main.c:35:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0Nothing happened besides the above ....Then i disconnected the Ethernet Jack , and reconnectedAnd it saw a mac address , and after a few seconds it got an IPThat method works .... SometimesWhat always work , is to press reset when it "doesn't see (show) the ethernet MAC.Code:0 2 main.c:88:main Starting, CPU freq 144 MHz6 2 main.c:102:main MAC: 02:38:32:38:39:e3. Waiting for IP...3ee 3 stm32.c:193:mg_tcpip_driver_st Link is 10M half-duplex3f3 1 net_builtin.c:202:onstatechang Link up3f7 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e33ff 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:1, dr:0, er:07d6 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e37dd 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:2, dr:0, er:0bbe 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3bc5 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:3, dr:0, er:0fa6 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3fad 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:4, dr:0, er:0138e 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31395 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:5, dr:0, er:01776 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3177d 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:1, tx:6, dr:0, er:01b5e 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31b65 3 net_builtin.c:281:tx_dhcp_requ DHCP req sent1b6a 2 net_builtin.c:407:rx_dhcp_clie Lease: 6210 sec (6217)1b70 2 net_builtin.c:197:onstatechang READY, IP: 10.117.10.2101b75 2 net_builtin.c:198:onstatechang GW: 10.117.10.11b7b 2 net_builtin.c:199:onstatechang MAC: 02:38:32:38:39:e31b81 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:9, dr:0, er:01b8a 2 main.c:107:main Initialising application...1b90 3 net.c:195:mg_listen 1 0 http://0.0.0.01b95 2 main.c:110:main Starting event loop1f4d 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:9, dr:0, er:0Code:1adbd 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:8, dr:0, er:01b1a5 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:8, dr:0, er:01b58d 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:8, dr:0, er:01b975 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:8, dr:0, er:01bd5d 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:8, dr:0, er:01c145 2 main.c:35:timer_fn Ethernet: ready, IP: 10.117.10.210, rx:4, tx:8, dr:0, er:00 2 main.c:88:main Starting, CPU freq 144 MHz6 2 main.c:102:main MAC: 02:38:32:38:39:e3. Waiting for IP...3ee 3 stm32.c:193:mg_tcpip_driver_st Link is 10M half-duplex3f3 1 net_builtin.c:202:onstatechang Link up3f7 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e33ff 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:1, dr:0, er:07d6 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e37dd 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:2, dr:0, er:0bbe 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3bc5 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:3, dr:0, er:0fa6 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3fad 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:4, dr:0, er:0138e 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31395 2 main.c:35:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:5, dr:0, er:0I see same issue when doing a Power Reset.It doesn't see the link-up (Ethernet link) , until i press Reset button.Does the ethernet link check start too fast ??Edit:I have attached my Makefile (had to append .txt - to upload)It uses the linux (wch clone) programmer :https://github.com/cnlohr/ch32v003fun/tree/master/minichlink"clone" , build , and copy to "somewhere on path"Note: There seems to be an issue w minichlink - It resets the chip to 288K/32K Flash/Ram partitioningBut ATM that's fine for mongoose.https://blog.dan.drown.org/ch32v307-dev-board-part-5/QuoteThere's a hack/fix herehttps://www.eevblog.com/forum/microcontrollers/ch32v307-risc-v-minicore-with-ethernet/msg5195862/#msg5195862Edit2:ddrown's lwip demo also needs an extra button reset to get an ip.So it could be board related ... I'm using a HP 1820 switch, and have no issues w. that/Bingo

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: November 30, 2023, 08:44:35 am
content: QuoteI have tired, here is the results

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 30, 2023, 09:00:24 am
content: I guess you haven't tried adding the '-pipe' option to CFLAGS as I have suggested earlier, to circumvent this temp files altogether?

author: bingo600
author_rank: Super Contributor
timestamp: November 30, 2023, 10:29:05 am
content: Quote from: ali_asadzadeh on November 30, 2023, 08:44:35 amWhy doesn't $TMPDIR point at the same as $TMPDoes c:\temp exist

author: tellurium
author_rank: Frequent Contributor
timestamp: November 30, 2023, 11:30:51 am
content: Quote from: bingo600 on November 29, 2023, 07:52:33 pmI don't have that board, ordered and expecting it to arrive in a couple of weeks.I use this one:https://www.aliexpress.com/item/1005004350410929.htmlI don't know who makes those boards. They are set to 32k RAM / 288K flash by default.To reprogram it, I press boot + reset buttons, then use "wchisp flash" command. The wchisp is this one:https://github.com/ch32-rs/wchispThis board always picks up and IP from DHCP , I haven't seen an issue that you described. Will test on the WCH's board when it arrives.Option byte notes:I would like to set the board to the 96k RAM / 224k flash configuration, but unfortunately wchisp does not yet know how to set option bytes.I can do in in the firmware code, but it needs a bootstrapping phase:1. Add a code to the firmware that checks option byte to 96/2242. Build a firmware with 32/288 linker script, flash & run it. This is necessary cause running a 96/224 linked firmware won't work if chip is configured to 32/2883. Rebuild the firmware wirh 96/224 linker script, and flash it again: now chip should be 96/224That works, I've tried that, but it is kinda cumbersome and confusing. I wish option bytes can be set by a utility before flashing. Maybe wchlink utility can do it, I don't have one yet, will test when it arrives.

author: bingo600
author_rank: Super Contributor
timestamp: November 30, 2023, 02:51:14 pm
content: Quote from: tellurium on November 30, 2023, 11:30:51 amI just hacked Ram partitioning into minichlinkSeehttps://www.eevblog.com/forum/microcontrollers/ch32v307-risc-v-minicore-with-ethernet/msg5197074/#msg5197074Code:mongose/mongoose/examples/wch/ch32v307-make-baremetal-builtin$ make flashminichlink -K 96 -a -w firmware.bin 0x08000000 -bFound WCH LinkWCH Programmer is CH549 version 2.10Chip Type: 307CH32V30x or CH32V20x MCU detected. Using binary blob write for operation.Setup successFlash Storage: 288 kBPart UUID : 26-cb-d9-2c-38-32-38-3bPFlags : e3-39-e3-39Part Type (B): 30-70-05-18Read protection: disabledInterface SetupMCU Ram set to 96KB on next bootImage written.But my board still requires an extra reset .../Bingo

author: bingo600
author_rank: Super Contributor
timestamp: November 30, 2023, 03:26:33 pm
content: Quote from: tellurium on November 30, 2023, 11:30:51 amThanx for the support.I'm just a "hobbyist"I have only used the wchlink or wclink-e dongle to program my board.I have no idea if the rust program supports my board or dongle.I don't have that addon PCB with the USBC programmer/debugger , just the dongle(s).I suppose there's no DFU loader on the CHIP USB's ?? ... Like on a STM32F4 ??/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: November 30, 2023, 03:58:59 pm
content: I just tried to connect USB , and the Boot0 key.I could program viawchlinkwchisp (rust binary) ....But i still need to do a "button reset" , in order to get an IP.So it's prob not the programmer./Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: December 01, 2023, 12:20:00 am
content: Quick update:1. Still using 32k ram / 288k flash in the linker file. That should work also for devices configured for larger RAM, just not all RAM would be utilized. I'll try to use Bingo's whlink update to set device config (when I'll get a board with wchlink). If that works, I'll switch the build for larger RAM, perhaps 64/256.2. Added ability to save configuration on flash permanently - so now it survives reboots. The code uses the sector that follows a mapped 320k area, no wear levelling is done. Attempted to use littlefs on the whole "unmapped" flash region - but littlefs eats too much RAM, so went for a simple sector write instead3. Followed SiliconWizard's finding about bss. Hand-crafted linker script considering that, with pieces taken from the wch's SDK. Here's current linker script file for the project:https://github.com/cesanta/mongoose/blob/master/examples/wch/ch32v307-make-baremetal-builtin/link.ld4. Attached an updated binary download to the first post (ch32v307.modbus.firmware.2023-12-01.zip)

author: bingo600
author_rank: Super Contributor
timestamp: December 02, 2023, 11:44:04 am
content: I just noticed a much different 307 demo now.And i haven't saved the old source ....Well strange belowI programmed with the minichlink , that's supposed to set 96K RamOn 1'st Boot (after being flashed) it shows correctCode:0 2 main.c:100:main Starting, CPU freq 144 MHz5 2 main.c:103:main Heap size: 17440 bytesb 2 main.c:108:main RAM/FLASH configuration: 96/224 <-------------------On Reset (Button) it changed to 32K Ram ....Code:12 2 main.c:100:main Starting, CPU freq 144 MHz17 2 main.c:103:main Heap size: 17440 bytes1d 2 main.c:108:main RAM/FLASH configuration: 32/288 <-------------------24 2 main.c:124:main MAC: 02:38:32:38:39:e3. Waiting for IP...40c 3 stm32.c:193:mg_tcpip_driver_st Link is 10M half-duplex411 1 net_builtin.c:202:onstatechang Link up415 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e37f4 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3bdc 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3fc4 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e313ac 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31794 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3179b 3 net_builtin.c:281:tx_dhcp_requ DHCP req sent17a0 2 net_builtin.c:407:rx_dhcp_clie Lease: 6884 sec (6890)17a6 2 net_builtin.c:197:onstatechang READY, IP: 10.117.10.21017ab 2 net_builtin.c:198:onstatechang GW: 10.117.10.117b1 2 net_builtin.c:199:onstatechang MAC: 02:38:32:38:39:e317b7 2 main.c:129:main Initialising application...17bd 3 net.c:195:mg_listen 1 0 http://0.0.0.0:800017c3 3 net.c:195:mg_listen 2 0 http://0.0.0.0/17c8 3 net.c:195:mg_listen 3 0 https://0.0.0.0/17cd 2 main.c:133:main Starting event loop17d2 3 net.c:171:mg_connect 4 -1 udp://time.google.com:12317d9 3 net.c:171:mg_connect 5 -1 udp://8.8.8.8:5317de 3 net_builtin.c:1002:mg_connect_ 5 10.117.10.210:32768 -> 8.8.8.8:532392 3 net.c:148:mg_close_conn 4 -1 closedWonder if that's the programmer ?Can you set ram partitioning , so it's not written/saved to flashWell if i comment out :Code://if (mode != 3) set_ram_size(2), mg_device_reset();It will always showCode:b 2 main.c:108:main RAM/FLASH configuration: 96/224 <-------------------And i have issues getting an ip (DHCP) .... Also after a button Reset.The button reset worked 100% on the old vers.And so did a NVIC_Reset (instead of Button Reset) in the "Timer loop" after 10 loops of "down state" , on the old vers./Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: December 02, 2023, 02:49:39 pm
content: Quote from: bingo600 on December 02, 2023, 11:44:04 amAh, that's just the firrmware code flips the option byte back to 32/388, you figured it out right.Disable it by commenting out this line:https://github.com/cesanta/mongoose/blob/7f8cdf1e79f609e834f59f247b69b51bc7444c9e/examples/wch/ch32v307-make-baremetal-builtin/main.c#L109Then, reprogram the board again to 96/224And, change the link.ld to 96/224 here:https://github.com/cesanta/mongoose/blob/7f8cdf1e79f609e834f59f247b69b51bc7444c9e/examples/wch/ch32v307-make-baremetal-builtin/link.ld#L3-L4Then your board should work on 96/224 configuration.See what is the log message about heap size, it should be somewhat less than 96kWithout changling link.ld, you're still using little ram, see17 2 main.c:103:main Heap size: 17440 bytesThis heap size of ~17k is 32k minus static DMA Ethernet buffers.

author: bingo600
author_rank: Super Contributor
timestamp: December 02, 2023, 06:10:01 pm
content: Hmmm ... You moved the linkerfile (used) from vendor to main dir, But kept the vendor linkerfile ....At first I did do the 224/96 adaptation at the beginning but in vendor linker file, and nothing happened ...I have adapted makefile to vendor ld file againNow i'm back to : It works after a button resetCode:▒0 2 main.c:100:main Starting, CPU freq 144 MHz5 2 main.c:103:main Heap size: 82848 bytesb 2 main.c:108:main RAM/FLASH configuration: 96/22412 2 main.c:124:main MAC: 02:38:32:38:39:e3. Waiting for IP...0 2 main.c:100:main Starting, CPU freq 144 MHz5 2 main.c:103:main Heap size: 82848 bytesb 2 main.c:108:main RAM/FLASH configuration: 96/22412 2 main.c:124:main MAC: 02:38:32:38:39:e3. Waiting for IP...3fa 3 stm32.c:193:mg_tcpip_driver_st Link is 10M half-duplex3ff 1 net_builtin.c:202:onstatechang Link up403 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e37e2 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3bca 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3fb2 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3139a 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31782 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31789 3 net_builtin.c:281:tx_dhcp_requ DHCP req sent178e 2 net_builtin.c:407:rx_dhcp_clie Lease: 7044 sec (7050)1794 2 net_builtin.c:197:onstatechang READY, IP: 10.117.10.2101799 2 net_builtin.c:198:onstatechang GW: 10.117.10.1179f 2 net_builtin.c:199:onstatechang MAC: 02:38:32:38:39:e317a5 2 main.c:129:main Initialising application...17ab 3 net.c:195:mg_listen 1 0 http://0.0.0.0:800017b1 3 net.c:195:mg_listen 2 0 http://0.0.0.0/17b6 3 net.c:195:mg_listen 3 0 https://0.0.0.0/17bb 2 main.c:133:main Starting event loop17c0 3 net.c:171:mg_connect 4 -1 udp://time.google.com:12317c7 3 net.c:171:mg_connect 5 -1 udp://8.8.8.8:5317cc 3 net_builtin.c:1002:mg_connect_ 5 10.117.10.210:32768 -> 8.8.8.8:53And i did a NVIC_Reset if link was down ...That got the board to get "link-up" , and a DHCP IP. Wo. any inteventionCode:static void timer_fn(void *arg) {gpio_toggle(LED_PIN); // Blink LED_PINstruct mg_tcpip_if *ifp = arg; // And showconst char *names[] = {"down", "up", "req", "ready"}; // network statsif(0 == ifp->state){NVIC_SystemReset();}return;MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u",names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent,ifp->ndrop, ifp->nerr));}Code:0 2 main.c:105:main Starting, CPU freq 144 MHz <---------------- Programmer/Flash-done Boot5 2 main.c:108:main Heap size: 82848 bytesb 2 main.c:113:main RAM/FLASH configuration: 96/22412 2 main.c:129:main MAC: 02:38:32:38:39:e3. Waiting for IP...0 2 main.c:105:main Starting, CPU freq 144 MHz <---------------- NVIC_Reset5 2 main.c:108:main Heap size: 82848 bytesb 2 main.c:113:main RAM/FLASH configuration: 96/22412 2 main.c:129:main MAC: 02:38:32:38:39:e3. Waiting for IP...3fa 3 stm32.c:193:mg_tcpip_driver_st Link is 10M half-duplex3ff 1 net_builtin.c:202:onstatechang Link up403 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e37e2 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3bca 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3fb2 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e3139a 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31782 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31b6a 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:39:e31b71 3 net_builtin.c:281:tx_dhcp_requ DHCP req sent1b76 2 net_builtin.c:407:rx_dhcp_clie Lease: 5629 sec (5636)1b7c 2 net_builtin.c:197:onstatechang READY, IP: 10.117.10.2101b81 2 net_builtin.c:198:onstatechang GW: 10.117.10.11b87 2 net_builtin.c:199:onstatechang MAC: 02:38:32:38:39:e31b8d 2 main.c:134:main Initialising application...1b93 3 net.c:195:mg_listen 1 0 http://0.0.0.0:80001b99 3 net.c:195:mg_listen 2 0 http://0.0.0.0/1b9e 3 net.c:195:mg_listen 3 0 https://0.0.0.0/1ba3 2 main.c:138:main Starting event loop1ba8 3 net.c:171:mg_connect 4 -1 udp://time.google.com:1231baf 3 net.c:171:mg_connect 5 -1 udp://8.8.8.8:531bb4 3 net_builtin.c:1002:mg_connect_ 5 10.117.10.210:32768 -> 8.8.8.8:532768 3 net.c:148:mg_close_conn 4 -1 closedNow it doesn't need the Button ResetBtw:Just an hunch.The Board missing Ethernet link on POR "issue" ....Maybe it could be power related (I power via the wchlink dongle) ... If i disconnect the dongle--> board cable for a short while (1 sec or so) , and the reconnect.It does make the link ... If i disconnect for 5 sec or more , it doesn't.I'm not an EE , but does the MAC-Jack pull a lot of power to energize ?Maybe the dongle can't supply on first boot.I don't have a PSU beside me , but maybe i can solder ?? (isn't there a limit on how much capacitance you can put behind usb ?) ... 10uF or ?? on the board.I see several of the boards have 10uF before and after the LDO , and other have 10uF before & 2.2uF after.Judging from the size of my cap's , i think i have 10uF & 2.2uF on mine.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 03, 2023, 10:07:52 am
content: my ch32v307V-R1-1V0 board has WCH-Link Utility onboard, and Finlay I managed to compile the code, I think the msys2 was conflicting with this new installationAfter compiling the code I used the WCH-LinkUtility to load the bin file and program the board, the uart output is something like288 2 main.c:100:main Starting, CPU freq 144 MHz28d 2 main.c:103:main Heap size: 82976 bytes293 2 main.c:108:main RAM/FLASH configuration: 96/224I think the board would crash and do not move forward, after plunging and unplugging the board from power, there is no UART output again:'( :'(, I should reprogram the board with some examples in mounriver studio to be able to see the UART output again,what am I doing wrong? is there a way to debug the code?

author: bingo600
author_rank: Super Contributor
timestamp: December 03, 2023, 04:37:27 pm
content: Quote from: ali_asadzadeh on December 03, 2023, 10:07:52 amYour output looks correct to me.But ....Did you use the linker file from main-dir or the one from the vendor dir ?The one from main dir prob. has to be adapted to 96K Ram.Did you have the Bord LAN Jack connected to a working switchport ?Have you connected the "Blinky led" ?See LED2 (top of main.c) for port/pin - That one should/would blink to show mongoose is running.Could the Board Com-Port have switched to another number ??

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 04, 2023, 01:29:29 pm
content: QuoteIt's like yours but it does not print more stuff to the console,QuoteI have used the linker file with is beside the mian.c fileQuoteYes, and it's do not do anything, I think the board would crash after doing some stuff, since I do not know how to debug the code, I can not say what's the buggy function.

author: bingo600
author_rank: Super Contributor
timestamp: December 04, 2023, 02:07:38 pm
content: Quote from: ali_asadzadeh on December 04, 2023, 01:29:29 pmYouhaveto modify the linkerfile to 96KB RamEither edit the one besides main , or copy the one from thevendor dirto the one in the main dir

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 04, 2023, 03:15:17 pm
content: Now, it starts to work, is there any chance that we can add FreeRTOS to it? also Is there a way to debug the code?

author: bingo600
author_rank: Super Contributor
timestamp: December 04, 2023, 05:07:26 pm
content: Quote from: ali_asadzadeh on December 04, 2023, 03:15:17 pmWhy would you add FreeRTOS to mongoose

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 05, 2023, 08:08:33 am
content: QuoteI need it to implement some tasks, also I have tested the demo app with ModbusDoctorV2 app, and it can not connect to the device using the 502 port, it only accepts port 80 But it would not respond back with modbus messages, I have tried the 192.168.1.3 and 192.168.1.100 IP's, the board would boot with 192.168.1.3 IP in my case.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 05, 2023, 10:34:42 am
content: I'm trying to port mongoose to mounriver studio, so at least we can debug it, Here is the progress till now, I have used FreeRTOS,And this is the output uartQuotewhen the program would hit this linemg_tcpip_init(&mgr, &mif);It would not go any further and mounriver would not show the source file!!! But the task 1 is doing it's job, do you have any Idea what can cause this problem?you can get the ported project at this linkhttps://www.file.io/GnAr/download/DYIfQcliAdGX

author: tellurium
author_rank: Frequent Contributor
timestamp: December 06, 2023, 12:48:34 pm
content: Quote from: ali_asadzadeh on December 05, 2023, 10:34:42 amComment out "#define MG_ENABLE_LINES 1" in the mongoose_custom.h and rebuild. Then it should show the source.Give mongoose task at least 8k of stack space.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: December 07, 2023, 08:43:22 am
content: Thanks telluriumNow it shows the sources, But it would stuck at this lineit's line 9309 in mongoose.cQuote

author: tellurium
author_rank: Frequent Contributor
timestamp: December 26, 2023, 07:58:25 pm
content: Quote from: ali_asadzadeh on December 07, 2023, 08:43:22 amI have installed MRS, created a basic printf project, and moved mongoose code from the bare metal example - works for me.Must be something with initialisation, I suspect ethernet MAC/PHY controller init is missing.Could you share your MRS project please?

author: tellurium
author_rank: Frequent Contributor
timestamp: December 27, 2023, 10:56:16 pm
content: We recently added a built-in TLS1.3 stack to Mongoose Library (server part for now).I did an experimental build of the modbus firmware with TLS enabled.Didn't manage to get it to work on 32k RAM configuration - too tight!Note that the browser spawns multiple (~5) connections to speed up HTML GUI rendering, meaning that the box gets hit by ~5 simultaneous TLS connections, which are both RAM and CPU hungry.But lo and behold, with 64k RAM configuration, it works! Flaky sometimes, but works.To build with TLS, change vendor/link.ld to 256/64 configuration, then "make CFLAGS_EXTRA="-DMG_TLS=MG_TLS_BUILTIN".Screenshot attached.TLS-enabled firmware build is attached to the 1st post.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2023, 11:12:39 pm
content: How much Flash do you use? You know you can get up to 128KB RAM with the proper config - it'll limit the available code memory to 192KB though. Might still be workable!

author: tellurium
author_rank: Frequent Contributor
timestamp: December 27, 2023, 11:23:18 pm
content: Quote from: SiliconWizard on December 27, 2023, 11:12:39 pmThis current TLS-enabled build is 110344 bytes, which is below half of the available flash size (256 / 2 = 128k). Plenty of room is there yet!Meaning, even firmware update is possible.So, on this CH32V307, it is possible to create a TLS-enabled Web UI dashboard with firmware update functionality.The flash content would be wide open of course, but still.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2023, 11:36:07 pm
content: The memory layout of this chip is documented (sorta) but not really advertised. Not sure why. So people tend not to know, or assume that may not work, and so on.To sum up again, the CH32V307 has:- A total of 320KB RAM- A total of 480KB FlashDue to how the memory is mapped for code execution (which uses some amount of RAM to cache access, which I suspect is just a full copy of your code Flash content at boot), you only have access to a maximum of 288KB of code memory (in this case, with a data memory of 32KB), or a maximum of 192KB code memory (with a data memory of 128KB), and a couple combinations in between.The calculation is simple, available code memory = 320KB - available data memory. That makes it obvious all code is loaded from Flash to RAM at boot. No code ever executes directly from Flash, which is why the chip has a guaranteed zero-wait-state access to code memory at all system clock frequencies.Besides, anything in Flash above the max code memory size in a given configuration is usable for anything else up to the 480KB limit. So in a 192KB "Flash"/128KB "RAM" configuration, you still have 480KB - 192KB (288KB !) of Flash usable to store anything, a second copy of the whole code, user data, etc.That gives a lot more possibilities that many people appear to think when exposed to the CH32V307.Why WCH doesn't advertise this more is unknown to me. It's fully (albeit not overly detailed) documented in the DS and RM documents.But note that if you base your impression of the chip on just intrroduction parts of the docs and the provided SDK and examples, you'll miss out on a lot of stuff. The examples they provide are very limited and only show a fraction of the possibilities, and that's true for almost all aspects of the chip, from memory to USB.

author: tellurium
author_rank: Frequent Contributor
timestamp: December 28, 2023, 12:59:05 am
content: Would this be a correct summary?Possible RAM/Flash configurations for CH32V307:32k data / 288k code: |-32-|----------288------|64k data / 256k code: |-64---|--------256------|96k data / 224k code: |-96-----|------224------|128k data / 192k code: |-128-------|---192------||<--------- 320k ------->|This configuration is stored in the flash option bytes.Here is a function that sets the required configuration:https://github.com/cesanta/mongoose/blob/3965aecfd473cbd70027b636492bb19b615eadd4/examples/wch/ch32v307-make-baremetal-builtin/hal.h#L121-L136Flash is mapped at address 0x8000000 and 0x0, and is of size 480k.There is available flash "scratch space" of size "480k - codesize" thatcan be used for persistent storage. The initial "code" portion gets copied into RAM for execution.0x0|------ code -----|------------- storage space -------||<---------------------- 480k ----------------------->|

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 28, 2023, 02:50:47 am
content: Yes, the only thing to add probably is that as far as Flash address mapping goes, while it is indeed remapped at address 0 for *reading*, I think you still need to use addresses starting at 0x8000000 for *writing* to Flash.

author: bingo600
author_rank: Super Contributor
timestamp: January 21, 2024, 05:34:12 am
content: Quote from: tellurium on November 30, 2023, 11:30:51 am@telluriumDid you ever get the board above ?/Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: January 21, 2024, 11:51:21 am
content: Quote from: bingo600 on January 21, 2024, 05:34:12 amYes I did! The latest change to the code I've done with that board.

author: bingo600
author_rank: Super Contributor
timestamp: January 21, 2024, 02:48:12 pm
content: Quote from: tellurium on January 21, 2024, 11:51:21 amI just tried the latest code , and i still have that ethernet issue ....After programming or a POR it just "hangs here"Code:2b19 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80512f01 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/805132e9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/805136d1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80513ab9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80513ea1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80514289 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80514671 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80514a59 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80514e41 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80515229 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/80515611 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/8051If i press reset ... It will get an ipOr if i test for ethernet link , and do a NVIC Reset. It will also get an ip.Code:static void timer_fn(void *arg) {gpio_toggle(LED_PIN); // Blink LED_PINstruct mg_tcpip_if *ifp = arg; // And showconst char *names[] = {"down", "up", "req", "ready"}; // network statsMG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u RAM: %lu/%lu",names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent,ifp->ndrop, ifp->nerr, hal_ram_used(), hal_ram_free()));#if 1if(0 == ifp->state){NVIC_SystemReset();}#endif}Wonder if my board is strange ??I'm still waiting for a some of "your old" boards from Ali ....Edit: I'm programming & powering via a - WCHLink USB Dongle (the cheap one wo buttons) , that came w. the setUsing minichlink with my patches for Ram/Rom assignmenthttps://www.eevblog.com/forum/microcontrollers/ch32v307-risc-v-minicore-with-ethernet/msg5197074/#msg5197074Attached the modified makefile (just 3 lines)Edit2:I tried to add 22uF and even 100uF to the 5v rail ... Same issueEdit3:The reason i'm not doing wireshark traces, is that the "link is down" ..../Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: January 21, 2024, 07:56:47 pm
content: I consistently get everything working after flashing.Here is what I am doing:Terminal1 - building & flashingCode:$ git clone https://github.com/cesanta/mongoose$ cd mongoose/examples/wch/ch32v307-make-baremetal-builtin$ make CFLAGS_EXTRA='-Wl,--defsym -Wl,RAM_64K=1' clean all$ wlink flash firmware.elfTerminal2 - reading serial logsCode:$ cu -l /dev/cu.usb* -s 115200Connected.0 2 main.c:46:main Starting, CPU freq 144 MHz5 2 main.c:51:main RAM/FLASH configuration: 64/256c 2 main.c:55:main Heap size: 48032 bytes. RAM: used 1032, free 5082314 3 stm32f.c:152:mg_tcpip_driver_s PHY ID: 0x00 0x0019 2 main.c:70:main MAC: 02:50:5c:7e:39:e3. Waiting for IP...401 3 stm32f.c:201:mg_tcpip_driver_s Link is 10M half-duplex406 1 net_builtin.c:202:onstatechang Link up40a 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:50:5c:7e:39:e3412 3 net_builtin.c:281:tx_dhcp_requ DHCP req sent417 2 main.c:26:timer_fn Ethernet: req, IP: 0.0.0.0, rx:3, tx:2, dr:0, er:0 RAM: 10860/40787420 2 net_builtin.c:408:rx_dhcp_clie Lease: 86400 sec (86401)426 2 net_builtin.c:197:onstatechang READY, IP: 192.168.2.8642c 2 net_builtin.c:198:onstatechang GW: 192.168.2.1431 2 net_builtin.c:199:onstatechang MAC: 02:50:5c:7e:39:e3That I am getting consistently. I cannot reproduce that behavior you're talking about.Note that theCFLAGS_EXTRA='-Wl,--defsym -Wl,RAM_64K=1'build flag is used to build for 256/64 flash/ram configuration, which is the default for that board.I got my board from Elektor, unpacked and connected to my USB hub with Ethernet port, no modifications/alterations made.

author: bingo600
author_rank: Super Contributor
timestamp: January 22, 2024, 05:18:17 am
content: Quote from: tellurium on January 21, 2024, 07:56:47 pmI didn't use any extra flags , but gave it 96K Ram on flashing.I'll try your "extra's"/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: January 22, 2024, 03:46:05 pm
content: I tried with the EXTRA def's , and no luck ....But then i tried with another switchMy original switch is a HP-1820 8-port , and i switched to a Dlink DGS-1100-08 V2Now it's getting link , but it has to do a lot of "link down" firstCode:0 2 main.c:46:main Starting, CPU freq 144 MHz5 2 main.c:51:main RAM/FLASH configuration: 64/256c 2 main.c:55:main Heap size: 48032 bytes. RAM: used 1032, free 5082314 3 stm32f.c:152:mg_tcpip_driver_s PHY ID: 0x00 0x0019 2 main.c:70:main MAC: 02:38:32:38:38:e7. Waiting for IP...409 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408197f1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819bd9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819fc1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081913a9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408191791 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408191b79 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408191f61 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408192349 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408192731 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408192b19 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408192f01 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081932e9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081936d1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408193ab9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408193ea1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408194289 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408194671 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408194a59 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408194e41 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408195229 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408195611 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081959f9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408195de1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081961c9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081965b1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408196999 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408196d81 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408197169 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408197551 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408197939 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408197d21 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408198109 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081984f1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081988d9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408198cc1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/4081990a9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408199491 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408199879 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/408199c61 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819a049 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819a431 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819a819 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819ac01 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819afe9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819b3d1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819b7b9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819bba1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819bf89 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819c371 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819c759 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819cb41 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819cf29 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819d311 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819d6f9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819dae1 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819dec9 2 main.c:26:timer_fn Ethernet: down, IP: 0.0.0.0, rx:0, tx:0, dr:0, er:0 RAM: 10828/40819e2a9 3 stm32f.c:201:mg_tcpip_driver_s Link is 10M half-duplexe2ae 1 net_builtin.c:202:onstatechang Link upe2b2 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:38:e7e2ba 2 main.c:26:timer_fn Ethernet: up, IP: 0.0.0.0, rx:1, tx:1, dr:0, er:0 RAM: 10860/40787e691 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:38:32:38:38:e7e699 2 main.c:26:timer_fn Ethernet: up, IP: 0.0.0.0, rx:1, tx:2, dr:0, er:0 RAM: 10860/40787e6a2 3 net_builtin.c:281:tx_dhcp_requ DHCP req sente6a7 2 net_builtin.c:408:rx_dhcp_clie Lease: 6793 sec (6852)e6ac 2 net_builtin.c:197:onstatechang READY, IP: 10.1.1.210e6b2 2 net_builtin.c:198:onstatechang GW: 10.1.1.1e6b8 2 net_builtin.c:199:onstatechang MAC: 02:38:32:38:38:e7e6be 2 main.c:75:main Initialising application...e6c4 3 net.c:202:mg_listen 1 0 http://0.0.0.0:8000e6c9 3 net.c:202:mg_listen 2 0 http://0.0.0.0/e6cf 3 net.c:202:mg_listen 3 0 https://0.0.0.0/e6d4 2 main.c:79:main Starting event loope6d9 3 net.c:177:mg_connect 4 -1 udp://time.google.com:123e6e0 3 net.c:177:mg_connect 5 -1 udp://8.8.8.8:53e6e5 3 net_builtin.c:997:mg_connect_r 5 10.1.1.210:32768 -> 8.8.8.8:53ea81 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.210, rx:4, tx:5, dr:0, er:0 RAM: 12060/39587ee69 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.210, rx:5, tx:5, dr:0, er:0 RAM: 12060/39587f251 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.210, rx:5, tx:5, dr:0, er:0 RAM: 12060/39587f299 3 net.c:151:mg_close_conn 4 -1 closedf639 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.210, rx:5, tx:5, dr:0, er:0 RAM: 12060/39587Wonder if i'm fighting spanning tree (i have rstp) enabled on the HP ... Well no RSTP on the D-LinkIt seems like it gets a link quicker from POR , than programming ....Well ... I'll wait for my other boards (en route from Ali...)@telluriumThank you for your support ....And still strange that a NVIC Reset if no link , brings the link up immediately on next boot./Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: January 22, 2024, 03:54:37 pm
content: It looks like it has no problem getting an IP when it senses the link"Ethernet: down" - this means that the driver does not think there is a link, so it does not even try to send DHCP requests.And, by the way, you've built with 64k RAM support, I can see here: " RAM: 10828/40819"40k free RAM. By default, without CFLAGS_EXTRA, it is less than that.

author: bingo600
author_rank: Super Contributor
timestamp: January 22, 2024, 04:05:52 pm
content: Quote from: tellurium on January 22, 2024, 03:54:37 pmYepp , once it gets the ether-link it's quite fast to get the ip via dhcp.But it's struggling a bit to obtain the link, i can see the switchport led is out ...Quote from: tellurium on January 22, 2024, 03:54:37 pmYep - I did your extras flag.Here's my latest Makefile.I added a linker map , and a linker flash/ram printoutThe switchport strangeness is weird.I have no issue getting a link/ip - If i use the same cable/port on the HP , on a Raspi3 or OrangePi-One , but they prob linkup on 100Mb

author: tellurium
author_rank: Frequent Contributor
timestamp: January 22, 2024, 04:38:08 pm
content: Thank you!Did you try to build a Mounriver example? I am curious, would it be able to sense the link, or have the same issue

author: bingo600
author_rank: Super Contributor
timestamp: January 22, 2024, 05:54:40 pm
content: I don't have mounriver installed ...Right now i just use : xpack-riscv-none-elf-gcc-13.2.0-2I'm not always that keen on installing "strange IDE's"But i have just downloaded it ...I'm on linux (mint)Seems like the DL is just the toolchain + OOCDWell i do have Eclipse installed already ....Maybe i'll considerAny pointers to a "working" MounRiver example ?

author: bingo600
author_rank: Super Contributor
timestamp: January 22, 2024, 07:15:29 pm
content: Well I just did try ddrown's iperf serverhttps://github.com/ddrown/ch32v307-lwip-exampleHere i have an issue too..Code:Error:Wait phy linking timeout!Please cheak MID.Program has been blocked!And after pressing "Board reset" , it works.Code:Enter main loop.PLL3 is ready.PHY_SR value:0004.Full Duplex.CH307_INIT_PHY okenable rng okThis routine will use DHCP to dynamically assign IP addresses.本例程将使用DHCP动态分配IP地址,如果不需要则在lwipopts.h中将LWIP_DHCP定义为0lwip dhcp start success...IP 10.1.1.211Neat iperf testCode:~/1-RiscV/gcc$ iperf -i 1 -c ch32v307------------------------------------------------------------Client connecting to ch32v307, TCP port 5001TCP window size: 85.0 KByte (default)------------------------------------------------------------[ 1] local 10.1.1.182 port 54988 connected with 10.1.1.211 port 5001[ ID] Interval Transfer Bandwidth[ 1] 0.0000-1.0000 sec 1.13 MBytes 9.44 Mbits/sec[ 1] 1.0000-2.0000 sec 1.12 MBytes 9.44 Mbits/sec[ 1] 2.0000-3.0000 sec 1.12 MBytes 9.44 Mbits/sec[ 1] 3.0000-4.0000 sec 1.12 MBytes 9.44 Mbits/sec[ 1] 4.0000-5.0000 sec 896 KBytes 7.34 Mbits/sec[ 1] 5.0000-6.0000 sec 1.12 MBytes 9.44 Mbits/sec[ 1] 6.0000-7.0000 sec 1.12 MBytes 9.44 Mbits/sec[ 1] 7.0000-8.0000 sec 1.12 MBytes 9.44 Mbits/sec[ 1] 8.0000-9.0000 sec 1.00 MBytes 8.39 Mbits/sec[ 1] 9.0000-10.0000 sec 1.00 MBytes 8.39 Mbits/sec[ 1] 0.0000-10.1062 sec 10.9 MBytes 9.03 Mbits/sec:~/1-RiscV/gcc$So it seems like i have a local issue somewhereI think i'll get my other boards from ali soon , seems like they have cleared customs ...Let's see if they have same issue./Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: January 22, 2024, 10:08:16 pm
content: Quote from: bingo600 on January 22, 2024, 07:15:29 pmThank you, appreciate the effort!Concerning the firmware functionality itself. Do you have a specific use case, where you might use the modbus functionality for some practical task?

author: bingo600
author_rank: Super Contributor
timestamp: January 23, 2024, 05:15:46 am
content: Quote from: tellurium on January 22, 2024, 10:08:16 pmNo not really yet ...I just liked the way the mongoose framework was presenting it self, "easy webpage" etc ...But i do have a Solar Controller that speaks modbus, and was considering a "web status page" for that one.I was thinking more in the way ofHome Automation...Connect one of those cheap 4-chan relay boards, and make a webpage to turn on/off. Think mini "Tasmota" but forwired ethernetOr Temp sensors etc ...Maybe also control relay state via wget/curl, and read values via modbus and/or SNMP.I like the way the APC master switches can be controlled via SNMP. Makes controlling soo easy from a linux server.Note:I'm a hobbyist (w. a fulltime job) , so i might be "dreaming" a bit with the above ...I have never made any embeddd network programming or http page design./Bingo

author: tellurium
author_rank: Frequent Contributor
timestamp: January 23, 2024, 10:08:58 am
content: Great, thank you!I am looking for a feedback from anyone who'd use that modbus firmware, regardless whether it is a hobby or a commercial project.Those are not far apart anyways.My idea behind this particular implementation of modbus firmware was to make it possible to relay modbus to MQTT:1. Provide a UI to configure modbus endpoints: like, addresses, poll intervals, etc. That should be on the setting page,https://mongoose.ws/modbus-dashboard/#/settings2. Provide an optional MQTT endpoint, also on the settings page. If that is configured, the result of every modbus poll will be relayed to MQTT. This can be used for home/building automation3. The dashboard page,https://mongoose.ws/modbus-dashboard/#/, should just list configured devices (endpoints), and their status.4. Optionally, a reverse MQTT path could be implemented. For example, by writing to a certain topic a certain message, one could write to a modbus endpoint. This way, this firmware could act as a two-way Modbus <-> MQTT gatewayThat's what I have in mind, but that is something I just imagined. I'd like to have a feedback from someone who'd actually use that - or, similar functionality, before implementing it.bingo600, that said, if you have some practical use case and you'd like it to be reflected in the UI - please let me know!And I appreciate your time & attention so far.

author: bingo600
author_rank: Super Contributor
timestamp: January 24, 2024, 02:23:28 pm
content: Got my new boards from ALI todayHere's the mongoose fw on the same type board , as used previously (with the Ether-Link issue)Absolutely no issue ...with the new boardCode:0 2 main.c:46:main Starting, CPU freq 144 MHz5 2 main.c:51:main RAM/FLASH configuration: 64/256c 2 main.c:55:main Heap size: 48032 bytes. RAM: used 1032, free 5082314 3 stm32f.c:152:mg_tcpip_driver_s PHY ID: 0x00 0x0019 2 main.c:70:main MAC: 02:50:37:7e:37:e5. Waiting for IP...401 3 stm32f.c:201:mg_tcpip_driver_s Link is 10M half-duplex406 1 net_builtin.c:202:onstatechang Link up40a 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:50:37:7e:37:e5412 2 main.c:26:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:1, dr:0, er:0 RAM: 10860/407877e9 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:50:37:7e:37:e57f1 2 main.c:26:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:2, dr:0, er:0 RAM: 10860/40787bd1 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:50:37:7e:37:e5bd9 2 main.c:26:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:3, dr:0, er:0 RAM: 10860/40787fb9 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:50:37:7e:37:e5fc1 2 main.c:26:timer_fn Ethernet: up, IP: 0.0.0.0, rx:0, tx:4, dr:0, er:0 RAM: 10860/4078713a1 3 net_builtin.c:302:tx_dhcp_disc DHCP discover sent. Our MAC: 02:50:37:7e:37:e513a8 3 net_builtin.c:281:tx_dhcp_requ DHCP req sent13ad 2 net_builtin.c:408:rx_dhcp_clie Lease: 7132 sec (7137)13b3 2 net_builtin.c:197:onstatechang READY, IP: 10.1.1.21913b8 2 net_builtin.c:198:onstatechang GW: 10.1.1.113be 2 net_builtin.c:199:onstatechang MAC: 02:50:37:7e:37:e513c4 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.219, rx:2, tx:7, dr:0, er:0 RAM: 10860/4078713ce 2 main.c:75:main Initialising application...13d4 3 net.c:202:mg_listen 1 0 http://0.0.0.0:800013da 3 net.c:202:mg_listen 2 0 http://0.0.0.0/13df 3 net.c:202:mg_listen 3 0 https://0.0.0.0/13e5 2 main.c:79:main Starting event loop13ea 3 net.c:177:mg_connect 4 -1 udp://time.google.com:12313f0 3 net.c:177:mg_connect 5 -1 udp://8.8.8.8:5313f6 3 net_builtin.c:997:mg_connect_r 5 10.1.1.219:32768 -> 8.8.8.8:531791 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.219, rx:3, tx:8, dr:0, er:0 RAM: 12060/395871b79 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.219, rx:3, tx:8, dr:0, er:0 RAM: 12060/395871f61 2 main.c:26:timer_fn Ethernet: ready, IP: 10.1.1.219, rx:3, tx:8, dr:0, er:0 RAM: 12060/395871fa9 3 net.c:151:mg_close_conn 4 -1 closedSo my first board is strange ....Only difference is that i have soldered the dual header rows on the first board.But i have checked the soldering , and even cleaned it with a toothbrush and IPA.I also got some of the boards you tested on first port .....But it seems like i'd need to do DFU load on that one ... (Well it doesn't have the easy 10-pin header the other board has)Haven't tried DFU yet , but i think there might be a "Boot" button ...Edit:Well DFU was just as on a STM32F4 - Press RST + Boot , then release RST , and then Boot.I used the wchisp for programming that one ...No issues .../Bingo

author: bingo600
author_rank: Super Contributor
timestamp: February 02, 2024, 03:42:23 pm
content: I just had a headscratcherI got a few of these boardshttps://www.aliexpress.com/item/1005004350410929.htmlAnd tried to load the webapp.This time putting the board inDFU mode, and usewchispfor programming via an USB-C cable.One board was success , two other boards failed in verify.I tried to switch to another USB cable ... Same result.After digging a bit i found out the boards came from the factorywith flash protection activeBelow are my notes for disabling flash protection via wchisp.QuoteNote that the config reset will set the MCU fordefault32K Ram / 288K Flash.And that it seems like wchisp doesn't have code for setting the Ram/Flash config .... yet.If you're using wchisp , there is a way to get mongoose to set the (preferred) 64K Ram/ 256K Flash for you ... Thnx Tellurium1:Uncomment this line in main.c , to have mogoose set the config.2:Do a : make clean all (It will build for 32K)3:Upload that ...Now the chip should be set for 64K Ram.4:Now build for 64K Rammake CFLAGS_EXTRA='-Wl,--defsym -Wl,RAM_64K=1' clean all5:Upload that ....wchisp won't touch/change the Ram/Flash config, unless told to reset config.So you could "recomment" the line you uncommented in main.c. If you prefer mongoose not to alter the Ram/Flash config./Bingo

author: S. Petrukhin
author_rank: Super Contributor
timestamp: February 03, 2024, 07:08:08 pm
content: If it's not difficult, please tell me how it works?Does ch32v307 issue a Modbus exchange web page on an http request?

author: tellurium
author_rank: Frequent Contributor
timestamp: February 10, 2024, 12:22:13 am
content: Quote from: S. Petrukhin on February 03, 2024, 07:08:08 pmCorrect. This is how it works:1. A button click on the Web UI page triggers a REST API call, /api/modbus/exec:https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L262-L2632. Which in turn creates a modbus TCP connection to the target device:https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L187-L188The original HTTP REST request waits, but starts a software timer:https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L192-L1933. The modbus connection (https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L144C40-L145) sends a request to a target device (https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L147-L181)and when it receives a response (https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L104-L107),it finds an original REST request (https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L109-L111) and notifies it about the modbus response. An original REST request then sends a reponse to the Web UI (https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L285-L292)4. In case if modbus request times out, the original REST connection returns failure (https://github.com/cesanta/mongoose/blob/c8d45c9ff1b3042919d19ba823415d35ce1b0fbc/examples/modbus-dashboard/net.c#L281-L283)

author: S. Petrukhin
author_rank: Super Contributor
timestamp: February 11, 2024, 04:38:18 pm
content: Quote from: tellurium on February 10, 2024, 12:22:13 amThanks for the detailed answer!I have never used REST technology.That is, do you have your own application that exchanges with MK?I'm asking because my devices have a WEB interface targeted for using the browser.I did not find in JS the possibility of a direct binary request for Modbus exchange and made Modbus/HTTP.The browser sends get requests, usint fetch request.For example,/read?bank=4&startreg=10&count=2and receives responses in the body in the form ofvalues=34,56orerror=4

author: tellurium
author_rank: Frequent Contributor
timestamp: February 11, 2024, 09:05:53 pm
content: Quote from: S. Petrukhin on February 11, 2024, 04:38:18 pmJS inside the browser is limited only to HTTP and Websocket protocols. It cannot create arbitrary TCP/UDP connections.Therefore, the Web UI talks (via HTTP REST) to a device, and a device in turn creates arbitrary connections. In our case, it is Modbus.REST means "representational state transfer", but basically, if you think that "HTTP", "REST", or "Ajax" is the same - you won't be mistaken. It's the same stuff. That is, making HTTP requests to get some data.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: February 11, 2024, 09:24:09 pm
content: Thanks! I had a doubt that I was behind the times and missed the opportunities of JS.