add ch32v303cbt6 - #239
Conversation
|
Excellent! (Unfortunately I don't have a V303 in my collection to test this. Perhaps others can help out...) |
|
Max, do you have CH570D in your collection ? |
|
The PR has a |
|
There is no ch32v303cbt6 official eval board, only ch32v303vct6, I just wanted to add the cbt6 as a general mcu like you can do with the smt32duino where you are not stuck with only EVT boards. Anyway I can add it as a generic board if that makes sense. |
Hallo @BitByteBeetle , no I don't have any CH57x yet. If you've any spares I'd be happy to receive one. I've continued my response here in your issue about the CH570D. |
|
Hi @maxint-rd, I'm ordering V303 devboard from official WCH ali store. Do you want one for the testing ? How can I generate a working Arduino test environnement? |
|
Hello @kingovchouffe ,
Thank you for that offer. If it's not too costly for you I'd very much appreciate your contribution to my collection! Unfortunately I cannot commit to spend much time, but I'd try my best to test things and look into issues. You can get my address details via e-mail: info [at] maxint.nl My electronics hobby would quickly ran out of budget if I were to buy every WCH dev board, so I only bought the V003 EVT board and a bunch of the most affordable bare chips, e.g. V003, V002, V006. If you're interested I can send you some of those in return. (BTW. On the WCH AliExpress store I saw the V303CBT6-EVT-R0 board and also the V303VCT6-EVT-R0 and V303RCT6-EVT-R1. I presume you're ordering the CBT6 board, since that's the topic of your PR. Are you making your own CBT6 board, perhaps something audio related? ;-)
I know that in PR #121 the makeboards.py python script was added to the tools, but I didn't use that. What I did for the V002/V006 (in PR #200) and for the X033 (in PR #171) was basically:
From looking at the changed files in your PR, you already did much of this already. |
|
Hello @maxint-rd I already have a CH32V303CBT6 board with the goal to do audio effects. I can't test on it the ADC, DAC, LED, and GPIO reading but not much. I don't know if it could be sufficient for this PR or if it needs to be tested on the devboard. Thank you for the guidelines I'll try to do the testing when I have the time. |
|
I think using that board could be sufficient to test this PR. If the PR works for you, then that's already something. In the board definitions I added, I found it sufficient to have the peripherals working on the available pins. I only have the V003 EVT board and use the others as bare chips on breakout boards, (or directly on project specific PCB's). Please note that like other PRs this PR will not be merged into a new release by WCH, unless they dedicate some manpower to do so, or delegate their authorization to the community. However, knowing this PR works might help others to include it in their board files. Personally I still like using the CH32 platform for my Arduino projects. Mainly for its affordability, but also for features such as easy debugging and the ease of upgrading when flash gets too low. My main goal is to be able to use these processors in a wide range of Arduino projects, so I mainly worked on getting basic Arduino functionality working and add support to common Arduino libraries. |
|
Hey and thanks a lot for your PR ! I've been trying it on my own chip, but seem to be hitting a HardFault within the startup script, on line 365. I'll be looking a bit more in detail later and report back 😄 |
mickabrig7
left a comment
There was a problem hiding this comment.
Found it !
Fixing CH32V303CBT6.build.chip + setting the correct sizes in system/CH32V30x/SRC/Ld/Link.ld made it work (the latter should maybe not be applied in this PR since it would break compatibility with the other chips with more memory, I'm not sure how PlatformIO is supposed to handle this normally).
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.board=CH32V303CBT6 | ||
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.series=CH32V30x | ||
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.variant=CH32V30x/CH32V303CBT6 | ||
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.chip=CH32V30x_C |
There was a problem hiding this comment.
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.chip=CH32V30x_C | |
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.chip=CH32V30x |
|
Congratulations @mickabrig7 FYI: in PR #200 to add support for CH32V002 I added a link file to specifically match the V002 characteristics. In the board.txt file I used the Perhaps you can use that method to avoid breaking compatibility? |
|
Hey @mickabrig7 ! They are a lot of issues with this PR and I submitted it a bit too early sorry for that without having the time to properly test itsorry for that. Thanks you for this modification, have you test the PR with a blinky ? I will test this modification on my board after work (UE time). @maxint-rd I will do another link file again after work. Again thanks for your support :) |
|
@kingovchouffe Avec plaisir copain, merci a toi ! 🙆♂️ So after some testing, I was able to enumerate my chip as a USB device by defining It's bed time in my time zone so I'll check this out more in depth tomorrow, in the meantime have a good evening 😊 |
|
I made another link file, and I checked other configuration file but I'm not able to do some basic blinky also. But it's nice that the USB work ! maybe the end of the tunnel isn't that far. I'll work on that this week-end :) |
There was a problem hiding this comment.
Okay so turns out I'm stupid and was just accidentally calling Arduino GPIO functions with the PinNames.h pin definitions (the ones with an underscore like PB_2) instead of the ones defined in the variant_*.h files 🫠
I just found 2 small mistakes that I'm suggesting changes for in this review.
However, even after fixing the ldscript typo and clean building my project, the linker file doesn't seem properly applied: I still need to edit the default Link.ld for the chip to boot properly.
I've been looking at #200 that @maxint-rd linked and I honestly cannot figure out what we're doing differently here 🤷
Otherwise everything works nicely, I got my project running just like on a CH32V203 with more memory which is exactly what I wanted, and it uses Adafruit TinyUSB + Adafruit NeoPixel + SimpleFOC (with an I2C sensor using TwoWire) + HX711_ADC.
Thanks again !
Co-authored-by: ガラベロ ミカエル <mickaelgarabello7@gmail.com>
Co-authored-by: ガラベロ ミカエル <mickaelgarabello7@gmail.com>
|
WOW thanks a lot @mickabrig7 it works on my side too ! it was a stupid mistake but good catch ! |
|
Hello again @mickabrig7 and @kingovchouffe , Although I can't help you in testing (yet), I do wish you both all the luck in getting everything working. Always nice to have support for more CH32 chips. Congratulations on the results of your efforts so far! @mickabrig7, can I presume you were using the Arduino IDE v2.x in your latest test? (I'm not familiar with the way Platformio does the linking). I wonder why you still need to change the regular link file. I saw that you fixed the If you are using the IDE; I remember that when changing things in the board,txt, these changes were not always followed by the IDE. Adding things such as the peripheral menu required clearing the IDE cache. It's a known issue that bugged me enough to write a section about dealing with it. If you're using Platformio: I guess you still need to look at the command line that is used at the final step of linking and make sure your alternative link file is used. For the IDE the I don't know if those files are used the same way in Platformio. The IDE uses that value later in platform.txt to do the linking: |
mickabrig7
left a comment
There was a problem hiding this comment.
@maxint-rd Thanks for the info !
I am indeed using PlatformIO exclusively and have never tried using this core with the Arduino IDE.
After looking around to see how multiple memory sizes were handled for the CH32V20x (which has plenty of variants), I went for what I believe is the cleanest way to do it: using the __FLASH_SIZE, __RAM_SIZE and __STACK_SIZE defines that are linked to the upload.maximum_size / upload.maximum_data_size properties within platform.txt.
So our Link.ld becomes this:
__flash_size = DEFINED(__FLASH_SIZE) ? __FLASH_SIZE : 256K;
__ram_size = DEFINED(__RAM_SIZE) ? __RAM_SIZE : 64K;
__stack_size = DEFINED(__STACK_SIZE) ? __STACK_SIZE : 2048;
ENTRY( _start )
PROVIDE( _stack_size = __stack_size );
MEMORY
{
/* CH32V30x_D8C - CH32V305RB-CH32V305FB
CH32V30x_D8 - CH32V303CB-CH32V303RB
*/
/*
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
*/
/* CH32V30x_D8C - CH32V307VC-CH32V307WC-CH32V307RC
CH32V30x_D8 - CH32V303VC-CH32V303RC
FLASH + RAM supports the following configuration
FLASH-192K + RAM-128K
FLASH-224K + RAM-96K
FLASH-256K + RAM-64K
FLASH-288K + RAM-32K
*/
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = __flash_size
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = __ram_size
}
It works properly on my side and I would imagine it does on Arduino IDE too ?
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.math_lib_gcc=-lm | ||
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.IQ_math_RV32= | ||
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.ch_extra_lib=-lprintfloat | ||
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.ldscript=Link_v303.ld |
There was a problem hiding this comment.
| CH32V30x_EVT.menu.pnum.CH32V303CBT6.build.ldscript=Link_v303.ld |
Sounds like a great solution. I haven't tried using these definitions, but it's definitely cleaner than using a blunt modification of a copied link file like I did. Unfortunately I don't have the spare time now, but as soon as I get the opportunity, I'd like to test this for my V002 PR. Thank you for your help and for giving this suggestion! |
Add support for CH32V303CBT6 generic board