Skip to content

Commit

Permalink
Merge pull request #647 from kaluma-project/develop/pico2_rp2350_bringup
Browse files Browse the repository at this point in the history
Pico2 - RP2350 board bringup
  • Loading branch information
communix authored Nov 3, 2024
2 parents 9c7fc61 + f6bd26c commit 70e31d9
Show file tree
Hide file tree
Showing 24 changed files with 262 additions and 101 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(NOT "${TARGET}" STREQUAL "rp2")
endif()

if(NOT VER)
set(VER "1.1.0")
set(VER "1.2.0-beta.1")
endif()

include(${CMAKE_SOURCE_DIR}/targets/${TARGET}/target.cmake)
Expand Down
2 changes: 1 addition & 1 deletion lib/jerryscript
2 changes: 1 addition & 1 deletion lib/pico-sdk
Submodule pico-sdk updated 977 files
8 changes: 6 additions & 2 deletions src/modules/rp2/module_rp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

#define __RP2_TEMP_ADC_PORT 30

static jerry_value_t __pio_call_back[PIO_NUM];
static jerry_value_t __pio_call_back[KALUMA_PIO_NUM];

static PIO __pio(uint8_t pio) {
if (pio == 0) {
Expand Down Expand Up @@ -447,10 +447,12 @@ JERRYXX_FUN(dormant_fn) {
clock_stop(clk_usb);
// CLK ADC = 0MHz
clock_stop(clk_adc);
#ifdef PICO_RP2040
// CLK RTC = ideally XOSC (12MHz) / 256 = 46875Hz but could be rosc
uint clk_rtc_src = CLOCKS_CLK_RTC_CTRL_AUXSRC_VALUE_XOSC_CLKSRC;
clock_configure(clk_rtc, 0, // No GLMUX
clk_rtc_src, src_hz, 46875);
#endif
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so
// just select and enable
clock_configure(clk_peri, 0, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS,
Expand Down Expand Up @@ -497,10 +499,12 @@ JERRYXX_FUN(dormant_fn) {
CLOCKS_CLK_ADC_CTRL_AUXSRC_VALUE_CLKSRC_PLL_USB, 48 * MHZ,
48 * MHZ);
// CLK RTC = PLL USB (48MHz) / 1024 = 46875Hz
#ifdef PICO_RP2040
clock_configure(clk_rtc,
0, // No GLMUX
CLOCKS_CLK_RTC_CTRL_AUXSRC_VALUE_CLKSRC_PLL_USB, 48 * MHZ,
46875);
#endif
// CLK PERI = clk_sys. Used as reference clock for Peripherals. No dividers so
// just select and enable Normally choose clk_sys or clk_usb
clock_configure(clk_peri, 0, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS,
Expand All @@ -513,7 +517,7 @@ JERRYXX_FUN(dormant_fn) {
jerry_value_t module_rp2_init() {
irq_set_exclusive_handler(PIO0_IRQ_0, __pio0_irq_0_handler);
irq_set_exclusive_handler(PIO1_IRQ_0, __pio1_irq_0_handler);
for (int i = 0; i < PIO_NUM; i++) {
for (int i = 0; i < KALUMA_PIO_NUM; i++) {
__pio_call_back[i] = jerry_create_undefined();
}

Expand Down
14 changes: 7 additions & 7 deletions targets/linux/boards/default/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
#define KALUMA_STORAGE_SECTOR_COUNT 4

// #define KALUMA_GPIO_COUNT 22
// #define ADC_NUM 6
// #define PWM_NUM 6
// #define I2C_NUM 2
// #define SPI_NUM 2
// #define UART_NUM 2
// #define LED_NUM 1
// #define BUTTON_NUM 1
// #define KALUMA_ADC_NUM 6
// #define KALUMA_PWM_NUM 6
// #define KALUMA_I2C_NUM 2
// #define KALUMA_SPI_NUM 2
// #define KALUMA_UART_NUM 2
// #define KALUMA_LED_NUM 1
// #define KALUMA_BUTTON_NUM 1

void board_init();

Expand Down
20 changes: 10 additions & 10 deletions targets/rp2/boards/pico-w/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// system
#define KALUMA_SYSTEM_ARCH "cortex-m0-plus"
#define KALUMA_SYSTEM_PLATFORM "rp2"
#define PICO_CYW43

// repl
#define KALUMA_REPL_BUFFER_SIZE 1024
Expand Down Expand Up @@ -69,21 +70,20 @@
// -----------------------------------------------------------------

#define KALUMA_GPIO_COUNT 29
// #define ADC_NUM 3
#define PWM_NUM 27
#define I2C_NUM 2
#define SPI_NUM 2
#define UART_NUM 2
// #define LED_NUM 1
// #define BUTTON_NUM 0
#define PIO_NUM 2
#define PIO_SM_NUM 4
// #define KALUMA_ADC_NUM 3
#define KALUMA_PWM_NUM 27
#define KALUMA_I2C_NUM 2
#define KALUMA_SPI_NUM 2
#define KALUMA_UART_NUM 2
// #define KALUMA_LED_NUM 1
// #define KALUMA_BUTTON_NUM 0
#define KALUMA_PIO_NUM 2
#define KALUMA_PIO_SM_NUM 4

#define ADC_RESOLUTION_BIT 12
#define PWM_CLK_REF 1250
#define I2C_MAX_CLOCK 1000000
#define SCR_LOAD_GPIO 22 // GPIO 22
#define PICO_CYW43
#ifdef PICO_CYW43
#define WIFI_EN_GPIO 23 // GPIO 23
#endif /* PICO_CWY43 */
Expand Down
18 changes: 9 additions & 9 deletions targets/rp2/boards/pico/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
// -----------------------------------------------------------------

#define KALUMA_GPIO_COUNT 29
// #define ADC_NUM 3
#define PWM_NUM 27
#define I2C_NUM 2
#define SPI_NUM 2
#define UART_NUM 2
// #define LED_NUM 1
// #define BUTTON_NUM 0
#define PIO_NUM 2
#define PIO_SM_NUM 4
// #define KALUMA_ADC_NUM 3
#define KALUMA_PWM_NUM 27
#define KALUMA_I2C_NUM 2
#define KALUMA_SPI_NUM 2
#define KALUMA_UART_NUM 2
// #define KALUMA_LED_NUM 1
// #define KALUMA_BUTTON_NUM 0
#define KALUMA_PIO_NUM 2
#define KALUMA_PIO_SM_NUM 4

#define ADC_RESOLUTION_BIT 12
#define PWM_CLK_REF 1250
Expand Down
23 changes: 23 additions & 0 deletions targets/rp2/boards/pico2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Raspberry Pi Pico

## Flash

Flash partitions

```
|------------------------------------------------|
| A | B | C | D |
|--------------------|---|-----------|-----------|
| 960K |64K| 1536K | 1536K |
|------------------------------------------------|
|------------- flash.c -------------|
|------ 1MB -----|------------- 3MB -------------|
|---------------------- 4MB ---------------------|
```

- A : Binary (firmware)
- B : Storage (key-value database)
- C : User program (js)
- D : File system (lfs)
(Total : 4MB)
27 changes: 27 additions & 0 deletions targets/rp2/boards/pico2/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright (c) 2017 Kaluma
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "board.h"

/**
* Initialize board
*/
void board_init() {}
96 changes: 96 additions & 0 deletions targets/rp2/boards/pico2/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* Copyright (c) 2017 Kaluma
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef __RP2_PICO2_H
#define __RP2_PICO2_H

#include "jerryscript.h"

// system
#define KALUMA_SYSTEM_ARCH "cortex-m33"
#define KALUMA_SYSTEM_PLATFORM "rp2"

// repl
#define KALUMA_REPL_BUFFER_SIZE 1024
#define KALUMA_REPL_HISTORY_SIZE 10

// Flash allocation map 4MB for pico 2
//
// |------------------------------------------------|
// | A | B | C | D |
// |--------------------|---|-----------|-----------|
// | 960K |64K| 1536K | 1536K |
// |------------------------------------------------|
// |------------- flash.c -------------|

// |------ 1MB -----|------------- 3MB -------------|
// |---------------------- 4MB ---------------------|
//
// - A : binary (firmware)
// - B : storage (key-value database)
// - C : user program (js)
// - D : file system (lfs)
// (Total : 4MB)

// binary (1008KB)
#define KALUMA_BINARY_MAX 0xF0000

// flash (B + C + D = 1040KB (=64KB + 2048KB))
#define KALUMA_FLASH_OFFSET KALUMA_BINARY_MAX
#define KALUMA_FLASH_SECTOR_SIZE 4096
#define KALUMA_FLASH_SECTOR_COUNT 784
#define KALUMA_FLASH_PAGE_SIZE 256

// user program on flash (1024KB)
#define KALUMA_PROG_SECTOR_BASE 16
#define KALUMA_PROG_SECTOR_COUNT 384

// storage on flash (64KB)
#define KALUMA_STORAGE_SECTOR_BASE 0
#define KALUMA_STORAGE_SECTOR_COUNT 16

// file system on flash (1024K)
// - sector base : 400
// - sector count : 384
// - use block device : new Flash(400, 384)

// -----------------------------------------------------------------

#define KALUMA_GPIO_COUNT 29
// #define KALUMA_ADC_NUM 3
#define KALUMA_PWM_NUM 27
#define KALUMA_I2C_NUM 2
#define KALUMA_SPI_NUM 2
#define KALUMA_UART_NUM 2
// #define KALUMA_LED_NUM 1
// #define KALUMA_BUTTON_NUM 0
#define KALUMA_PIO_NUM 2
#define KALUMA_PIO_SM_NUM 4

#define ADC_RESOLUTION_BIT 12
#define PWM_CLK_REF 1250
#define I2C_MAX_CLOCK 1000000
#define SCR_LOAD_GPIO 22 // GPIO 22


void board_init();

#endif /* __RP2_PICO2_H */
12 changes: 12 additions & 0 deletions targets/rp2/boards/pico2/board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// initialize board object
global.board.name = "pico2";
global.board.LED = 25;

// mount lfs on "/"
const fs = require("fs");
const { VFSLittleFS } = require("vfs_lfs");
const { Flash } = require("flash");
fs.register("lfs", VFSLittleFS);
// fs block starts after 16(storage) + 384(program)
const bd = new Flash(400, 384);
fs.mount("/", bd, "lfs", true);
4 changes: 2 additions & 2 deletions targets/rp2/src/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

static struct __i2c_status_s {
km_i2c_mode_t mode;
} __i2c_status[I2C_NUM];
} __i2c_status[KALUMA_I2C_NUM];

static bool __check_i2c_pins(uint8_t bus, km_i2c_pins_t pins) {
if ((pins.sda > 27) || (pins.scl > 27)) {
Expand Down Expand Up @@ -79,7 +79,7 @@ km_i2c_pins_t km_i2c_get_default_pins(uint8_t bus) {
* Initialize all I2C when system started
*/
void km_i2c_init() {
for (int i = 0; i < I2C_NUM; i++) {
for (int i = 0; i < KALUMA_I2C_NUM; i++) {
__i2c_status[i].mode = KM_I2C_NONE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions targets/rp2/src/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static struct __pwm_config_s {
double duty;
uint16_t period;
bool enabled;
} __pwm_config[PWM_NUM];
} __pwm_config[KALUMA_PWM_NUM];

static int __get_pwm_index(uint8_t pin) {
if (pin <= 22) {
Expand All @@ -49,7 +49,7 @@ static int __get_pwm_index(uint8_t pin) {
* Initialize all PWM when system started
*/
void km_pwm_init() {
for (int i = 0; i < PWM_NUM; i++) {
for (int i = 0; i < KALUMA_PWM_NUM; i++) {
__pwm_config[i].freq = 0;
__pwm_config[i].duty = 0;
__pwm_config[i].period = 0;
Expand Down
Loading

0 comments on commit 70e31d9

Please sign in to comment.