Issue trying to receive on a UART with rrf52833 and lots of other compiler/IDE questions

Folks,

Am running VSC 1.95.1 on Mageia Linux.

I have a  52833 board that I have working in that I can write to and read from custom BLE characteristics and send data out on the UART, but receiving is proving impossible.

Issue 1

The biggest issue is that in the UART callback function I'm constantly getting calls with UART_RX_DISABLED being the evt->type

static void uart_callback(const struct device *dev, struct uart_event *evt, void *user_data)
{
uint8_t i;

switch (evt->type)
{
case UART_TX_DONE: break;
case UART_TX_ABORTED: break;
case UART_RX_RDY:
for (i=0; i<evt->data.rx.len; i++)
{
serial_mess_in[mess_in_index++] = evt->data.rx.buf[i];
if (mess_in_index >= MESS_IN_SIZE)
mess_in_index = 0;
} break;
case UART_RX_BUF_REQUEST: set_uart_buffer(); break;
case UART_RX_BUF_RELEASED: break;
case UART_RX_DISABLED:
printk("callback: RX Disabled \n");
rx_enabled = false;
rx_enable(dev); break;
case UART_RX_STOPPED: break;
default:
printk("callback: other, go investigate\n");
break;
}

}
static void set_uart_buffer(void)
{
current_buffer ^= 0x01;
uint16_t sof;
sof = sizeof(rx_buff[current_buffer]);
uart_rx_buf_rsp (cuteU, &rx_buff[current_buffer][0], RX_BUFF_SIZE);
}
Issue 2
I get these errors but it still compiles:

    "message": "cannot open source file \"stddef.h\" (dependency of \"zephyr/types.h\")",

Similarly for stdbool
Issue 3
I get these sorts of errors:

    "message": "ignoring malformed line 'CONFIG_ARM_MPU=y'",
For every line in nrf52833dk_nrf52833_defconfig. I saw one post stying there was a superfluous space, that that's not the case here:


# SPDX-License-Identifier: Apache-2.0

# Enable MPU
CONFIG_ARM_MPU=y

# Enable hardware stack protection
CONFIG_HW_STACK_PROTECTION=y

# Enable RTT
CONFIG_USE_SEGGER_RTT=y

# enable GPIO
CONFIG_GPIO=y

# enable uart driver
CONFIG_SERIAL=y

# enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
Issue 4
I can't debug properly, if you set a breakpoint it jumps all over the place and tells you variables are optimised out when I have chosen optimise for debugging in sys build.
Issue 5
Am wondering whether this line:
k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
Is causing an issue in that I wonder whether it's putting the unit to sleep and screwing up the UART? Is the re like an equivalent to FreeRTOS vTaskDelay() where you're delaying but not putting the unit to sleep?
Issue 6
[{
    "resource": "/home/XXXXX/ncs/v2.7.0/zephyr/boards/nordic/nrf52833dk/nrf52833dk_nrf52833_defconfig",
    "owner": "Kconfig no context",
    "severity": 4,
    "message": "The active build context 'build/BLE_LBS' does not use this file.",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}]

What does this mean and is it an issue?

Issue 7
[{
    "resource": "/home/XXXXXX/ncs/v2.7.0/zephyr/CMakeLists.txt",
    "owner": "nrf-connect",
    "severity": 4,
    "message": "CMake Warning at /home/robertw/ncs/v2.7.0/zephyr/CMakeLists.txt:2027 (message):",
    "source": "cmake",
    "startLineNumber": 2027,
    "startColumn": 1,
    "endLineNumber": 2027,
    "endColumn": 2147483647
}]
Thanks!
Parents
  • Hello!

    Quite a few questions, so I will try to answer all of them. Let me know if I missed some, or if anything was unclear. 

    1: Are you actually missing UART data? The way the uart works in this sample is a bit complex. At least if you got it from the ncs\nrf\samples\bluetooth\peripheral_uart sample. But it works, although it involves disabling the uart to process the incoming data, but it should be "automatically" enabled again. If that is not where you got it from, perhaps you can look into that sample, and see if you can copy the UART handling from there. 

    2: I need more context here. Can you provide the entire build log? How did you install the SDK? nRF Connect for Desktop -> Toolchain Manager? VS Code directly?

    3: The same. I need more context. What are you trying to build? And what is your environment?

    Are you able to build with these error messages? Because you say that you can debug, so I am a bit confused. Perhaps you can zip and send the application folder that you are currently working on, and I can have a look.

    4: How did you set debug optimization? Can you please try to delete the build folder, and select it once more? And please note that when you are using the BLE stack, it is not possible to break and step all you want, because the Bluetooth stack will miss too many time sensitive events.

    5: No, that line will not mess with anything. It puts it in a state that any events that are generated will wake up the device again.

    6: Where and when do you see it? 

    7: Where do you see this?

    Best regards,

    Edvin

  • Hi,

    Thanks for the reply.

    I'm never getting any UART info in, I can only send out. As I say I am constantly getting a call into the UART callback function with it telling me the UART is disconnected, at which point I attempt to reconnect.

    I got most of the code from a friend who has got the UART working on a different system. I've had a look at that sample code and it looks similarish, only he doesn't have to disable the UART in the UART_RX_RDY case statement.

    I don't really understand the need for mallocs in that sample code. Surely you can just have arrays and write to them? And surely you don't need those macro CONTAINER_OF? Again, my friend did it just by copying from the evt->data.rx.buf into a local array, so that must be possible?

    I can't see what might be wrong compared to that sample file, but I find your coding style incredibly difficult to read, so could be missing something I suppose. The big thing is why does it keep telling me the UART is disconnected? How do we get to the bottom of that?

    2. Executing task: nRF Connect: Build [pristine]: BLE_LBS/build (active)

    Building BLE_LBS
    west build --build-dir /home/xxxxxx/Software/someone/BLE_LBS/build /home/xxxxxx/Software/someone/BLE_LBS --pristine --board nrf52833dk/nrf52833 --sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DCONFIG_DEBUG_OPTIMIZATIONS=y -DCONFIG_DEBUG_THREAD_INFO=y -DBOARD_ROOT=/home/xxxxxx/ncs/v2.7.0/zephyr/samples/basic/blinky_pwm;/home/xxxxxx/Software/someone/BLE_LBS;/home/xxxxxx/Software/someone/NRF52840_LBS

    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: /home/xxxxxx/ncs/toolchains/e9dba88316/usr/local/bin/python3.9 (found suitable version "3.9.18", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /home/xxxxxx/.cache/zephyr
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52833dk, qualifiers: nrf52833
    Parsing /home/xxxxxx/Software/someone/BLE_LBS/Kconfig.sysbuild
    Loaded configuration '/home/xxxxxx/Software/someone/BLE_LBS/build/_sysbuild/empty.conf'
    Merged configuration '/home/xxxxxx/Software/someone/BLE_LBS/build/_sysbuild/empty.conf'
    Configuration saved to '/home/xxxxxx/Software/someone/BLE_LBS/build/zephyr/.config'
    Kconfig header saved to '/home/xxxxxx/Software/someone/BLE_LBS/build/_sysbuild/autoconf.h'
    --
       *****************************
       * Running CMake for BLE_LBS *
       *****************************

    Loading Zephyr default modules (Zephyr base).
    -- Application: /home/xxxxxx/Software/someone/BLE_LBS
    -- CMake version: 3.21.0
    -- Using NCS Toolchain 2.6.20240605.1004412633878 for building. (/home/xxxxxx/ncs/toolchains/e9dba88316/cmake)
    -- Found Python3: /home/xxxxxx/ncs/toolchains/e9dba88316/usr/local/bin/python3 (found suitable version "3.9.18", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /home/xxxxxx/.cache/zephyr
    -- Zephyr version: 3.6.99 (/home/xxxxxx/ncs/v2.7.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52833dk, qualifiers: nrf52833
    -- Found host-tools: zephyr 0.16.5 (/home/xxxxxx/ncs/toolchains/e9dba88316/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (/home/xxxxxx/ncs/toolchains/e9dba88316/opt/zephyr-sdk)
    -- Found Dtc: /home/xxxxxx/ncs/toolchains/e9dba88316/usr/local/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
    -- Found BOARD.dts: /home/xxxxxx/ncs/v2.7.0/zephyr/boards/nordic/nrf52833dk/nrf52833dk_nrf52833.dts
    -- Found devicetree overlay: /home/xxxxxx/Software/someone/BLE_LBS/nrf52833dk_nrf52833.overlay
    -- Generated zephyr.dts: /home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/dts.cmake
    Parsing /home/xxxxxx/Software/someone/BLE_LBS/Kconfig
    Loaded configuration '/home/xxxxxx/ncs/v2.7.0/zephyr/boards/nordic/nrf52833dk/nrf52833dk_nrf52833_defconfig'
    Merged configuration '/home/xxxxxx/Software/someone/BLE_LBS/prj.conf'
    Merged configuration '/home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/misc/generated/extra_kconfig_options.conf'
    Merged configuration '/home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/.config.sysbuild'
    Configuration saved to '/home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/.config'
    Kconfig header saved to '/home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /home/xxxxxx/ncs/toolchains/e9dba88316/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/xxxxxx/ncs/toolchains/e9dba88316/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    -- Using ccache: /home/xxxxxx/ncs/toolchains/e9dba88316/usr/bin/ccache
    CMake Warning at /home/xxxxxx/ncs/v2.7.0/zephyr/CMakeLists.txt:2027 (message):
      __ASSERT() statements are globally ENABLED


    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/xxxxxx/Software/someone/BLE_LBS/build
    -- west build: building application
    [1/226] Preparing syscall dependency handling

    [7/226] Generating include/generated/version.h
    -- Zephyr version: 3.6.99 (/home/xxxxxx/ncs/v2.7.0/zephyr), build: v3.6.99-ncs2
    [226/226] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      208172 B       504 KB     40.34%
                 RAM:       30048 B       128 KB     22.92%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from /home/xxxxxx/Software/someone/BLE_LBS/build/BLE_LBS/zephyr/zephyr.elf for board: nrf52833dk
    [10/10] Generating ../merged.hex
     *  Terminal will be reused by tasks, press any key to close it.

    I can't really remember how I installed the SDK, I might have just unzipped it. I found it such a struggle to installed VSC and had to try so many things to get it working.

    3. Am trying to build/am building the peripheral_lbs from the Copy A Sample thing in VSC.

    4. I did it in the Edit Build Configuration tab in the combo box and selected optimise for debugging. It's not stepping through BLE that is the problem, I know because you supply a binary blob you can't step through that. And that doesn't explain why all variables are optimised out when setting the UART up. In fact it just steps over many lines as if they are optimised out when they shouldn't be.

    5. Yes, but is it sending the Cortex to sleep and potentialyl disconnecting the UART? I suppose I should trya for next loop to see if that helps.

    6 and 7. These are seen in the Problems tab.

    I suspect some of these so-called errors are just warnings, but I hate having any sort of warning when writing code, they can bite you in the bum.

  • Perhaps you can upload the application that you are working on, so that I can have a look at your UART implementation?

    Best regards,

    Edvin

  • I've made some progress now using a 52840 dev kit and am understanding a little bit more how this works.

    One of the big issues was this misuse of the Zephyr FIFO and its mallocs which s a BIG no-no in embedded code. Was causing some real issues and making stuff so hard to read. Using message queues makes it a lot better and safer.

    Zephyr is horrible for little embedded systems like this, as is VSC. Will be looking for a different ecosystem altogether when it comes to the next BLE project I  have to do. Such a shame you dropped SES.

    Am still getting these malformed lines issues, once I've tidied up this project and made it nice and readable I'll zip up the project and send it.

Reply
  • I've made some progress now using a 52840 dev kit and am understanding a little bit more how this works.

    One of the big issues was this misuse of the Zephyr FIFO and its mallocs which s a BIG no-no in embedded code. Was causing some real issues and making stuff so hard to read. Using message queues makes it a lot better and safer.

    Zephyr is horrible for little embedded systems like this, as is VSC. Will be looking for a different ecosystem altogether when it comes to the next BLE project I  have to do. Such a shame you dropped SES.

    Am still getting these malformed lines issues, once I've tidied up this project and made it nice and readable I'll zip up the project and send it.

Children
  • I understand. Yes, unfortunately, things are a bit more complex in Zephyr, but it was a needed step to increase the number of supported devices on different platforms (nRF52, nRF53 with multicore, nRF91, nRF7002, and now nRF54. 

    For the old devices, such as nRF52833, it is absolutely possible to use the nRF5 SDK, but it will not get any of the new features. 

    Best regards,

    Edvin

Related