This is a step along the way. For me, it is about getting comfortable with the RP2040 and getting my toolchain set up. You could also view the C code I am about to show you as "pseudo-code" for assembly language code we will soon be writing. And, to boot, we can let the C compiler show us how to write assembly code, which is never a bad idea.
Really what we are doing is avoiding tackling two problems at once. One is figuring out the RP2040 and our toolchain, the other is figuring out assembly language.
The whole shebang is on my Github here:
I owe a debt to Dwelch67, as I studied his blink00 demo to learn how to do this. I coded it with a very different style than he did, just because I have my own way of doing things. Here is the heart of the C code:void blink ( void ) { struct resets *rp; struct sio *sp; struct io_bank0 *iop; /* reset IO Bank 0 */ rp = (struct resets *) RESET_BASE_CLR; rp->reset = R_IO_BANK0; rp = (struct resets *) RESET_BASE_RW; while ( (rp->done & R_IO_BANK0) == 0 ) ; sp = (struct sio *) SIO_BASE; // sp->gpio_oe_clr = GPIO_25; // sp->gpio_out_clr = GPIO_25; /* Set function select to software IO */ iop = (struct io_bank0 *) IO_BANK0_BASE_RW; iop->io[25].ctrl = 5; sp->gpio_oe_set = GPIO_25; // sp->gpio_out_set = GPIO_25; // led on // sp->gpio_out_clr = GPIO_25; // led off for ( ;; ) { // on sp->gpio_out_set = GPIO_25; blink_delay (); // off sp->gpio_out_clr = GPIO_25; blink_delay (); } }So, let me go step by step through what we are doing here.
To save space, I am not showing all the code here, but you can either go to Github to look at it all, or even better, clone and then build and run it yourself.
You may also wonder about why we have to fiddle with reset at all. This is common in microcontrollers and SoC in general. After power up, most peripherals are held in reset and you have to release the reset (and sometimes enable a clock) to get them to run. With some chips this is done to save power -- you don't run any part of the chip unless you actually need it.
Tom's Computer Info / [email protected]