Skip to content

Commit

Permalink
Merge pull request #465 from sneakywumpus/riscv-fatfs
Browse files Browse the repository at this point in the history
no-OS-FatFS-SD-SDIO-SPI-RPi-Pico: use Pico SDK API's instead of ARM CMSIS ones
  • Loading branch information
udo-munk authored Dec 3, 2024
2 parents 9ea683d + 6f7224b commit 77d8450
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ target_link_libraries(no-OS-FatFS-SD-SDIO-SPI-RPi-Pico INTERFACE
hardware_spi
pico_aon_timer
pico_stdlib
cmsis_core
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,25 @@ call to millis() returns 0xFFFFFFFF:
#include <stdint.h>
//
#include "pico/stdlib.h"
#if PICO_RP2040
#include "RP2040.h"
#else
#include "RP2350.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

static inline uint32_t millis() {
__COMPILER_BARRIER();
__compiler_memory_barrier();
return time_us_64() / 1000;
__COMPILER_BARRIER();
__compiler_memory_barrier();
}

static inline void delay_ms(uint32_t ulTime_ms) {
sleep_ms(ulTime_ms);
}

static inline uint64_t micros() {
__COMPILER_BARRIER();
__compiler_memory_barrier();
return to_us_since_boot(get_absolute_time());
__COMPILER_BARRIER();
__compiler_memory_barrier();
}

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ specific language governing permissions and limitations under the License.
#include <stdint.h>
#include <string.h>
//
#if PICO_RP2040
#include "RP2040.h"
#else
#include "RP2350.h"
#endif
//
#include "my_debug.h"

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#include "hardware/dma.h"
#include "hardware/gpio.h"
#include "hardware/pio.h"
#if PICO_RP2040
#include "RP2040.h"
#else
#include "RP2350.h"
#endif
//
#include "dma_interrupts.h"
#include "hw_config.h"
Expand Down Expand Up @@ -686,11 +681,20 @@ void sdio_irq_handler(sd_card_t *sd_card_p) {
// Check if transmission is complete
sdio_status_t rp2040_sdio_tx_poll(sd_card_t *sd_card_p, uint32_t *bytes_complete)
{
if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
#if !__riscv
# if PICO_RP2040
const uint32_t icsr_vectactive_bits = M0PLUS_ICSR_VECTACTIVE_BITS;
# endif
# if PICO_RP2350
const uint32_t icsr_vectactive_bits = M33_ICSR_VECTACTIVE_BITS;
# endif

if (scb_hw->icsr & icsr_vectactive_bits)
{
// Verify that IRQ handler gets called even if we are in hardfault handler
sdio_irq_handler(sd_card_p);
}
#endif // !__riscv

if (bytes_complete)
{
Expand Down
19 changes: 14 additions & 5 deletions picosim/rp2350/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico/src/src/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ specific language governing permissions and limitations under the License.
#include <time.h>
//
#include "pico/stdlib.h"
#include "hardware/sync.h"
#include "hardware/watchdog.h"
//
#include "crc.h"
#include "my_debug.h"
Expand All @@ -40,7 +42,10 @@ static inline void reset() {
// if (debugger_connected()) {
__breakpoint();
// } else {
NVIC_SystemReset();
watchdog_reboot(0, 0, 0);
for (;;) {
__wfi();
}
// }
__builtin_unreachable();
}
Expand Down Expand Up @@ -79,7 +84,7 @@ void system_reset_func(char const *const func) {
func);
crash_info_ram.xor_checksum =
crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum));
__DSB();
__dsb();

reset();
__builtin_unreachable();
Expand All @@ -104,11 +109,13 @@ void capture_assert(const char *file, int line, const char *func, const char *pr
crash_info_ram.assert.line = line;
crash_info_ram.xor_checksum =
crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum));
__DSB();
__dsb();
reset();
__builtin_unreachable();
}

#if !__riscv

__attribute__((used)) extern void DebugMon_HandlerC(uint32_t const *faultStackAddr) {
memset((void *)crash_info_ram_p, 0, sizeof crash_info_ram);
crash_info_ram.magic = crash_magic_debug_mon;
Expand Down Expand Up @@ -144,7 +151,7 @@ __attribute__((used)) extern void DebugMon_HandlerC(uint32_t const *faultStackAd
//}
crash_info_ram.xor_checksum =
crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum));
__DSB(); // make sure all data is really written into the memory before
__dsb(); // make sure all data is really written into the memory before
// doing a reset
reset();
}
Expand Down Expand Up @@ -182,7 +189,7 @@ void Hardfault_HandlerC(uint32_t const *faultStackAddr) {

crash_info_ram.xor_checksum =
crc7((uint8_t *)&crash_info_ram, offsetof(crash_info_t, xor_checksum));
__DSB(); // make sure all data is really written into the memory before
__dsb(); // make sure all data is really written into the memory before
// doing a reset

reset();
Expand All @@ -202,6 +209,8 @@ __attribute__((naked)) void isr_hardfault(void) {
" b Hardfault_HandlerC \n");
}

#endif // !__riscv

enum {
crash_info_magic,
crash_info_hf_lr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ specific language governing permissions and limitations under the License.
#include <stdint.h>
#include <string.h>
//
#if PICO_RP2040
#include "RP2040.h"
#else
#include "RP2350.h"
#endif
#include "pico/stdlib.h"
#include "hardware/sync.h"
//
#include "crash.h"
//
Expand Down Expand Up @@ -144,7 +140,7 @@ void __attribute__((weak)) my_assert_func(const char *file, int line, const char
const char *pred) {
error_message_printf_plain("assertion \"%s\" failed: file \"%s\", line %d, function: %s\n",
pred, file, line, func);
__disable_irq(); /* Disable global interrupts. */
(void)save_and_disable_interrupts(); /* Disable global interrupts. */
capture_assert(file, line, func, pred);
}

Expand Down

0 comments on commit 77d8450

Please sign in to comment.