Skip to content

Commit cc8f787

Browse files
authored
Merge pull request #209 from BlueSCSI/eric/pico1-sdk2
SDK updates & timeout fixes
2 parents 5e279a5 + b0432fe commit cc8f787

15 files changed

+118
-80
lines changed

lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#endif
2323

2424
#ifndef __MBED__
25-
# include <SerialUSB.h>
25+
#include <Adafruit_TinyUSB.h>
2626
# include <class/cdc/cdc_device.h>
2727
#else
2828
# include <platform/mbed_error.h>
@@ -34,7 +34,6 @@
3434
#include "hardware/i2c.h"
3535

3636
extern "C" {
37-
#include <pico/cyw43_arch.h>
3837

3938
const char *g_platform_name = PLATFORM_NAME;
4039
static bool g_scsi_initiator = false;
@@ -73,7 +72,7 @@ void mbed_error_hook(const mbed_error_ctx * error_context);
7372
/***************/
7473

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

8382
if (fast_slew)
8483
{
85-
padsbank0_hw->io[gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
84+
pads_bank0_hw->io[gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
8685
}
8786
}
8887

@@ -127,13 +126,17 @@ void platform_init()
127126
{
128127
// Make sure second core is stopped
129128
multicore_reset_core1();
129+
#ifndef __MBED__
130+
Serial.begin(115200);
131+
#endif // __MBED__
130132

131133
// Default debug logging to disabled
132134
g_log_debug = false;
133135

134136
// Report platform and firmware version
135137
log("Platform: ", g_platform_name);
136138
log("FW Version: ", g_log_firmwareversion);
139+
debuglog("PicoSDK: ", PICO_SDK_VERSION_STRING);
137140

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

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

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

292295

293-
#ifndef __MBED__
294-
Serial.begin();
295-
#endif // __MBED__
296296

297297
#ifdef ENABLE_AUDIO_OUTPUT
298298
// one-time control setup for DMA channels and second core
@@ -495,7 +495,7 @@ static void adc_poll()
495495
* If ADC sample reads are done, either via direct reading, FIFO, or DMA,
496496
* at the same time a SPI DMA write begins, it appears that the first
497497
* 16-bit word of the DMA data is lost. This causes the bitstream to glitch
498-
* and audio to 'pop' noticably. For now, just disable ADC reads when audio
498+
* and audio to 'pop' noticeably. For now, just disable ADC reads when audio
499499
* is playing.
500500
*/
501501
if (audio_is_active()) return;
@@ -570,7 +570,9 @@ static void watchdog_callback(unsigned alarm_num)
570570
#ifdef __MBED__
571571
uint32_t *p = (uint32_t*)__get_PSP();
572572
#else
573-
uint32_t *p = (uint32_t*)__get_MSP();
573+
uint32_t msp;
574+
asm volatile ("MRS %0, msp" : "=r" (msp) );
575+
uint32_t *p = (uint32_t*)msp;
574576
#endif
575577
for (int i = 0; i < 8; i++)
576578
{
@@ -597,7 +599,9 @@ static void watchdog_callback(unsigned alarm_num)
597599
#ifdef __MBED__
598600
uint32_t *p = (uint32_t*)__get_PSP();
599601
#else
600-
uint32_t *p = (uint32_t*)__get_MSP();
602+
uint32_t msp;
603+
asm volatile ("MRS %0, msp" : "=r" (msp) );
604+
uint32_t *p = (uint32_t*)msp;
601605
#endif
602606
for (int i = 0; i < 8; i++)
603607
{
@@ -627,7 +631,7 @@ void platform_reset_watchdog()
627631
if (!g_watchdog_initialized)
628632
{
629633
int alarm_num = -1;
630-
for (int i = 0; i < NUM_TIMERS; i++)
634+
for (int i = 0; i < NUM_GENERIC_TIMERS; i++)
631635
{
632636
if (!hardware_alarm_is_claimed(i))
633637
{
@@ -736,7 +740,7 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
736740
assert(offset >= PLATFORM_BOOTLOADER_SIZE);
737741

738742
// Avoid any mbed timer interrupts triggering during the flashing.
739-
__disable_irq();
743+
uint32_t status = save_and_disable_interrupts();
740744

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

759763
if (actual != expected)
760764
{
761765
log("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
762-
__enable_irq();
766+
restore_interrupts_from_disabled(status);
763767
return false;
764768
}
765769
}
766770

767-
__enable_irq();
771+
restore_interrupts_from_disabled(status);
768772

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

@@ -787,7 +791,7 @@ void btldr_reset_handler()
787791
application_base = (uint32_t*)(XIP_BASE + PLATFORM_BOOTLOADER_SIZE);
788792
}
789793

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

862-
__disable_irq();
866+
uint32_t status = save_and_disable_interrupts();
863867
flash_range_erase(start + ROMDRIVE_OFFSET, count);
864868
flash_range_program(start + ROMDRIVE_OFFSET, data, count);
865-
__enable_irq();
869+
restore_interrupts_from_disabled(status);
866870
return true;
867871
}
868872

lib/BlueSCSI_platform_RP2040/BlueSCSI_platform_gpio.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#pragma once
44

55
#include <hardware/gpio.h>
6+
#ifdef BLUESCSI_NETWORK
67
#include <pico/cyw43_arch.h>
8+
#endif
79

810
// SCSI data input/output port.
911
// The data bus uses external bidirectional buffer, with
@@ -56,8 +58,13 @@
5658

5759
// Status LED pins
5860
#define LED_PIN 25
59-
#define LED_ON() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, true) : sio_hw->gpio_set = 1 << LED_PIN
60-
#define LED_OFF() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, false) : sio_hw->gpio_clr = 1 << LED_PIN
61+
#ifdef BLUESCSI_NETWORK
62+
#define LED_ON() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, true) : sio_hw->gpio_set = 1 << LED_PIN
63+
#define LED_OFF() platform_network_supported() ? cyw43_gpio_set(&cyw43_state, 0, false) : sio_hw->gpio_clr = 1 << LED_PIN
64+
#else
65+
#define LED_ON() sio_hw->gpio_set = 1 << LED_PIN
66+
#define LED_OFF() sio_hw->gpio_clr = 1 << LED_PIN
67+
#endif
6168

6269
// SDIO and SPI block
6370
#define SD_SPI_SCK 10

lib/BlueSCSI_platform_RP2040/BlueSCSI_platform_network.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
#include <network.h>
2222

2323
extern "C" {
24-
24+
#ifdef BLUESCSI_NETWORK
2525
#include <cyw43.h>
2626
#include <pico/cyw43_arch.h>
27+
#endif
2728

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

3536
static bool network_in_use = false;
3637

37-
bool platform_network_supported()
38+
bool __not_in_flash_func(platform_network_supported)()
3839
{
39-
/* from cores/rp2040/RP2040Support.h */
40-
#if !defined(ARDUINO_RASPBERRY_PI_PICO_W)
41-
return false;
42-
#else
43-
extern bool __isPicoW;
44-
return __isPicoW;
45-
#endif
40+
return rp2040.isPicoW();
4641
}
4742

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

310+
#endif
314311
}

lib/BlueSCSI_platform_RP2040/audio.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const uint8_t snd_parity[256] __attribute__((aligned(256), section(".scratch_y.s
6363
* receiver.
6464
*
6565
* To facilitate fast lookups this table should be put in SRAM with low
66-
* contention, aligned to an apppropriate boundry.
66+
* contention, aligned to an appropriate boundary.
6767
*/
6868
const uint16_t biphase[256] __attribute__((aligned(512), section(".scratch_y.biphase"))) = {
6969
0xCCCC, 0xB333, 0xD333, 0xACCC, 0xCB33, 0xB4CC, 0xD4CC, 0xAB33,
@@ -306,7 +306,7 @@ static void snd_process_b() {
306306
}
307307

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

500-
// setup the two DMA units to hand-off to each other
500+
// setup the two DMA units to hand off to each other
501501
// to maintain a stable bitstream these need to run without interruption
502502
snd_dma_a_cfg = dma_channel_get_default_config(SOUND_DMA_CHA);
503503
channel_config_set_transfer_data_size(&snd_dma_a_cfg, DMA_SIZE_16);

lib/BlueSCSI_platform_RP2040/rp2040.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MEMORY
22
{
33
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 352k
4-
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k /* Leave space for pico-debug */
4+
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
55
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
66
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
77
}

lib/BlueSCSI_platform_RP2040/rp2040_btldr.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* which comes as part of the main firmware.elf and is never overwritten.
1212
*/
1313
FLASH(rx) : ORIGIN = 0x10000100, LENGTH = 128k-256
14-
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k /* Leave space for pico-debug */
14+
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k /* Leave space for pico-debug */
1515
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
1616
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
1717
}

0 commit comments

Comments
 (0)