ubuntu host PC rs232usb:
nrf9160 target board:
Get log from PC /dev/ttyACM0 change to PC /dev/ttyUSB0
PC Tx ---- target rx p0.00
PC Rx ---- target tx p0.01
#########################################################
ubuntu PC host:
the /dev/ttyUSB0 will receive message from nrf9160
#########################################################
SEGGER Embedded Studio for ARM
Release 5.34a Build 2021011401.44914
Nordic Edition
Linux x64
#########################################################
1.
Hardware support for boardname:
nrf9160dk_nrf9160ns -> Sw10 -> NRF91
2.
nrf9160dk_nrf9160ns:
~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig
#add in last line
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_DEBUG=y
the CONFIG_DEBUG=y help you trace into ~/ncs/zephyr/drivers/serial/uart_nrfx_uarte.c
3.
create file nrf9160dk_nrf9160ns.overlay in ~/ncs/zephyr/samples/hello_world
add follows setting
&uart0 {
current-speed = <115200>;
status = "okay";
tx-pin = <1>;
rx-pin = <0>;
rts-pin = <0xFFFFFFFF>;
cts-pin = <0xFFFFFFFF>;
};
&uart1 {
current-speed = <115200>;
status = "okay";
tx-pin = <27>;
rx-pin = <26>;
rts-pin = <0xFFFFFFFF>;
cts-pin = <0xFFFFFFFF>;
};
4.
add ${BOARD}.overlay in ~/ncs/zephyr/samples/hello_world/CMakeLists.txt
cmake_minimum_required(VERSION 3.13.1)
#add this line
set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)
target_sources(app PRIVATE src/main.c)
(you do not need to change ~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns.dts)
(overlay file will do it)
5.
SEGGER Embedded Studio open hello_world project
BoardName: nrf9160dk_nrf9160ns
6. check only
/root/ncs/zephyr/samples/hello_world/build_nrf9160dk_nrf9160ns/zephyr/zephyr.dts
there are uart0 and uart1 setting same as overlay file
uart0: uart@8000 {
compatible = "nordic,nrf-uarte";
reg = < 0x8000 0x1000 >;
interrupts = < 0x8 0x1 >;
status = "okay";
label = "UART_0";
current-speed = < 0x1c200 >;
tx-pin = < 0x1 >;
rx-pin = < 0x0 >;
rts-pin = < 0xffffffff >;
cts-pin = < 0xffffffff >;
};
uart1: uart@9000 {
compatible = "nordic,nrf-uarte";
reg = < 0x9000 0x1000 >;
interrupts = < 0x9 0x1 >;
status = "okay";
label = "UART_1";
current-speed = < 0x1c200 >;
tx-pin = < 0x1b >;
rx-pin = < 0x1a >;
rts-pin = < 0xffffffff >;
cts-pin = < 0xffffffff >;
};
7. set breakpoint
~/ncs/zephyr/drivers/serial/uart_nrfx_uarte.c
switch (cfg->flow_ctrl) { ////---->set breakpoint here, can help you trace CTS_RTC used or not.
case UART_CFG_FLOW_CTRL_NONE:
uarte_cfg.hwfc = NRF_UARTE_HWFC_DISABLED;
break;
case UART_CFG_FLOW_CTRL_RTS_CTS:
if (get_dev_config(dev)->rts_cts_pins_set) {
uarte_cfg.hwfc = NRF_UARTE_HWFC_ENABLED;
} else {
return -ENOTSUP;
}
break;
default:
return -ENOTSUP;
}
//////////////////////////////////Note//////////////////////////////////////
//////////////////////////////////
//////////////////////////////////
The nrf9160 distribute 4 IRQs for uart and i2c and spi
IRQ number from 0x08~0x0b
in ~/ncs/zephyr/soc/arm/nordic_nrf/validate_enabled_instances.c
#define CHECK(idx) \
!(I2C_ENABLED(idx) && SPI_ENABLED(idx)) && \
!(I2C_ENABLED(idx) && UART_ENABLED(idx)) && \
!(SPI_ENABLED(idx) && UART_ENABLED(idx))
#define MSG(idx) \
"Only one of the following peripherals can be enabled: " \
"SPI"#idx", SPIM"#idx", SPIS"#idx", TWI"#idx", TWIM"#idx", TWIS"#idx \
IF_ENABLED(CONFIG_SOC_SERIES_NRF53X, (", UARTE"#idx)) \
IF_ENABLED(CONFIG_SOC_SERIES_NRF91X, (", UARTE"#idx)) \
". Check nodes with status \"okay\" in zephyr.dts."
#if !IS_ENABLED(CONFIG_SOC_NRF52810)
BUILD_ASSERT(CHECK(0), MSG(0));
#endif
BUILD_ASSERT(CHECK(1), MSG(1));
BUILD_ASSERT(CHECK(2), MSG(2));
BUILD_ASSERT(CHECK(3), MSG(3));
The macros check device idx.
If .overlay using device idx repeatedly, compiler will tell you error:
EX: ~/ncs/zephyr/samples/hello_world/nrf9160dk_nrf9160ns.overlay
&uart0 {
current-speed = <115200>;
status = "okay";
tx-pin = <1>;
rx-pin = <0>;
rts-pin = <0xFFFFFFFF>;
cts-pin = <0xFFFFFFFF>;
};
&uart1 {
current-speed = <115200>;
status = "okay";
tx-pin = <0x1a>;
rx-pin = <0x19>;
rts-pin = <0xFFFFFFFF>;
cts-pin = <0xFFFFFFFF>;
};
&uart2 {
current-speed = <115200>;
status = "okay";
tx-pin = <0x1c>;
rx-pin = <0x1b>;
rts-pin = <0xFFFFFFFF>;
cts-pin = <0xFFFFFFFF>;
};
&i2c2 {
compatible = "nordic,nrf-twim";
status = "okay";
sda-gpios = < &gpio0 0x1e 0x0 >;
scl-gpios = < &gpio0 0x1f 0x0 >;
clock-frequency = <I2C_BITRATE_STANDARD>;
};
};
compiler:
"Only one of the following peripherals can be enabled: SPI2, SPIM2,
SPIS2, TWI2, TWIM2, TWIS2, UARTE2. Check nodes with status \"okay\" in
zephyr.dts."
It because uart_2 and i2c_2.
Their idx = 2, using repeatedly
look ~/ncs/zephyr/samples/hello_world/build_nrf9160dk_nrf9160ns/zephyr/zephyr.dts
uart2: uart@a000 {
compatible = "nordic,nrf-uarte";
reg = < 0xa000 0x1000 >;
interrupts = < 0xa 0x1 >;
status = "disabled";
label = "UART_2";
tx-pin = < 0x18 >;
rx-pin = < 0x17 >;
};
i2c2: i2c@a000 {
#address-cells = < 0x1 >;
#size-cells = < 0x0 >;
reg = < 0xa000 0x1000 >;
clock-frequency = < 0x186a0 >;
interrupts = < 0xa 0x1 >;
status = "okay";
label = "I2C_2";
compatible = "nordic,nrf-twim";
sda-gpios = < &gpio0 0x1e 0x0 >;
scl-gpios = < &gpio0 0x1f 0x0 >;
};
both interrupts are using the same number 0x0a, it's wrong using.
//////////////////////////////////////////UICR//////////////////////////////////////////
https://infocenter.nordicsemi.com/pdf/nRF9160_PS_v2.0.pdf in page 41
APPROTECT 0x000 Access port protection
SECUREAPPROTECT 0x02C Secure access port protection
in terminal:
write
nrfjprog --memwr 0x00ff8000 --val 0x00000000"
nrfjprog --memwr 0x00ff802C --val 0x00000000"
read in screen
nrfjprog -f NRF91 --memrd 0x00ff8000 --w 16 --n 64
read in file
nrfjprog -f NRF91 --readuicr uicr.hex
////////////////////////////////////////////////////////////////////////////////////////////////////
source: using 3 uarts in external pins
https://www.mediafire.com/file/v3o7u672dx05z23/nrf9160dk_nrf9160.tar.xz
extract nrf9160dk_nrf9160ns_defconfig
cover to ~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig
refer to:
https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/uart
沒有留言:
張貼留言