Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK updates & timeout fixes #209

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#endif

#ifndef __MBED__
# include <SerialUSB.h>
#include <Adafruit_TinyUSB.h>
# include <class/cdc/cdc_device.h>
#else
# include <platform/mbed_error.h>
Expand All @@ -34,7 +34,6 @@
#include "hardware/i2c.h"

extern "C" {
#include <pico/cyw43_arch.h>

const char *g_platform_name = PLATFORM_NAME;
static bool g_scsi_initiator = false;
Expand Down Expand Up @@ -73,7 +72,7 @@ void mbed_error_hook(const mbed_error_ctx * error_context);
/***************/

// Helper function to configure whole GPIO in one line
static void gpio_conf(uint gpio, enum gpio_function fn, bool pullup, bool pulldown, bool output, bool initial_state, bool fast_slew)
static void gpio_conf(uint gpio, gpio_function_t fn, bool pullup, bool pulldown, bool output, bool initial_state, bool fast_slew)
{
gpio_put(gpio, initial_state);
gpio_set_dir(gpio, output);
Expand All @@ -82,7 +81,7 @@ static void gpio_conf(uint gpio, enum gpio_function fn, bool pullup, bool pulldo

if (fast_slew)
{
padsbank0_hw->io[gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
pads_bank0_hw->io[gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
}
}

Expand Down Expand Up @@ -127,13 +126,17 @@ void platform_init()
{
// Make sure second core is stopped
multicore_reset_core1();
#ifndef __MBED__
Serial.begin(115200);
#endif // __MBED__

// Default debug logging to disabled
g_log_debug = false;

// Report platform and firmware version
log("Platform: ", g_platform_name);
log("FW Version: ", g_log_firmwareversion);
debuglog("PicoSDK: ", PICO_SDK_VERSION_STRING);

/* First configure the pins that affect external buffer directions.
* RP2040 defaults to pulldowns, while these pins have external pull-ups.
Expand Down Expand Up @@ -173,8 +176,8 @@ void platform_init()
gpio_conf(scsi_pins.IN_ATN, GPIO_FUNC_SIO, false, false, false, false, false);
delay(10); /// Settle time
// Check option switches
bool optionS1 = !gpio_get(scsi_pins.IN_ATN);
bool optionS2 = !gpio_get(scsi_pins.IN_ACK);
[[maybe_unused]] bool optionS1 = !gpio_get(scsi_pins.IN_ATN);
[[maybe_unused]] bool optionS2 = !gpio_get(scsi_pins.IN_ACK);

// Reset REQ to appropriate pin for older hardware
scsi_pins.OUT_REQ = SCSI_OUT_REQ_BEFORE_2023_09a;
Expand All @@ -201,9 +204,9 @@ void platform_init()
// Get flash chip size
uint8_t cmd_read_jedec_id[4] = {0x9f, 0, 0, 0};
uint8_t response_jedec[4] = {0};
__disable_irq();
uint32_t status = save_and_disable_interrupts();
flash_do_cmd(cmd_read_jedec_id, response_jedec, 4);
__enable_irq();
restore_interrupts_from_disabled(status);
g_flash_chip_size = (1 << response_jedec[3]);
log("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");

Expand Down Expand Up @@ -290,9 +293,6 @@ void platform_late_init()
gpio_conf(scsi_pins.IN_RST, GPIO_FUNC_SIO, true, false, false, true, false);


#ifndef __MBED__
Serial.begin();
#endif // __MBED__

#ifdef ENABLE_AUDIO_OUTPUT
// one-time control setup for DMA channels and second core
Expand Down Expand Up @@ -495,7 +495,7 @@ static void adc_poll()
* If ADC sample reads are done, either via direct reading, FIFO, or DMA,
* at the same time a SPI DMA write begins, it appears that the first
* 16-bit word of the DMA data is lost. This causes the bitstream to glitch
* and audio to 'pop' noticably. For now, just disable ADC reads when audio
* and audio to 'pop' noticeably. For now, just disable ADC reads when audio
* is playing.
*/
if (audio_is_active()) return;
Expand Down Expand Up @@ -570,7 +570,9 @@ static void watchdog_callback(unsigned alarm_num)
#ifdef __MBED__
uint32_t *p = (uint32_t*)__get_PSP();
#else
uint32_t *p = (uint32_t*)__get_MSP();
uint32_t msp;
asm volatile ("MRS %0, msp" : "=r" (msp) );
uint32_t *p = (uint32_t*)msp;
#endif
for (int i = 0; i < 8; i++)
{
Expand All @@ -597,7 +599,9 @@ static void watchdog_callback(unsigned alarm_num)
#ifdef __MBED__
uint32_t *p = (uint32_t*)__get_PSP();
#else
uint32_t *p = (uint32_t*)__get_MSP();
uint32_t msp;
asm volatile ("MRS %0, msp" : "=r" (msp) );
uint32_t *p = (uint32_t*)msp;
#endif
for (int i = 0; i < 8; i++)
{
Expand Down Expand Up @@ -627,7 +631,7 @@ void platform_reset_watchdog()
if (!g_watchdog_initialized)
{
int alarm_num = -1;
for (int i = 0; i < NUM_TIMERS; i++)
for (int i = 0; i < NUM_GENERIC_TIMERS; i++)
{
if (!hardware_alarm_is_claimed(i))
{
Expand Down Expand Up @@ -736,7 +740,7 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
assert(offset >= PLATFORM_BOOTLOADER_SIZE);

// Avoid any mbed timer interrupts triggering during the flashing.
__disable_irq();
uint32_t status = save_and_disable_interrupts();

// For some reason any code executed after flashing crashes
// unless we disable the XIP cache.
Expand All @@ -754,17 +758,17 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
for (int i = 0; i < num_words; i++)
{
uint32_t expected = buf32[i];
uint32_t actual = *(volatile uint32_t*)(XIP_NOCACHE_BASE + offset + i * 4);
uint32_t actual = *(volatile uint32_t*)(XIP_SRAM_BASE + offset + i * 4);

if (actual != expected)
{
log("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
__enable_irq();
restore_interrupts_from_disabled(status);
return false;
}
}

__enable_irq();
restore_interrupts_from_disabled(status);

return true;
}
Expand All @@ -774,7 +778,7 @@ void platform_boot_to_main_firmware()
// To ensure that the system state is reset properly, we perform
// a SYSRESETREQ and jump straight from the reset vector to main application.
g_bootloader_exit_req = &g_bootloader_exit_req;
SCB->AIRCR = 0x05FA0004;
scb_hw->aircr = 0x05FA0004;
while(1);
}

Expand All @@ -787,7 +791,7 @@ void btldr_reset_handler()
application_base = (uint32_t*)(XIP_BASE + PLATFORM_BOOTLOADER_SIZE);
}

SCB->VTOR = (uint32_t)application_base;
scb_hw->aircr = (uint32_t)application_base;
__asm__(
"msr msp, %0\n\t"
"bx %1" : : "r" (application_base[0]),
Expand Down Expand Up @@ -859,10 +863,10 @@ bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count
assert(start < platform_get_romdrive_maxsize());
assert((count % PLATFORM_ROMDRIVE_PAGE_SIZE) == 0);

__disable_irq();
uint32_t status = save_and_disable_interrupts();
flash_range_erase(start + ROMDRIVE_OFFSET, count);
flash_range_program(start + ROMDRIVE_OFFSET, data, count);
__enable_irq();
restore_interrupts_from_disabled(status);
return true;
}

Expand Down
11 changes: 9 additions & 2 deletions lib/BlueSCSI_platform_RP2040/BlueSCSI_platform_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#pragma once

#include <hardware/gpio.h>
#ifdef BLUESCSI_NETWORK
#include <pico/cyw43_arch.h>
#endif

// SCSI data input/output port.
// The data bus uses external bidirectional buffer, with
Expand Down Expand Up @@ -56,8 +58,13 @@

// Status LED pins
#define LED_PIN 25
#define LED_ON() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, true) : sio_hw->gpio_set = 1 << LED_PIN
#define LED_OFF() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, false) : sio_hw->gpio_clr = 1 << LED_PIN
#ifdef BLUESCSI_NETWORK
#define LED_ON() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, true) : sio_hw->gpio_set = 1 << LED_PIN
#define LED_OFF() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, false) : sio_hw->gpio_clr = 1 << LED_PIN
#else
#define LED_ON() sio_hw->gpio_set = 1 << LED_PIN
#define LED_OFF() sio_hw->gpio_clr = 1 << LED_PIN
#endif

// SDIO and SPI block
#define SD_SPI_SCK 10
Expand Down
15 changes: 6 additions & 9 deletions lib/BlueSCSI_platform_RP2040/BlueSCSI_platform_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include <network.h>

extern "C" {

#ifdef BLUESCSI_NETWORK
#include <cyw43.h>
#include <pico/cyw43_arch.h>
#endif

#ifndef CYW43_IOCTL_GET_RSSI
#define CYW43_IOCTL_GET_RSSI (0xfe)
Expand All @@ -34,17 +35,12 @@ static const char defaultMAC[] = { 0x00, 0x80, 0x19, 0xc0, 0xff, 0xee };

static bool network_in_use = false;

bool platform_network_supported()
bool __not_in_flash_func(platform_network_supported)()
{
/* from cores/rp2040/RP2040Support.h */
#if !defined(ARDUINO_RASPBERRY_PI_PICO_W)
return false;
#else
extern bool __isPicoW;
return __isPicoW;
#endif
return rp2040.isPicoW();
}

#ifdef BLUESCSI_NETWORK
int platform_network_init(char *mac)
{
pico_unique_board_id_t board_id;
Expand Down Expand Up @@ -311,4 +307,5 @@ void cyw43_cb_tcpip_set_link_up(cyw43_t *self, int itf)
log_f("Successfully connected to Wi-Fi SSID \"%s\"", ssid);
}

#endif
}
6 changes: 3 additions & 3 deletions lib/BlueSCSI_platform_RP2040/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const uint8_t snd_parity[256] __attribute__((aligned(256), section(".scratch_y.s
* receiver.
*
* To facilitate fast lookups this table should be put in SRAM with low
* contention, aligned to an apppropriate boundry.
* contention, aligned to an appropriate boundary.
*/
const uint16_t biphase[256] __attribute__((aligned(512), section(".scratch_y.biphase"))) = {
0xCCCC, 0xB333, 0xD333, 0xACCC, 0xCB33, 0xB4CC, 0xD4CC, 0xAB33,
Expand Down Expand Up @@ -306,7 +306,7 @@ static void snd_process_b() {
}

// Allows execution on Core1 via function pointers. Each function can take
// no parameters and should return nothing, operating via side-effects only.
// no parameters and should return nothing, operating via side effects only.
static void core1_handler() {
while (1) {
void (*function)() = (void (*)()) multicore_fifo_pop_blocking();
Expand Down Expand Up @@ -497,7 +497,7 @@ bool audio_play(uint8_t owner, ImageBackingStore* img, uint64_t start, uint64_t
sfcnt = 0;
invert = 0;

// setup the two DMA units to hand-off to each other
// setup the two DMA units to hand off to each other
// to maintain a stable bitstream these need to run without interruption
snd_dma_a_cfg = dma_channel_get_default_config(SOUND_DMA_CHA);
channel_config_set_transfer_data_size(&snd_dma_a_cfg, DMA_SIZE_16);
Expand Down
2 changes: 1 addition & 1 deletion lib/BlueSCSI_platform_RP2040/rp2040.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MEMORY
{
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 352k
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k /* Leave space for pico-debug */
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}
Expand Down
2 changes: 1 addition & 1 deletion lib/BlueSCSI_platform_RP2040/rp2040_btldr.ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* which comes as part of the main firmware.elf and is never overwritten.
*/
FLASH(rx) : ORIGIN = 0x10000100, LENGTH = 128k-256
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k /* Leave space for pico-debug */
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}
Expand Down
Loading