Author Topic: CH32V003 blinky in RISCV assembly  (Read 2394 times)

0 Members and 1 Guest are viewing this topic.

Offline SajeevTopic starter

  • Contributor
  • Posts: 20
  • Country: in
CH32V003 blinky in RISCV assembly
« on: July 23, 2023, 05:20:13 pm »
Dear forum members,
Please find attached PD4 LED blinky in assembler. Used BRONZEBEARD assembler and WCHELINK. Get BRONZEBEARD here https://github.com/theandrew168/bronzebeard
regards
sajeev

attached the correct GPIO_asm.asm file. Thanks for feedback from siliconwizard and westwf
« Last Edit: July 26, 2023, 02:14:02 pm by Sajeev »
 
The following users thanked this post: DiTBho

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: us
Re: CH32V003 blinky in RISCV assembly
« Reply #1 on: July 25, 2023, 05:29:08 am »
the asm code seems to be a copy of the register definitions?


Why use a weird assembler instead of GAS?

 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: gb
Re: CH32V003 blinky in RISCV assembly
« Reply #2 on: July 25, 2023, 09:22:03 am »
Why use a weird assembler instead of GAS?

comparing "GNU/as" with "nasm" (x86), "G/as" is very unfriendly.
and it's the same for other architectures.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15097
  • Country: fr
Re: CH32V003 blinky in RISCV assembly
« Reply #3 on: July 25, 2023, 09:33:23 pm »
I don't see a single line of RISC-V assembly in these files.
 
The following users thanked this post: rhodges

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: us
Re: CH32V003 blinky in RISCV assembly
« Reply #4 on: July 25, 2023, 11:37:24 pm »
Quote
comparing "GNU/as" with "nasm" (x86), "G/as" is very unfriendly.
Well, 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.



 
The following users thanked this post: rhodges

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4348
  • Country: nz
Re: CH32V003 blinky in RISCV assembly
« Reply #5 on: July 26, 2023, 12:33:22 am »
Quote
comparing "GNU/as" with "nasm" (x86), "G/as" is very unfriendly.
Well, 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.

It 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.
 

Offline SajeevTopic starter

  • Contributor
  • Posts: 20
  • Country: in
Re: CH32V003 blinky in RISCV assembly
« Reply #6 on: July 26, 2023, 04:48:56 am »
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.
Regards
Sajeev
 

Offline SajeevTopic starter

  • Contributor
  • Posts: 20
  • Country: in
Re: CH32V003 blinky in RISCV assembly
« Reply #7 on: July 26, 2023, 04:58:03 am »
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.
Regards
Sajeev
 

Offline SajeevTopic starter

  • Contributor
  • Posts: 20
  • Country: in
Re: CH32V003 blinky in RISCV assembly
« Reply #8 on: July 26, 2023, 05:37:02 am »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: us
Re: CH32V003 blinky in RISCV assembly
« Reply #9 on: July 26, 2023, 06:59:10 am »
Quote
Good assemblers for example allow you to say that SP or some other register currently points to data conforming to some struct
Ah, 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 in the "minimal ARM" discussion days (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: [Select]
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
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: us
Re: CH32V003 blinky in RISCV assembly
« Reply #10 on: July 26, 2023, 07:01:11 am »
Quote
I tried to install GCC in windows for riscv and it was a nightmare


I 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.)

 

Offline SajeevTopic starter

  • Contributor
  • Posts: 20
  • Country: in
Re: CH32V003 blinky in RISCV assembly
« Reply #11 on: July 26, 2023, 07:19:57 am »
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.
Regards
Sajeev   
 

Offline SajeevTopic starter

  • Contributor
  • Posts: 20
  • Country: in
Re: CH32V003 blinky in RISCV assembly
« Reply #12 on: July 26, 2023, 08:36:35 am »
get bronzebeard assembler from https://github.com/theandrew168/bronzebeard
 WINDOWS
 To 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.bat

if GPIO_asm and CH32V003_reg1.asm (inc files) are on desktop ( both files should be in the same folder) use command

bronzebeard --hex-offset 0x08000000 Desktop/GPIO_asm.asm

Use 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
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4348
  • Country: nz
Re: CH32V003 blinky in RISCV assembly
« Reply #13 on: July 26, 2023, 09:06:47 am »
Quote
Good assemblers for example allow you to say that SP or some other register currently points to data conforming to some struct
Ah, 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 in the "minimal ARM" discussion days (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: [Select]
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

Ok, so that's slightly tidier than ...

Code: [Select]
.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: [Select]
    ldr r0, =RCC_BASE
    ldr r1, [r0, #RCC_CR]
    orr r1, #RCC_CR_HSEON
    str r1, [r0, #RCC_CR]

What IBM's (and Apple's MPW) assemblers allow you to write is more like...

Code: [Select]
rcc:    USING r0, RCC_BASE
        ldr r1, rcc.CR
        orr r1, #RCC_CR_HSEON ; you can do something with this too, but that's a different topic
        str r1, rcc.CR
        DROP rcc

Or you can dispense with the rcc: label and use r0.CR.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf