1

I'm trying to create a hello world program but whenever I try to build it no errors are thrown up but I can't find the .uf2 file to put onto my rasberry pi pico

HelloWorld.cpp

#include <stdio.h>
#include "pico/stdlib.h"
int main() {
    stdio_init_all();
    while(true) {
        printf("Hello world! \n");
        sleep_ms(1000);
    }

}

CmakeLists.txt

cmake_minimum_required(VERSION 3.12)

# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(HelloWorld C CXX ASM) 
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# initialize the Raspberry Pi Pico SDK
pico_sdk_init()


# rest of your project
add_executable(HelloWorld
    HelloWorld.cpp
)

# Add pico_stdlib library which aggregates commonly used features
target_link_libraries(HelloWorld pico_stdlib)

# enable usb output, disable uart output
pico_enable_stdio_usb(HelloWorld 1)
pico_enable_stdio_uart(HelloWorld 0)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(HelloWorld
)
starball
  • 20,030
  • 7
  • 43
  • 238
Chris22
  • 21
  • 3
  • I don't know anything about raspi development, but [the docs](https://github.com/raspberrypi/pico-sdk/blob/master/README.md#quick-start-your-own-project) say "_You now have hello_world.elf to load via a debugger, or hello_world.uf2 that can be installed and run on your Raspberry Pi Pico via drag and drop._". Do you have the elf file instead? – starball Mar 20 '23 at 20:12
  • Did you set `PICO_NO_UF2` to a truthy value anywhere in your configuration command? Related source: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common.cmake and https://github.com/raspberrypi/pico-sdk/blob/master/tools/CMakeLists.txt The uf2 file should be placed in the same directory as the target output file. – starball Mar 20 '23 at 20:18
  • 1
    @Hoven I was trying to build the c/cpp file rather than the project itself. Hope that fixes it – Chris22 Jul 09 '23 at 14:24
  • @Chris22 I encourage you to write up an elaborated answer in an answer post. – starball Jul 09 '23 at 17:35
  • Thanks @Chris22 - I was experimenting with Visual Studio 2022 GUI - and the build under "Build > Build All" works! - Great! We have Build after CMake stops at "CMake generation finished." – Hoven Jul 10 '23 at 04:50

1 Answers1

0

Did you make sure that you ran "make" after you ran "cmake"? The typical build steps for a PICO using CMake are as follows:

$ mkdir build
$ cd build
$ cmake ..
$ make

I'm guessing I just made the same mistake as you, I ran cmake .. and no errors were thrown but I couldn't find the .uf2 file to put on the PICO, until I remembered that CMake only generates the Make file, you must obviously run the Make file afterwards with the "make" command to actually get your executable.

masonjacob
  • 36
  • 9