diff --git a/CMakeLists.txt b/CMakeLists.txt index 766e3b49..59855872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/lib/jerryscript b/lib/jerryscript index 99bf35e9..984c39fa 160000 --- a/lib/jerryscript +++ b/lib/jerryscript @@ -1 +1 @@ -Subproject commit 99bf35e97875a270f849529a2ea62a8128987ca9 +Subproject commit 984c39fa9efcf8f154d4f4369287d20beb45af85 diff --git a/lib/pico-sdk b/lib/pico-sdk index 6a7db34f..efe2103f 160000 --- a/lib/pico-sdk +++ b/lib/pico-sdk @@ -1 +1 @@ -Subproject commit 6a7db34ff63345a7badec79ebea3aaef1712f374 +Subproject commit efe2103f9b28458a1615ff096054479743ade236 diff --git a/src/modules/rp2/module_rp2.c b/src/modules/rp2/module_rp2.c index 36204e06..64358717 100644 --- a/src/modules/rp2/module_rp2.c +++ b/src/modules/rp2/module_rp2.c @@ -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) { @@ -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, @@ -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, @@ -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(); } diff --git a/targets/linux/boards/default/board.h b/targets/linux/boards/default/board.h index c6cde9ca..15dc4b44 100644 --- a/targets/linux/boards/default/board.h +++ b/targets/linux/boards/default/board.h @@ -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(); diff --git a/targets/rp2/boards/pico-w/board.h b/targets/rp2/boards/pico-w/board.h index b52b3d44..b835672f 100644 --- a/targets/rp2/boards/pico-w/board.h +++ b/targets/rp2/boards/pico-w/board.h @@ -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 @@ -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 */ diff --git a/targets/rp2/boards/pico/board.h b/targets/rp2/boards/pico/board.h index 4a23a371..8bae2393 100644 --- a/targets/rp2/boards/pico/board.h +++ b/targets/rp2/boards/pico/board.h @@ -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 diff --git a/targets/rp2/boards/pico2/README.md b/targets/rp2/boards/pico2/README.md new file mode 100644 index 00000000..573d3a69 --- /dev/null +++ b/targets/rp2/boards/pico2/README.md @@ -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) diff --git a/targets/rp2/boards/pico2/board.c b/targets/rp2/boards/pico2/board.c new file mode 100644 index 00000000..7ebb793a --- /dev/null +++ b/targets/rp2/boards/pico2/board.c @@ -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() {} diff --git a/targets/rp2/boards/pico2/board.h b/targets/rp2/boards/pico2/board.h new file mode 100644 index 00000000..1f3ccca4 --- /dev/null +++ b/targets/rp2/boards/pico2/board.h @@ -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 */ diff --git a/targets/rp2/boards/pico2/board.js b/targets/rp2/boards/pico2/board.js new file mode 100644 index 00000000..99b2a0b3 --- /dev/null +++ b/targets/rp2/boards/pico2/board.js @@ -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); diff --git a/targets/rp2/src/i2c.c b/targets/rp2/src/i2c.c index f6633879..52b14cac 100644 --- a/targets/rp2/src/i2c.c +++ b/targets/rp2/src/i2c.c @@ -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)) { @@ -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; } } diff --git a/targets/rp2/src/pwm.c b/targets/rp2/src/pwm.c index d29d82c4..8409e78a 100644 --- a/targets/rp2/src/pwm.c +++ b/targets/rp2/src/pwm.c @@ -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) { @@ -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; diff --git a/targets/rp2/src/rtc.c b/targets/rp2/src/rtc.c index 6c19b6ff..de688424 100644 --- a/targets/rp2/src/rtc.c +++ b/targets/rp2/src/rtc.c @@ -23,47 +23,32 @@ #include -#include "hardware/rtc.h" +#include "pico/aon_timer.h" #include "pico/stdlib.h" #include "pico/util/datetime.h" +#define DIV_NS_2_MS 1000000 +#define MUL_MS_2_NS 1000000 +#define DIV_MS_2_S 1000 +#define MUL_S_2_MS 1000 +#define TAKE_MS 1000 + void km_rtc_init() { - rtc_init(); - // set as unix epoch time - datetime_t t = { - .year = 1970, .month = 1, .day = 1, .dotw = 4, .min = 0, .sec = 0}; - rtc_set_datetime(&t); + aon_timer_start_with_timeofday(); } void km_rtc_cleanup() {} void km_rtc_set_time(uint64_t time) { - struct tm* ptm; - uint64_t stime = time / 1000; - // uint64_t ms = time % 1000; - time_t t = (time_t)stime; - ptm = gmtime(&t); - datetime_t datetime; - datetime.sec = ptm->tm_sec; - datetime.min = ptm->tm_min; - datetime.hour = ptm->tm_hour; - datetime.day = ptm->tm_mday; - datetime.dotw = ptm->tm_wday; - datetime.month = ptm->tm_mon + 1; - datetime.year = ptm->tm_year + 1900; - rtc_set_datetime(&datetime); + struct timespec ts; + ts.tv_sec = time / DIV_MS_2_S; + ts.tv_nsec = (time % TAKE_MS) * MUL_MS_2_NS; + aon_timer_set_time(&ts); } uint64_t km_rtc_get_time() { - datetime_t datetime; - rtc_get_datetime(&datetime); - struct tm ts; - ts.tm_sec = datetime.sec; - ts.tm_min = datetime.min; - ts.tm_hour = datetime.hour; - ts.tm_mday = datetime.day; - ts.tm_mon = datetime.month - 1; - ts.tm_year = datetime.year - 1900; - time_t tsec = mktime(&ts); - return (uint64_t)(tsec * 1000); + struct timespec ts; + aon_timer_get_time(&ts); + uint32_t msec = (uint32_t)(ts.tv_nsec / DIV_NS_2_MS) % TAKE_MS; + return (uint64_t)(ts.tv_sec * MUL_S_2_MS + msec); } diff --git a/targets/rp2/src/spi.c b/targets/rp2/src/spi.c index e29c9c78..48a7eeb9 100644 --- a/targets/rp2/src/spi.c +++ b/targets/rp2/src/spi.c @@ -28,7 +28,7 @@ struct __spi_status_s { bool enabled; -} __spi_status[SPI_NUM]; +} __spi_status[KALUMA_SPI_NUM]; static bool __check_spi_pins(uint8_t bus, km_spi_pins_t pins) { if (bus == 0) { @@ -95,7 +95,7 @@ static spi_inst_t *__get_spi_no(uint8_t bus) { * Initialize all SPI when system started */ void km_spi_init() { - for (int i = 0; i < SPI_NUM; i++) { + for (int i = 0; i < KALUMA_SPI_NUM; i++) { __spi_status[i].enabled = false; } } diff --git a/targets/rp2/src/system.c b/targets/rp2/src/system.c index ff570ede..ee645205 100644 --- a/targets/rp2/src/system.c +++ b/targets/rp2/src/system.c @@ -91,7 +91,7 @@ static void km_uid_init() { } static void km_pio_init() { - for (int i = 0; i < PIO_SM_NUM; i++) { + for (int i = 0; i < KALUMA_PIO_SM_NUM; i++) { if (pio_sm_is_claimed(pio0, i)) pio_sm_unclaim(pio0, i); if (pio_sm_is_claimed(pio1, i)) diff --git a/targets/rp2/src/uart.c b/targets/rp2/src/uart.c index b85eeb13..ecf495ec 100644 --- a/targets/rp2/src/uart.c +++ b/targets/rp2/src/uart.c @@ -29,11 +29,11 @@ #include "pico/stdlib.h" #include "ringbuffer.h" -static ringbuffer_t __uart_rx_ringbuffer[UART_NUM]; -static uint8_t *__read_buffer[UART_NUM]; +static ringbuffer_t __uart_rx_ringbuffer[KALUMA_UART_NUM]; +static uint8_t *__read_buffer[KALUMA_UART_NUM]; static struct __uart_status_s { bool enabled; -} __uart_status[UART_NUM]; +} __uart_status[KALUMA_UART_NUM]; static uart_inst_t *__get_uart_no(uint8_t bus) { if (bus == 0) { @@ -120,7 +120,7 @@ km_uart_pins_t km_uart_get_default_pins(uint8_t port) { * Initialize all UART when system started */ void km_uart_init() { - for (int i = 0; i < UART_NUM; i++) { + for (int i = 0; i < KALUMA_UART_NUM; i++) { __uart_status[i].enabled = false; __read_buffer[i] = NULL; } @@ -130,7 +130,7 @@ void km_uart_init() { * Cleanup all UART when system cleanup */ void km_uart_cleanup() { - for (int i = 0; i < UART_NUM; i++) { + for (int i = 0; i < KALUMA_UART_NUM; i++) { if (__uart_status[i].enabled) { km_uart_close(i); } diff --git a/targets/rp2/target.cmake b/targets/rp2/target.cmake index 7721ec2f..71440edf 100644 --- a/targets/rp2/target.cmake +++ b/targets/rp2/target.cmake @@ -13,8 +13,14 @@ if(NOT BOARD) set(BOARD "pico-w") endif() -if(BOARD STREQUAL "pico-w") +if(BOARD STREQUAL "pico") + set(PICO_BOARD pico) +elseif(BOARD STREQUAL "pico-w") set(PICO_BOARD pico_w) +elseif(BOARD STREQUAL "pico2") + set(PICO_BOARD pico2) +else() + message(FATAL_ERROR "KalumaJS does not support this board yet.") endif() # default modules @@ -79,16 +85,24 @@ set(SOURCES include_directories(${TARGET_INC_DIR} ${BOARD_DIR}) -set(TARGET_HEAPSIZE 180) -set(JERRY_TOOLCHAIN toolchain_mcu_cortexm0plus.cmake) +if(BOARD STREQUAL "pico2") + # For RP2350 + set(CMAKE_SYSTEM_PROCESSOR cortex-m33) + set(CMAKE_C_FLAGS "-march=armv8-m.main+dsp+fp -mcpu=cortex-m33 -mthumb -mfloat-abi=softfp") + set(JERRY_TOOLCHAIN toolchain_mcu_cortexm33.cmake) + set(TARGET_HEAPSIZE 256) +else() # pico and pico-w have the same settings + # For RP2040 + set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus) + set(CMAKE_C_FLAGS "-march=armv6-m -mcpu=cortex-m0plus -mthumb") + set(JERRY_TOOLCHAIN toolchain_mcu_cortexm0plus.cmake) + set(TARGET_HEAPSIZE 180) +endif() -set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus) -set(CMAKE_C_FLAGS "-march=armv6-m -mcpu=cortex-m0plus -mthumb ${OPT} -Wall -fdata-sections -ffunction-sections") if(DEBUG EQUAL 1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -gdwarf-2") endif() -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MP") - +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT} -Wall -fdata-sections -ffunction-sections -MMD -MP") set(PREFIX arm-none-eabi-) set(CMAKE_ASM_COMPILER ${PREFIX}gcc) set(CMAKE_C_COMPILER ${PREFIX}gcc) @@ -106,7 +120,7 @@ set(TARGET_LIBS c nosys m hardware_uart hardware_pio hardware_flash - hardware_rtc + pico_aon_timer hardware_watchdog hardware_sync) set(CMAKE_EXE_LINKER_FLAGS "-specs=nano.specs -u _printf_float -Wl,-Map=${OUTPUT_TARGET}.map,--cref,--gc-sections") diff --git a/targets/stm32/boards/kameleon-core/board.h b/targets/stm32/boards/kameleon-core/board.h index b5d079a8..80f3ae6b 100755 --- a/targets/stm32/boards/kameleon-core/board.h +++ b/targets/stm32/boards/kameleon-core/board.h @@ -46,13 +46,13 @@ #define SRAM_BASE_ADDR (0x20000000) #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 #define APB1 0 #define APB2 1 diff --git a/targets/stm32/src/adc.c b/targets/stm32/src/adc.c index 5b593620..7c0f2c17 100755 --- a/targets/stm32/src/adc.c +++ b/targets/stm32/src/adc.c @@ -27,8 +27,8 @@ #include "err.h" DMA_HandleTypeDef hdma_adc1; -static uint16_t adc_buf[ADC_NUM]; -static uint8_t adc_configured[ADC_NUM]; +static uint16_t adc_buf[KALUMA_ADC_NUM]; +static uint8_t adc_configured[KALUMA_ADC_NUM]; static ADC_HandleTypeDef hadc1; static const struct __adc_config { @@ -37,7 +37,7 @@ static const struct __adc_config { uint32_t pin; uint32_t channel; } adc_config[] = { - // Same as ADC_NUM + // Same as KALUMA_ADC_NUM {3, GPIOA, GPIO_PIN_1, ADC_CHANNEL_1}, {4, GPIOA, GPIO_PIN_2, ADC_CHANNEL_2}, {5, GPIOA, GPIO_PIN_3, ADC_CHANNEL_3}, @@ -87,7 +87,7 @@ void adc1_init() { hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.NbrOfConversion = ADC_NUM; + hadc1.Init.NbrOfConversion = KALUMA_ADC_NUM; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc1) != HAL_OK) { @@ -136,7 +136,7 @@ void km_adc_cleanup() { double km_adc_read(uint8_t adcIndex) { HAL_ADC_Start(&hadc1); - for (int k = 0; k < ADC_NUM; k++) { + for (int k = 0; k < KALUMA_ADC_NUM; k++) { HAL_StatusTypeDef status = HAL_ADC_PollForConversion(&hadc1, 100); if (status == HAL_TIMEOUT) { @@ -157,7 +157,7 @@ int km_adc_setup(uint8_t pin) { if (n < 0) return ENOPHRPL; uint8_t adc_need_init = 1; - for (int k = 0; k < ADC_NUM; k++) { + for (int k = 0; k < KALUMA_ADC_NUM; k++) { if (adc_configured[k]) { adc_need_init = 0; break; @@ -184,7 +184,7 @@ int km_adc_close(uint8_t pin) { adc_configured[n] = 0; uint8_t adc_need_deinit = 1; - for (int k = 0; k < ADC_NUM; k++) { + for (int k = 0; k < KALUMA_ADC_NUM; k++) { if (adc_configured[k]) { adc_need_deinit = 0; break; diff --git a/targets/stm32/src/i2c.c b/targets/stm32/src/i2c.c index e4d2f162..10611f3f 100755 --- a/targets/stm32/src/i2c.c +++ b/targets/stm32/src/i2c.c @@ -59,7 +59,7 @@ void km_i2c_init() {} * Cleanup all I2C when system cleanup */ void km_i2c_cleanup() { - for (int k = 0; k < I2C_NUM; k++) { + for (int k = 0; k < KALUMA_I2C_NUM; k++) { if (handle[k]->Instance == instance[k]) km_i2c_close(k); } } diff --git a/targets/stm32/src/pwm.c b/targets/stm32/src/pwm.c index 253ac223..79736640 100644 --- a/targets/stm32/src/pwm.c +++ b/targets/stm32/src/pwm.c @@ -27,7 +27,7 @@ #include "err.h" extern void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); -static uint8_t pwm_configured[PWM_NUM]; +static uint8_t pwm_configured[KALUMA_PWM_NUM]; static void tim1_pwm_setup(uint32_t, uint32_t, uint32_t, uint32_t); static void tim2_pwm_setup(uint32_t, uint32_t, uint32_t, uint32_t); static void tim3_pwm_setup(uint32_t, uint32_t, uint32_t, uint32_t); diff --git a/targets/stm32/src/spi.c b/targets/stm32/src/spi.c index 5b4dcc64..7f47199e 100644 --- a/targets/stm32/src/spi.c +++ b/targets/stm32/src/spi.c @@ -94,7 +94,7 @@ void km_spi_init() {} * Cleanup all SPI when system cleanup */ void km_spi_cleanup() { - for (int k = 0; k < SPI_NUM; k++) { + for (int k = 0; k < KALUMA_SPI_NUM; k++) { if (spi_handle[k]->Instance == spi_ch[k]) km_spi_close(k); } } diff --git a/targets/stm32/src/uart.c b/targets/stm32/src/uart.c index c30cd2b2..67ee7676 100755 --- a/targets/stm32/src/uart.c +++ b/targets/stm32/src/uart.c @@ -37,7 +37,7 @@ static const uint32_t uart_parity[] = {UART_PARITY_NONE, UART_PARITY_ODD, static const uint32_t uart_hw_control[] = { UART_HWCONTROL_NONE, UART_HWCONTROL_RTS, UART_HWCONTROL_CTS, UART_HWCONTROL_RTS_CTS}; -static ringbuffer_t uart_rx_ringbuffer[UART_NUM]; +static ringbuffer_t uart_rx_ringbuffer[KALUMA_UART_NUM]; static uint8_t *read_buffer[] = {NULL, NULL}; /** @@ -76,7 +76,7 @@ void km_uart_init() {} * Cleanup all UART when system cleanup */ void km_uart_cleanup() { - for (int k = 0; k < UART_NUM; k++) { + for (int k = 0; k < KALUMA_UART_NUM; k++) { if (uart_handle[k]->Instance == uart_ch[k]) km_uart_close(k); } }