[GitHub] [mynewt-core] mlaz commented on a change in pull request #2467: [KINETIS] mcu/nxp: adding K8xF support. hw/bsp: adding frdm-k82f BSP

2021-02-05 Thread GitBox


mlaz commented on a change in pull request #2467:
URL: https://github.com/apache/mynewt-core/pull/2467#discussion_r571145012



##
File path: hw/bsp/frdm-k82f/src/hal_bsp.c
##
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "os/mynewt.h"
+#include "bsp/bsp.h"
+#include "hal/hal_bsp.h"
+#include "hal/hal_flash_int.h"
+#include "flash_map/flash_map.h"
+#include "hal/hal_flash.h"
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+#include 
+#endif
+#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
+MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4)
+#include "uart/uart.h"
+#include "uart_hal/uart_hal.h"
+#include "hal/hal_uart.h"
+#endif
+#if MYNEWT_VAL(I2C_0) || MYNEWT_VAL(I2C_1) || MYNEWT_VAL(I2C_2) || 
MYNEWT_VAL(I2C_3)
+#include "hal/hal_i2c.h"
+#endif
+#if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_1_MASTER) || \
+MYNEWT_VAL(SPI_2_MASTER) || MYNEWT_VAL(SPI_0_SLAVE) || \
+MYNEWT_VAL(SPI_1_SLAVE) || MYNEWT_VAL(SPI_2_SLAVE)
+#include "hal/hal_spi.h"
+#endif
+#include "mcu/cmsis_nvic.h"
+#include "mcu/frdm-k8xf_hal.h"
+#include "fsl_device_registers.h"
+#include "fsl_common.h"
+#include "fsl_clock.h"
+#include "fsl_port.h"
+#include "clock_config.h"
+
+#if MYNEWT_VAL(UART_0)
+static struct uart_dev os_bsp_uart0;
+#endif
+#if MYNEWT_VAL(UART_1)
+static struct uart_dev os_bsp_uart1;
+#endif
+#if MYNEWT_VAL(UART_2)
+static struct uart_dev os_bsp_uart2;
+#endif
+#if MYNEWT_VAL(UART_3)
+static struct uart_dev os_bsp_uart3;
+#endif
+#if MYNEWT_VAL(UART_4)
+static struct uart_dev os_bsp_uart4;
+#endif
+
+#if MYNEWT_VAL(I2C_0)
+static const struct nxp_hal_i2c_cfg hal_i2c0_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_0_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_0_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_0_FREQ_KHZ),
+};
+#endif
+#if MYNEWT_VAL(I2C_1)
+static const struct nxp_hal_i2c_cfg hal_i2c1_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_1_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_1_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_1_FREQ_KHZ),
+};
+#endif
+#if MYNEWT_VAL(I2C_2)
+static const struct nxp_hal_i2c_cfg hal_i2c2_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_2_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_2_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_2_FREQ_KHZ),
+};
+#endif
+#if MYNEWT_VAL(I2C_3)
+static const struct nxp_hal_i2c_cfg hal_i2c3_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_3_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_3_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_3_FREQ_KHZ),
+};
+#endif
+
+
+/*
+ * What memory to include in coredump.
+ */
+static const struct hal_bsp_mem_dump dump_cfg[] = {
+[0] = {
+.hbmd_start = &__DATA_ROM,
+.hbmd_size = RAM_SIZE
+}
+};
+
+static void init_hardware(void)
+{
+/* Disable the MPU otherwise USB cannot access the bus */
+SYSMPU->CESR = 0;
+
+/* Enable all the ports */
+SIM->SCGC5 |= (SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | 
SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK |
+   SIM_SCGC5_PORTE_MASK);
+}
+
+extern void BOARD_BootClockRUN(void);
+
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+static struct eflash_crypto_dev enc_flash_dev0 = {
+.ecd_dev = {
+.efd_hal = {
+.hf_itf = _flash_funcs,
+},
+.efd_hwdev = _flash_dev,
+}
+};
+#endif
+
+const struct hal_flash *
+hal_bsp_flash_dev(uint8_t id)
+{
+if (id == 0) {
+return _flash_dev;
+}
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+if (id == 1) {
+return _qspi_dev;
+}
+#endif
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+if (id == 2) {
+return _flash_dev0.ecd_dev.efd_hal;
+}
+#endif
+return NULL;
+}
+
+const struct hal_bsp_mem_dump *
+hal_bsp_core_dump(int *area_cnt)
+{
+*area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+return dump_cfg;
+}
+
+int
+hal_bsp_power_state(int state)
+{
+return (0);
+}
+
+/*!
+ * @brief Function to override ARMGCC default function _sbrk
+ *
+ * _sbrk is called by malloc. ARMGCC default _sbrk compares "SP" register and
+ * heap end, if heap end is larger than "SP", then _sbrk returns error and
+ * memory allocation failed. This function changes to compare __HeapLimit with
+ * heap end.
+ */
+void *_sbrk(int incr)
+{
+extern char 

[GitHub] [mynewt-core] mlaz commented on a change in pull request #2467: [KINETIS] mcu/nxp: adding K8xF support. hw/bsp: adding frdm-k82f BSP

2021-02-05 Thread GitBox


mlaz commented on a change in pull request #2467:
URL: https://github.com/apache/mynewt-core/pull/2467#discussion_r571093344



##
File path: hw/bsp/frdm-k82f/src/hal_bsp.c
##
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "os/mynewt.h"
+#include "bsp/bsp.h"
+#include "hal/hal_bsp.h"
+#include "hal/hal_flash_int.h"
+#include "flash_map/flash_map.h"
+#include "hal/hal_flash.h"
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+#include 
+#endif
+#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
+MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4)
+#include "uart/uart.h"
+#include "uart_hal/uart_hal.h"
+#include "hal/hal_uart.h"
+#endif
+#if MYNEWT_VAL(I2C_0) || MYNEWT_VAL(I2C_1) || MYNEWT_VAL(I2C_2) || 
MYNEWT_VAL(I2C_3)
+#include "hal/hal_i2c.h"
+#endif
+#if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_1_MASTER) || \
+MYNEWT_VAL(SPI_2_MASTER) || MYNEWT_VAL(SPI_0_SLAVE) || \
+MYNEWT_VAL(SPI_1_SLAVE) || MYNEWT_VAL(SPI_2_SLAVE)
+#include "hal/hal_spi.h"
+#endif
+#include "mcu/cmsis_nvic.h"
+#include "mcu/frdm-k8xf_hal.h"
+#include "fsl_device_registers.h"
+#include "fsl_common.h"
+#include "fsl_clock.h"
+#include "fsl_port.h"
+#include "clock_config.h"
+
+#if MYNEWT_VAL(UART_0)
+static struct uart_dev os_bsp_uart0;
+#endif
+#if MYNEWT_VAL(UART_1)
+static struct uart_dev os_bsp_uart1;
+#endif
+#if MYNEWT_VAL(UART_2)
+static struct uart_dev os_bsp_uart2;
+#endif
+#if MYNEWT_VAL(UART_3)
+static struct uart_dev os_bsp_uart3;
+#endif
+#if MYNEWT_VAL(UART_4)
+static struct uart_dev os_bsp_uart4;
+#endif
+
+#if MYNEWT_VAL(I2C_0)
+static const struct nxp_hal_i2c_cfg hal_i2c0_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_0_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_0_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_0_FREQ_KHZ),
+};
+#endif
+#if MYNEWT_VAL(I2C_1)
+static const struct nxp_hal_i2c_cfg hal_i2c1_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_1_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_1_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_1_FREQ_KHZ),
+};
+#endif
+#if MYNEWT_VAL(I2C_2)
+static const struct nxp_hal_i2c_cfg hal_i2c2_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_2_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_2_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_2_FREQ_KHZ),
+};
+#endif
+#if MYNEWT_VAL(I2C_3)
+static const struct nxp_hal_i2c_cfg hal_i2c3_cfg = {
+.pin_sda = MYNEWT_VAL(I2C_3_PIN_SDA),
+.pin_scl = MYNEWT_VAL(I2C_3_PIN_SCL),
+.frequency = MYNEWT_VAL(I2C_3_FREQ_KHZ),
+};
+#endif
+
+
+/*
+ * What memory to include in coredump.
+ */
+static const struct hal_bsp_mem_dump dump_cfg[] = {
+[0] = {
+.hbmd_start = &__DATA_ROM,
+.hbmd_size = RAM_SIZE
+}
+};
+
+static void init_hardware(void)
+{
+/* Disable the MPU otherwise USB cannot access the bus */
+SYSMPU->CESR = 0;
+
+/* Enable all the ports */
+SIM->SCGC5 |= (SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | 
SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK |
+   SIM_SCGC5_PORTE_MASK);
+}
+
+extern void BOARD_BootClockRUN(void);
+
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+static struct eflash_crypto_dev enc_flash_dev0 = {
+.ecd_dev = {
+.efd_hal = {
+.hf_itf = _flash_funcs,
+},
+.efd_hwdev = _flash_dev,
+}
+};
+#endif
+
+const struct hal_flash *
+hal_bsp_flash_dev(uint8_t id)
+{
+if (id == 0) {
+return _flash_dev;
+}
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+if (id == 1) {
+return _qspi_dev;
+}
+#endif
+#if MYNEWT_VAL(ENC_FLASH_DEV)
+if (id == 2) {
+return _flash_dev0.ecd_dev.efd_hal;
+}
+#endif
+return NULL;
+}
+
+const struct hal_bsp_mem_dump *
+hal_bsp_core_dump(int *area_cnt)
+{
+*area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+return dump_cfg;
+}
+
+int
+hal_bsp_power_state(int state)
+{
+return (0);
+}
+
+/*!
+ * @brief Function to override ARMGCC default function _sbrk
+ *
+ * _sbrk is called by malloc. ARMGCC default _sbrk compares "SP" register and
+ * heap end, if heap end is larger than "SP", then _sbrk returns error and
+ * memory allocation failed. This function changes to compare __HeapLimit with
+ * heap end.
+ */
+void *_sbrk(int incr)
+{
+extern char 

[GitHub] [mynewt-core] mlaz commented on a change in pull request #2467: [KINETIS] mcu/nxp: adding K8xF support. hw/bsp: adding frdm-k82f BSP

2021-02-05 Thread GitBox


mlaz commented on a change in pull request #2467:
URL: https://github.com/apache/mynewt-core/pull/2467#discussion_r571021811



##
File path: hw/mcu/nxp/kinetis/MK8xF/include/mcu/frdm-k8xf_hal.h
##
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __MCU_FRDMK8XF_BSP_H_
+#define __MCU_FRDMK8XF_BSP_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+struct hal_flash;
+extern const struct hal_flash kinetis_flash_dev;
+extern const struct hal_flash nxp_qspi_dev;
+
+struct nxp_hal_i2c_cfg {
+int8_t pin_scl;
+int8_t pin_sda;
+uint32_t frequency;
+};
+
+struct nxp_hal_spi_cfg {
+uint32_t clk_pin;
+uint32_t pcs_pin;
+uint32_t sout_pin;
+uint32_t sin_pin;
+};

Review comment:
   Done.

##
File path: .rat-excludes
##
@@ -291,6 +291,15 @@ fsl_clock.c
 MK64FN1M0xxx12_flash.ld
 boot-MK64FN1M0xxx12_flash.ld
 startup_MK64F12.S
+MK82FN256xxx15_flash.ld
+boot-MK82FN256xxx15_flash.ld
+startup_MK82F25615.S
+MK82F25615.h
+MK82F25615_features.h
+system_MK82F25615.h
+system_MK82F25615.c
+fsl_clock.h
+

Review comment:
   Done.

##
File path: hw/mcu/nxp/kinetis/MK64F12/pkg.yml
##
@@ -23,6 +23,4 @@ pkg.author: "Apache Mynewt "
 pkg.homepage: "http://mynewt.apache.org/;
 
 pkg.deps:
-- "@apache-mynewt-core/hw/hal"
-- "@apache-mynewt-core/hw/cmsis-core"

Review comment:
   Done.

##
File path: hw/mcu/nxp/kinetis/MK64F12/syscfg.yml
##
@@ -17,3 +17,4 @@
 #
 syscfg.vals:
 OS_TICKS_PER_SEC: 1000
+MCU_FLASH_MIN_WRITE_SIZE: 2

Review comment:
   Done.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org