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

Updated to micropython 1.12 #31

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
A lot of bare metal examples by David Welch. ([dwelch67/raspberrypi: Raspberry Pi ARM based bare metal examples](https://github.com/dwelch67/raspberrypi))
13 changes: 13 additions & 0 deletions build/config.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file added build/firmware.img
Binary file not shown.
2 changes: 1 addition & 1 deletion micropython
Submodule micropython updated 2013 files
29 changes: 15 additions & 14 deletions raspberrypi/machine_sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand All @@ -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);
}

2 changes: 1 addition & 1 deletion raspberrypi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions raspberrypi/mini-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 13 additions & 4 deletions raspberrypi/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdint.h>
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/stream.h"
#include "rpi.h"
#include "mphalport.h"
#include "mini-uart.h"
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
3 changes: 3 additions & 0 deletions raspberrypi/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down