22
22
#endif
23
23
24
24
#ifndef __MBED__
25
- # include < SerialUSB .h>
25
+ #include < Adafruit_TinyUSB .h>
26
26
# include < class/cdc/cdc_device.h>
27
27
#else
28
28
# include < platform/mbed_error.h>
34
34
#include " hardware/i2c.h"
35
35
36
36
extern " C" {
37
- #include < pico/cyw43_arch.h>
38
37
39
38
const char *g_platform_name = PLATFORM_NAME;
40
39
static bool g_scsi_initiator = false ;
@@ -73,7 +72,7 @@ void mbed_error_hook(const mbed_error_ctx * error_context);
73
72
/* **************/
74
73
75
74
// 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)
77
76
{
78
77
gpio_put (gpio, initial_state);
79
78
gpio_set_dir (gpio, output);
@@ -82,7 +81,7 @@ static void gpio_conf(uint gpio, enum gpio_function fn, bool pullup, bool pulldo
82
81
83
82
if (fast_slew)
84
83
{
85
- padsbank0_hw ->io [gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
84
+ pads_bank0_hw ->io [gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
86
85
}
87
86
}
88
87
@@ -127,13 +126,17 @@ void platform_init()
127
126
{
128
127
// Make sure second core is stopped
129
128
multicore_reset_core1 ();
129
+ #ifndef __MBED__
130
+ Serial.begin (115200 );
131
+ #endif // __MBED__
130
132
131
133
// Default debug logging to disabled
132
134
g_log_debug = false ;
133
135
134
136
// Report platform and firmware version
135
137
log (" Platform: " , g_platform_name);
136
138
log (" FW Version: " , g_log_firmwareversion);
139
+ debuglog (" PicoSDK: " , PICO_SDK_VERSION_STRING);
137
140
138
141
/* First configure the pins that affect external buffer directions.
139
142
* RP2040 defaults to pulldowns, while these pins have external pull-ups.
@@ -173,8 +176,8 @@ void platform_init()
173
176
gpio_conf (scsi_pins.IN_ATN , GPIO_FUNC_SIO, false , false , false , false , false );
174
177
delay (10 ); // / Settle time
175
178
// 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 );
178
181
179
182
// Reset REQ to appropriate pin for older hardware
180
183
scsi_pins.OUT_REQ = SCSI_OUT_REQ_BEFORE_2023_09a;
@@ -201,9 +204,9 @@ void platform_init()
201
204
// Get flash chip size
202
205
uint8_t cmd_read_jedec_id[4 ] = {0x9f , 0 , 0 , 0 };
203
206
uint8_t response_jedec[4 ] = {0 };
204
- __disable_irq ();
207
+ uint32_t status = save_and_disable_interrupts ();
205
208
flash_do_cmd (cmd_read_jedec_id, response_jedec, 4 );
206
- __enable_irq ( );
209
+ restore_interrupts_from_disabled (status );
207
210
g_flash_chip_size = (1 << response_jedec[3 ]);
208
211
log (" Flash chip size: " , (int )(g_flash_chip_size / 1024 ), " kB" );
209
212
@@ -290,9 +293,6 @@ void platform_late_init()
290
293
gpio_conf (scsi_pins.IN_RST , GPIO_FUNC_SIO, true , false , false , true , false );
291
294
292
295
293
- #ifndef __MBED__
294
- Serial.begin ();
295
- #endif // __MBED__
296
296
297
297
#ifdef ENABLE_AUDIO_OUTPUT
298
298
// one-time control setup for DMA channels and second core
@@ -495,7 +495,7 @@ static void adc_poll()
495
495
* If ADC sample reads are done, either via direct reading, FIFO, or DMA,
496
496
* at the same time a SPI DMA write begins, it appears that the first
497
497
* 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
499
499
* is playing.
500
500
*/
501
501
if (audio_is_active ()) return ;
@@ -570,7 +570,9 @@ static void watchdog_callback(unsigned alarm_num)
570
570
#ifdef __MBED__
571
571
uint32_t *p = (uint32_t *)__get_PSP ();
572
572
#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;
574
576
#endif
575
577
for (int i = 0 ; i < 8 ; i++)
576
578
{
@@ -597,7 +599,9 @@ static void watchdog_callback(unsigned alarm_num)
597
599
#ifdef __MBED__
598
600
uint32_t *p = (uint32_t *)__get_PSP ();
599
601
#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;
601
605
#endif
602
606
for (int i = 0 ; i < 8 ; i++)
603
607
{
@@ -627,7 +631,7 @@ void platform_reset_watchdog()
627
631
if (!g_watchdog_initialized)
628
632
{
629
633
int alarm_num = -1 ;
630
- for (int i = 0 ; i < NUM_TIMERS ; i++)
634
+ for (int i = 0 ; i < NUM_GENERIC_TIMERS ; i++)
631
635
{
632
636
if (!hardware_alarm_is_claimed (i))
633
637
{
@@ -736,7 +740,7 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
736
740
assert (offset >= PLATFORM_BOOTLOADER_SIZE);
737
741
738
742
// Avoid any mbed timer interrupts triggering during the flashing.
739
- __disable_irq ();
743
+ uint32_t status = save_and_disable_interrupts ();
740
744
741
745
// For some reason any code executed after flashing crashes
742
746
// unless we disable the XIP cache.
@@ -754,17 +758,17 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
754
758
for (int i = 0 ; i < num_words; i++)
755
759
{
756
760
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 );
758
762
759
763
if (actual != expected)
760
764
{
761
765
log (" Flash verify failed at offset " , offset + i * 4 , " got " , actual, " expected " , expected);
762
- __enable_irq ( );
766
+ restore_interrupts_from_disabled (status );
763
767
return false ;
764
768
}
765
769
}
766
770
767
- __enable_irq ( );
771
+ restore_interrupts_from_disabled (status );
768
772
769
773
return true ;
770
774
}
@@ -774,7 +778,7 @@ void platform_boot_to_main_firmware()
774
778
// To ensure that the system state is reset properly, we perform
775
779
// a SYSRESETREQ and jump straight from the reset vector to main application.
776
780
g_bootloader_exit_req = &g_bootloader_exit_req;
777
- SCB-> AIRCR = 0x05FA0004 ;
781
+ scb_hw-> aircr = 0x05FA0004 ;
778
782
while (1 );
779
783
}
780
784
@@ -787,7 +791,7 @@ void btldr_reset_handler()
787
791
application_base = (uint32_t *)(XIP_BASE + PLATFORM_BOOTLOADER_SIZE);
788
792
}
789
793
790
- SCB-> VTOR = (uint32_t )application_base;
794
+ scb_hw-> aircr = (uint32_t )application_base;
791
795
__asm__ (
792
796
" msr msp, %0\n\t "
793
797
" bx %1" : : " r" (application_base[0 ]),
@@ -859,10 +863,10 @@ bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count
859
863
assert (start < platform_get_romdrive_maxsize ());
860
864
assert ((count % PLATFORM_ROMDRIVE_PAGE_SIZE) == 0 );
861
865
862
- __disable_irq ();
866
+ uint32_t status = save_and_disable_interrupts ();
863
867
flash_range_erase (start + ROMDRIVE_OFFSET, count);
864
868
flash_range_program (start + ROMDRIVE_OFFSET, data, count);
865
- __enable_irq ( );
869
+ restore_interrupts_from_disabled (status );
866
870
return true ;
867
871
}
868
872
0 commit comments