diff --git a/RaspberryPiPico/CMakeLists.txt b/RaspberryPiPico/CMakeLists.txt index 1364538..bdf0e81 100644 --- a/RaspberryPiPico/CMakeLists.txt +++ b/RaspberryPiPico/CMakeLists.txt @@ -25,3 +25,9 @@ target_link_libraries(${PROJECT_NAME} PRIVATE pico_multicore hardware_pio ) + +if(${PICO_BOARD} STREQUAL "pico_w") +target_link_libraries(${PROJECT_NAME} PRIVATE + pico_cyw43_arch_none + ) +endif() diff --git a/RaspberryPiPico/board.c b/RaspberryPiPico/board.c index e8e6dc0..953f29d 100644 --- a/RaspberryPiPico/board.c +++ b/RaspberryPiPico/board.c @@ -28,11 +28,43 @@ SOFTWARE. #include "bus.pio.h" +#include "board.h" + extern const __attribute__((aligned(4))) uint8_t firmware[]; static uint32_t __not_in_flash("page") page; -void __not_in_flash_func(board)() { +void __not_in_flash_func(board)(void) { + for (uint gpio = gpio_addr; gpio < gpio_addr + size_addr; gpio++) { + gpio_init(gpio); + gpio_set_pulls(gpio, false, false); // floating + } + + for (uint gpio = gpio_data; gpio < gpio_data + size_data; gpio++) { + pio_gpio_init(pio0, gpio); + gpio_set_pulls(gpio, false, false); // floating + } + + gpio_init(gpio_enbl); + gpio_pull_up(gpio_enbl); + + gpio_init(gpio_irq); + gpio_pull_up(gpio_irq); + + gpio_init(gpio_nmi); + gpio_pull_up(gpio_nmi); + + uint offset; + + offset = pio_add_program(pio0, &enbl_program); + enbl_program_init(offset); + + offset = pio_add_program(pio0, &write_program); + write_program_init(offset); + + offset = pio_add_program(pio0, &read_program); + read_program_init(offset); + while (true) { uint32_t enbl = pio_sm_get_blocking(pio0, sm_enbl); uint32_t addr = enbl & 0x0FFF; diff --git a/RaspberryPiPico/board.h b/RaspberryPiPico/board.h new file mode 100644 index 0000000..b1ac9c5 --- /dev/null +++ b/RaspberryPiPico/board.h @@ -0,0 +1,32 @@ +/* + +MIT License + +Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#ifndef _BOARD_H +#define _BOARD_H + +void board(void); + +#endif diff --git a/RaspberryPiPico/bus.pio b/RaspberryPiPico/bus.pio index 496bb65..9098e56 100644 --- a/RaspberryPiPico/bus.pio +++ b/RaspberryPiPico/bus.pio @@ -31,10 +31,9 @@ SOFTWARE. .define public gpio_addr 2 // 12 pins .define public gpio_rw 14 .define public gpio_data 15 // 8 pins -.define public gpio_led 25 .define public gpio_enbl 26 // DEVSEL | IOSEL | IOSTRB .define public gpio_irq 27 -.define public gpio_rdy 28 +.define public gpio_nmi 28 .define public size_addr 13 // incl. R/W .define public size_data 8 @@ -74,9 +73,9 @@ idle: in pins, size_addr // shift A0-A11 + R/W into ISR - jmp pin idle // jump to idle if R/W is high + jmp pin idle // jump to 'idle' if R/W is high - irq irq_write // Set 'write' IRQ + irq irq_write // set 'write' IRQ .wrap diff --git a/RaspberryPiPico/main.c b/RaspberryPiPico/main.c index 6184a85..df27a45 100644 --- a/RaspberryPiPico/main.c +++ b/RaspberryPiPico/main.c @@ -28,10 +28,11 @@ SOFTWARE. #include "pico/printf.h" #include "pico/stdlib.h" #include "pico/multicore.h" +#ifdef RASPBERRYPI_PICO_W +#include "pico/cyw43_arch.h" +#endif -#include "bus.pio.h" - -void board(); +#include "board.h" #ifdef TRACE void uart_printf(uart_inst_t *uart, const char *format, ...) { @@ -47,7 +48,16 @@ void uart_printf(uart_inst_t *uart, const char *format, ...) { } #endif -int main() { +void main(void) { + multicore_launch_core1(board); + +#ifdef RASPBERRYPI_PICO_W + cyw43_arch_init(); +#else + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); +#endif + stdio_init_all(); stdio_set_translate_crlf(&stdio_usb, false); @@ -58,41 +68,6 @@ int main() { gpio_set_function(1, GPIO_FUNC_UART); #endif - for (uint gpio = gpio_addr; gpio < gpio_addr + size_addr; gpio++) { - gpio_init(gpio); - gpio_set_pulls(gpio, false, false); // floating - } - - for (uint gpio = gpio_data; gpio < gpio_data + size_data; gpio++) { - pio_gpio_init(pio0, gpio); - gpio_set_pulls(gpio, false, false); // floating - } - - gpio_init(gpio_enbl); - gpio_set_pulls(gpio_enbl, false, false); // floating - - gpio_init(gpio_irq); - gpio_pull_up(gpio_irq); - - gpio_init(gpio_rdy); - gpio_pull_up(gpio_rdy); - - gpio_init(gpio_led); - gpio_set_dir(gpio_led, GPIO_OUT); - - uint offset; - - offset = pio_add_program(pio0, &enbl_program); - enbl_program_init(offset); - - offset = pio_add_program(pio0, &write_program); - write_program_init(offset); - - offset = pio_add_program(pio0, &read_program); - read_program_init(offset); - - multicore_launch_core1(board); - while (true) { bool conn = stdio_usb_connected(); if (conn) { @@ -115,8 +90,14 @@ int main() { } } - gpio_put(gpio_led, conn); +#ifdef RASPBERRYPI_PICO_W + static bool last_conn; + if (conn != last_conn) { + cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, conn); + last_conn = conn; + } +#else + gpio_put(PICO_DEFAULT_LED_PIN, conn); +#endif } - - return 0; }