diff --git a/.gitmodules b/.gitmodules index ee94fd7..b5f6b70 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ -[submodule "micropython"] - path = micropython - url = https://github.com/micropython/micropython.git [submodule "raspberrypi/csud"] path = raspberrypi/csud url = https://github.com/boochow/csud +[submodule "micropython"] + path = micropython + url = https://github.com/micropython/micropython diff --git a/README.md b/README.md index d7f7445..d6294a3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ MicroPython on bare metal Raspberry Pi Zero / Zero W / 2 +## Pre-built files +The source has been precompiled and the binaries placed in the build folder for convenience. Feel free to use those if you do not want to build yourself or are having difficult time building. + +The files are: +- firmware.img +- config.txt + +Download these and follow the "How to install" instructions below. + ## How to build ``` git clone https://github.com/boochow/micropython-raspberrypi.git @@ -41,4 +50,4 @@ csud USB host driver by Alex Chadwick. ([Chadderz121/csud: Chadderz's Simple USB sd.c SD card driver by Zoltan Baldaszti. ([raspi3\-tutorial/0B\_readsector at master ยท bztsrc/raspi3\-tutorial](https://github.com/bztsrc/raspi3-tutorial/tree/master/0B_readsector)) -A lot of bare metal examples by David Welch. ([dwelch67/raspberrypi: Raspberry Pi ARM based bare metal examples](https://github.com/dwelch67/raspberrypi)) \ No newline at end of file +A lot of bare metal examples by David Welch. ([dwelch67/raspberrypi: Raspberry Pi ARM based bare metal examples](https://github.com/dwelch67/raspberrypi)) diff --git a/build/config.txt b/build/config.txt new file mode 100644 index 0000000..14804d6 --- /dev/null +++ b/build/config.txt @@ -0,0 +1,13 @@ +# Raspberry Pi boot configration +# see https://www.raspberrypi.org/documentation/configuration/config-txt/ +# for more details. + +# fake_vsync_isr=1 +# framebuffer_swap=0 +# gpu_mem=48 +# init_emmc_clock=100000000 +# arm_freq=1000 +# gpu_freq=300 +# core_freq=400 +# sdram_freq=450 +kernel=firmware.img diff --git a/build/firmware.img b/build/firmware.img new file mode 100644 index 0000000..a0806cf Binary files /dev/null and b/build/firmware.img differ diff --git a/micropython b/micropython index 6f75c4f..0bfd55a 160000 --- a/micropython +++ b/micropython @@ -1 +1 @@ -Subproject commit 6f75c4f3cd393131579db70cdf0b35d1fe5b95ab +Subproject commit 0bfd55afbe8eb798a806605a735fb3a68dee07a0 diff --git a/raspberrypi/machine_sdcard.c b/raspberrypi/machine_sdcard.c index f39ca05..b590a35 100644 --- a/raspberrypi/machine_sdcard.c +++ b/raspberrypi/machine_sdcard.c @@ -96,32 +96,33 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_test_obj, machine_sdcard_test); STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { - case BP_IOCTL_INIT: + case MP_BLOCKDEV_IOCTL_INIT: if (sd_init() != SD_OK) { return MP_OBJ_NEW_SMALL_INT(-1); // error } return MP_OBJ_NEW_SMALL_INT(0); // success - case BP_IOCTL_DEINIT: + case MP_BLOCKDEV_IOCTL_DEINIT: // nothing to do return MP_OBJ_NEW_SMALL_INT(0); // success - case BP_IOCTL_SYNC: + case MP_BLOCKDEV_IOCTL_SYNC: // nothing to do return MP_OBJ_NEW_SMALL_INT(0); // success - case BP_IOCTL_SEC_COUNT: + case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: // nothing to do return MP_OBJ_NEW_SMALL_INT(-1); // error // return MP_OBJ_NEW_SMALL_INT(sdcard_get_capacity_in_bytes() / SDCARD_BLOCK_SIZE); - case BP_IOCTL_SEC_SIZE: + case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(SDCARD_BLOCK_SIZE); default: // unknown command return MP_OBJ_NEW_SMALL_INT(-1); // error } } + STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); STATIC const mp_rom_map_elem_t machine_sdcard_locals_dict_table[] = { @@ -143,16 +144,16 @@ const mp_obj_type_t machine_sdcard_type = { void sdcard_init_vfs(fs_user_mount_t *vfs, int part) { vfs->base.type = &mp_fat_vfs_type; - vfs->flags |= FSUSER_HAVE_IOCTL; + vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_HAVE_IOCTL; vfs->fatfs.drv = vfs; vfs->fatfs.part = part; - vfs->readblocks[0] = (mp_obj_t)&machine_sdcard_readblocks_obj; - vfs->readblocks[1] = (mp_obj_t)&machine_sdcard_obj; -// vfs->readblocks[2] = (mp_obj_t)sdcard_read_blocks; // native version - vfs->writeblocks[0] = (mp_obj_t)&machine_sdcard_writeblocks_obj; - vfs->writeblocks[1] = (mp_obj_t)&machine_sdcard_obj; -// vfs->writeblocks[2] = (mp_obj_t)sdcard_write_blocks; // native version - vfs->u.ioctl[0] = (mp_obj_t)&machine_sdcard_ioctl_obj; - vfs->u.ioctl[1] = (mp_obj_t)&machine_sdcard_obj; + vfs->blockdev.readblocks[0] = MP_OBJ_FROM_PTR(&machine_sdcard_readblocks_obj); + vfs->blockdev.readblocks[1] = MP_OBJ_FROM_PTR(&machine_sdcard_obj); +// vfs->blockdev.readblocks[2] = MP_OBJ_FROM_PTR(sdcard_read_blocks); // native version + vfs->blockdev.writeblocks[0] = MP_OBJ_FROM_PTR(&machine_sdcard_writeblocks_obj); + vfs->blockdev.writeblocks[1] = MP_OBJ_FROM_PTR(&machine_sdcard_obj); +// vfs->blockdev.writeblocks[2] = MP_OBJ_FROM_PTR(sdcard_write_blocks); // native version + vfs->blockdev.u.ioctl[0] = MP_OBJ_FROM_PTR(&machine_sdcard_ioctl_obj); + vfs->blockdev.u.ioctl[1] = MP_OBJ_FROM_PTR(&machine_sdcard_obj); } diff --git a/raspberrypi/main.c b/raspberrypi/main.c index 1e26962..dcc01ff 100644 --- a/raspberrypi/main.c +++ b/raspberrypi/main.c @@ -69,7 +69,7 @@ STATIC bool init_sdcard_fs(void) { printf("vfs=NULL\n"); break; } - vfs_fat->flags = FSUSER_FREE_OBJ; + vfs_fat->blockdev.flags = MP_BLOCKDEV_FLAG_FREE_OBJ; sdcard_init_vfs(vfs_fat, part_num); // try to mount the partition diff --git a/raspberrypi/mini-uart.h b/raspberrypi/mini-uart.h index 9dadb12..d91f121 100644 --- a/raspberrypi/mini-uart.h +++ b/raspberrypi/mini-uart.h @@ -10,5 +10,6 @@ uint32_t mini_uart_rx_state(void); void mini_uart_set_speed(uint32_t speed); void isr_irq_mini_uart(void); +void mp_keyboard_interrupt(void); #endif // MICROPY_INCLUDED_RPI_MINI_UART_H diff --git a/raspberrypi/mphalport.c b/raspberrypi/mphalport.c index 005482e..5bd01e8 100644 --- a/raspberrypi/mphalport.c +++ b/raspberrypi/mphalport.c @@ -3,6 +3,7 @@ #include #include "py/mpconfig.h" #include "py/obj.h" +#include "py/stream.h" #include "rpi.h" #include "mphalport.h" #include "mini-uart.h" @@ -20,8 +21,8 @@ void mp_hal_delay_ms(mp_uint_t ms) { end_time = systime() + ms * 1000; while(systime() < end_time) { - extern void mp_handle_pending(void); - mp_handle_pending(); + extern void mp_handle_pending(bool raise_exc); + mp_handle_pending(true); } return; @@ -110,8 +111,8 @@ int mp_hal_stdin_rx_chr(void) { if (uart_rx_state()) { return uart_getc(); } - extern void mp_handle_pending(void); - mp_handle_pending(); + extern void mp_handle_pending(bool raise_exc); + mp_handle_pending(true); } } @@ -122,3 +123,11 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { mp_uos_dupterm_tx_strn(str, len); #endif } + +/*This is a dummy function (needed because "lib/utils/sys_stdio_mphal: +Add support to poll sys.stdin and sys.stdou" was added to 1.12 in +to lib/utils/sys_stdio_mphal.c by commit b7da67cdaaf32317cfc9a3940bd58f2aab4976c9 +previous build for raspi (1.11) did not have this addition */ +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { + return 0; +} diff --git a/raspberrypi/mphalport.h b/raspberrypi/mphalport.h index 75c5a51..122196b 100644 --- a/raspberrypi/mphalport.h +++ b/raspberrypi/mphalport.h @@ -10,6 +10,9 @@ mp_uint_t mp_hal_ticks_ms(void); void mp_hal_set_interrupt_char(int c); int mp_hal_stdin_rx_chr(void); void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len); +#ifndef mp_hal_stdio_poll +uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags); +#endif typedef enum std_io_t { MINI_UART = 0,