CH32V003 blinky in RISCV assembly - Page 1
Forum section: electronics / general

author: Sajeev
author_rank: Contributor
timestamp: July 23, 2023, 05:20:13 pm
content: Dear forum members,Please find attached PD4 LED blinky in assembler. Used BRONZEBEARD assembler and WCHELINK. Get BRONZEBEARD herehttps://github.com/theandrew168/bronzebeardregardssajeevattached the correct GPIO_asm.asm file. Thanks for feedback from siliconwizard and westwf

author: westfw
author_rank: Super Contributor
timestamp: July 25, 2023, 05:29:08 am
content: the asm code seems to be a copy of the register definitions?Why use a weird assembler instead of GAS?

author: DiTBho
author_rank: Super Contributor
timestamp: July 25, 2023, 09:22:03 am
content: Quote from: westfw on July 25, 2023, 05:29:08 amcomparing "GNU/as" with "nasm" (x86), "G/as" is very unfriendly.and it's the same for other architectures.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 25, 2023, 09:33:23 pm
content: I don't see a single line of RISC-V assembly in these files.

author: westfw
author_rank: Super Contributor
timestamp: July 25, 2023, 11:37:24 pm
content: QuoteWell, yeah, IIRC GNU/as doesn't come close to supporting the complex instruction set syntax that Intel defined for the x86.But for the typical RISC CPUs, I wouldn't rate it as "very unfriendly." It seems to have all the generic features of any other assembler.

author: brucehoult
author_rank: Super Contributor
timestamp: July 26, 2023, 12:33:22 am
content: Quote from: westfw on July 25, 2023, 11:37:24 pmIt has pretty much exactly the features needed to support gcc output, but it's really not that great for large scale writing of assembly language by hand.For example, you can't make symbolic aliases (meaningful variable names) for registers, except by using the C preprocessor's #define.Arithmetic expressions are also very limited, and things you'd think can be done in one expression often actually need multiple steps with temporary variables.The support for macros is weak.There is no support at all for defining complex data, not even structs. Good assemblers for example allow you to say that SP or some other register currently points to data conforming to some struct and then allow you to use field names as offsets.It is a huge step down from e.g. IBM 360 mainframe assembly language from the 1970s (if not 1960s), which is so good that Apple copied it wholesale for their M68000 assembler in MPW in the mid 1980s -- it was powerful enough to allow CONVENIENTLY using and even defining and extending Object Pascal and C++ classes in assembly language.

author: Sajeev
author_rank: Contributor
timestamp: July 26, 2023, 04:48:56 am
content: Dear Sir,Greetings of the day!Thankyou for pointing out the mistake in the attached files. I am attaching the correct blinky file here. The GPIO_asm.asm is the code and ch32v003_reg1.asm is the include file for register definitions. I used the bronzebeard assembler because it is light and easy to use without much setup. I don't know C or any other higher languages and all those big compilers/tools are more C oriented , at least that what I thought.RegardsSajeev

author: Sajeev
author_rank: Contributor
timestamp: July 26, 2023, 04:58:03 am
content: Dear Sir,Infact I tried to install GCC in windows for riscv and it was a nightmare . The installation would always terminate with some error. Then i saw this assembler which was easy to install and assemble. The owner of the code was also helpful to add a .hex generator when i requested. After months using bronzebeard I got a copy of prebuilt GCC riscV from emboscom which was easy to install and use. Ithink GCC is still complicated and has too many commandline options to remember. Bronzebeard is simple and just assembles to a .hex file. It doesn't have a debug option. write the correct code and assemble it, thats all. If i need to debug ,I just print out all CPU/peripheral registers via UART. I am just a budding hobbyist and an automobile mechanic by profession.RegardsSajeev

author: Sajeev
author_rank: Contributor
timestamp: July 26, 2023, 05:37:02 am
content: https://youtu.be/6OKFrt8nYaE

author: westfw
author_rank: Super Contributor
timestamp: July 26, 2023, 06:59:10 am
content: QuoteAh, but is the "Bronzebeard assembler" a "Good Assembler", or is it some quick hack someone wrote that is even worse than gnu-asm?At least gas is a known quantity. And once you do stuff, it'll be portable to a lot of different architectures.Weren't things like structures usually implemented as macros? I was a big fan of Macro-10 (DEC's 36bit assembler), and it's structures/etc were all done as macros.I've implemented structures in GAS, back inthe "minimal ARM" discussiondays (wow, almost a decade ago!)It wasn't that hard, and it looks almost like C (indeed, was created by EMACS macros from ST's .h files.)Code:STRUCTDEF DAC__IO uint32_t CR;__IO uint32_t SWTRIGR;__IO uint32_t DHR12R1;__IO uint32_t DHR12L1;__IO uint32_t DHR8R1;__IO uint32_t DHR12R2;__IO uint32_t DHR12L2;__IO uint32_t DHR8R2;__IO uint32_t DHR12RD;__IO uint32_t DHR12LD;__IO uint32_t DHR8RD;__IO uint32_t DOR1;__IO uint32_t DOR2;__IO uint32_t SR;ENDSTRUCT

author: westfw
author_rank: Super Contributor
timestamp: July 26, 2023, 07:01:11 am
content: QuoteI can believe that.I probably would have installed one of the "board support packages" for RISC-V that comes with Arduino; that loads all the gcc tools for you, in a form that usually works (although the first time I tried to install the Sispeed package on my Mac, there was a bunch of utilities it claimed it couldn't get. I think the ESP-Cx board support is better.)

author: Sajeev
author_rank: Contributor
timestamp: July 26, 2023, 07:19:57 am
content: Dear Sir,Bronzebeard may not be a professional class assembler as GNU but does the minimal job as per RISCV ISA. specs I M & C is implemented. No macro and debug support . Most of the psuedo instructions are supported. It does the job for a beginner without hassles. One can upgrade to GNU with minimal change to syntax/keywords. The BB doesn't have (la) load address instruction instead it uses li (load immediate). The defines are little bit different , vector tables are defined using pack. The assembler is written in python. More than this i am ignorant.RegardsSajeev

author: Sajeev
author_rank: Contributor
timestamp: July 26, 2023, 08:36:35 am
content: get bronzebeard assembler fromhttps://github.com/theandrew168/bronzebeardWINDOWSTo create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path: python3 -m venv tutorial-env This will create the tutorial-env directory if it doesn’t exist, and also create directories inside it containing a copy of the Python interpreter and various supporting files. A common directory location for a virtual environment is .venv. This name keeps the directory typically hidden in your shell and thus out of the way while giving it a name that explains why the directory exists. It also prevents clashing with .env environment variable definition files that some tooling supports. Once you’ve created a virtual environment, you may activate it. On Windows, run:tutorial1-env\Scripts\activate.batif GPIO_asm and CH32V003_reg1.asm (inc files) are on desktop ( both files should be in the same folder) use commandbronzebeard --hex-offset 0x08000000 Desktop/GPIO_asm.asmUse WCH_LINK_UTILITY to upload the assembled bb.out.hex file to CH32V003 chip by connceting gnd, 3.3v,DIO pins. if successful led on PD4 pin flashes

author: brucehoult
author_rank: Super Contributor
timestamp: July 26, 2023, 09:06:47 am
content: Quote from: westfw on July 26, 2023, 06:59:10 amOk, so that's slightly tidier than ...Code:.equ DAC_CR 0.equ DAC_SWTRIGR DAC_CR+4...... or some similar thing equating each field to . and then bumping . -- which could use a single per-field macro if you wanted.But it's really only a small part of what real asm STRUCT definitions do!Code:ldr r0, =RCC_BASEldr r1, [r0, #RCC_CR]orr r1, #RCC_CR_HSEONstr r1, [r0, #RCC_CR]What IBM's (and Apple's MPW) assemblers allow you to write is more like...Code:rcc: USING r0, RCC_BASEldr r1, rcc.CRorr r1, #RCC_CR_HSEON ; you can do something with this too, but that's a different topicstr r1, rcc.CRDROP rccOr you can dispense with thercc:label and user0.CR.