3255 views|9 replies

1131

Posts

17

Resources
The OP
 

[Raspberry Pi Pico Review] - Start compiling the program 2 [Copy link]

This post was last edited by fxyc87 on 2021-1-28 11:05

Last time I posted a link

I talked about how to compile the program, but it didn't work. Then I talked about how to play with MicroPython.

Later, I didn't give up and tried again, and finally succeeded.

The following is the process:

1. First download SDK, GIT, VS2019 C++ tools, GCC compiler. The specific method is in the official PDF. Set the system environment variables, preferably absolute addresses, as shown in the figure:

2. Download pico-project-generator , which is a GUI CMAKE tool. After downloading, there is this file pico_project.py in its main directory

It cannot be executed directly, and a parameter is required. It is recommended to create a batch file gui.bat in its directory with the following content:

python pico_project.py --gui

In this way, you can directly execute gui.bat in the future, and the interface is as follows:

3. After creating the project location, modify your program. My program is as follows:

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/uart.h"
#include "hardware/gpio.h"
#include "hardware/divider.h"

// UART defines
// By default the stdout UART is `uart0`, so we will use the second one
#define UART_ID uart1
#define BAUD_RATE 9600

// Use pins 4 and 5 for UART1
// Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments
#define UART_TX_PIN 4
#define UART_RX_PIN 5

// GPIO defines
// Example uses GPIO 2
#define LED 25         //led 引脚




int main()
{
    stdio_init_all();

    // Set up our UART
    uart_init(UART_ID, BAUD_RATE);
    // Set the TX and RX pins by using the function select on the GPIO
    // Set datasheet for more information on function select
    gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART);
    gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART);
    

    // GPIO initialisation.
    // We will make this GPIO an input, and pull it up by default
    gpio_init(LED);
    gpio_set_dir(LED, GPIO_OUT);
    
    gpio_put(LED,1);        //打开LED


    // Example of using the HW divider. The pico_divider library provides a more user friendly set of APIs 
    // over the divider (and support for 64 bit divides), and of course by default regular C language integer
    // divisions are redirected thru that library, meaning you can just use C level `/` and `%` operators and
    // gain the benefits of the fast hardware divider.
    int32_t dividend = 123456;
    int32_t divisor = -321;
    // This is the recommended signed fast divider for general use.
    divmod_result_t result = hw_divider_divmod_s32(dividend, divisor);
    printf("%d/%d = %d remainder %d\n", dividend, divisor, to_quotient_s32(result), to_remainder_s32(result));
    // This is the recommended unsigned fast divider for general use.
    int32_t udividend = 123456;
    int32_t udivisor = 321;
    divmod_result_t uresult = hw_divider_divmod_u32(udividend, udivisor);
    printf("%d/%d = %d remainder %d\n", udividend, udivisor, to_quotient_u32(uresult), to_remainder_u32(uresult));

    puts("Hello, world!");

    return 0;
}

Most of it was automatically generated, I only turned on the LED light and left the rest alone.

You can use VS CODE or Notepad to modify the program

The LED indicator is on the grounded GP25, see the drawing:

4. Compile

After numerous tests in yesterday's post, I failed. Today, I accidentally tried a command and it was able to compile.

The official command is to use the nmake command directly, but I can't execute it directly

Then I used the absolute command, C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\nmake.exe

It still reported a bunch of errors. Later, I considered using the ARM version and tried C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29617\bin\Hostx86\x86\nmake.exe

Still doesn't work. I accidentally saw a DLL in the nmake directory, C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\2052\nmakeui.dll

Then I tried adding the -ui command, and a miracle happened. It could be compiled, and the elf file, hex file, and bin file were successfully compiled.

Note: As for why adding -ui works, I haven't checked it yet. I'll look for the help of namke later.

Note that it needs to be executed in the build directory under the project directory, such as ProjectName\build. The generated files are as shown below:

5. Conversion

This target board only supports uf2 files. I was planning to write a conversion program myself using c#, but I decided to use the official one.

There is a tool pico-sdk\tools\elf2uf2 in this directory of the official SDK, but it only has source code.

I created a C++ project with VS2019 and compiled it once. It was successful. The following is the compiled EXE. You can use it directly.

elf to uf2.exe, usage, command line input elf to uf2.exe original file.elf target file.uf2

elf转换到uf2.zip (9.23 KB, downloads: 14)

6. Download

This is relatively simple. Press and hold the button before powering on, then plug in the USB to power on, and directly drag the UF2 file into the target disk. Then you will find that the LED light miraculously becomes brighter.

Isn’t it amazing?

Reason for modification: Supplementary pictures

This post is from DIY/Open Source Hardware

Latest reply

good!   Details Published on 2021-2-24 15:08
 

1131

Posts

17

Resources
2
 

Thanks to RCSN for your help last time

This post is from DIY/Open Source Hardware

Comments

Did you do it in the system cmd? Compiling directly in the command line window of vs2019 will not be so troublesome. vs2019 also provides a cmd-like  Details Published on 2021-1-29 07:57
 
 

7172

Posts

195

Resources
3
 

Awesome! This kind of compilation is so troublesome. I still hope to have a fool-proof one-click

This post is from DIY/Open Source Hardware

Comments

It is very troublesome. It would be perfect if it can be developed directly in KEIL. People abroad seem to like to use CMAKE.  Details Published on 2021-1-28 16:07
 
 
 

1131

Posts

17

Resources
4
 
Common Ze 1 posted on 2021-1-28 14:56 Awesome, this kind of compilation is so troublesome. I still hope to have a fool-proof one-click

It is very troublesome. It would be perfect if it can be developed directly by KEIL.

People abroad seem to like using CMAKE

This post is from DIY/Open Source Hardware
 
 
 

7452

Posts

2

Resources
5
 

Awesome! It takes half a day to build the environment.

This post is from DIY/Open Source Hardware
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1366

Posts

6

Resources
6
 
fxyc87 posted on 2021-1-28 10:14 Thanks to RCSN for the help you gave last time

Did you do it in the system cmd? Compiling directly in the command line window of vs2019 will not be so troublesome. vs2019 also provides a cmd-like

This post is from DIY/Open Source Hardware

Comments

I tried it before, but it gave an error when I compiled it directly with VS2019. I haven't tried the command line of VS2019 yet. I'll try it again today.  Details Published on 2021-1-29 08:29
 
 
 

1131

Posts

17

Resources
7
 
RCSN posted on 2021-1-29 07:57 Did you do it in the system cmd? Compiling directly in the command line window of vs2019 will not be so troublesome. vs2019 also provides a cmd-like

I tried it before, but it gave an error when I compiled it directly with VS2019. I haven't tried the command line of VS2019 yet. I'll try it again today.

This post is from DIY/Open Source Hardware

Comments

Use this [attachimg]523623[/attachimg]  Details Published on 2021-1-29 10:00
 
 
 

1366

Posts

6

Resources
8
 
fxyc87 posted on 2021-1-29 08:29 I tried it before, but it was an error when I compiled it directly with VS2019. I haven't tried the command line of VS2019. I will try it again today

Use this

This post is from DIY/Open Source Hardware
Personal signature

1084534438 欢迎交流  [加油,一切皆有可能]

 
 
 

1131

Posts

17

Resources
9
 

I published the VS2019 source code of the ELF to UF2 project on GITHUB.

链接已隐藏,如需查看请登录或者注册

This post is from DIY/Open Source Hardware
 
 
 

6069

Posts

4

Resources
10
 
fxyc87 posted on 2021-1-31 14:06 I published the VS2019 source code of the ELF to UF2 project on GITHUB, https://github.com/fxyc87/elf2uf2.git

good!

This post is from DIY/Open Source Hardware
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list