kasjer commented on a change in pull request #2017: WIP - P-NUCLEO-WB55 URL: https://github.com/apache/mynewt-core/pull/2017#discussion_r328992644
########## File path: hw/bsp/p-nucleo-wb55/src/hal_bsp.c ########## @@ -0,0 +1,199 @@ +/* + * 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 <assert.h> + +#include "os/mynewt.h" + +#if MYNEWT_VAL(UART_0) +#include <uart/uart.h> +#include <uart_hal/uart_hal.h> +#endif + +#include <hal/hal_bsp.h> +#include <hal/hal_gpio.h> +#include <hal/hal_flash_int.h> +#include <hal/hal_timer.h> + +#if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_0_SLAVE) +#include <hal/hal_spi.h> +#endif + +#include <stm32wb55xx.h> +#include <stm32wbxx_hal_rcc.h> +#include <stm32wbxx_hal_pwr.h> +#include <stm32wbxx_hal_flash.h> +#include <stm32wbxx_hal_gpio_ex.h> +#include <mcu/stm32wb_bsp.h> +#include "mcu/stm32wbxx_mynewt_hal.h" +#include "mcu/stm32_hal.h" +#include "hal/hal_i2c.h" + +#include "bsp/bsp.h" + +#if MYNEWT_VAL(UART_0) +static struct uart_dev hal_uart0; + +static const struct stm32_uart_cfg uart0_cfg = { + .suc_uart = USART1, + .suc_rcc_reg = &RCC->APB2ENR, + .suc_rcc_dev = RCC_APB2ENR_USART1EN, + .suc_pin_tx = MCU_GPIO_PORTB(6), + .suc_pin_rx = MCU_GPIO_PORTB(7), + .suc_pin_rts = -1, + .suc_pin_cts = -1, + .suc_pin_af = GPIO_AF7_USART1, + .suc_irqn = USART1_IRQn +}; +#endif + +#if MYNEWT_VAL(I2C_0) +/* + * NOTE: The PB8 and PB9 pins are connected through jumpers in the board to + * both AIN and I2C pins. To enable I2C functionality SB51/SB56 need to + * be removed (they are the default connections) and SB46/SB52 need to + * be added. + */ +static struct stm32_hal_i2c_cfg i2c_cfg0 = { + .hic_i2c = I2C1, + .hic_rcc_reg = &RCC->APB1ENR1, + .hic_rcc_dev = RCC_APB1ENR1_I2C1EN, + .hic_pin_sda = MCU_GPIO_PORTB(9), /* PB9 - D14 on CN1 */ + .hic_pin_scl = MCU_GPIO_PORTB(8), /* PB8 - D15 on CN1 */ + .hic_pin_af = GPIO_AF4_I2C1, + .hic_10bit = 0, + .hic_timingr = 0x10420F13, /* 100KHz at 8MHz of SysCoreClock */ +}; +#endif + +#if MYNEWT_VAL(I2C_1) +static struct stm32_hal_i2c_cfg i2c_cfg1 = { + .hic_i2c = I2C2, + .hic_rcc_reg = &RCC->APB1ENR1, + .hic_rcc_dev = RCC_APB1ENR1_I2C2EN, + .hic_pin_sda = MCU_GPIO_PORTB(10), + .hic_pin_scl = MCU_GPIO_PORTB(11), + .hic_pin_af = GPIO_AF4_I2C2, + .hic_10bit = 0, + .hic_timingr = 0x10420F13, /* 100KHz at 8MHz of SysCoreClock */ +}; +#endif + +#if MYNEWT_VAL(SPI_0_MASTER) || MYNEWT_VAL(SPI_0_SLAVE) +struct stm32_hal_spi_cfg spi0_cfg = { + .ss_pin = MCU_GPIO_PORTA(2), /* D10 on CN1 */ + .sck_pin = MCU_GPIO_PORTA(5), /* D13 on CN1 */ + .miso_pin = MCU_GPIO_PORTA(6), /* D12 on CN1 */ + .mosi_pin = MCU_GPIO_PORTA(7), /* D11 on CN1 */ + .irq_prio = 2, +}; +#endif + +static const struct hal_bsp_mem_dump dump_cfg[] = { + [0] = { + .hbmd_start = &_ram_start, + .hbmd_size = RAM_SIZE + }, +}; + +extern const struct hal_flash stm32_flash_dev; +const struct hal_flash * +hal_bsp_flash_dev(uint8_t id) +{ + /* + * Internal flash mapped to id 0. + */ + if (id != 0) { + return NULL; + } + return &stm32_flash_dev; +} + +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; +} + +void +hal_bsp_init(void) +{ + int rc; + + (void)rc; + +#if MYNEWT_VAL(UART_0) + rc = os_dev_create((struct os_dev *) &hal_uart0, "uart0", Review comment: this and next line have cast space inconsistency ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
