added chapter 3 and refactor of chapter 1 and chapter 2

This commit is contained in:
Kevin Thomas
2023-10-15 13:12:32 -04:00
parent 94db311031
commit 36e5ee731b
24 changed files with 8130 additions and 362 deletions

View File

@@ -1,5 +1,7 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.idea
.vscode
_deps
cmake-*
build
.DS_Store
*.pdf

View File

@@ -1,10 +1,9 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
"recommendations": [
"marus25.cortex-debug",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.vscode-serial-monitor"
]
}

View File

@@ -1,5 +1,30 @@
{
// These settings tweaks to the cmake plugin will ensure
// that you debug using cortex-debug instead of trying to launch
// a Pico binary on the host
"cmake.statusbar.advanced": {
"debug": {
"visibility": "hidden"
},
"launch": {
"visibility": "hidden"
},
"build": {
"visibility": "hidden"
},
"buildTarget": {
"visibility": "hidden"
}
},
"cmake.buildBeforeRun": true,
"cmake.configureOnOpen": true,
"cmake.configureSettings": {
"CMAKE_MODULE_PATH": "${env:PICO_INSTALL_PATH}/pico-sdk-tools"
},
"cmake.generator": "Ninja",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"C_Cpp.errorSquiggles": "enabled",
"files.associations": {
"stm32f4xx.h": "c"
"stdlib.h": "c"
}
}
}

View File

@@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.13)
set(PICO_BOARD pico_w)
include(pico_sdk_import.cmake)
project(0x0001_hello-world C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
if (PICO_CYW43_SUPPORTED) # set by PICO_BOARD=pico_w
if (NOT TARGET pico_cyw43_arch)
message("Skipping Pico W examples as support is not available")
else()
if (DEFINED ENV{WIFI_SSID} AND (NOT WIFI_SSID))
set(WIFI_SSID $ENV{WIFI_SSID})
message("Using WIFI_SSID from environment ('${WIFI_SSID}')")
endif()
if (DEFINED ENV{WIFI_PASSWORD} AND (NOT WIFI_PASSWORD))
set(WIFI_PASSWORD $ENV{WIFI_PASSWORD})
message("Using WIFI_PASSWORD from environment")
endif()
set(WIFI_SSID "${WIFI_SSID}" CACHE INTERNAL "WiFi SSID for examples")
set(WIFI_PASSWORD "${WIFI_PASSWORD}" CACHE INTERNAL "WiFi password for examples")
endif()
endif()
set(WIFI_SSID "${WIFI_SSID}" CACHE INTERNAL "WiFi SSID")
set(WIFI_PASSWORD "${WIFI_PASSWORD}" CACHE INTERNAL "WiFi PASSWORD")
add_executable(0x0001_hello-world
main.c
)
target_compile_definitions(0x0001_hello-world PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
)
target_include_directories(0x0001_hello-world PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts
)
target_link_libraries(0x0001_hello-world
pico_cyw43_arch_lwip_threadsafe_background
pico_lwip_mbedtls
pico_mbedtls
pico_stdlib
)
pico_enable_stdio_usb(0x0001_hello-world 1)
pico_enable_stdio_uart(0x0001_hello-world 1)
pico_add_extra_outputs(0x0001_hello-world)

View File

@@ -1,39 +0,0 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@@ -1,87 +0,0 @@
/**
* FILE: usart.h
*
* DESCRIPTION: This file contains the usart function definitions utilizing the STM32F401CC6 microcontroller.
*
* AUTHOR: Kevin Thomas
* DATE: October 6, 2023
*/
#ifndef USART_H
#define USART_H
#include <stdint.h>
#include "stm32f4xx.h"
#define DEFAULT_CLK_SPEED 16000000U
extern int __io_putchar(int ch) __attribute__((weak));
/**
* @brief Sets the baud rate for a given USART peripheral.
*
* This function calculates and sets the baud rate register (BRR) for
* the specified USART peripheral based on the provided peripheral clock
* speed and desired baud rate.
*
* @param USARTx: Pointer to the USART peripheral (e.g., USART1, USART2, etc.).
* @param periph_clk: The frequency of the peripheral clock in Hertz.
* @param baud_rate: The desired baud rate for communication.
* @retval None
*/
static void set_baud_rate(USART_TypeDef *USARTx, uint32_t periph_clk, uint32_t baud_rate);
/**
* @brief Initializes USART2 for transmission on PA2 pin and receive on PA3 pin.
*
* This function configures the necessary settings for USART2 to enable
* transmission on pin PA2 and receive on PA3 pin. It includes configuring
* GPIO, setting alternate function mode, configuring the USART clock, setting the
* baud rate, and enabling the transmitter.
*
* @param None
* @retval None
*/
void usart2_init(void);
/**
* @brief Writes a single byte to USART2 for transmission.
*
* This function writes a single byte to the USART2 data
* register for transmission. It ensures that the data register
* is empty before writing the byte.
*
* @param char_: The byte to be transmitted.
* @retval None
*/
void usart2_write_char(uint8_t char_);
/**
* @brief Reads a single byte from USART2.
*
* This function reads a single byte from the USART2 data
* register. It ensures that the data register is not empty
* before reading the byte.
*
* @param None
* @retval The byte read from the data register.
*/
char usart2_read_char(void);
/**
* @brief Reads a string of characters from input and stores it in the buffer.
*
* This function reads characters from input and stores them in the
* provided buffer until either the buffer is full (reaching
* buffer_size - 1 characters) or a newline character is encountered.
* The input is null-terminated, ensuring proper string termination in
* the buffer.
*
* @param buffer: Pointer to the buffer where the input characters are stored.
* @param buffer_size: The size of the buffer, including space for the null-terminator.
* @retval None
*/
void input(char *buffer, size_t buffer_size);
#endif // USART_H

View File

@@ -1,46 +0,0 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@@ -0,0 +1,18 @@
#ifndef _LWIPOPTS_H
#define _LWIPOPTS_H
#include "lwipopts_examples_common.h"
/* TCP WND must be at least 16 kb to match TLS record size
or you will get a warning "altcp_tls: TCP_WND is smaller than the RX decrypion buffer, connection RX might stall!" */
#undef TCP_WND
#define TCP_WND 16384
#define LWIP_ALTCP 1
#define LWIP_ALTCP_TLS 1
#define LWIP_ALTCP_TLS_MBEDTLS 1
#define LWIP_DEBUG 1
#define ALTCP_MBEDTLS_DEBUG LWIP_DBG_ON
#endif

View File

@@ -0,0 +1,89 @@
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
#define _LWIPOPTS_EXAMPLE_COMMONH_H
// Common settings used in most of the pico_w examples
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
// allow override in some examples
#ifndef NO_SYS
#define NO_SYS 1
#endif
// allow override in some examples
#ifndef LWIP_SOCKET
#define LWIP_SOCKET 0
#endif
#if PICO_CYW43_ARCH_POLL
#define MEM_LIBC_MALLOC 1
#else
// MEM_LIBC_MALLOC is incompatible with non polling versions
#define MEM_LIBC_MALLOC 0
#endif
#define MEM_ALIGNMENT 4
#define MEM_SIZE 4000
#define MEMP_NUM_TCP_SEG 32
#define MEMP_NUM_ARP_QUEUE 10
#define PBUF_POOL_SIZE 24
#define LWIP_ARP 1
#define LWIP_ETHERNET 1
#define LWIP_ICMP 1
#define LWIP_RAW 1
#define TCP_WND (8 * TCP_MSS)
#define TCP_MSS 1460
#define TCP_SND_BUF (8 * TCP_MSS)
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETCONN 0
#define MEM_STATS 0
#define SYS_STATS 0
#define MEMP_STATS 0
#define LINK_STATS 0
// #define ETH_PAD_SIZE 2
#define LWIP_CHKSUM_ALGORITHM 3
#define LWIP_DHCP 1
#define LWIP_IPV4 1
#define LWIP_TCP 1
#define LWIP_UDP 1
#define LWIP_DNS 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#define DHCP_DOES_ARP_CHECK 0
#define LWIP_DHCP_DOES_ACD_CHECK 0
#ifndef NDEBUG
#define LWIP_DEBUG 1
#define LWIP_STATS 1
#define LWIP_STATS_DISPLAY 1
#endif
#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#endif /* __LWIPOPTS_H__ */

13
0x0001_hello-world/main.c Normal file
View File

@@ -0,0 +1,13 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
int main(void)
{
stdio_init_all();
while (true)
{
printf("hello, world\r\n");
}
}

View File

@@ -0,0 +1,62 @@
/* Workaround for some mbedtls source files using INT_MAX without including limits.h */
#include <limits.h>
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#define MBEDTLS_SSL_OUT_CONTENT_LEN 2048
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#define MBEDTLS_HAVE_TIME
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
#define MBEDTLS_ECP_DP_BP256R1_ENABLED
#define MBEDTLS_ECP_DP_BP384R1_ENABLED
#define MBEDTLS_ECP_DP_BP512R1_ENABLED
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_SHA256_SMALLER
#define MBEDTLS_SSL_SERVER_NAME_INDICATION
#define MBEDTLS_AES_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_ERROR_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_OID_C
#define MBEDTLS_PKCS5_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_RSA_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA224_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_SRV_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_AES_FEWER_TABLES
/* TLS 1.2 */
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#define MBEDTLS_GCM_C
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_ASN1_WRITE_C

View File

@@ -0,0 +1,73 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
endif ()
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
include(${PICO_SDK_INIT_CMAKE_FILE})

View File

@@ -1,16 +0,0 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:genericSTM32F401CC]
platform = ststm32
board = genericSTM32F401CC
framework = stm32cube
upload_protocol = stlink
debug_tool = stlink

View File

@@ -1,22 +0,0 @@
/**
* FILE: main.s
*
* DESCRIPTION: This file contains the main function for the hello-world program utilizing the STM32F401CC6 microcontroller.
*
* AUTHOR: Kevin Thomas
* DATE: October 6, 2023
*/
#include <stdio.h>
#include "usart.h"
int main(void)
{
usart2_init();
while (1)
{
printf("hello, world\r\n");
}
}

View File

@@ -1,126 +0,0 @@
/**
* FILE: usart.s
*
* DESCRIPTION: This file contains the usart functions utilizing the STM32F401CC6 microcontroller.
*
* AUTHOR: Kevin Thomas
* DATE: October 6, 2023
*/
#include "usart.h"
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int data_idx;
for (data_idx = 0; data_idx < len; data_idx++)
{
__io_putchar(*ptr++);
}
return len;
}
int __io_putchar(int char_)
{
// write a single char
usart2_write_char(char_);
return char_;
}
static void set_baud_rate(USART_TypeDef *USARTx, uint32_t periph_clk, uint32_t baud_rate)
{
// set baud rate register
USARTx->BRR = ((periph_clk + (baud_rate / 2)) / baud_rate);
}
void usart2_init(void)
{
// enable GPIOA clock
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
// set PA2 to output alternate function mode
GPIOA->MODER |= GPIO_MODER_MODE2_1;
GPIOA->MODER &= ~GPIO_MODER_MODE2_0;
// set PA2 alternate function type to UART_TX (AF07)
GPIOA->AFR[0] &= ~GPIO_AFRL_AFRL2_3;
GPIOA->AFR[0] |= GPIO_AFRL_AFRL2_2;
GPIOA->AFR[0] |= GPIO_AFRL_AFRL2_1;
GPIOA->AFR[0] |= GPIO_AFRL_AFRL2_0;
// set PA3 to output alternate function mode
GPIOA->MODER |= GPIO_MODER_MODE3_1;
GPIOA->MODER &= ~GPIO_MODER_MODE3_0;
// set PA3 alternate function type to UART_RX (AF07)
GPIOA->AFR[0] &= ~GPIO_AFRL_AFRL3_3;
GPIOA->AFR[0] |= GPIO_AFRL_AFRL3_2;
GPIOA->AFR[0] |= GPIO_AFRL_AFRL3_1;
GPIOA->AFR[0] |= GPIO_AFRL_AFRL3_0;
// enable USART2 clock
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
// configure baud rate to 9600
set_baud_rate(USART2, DEFAULT_CLK_SPEED, 9600);
// configure TX transmitter enable
USART2->CR1 |= USART_CR1_TE;
// configure RX receiver enable
USART2->CR1 |= USART_CR1_RE;
// enable UART2
USART2->CR1 |= USART_CR1_UE;
}
void usart2_write_char(uint8_t char_)
{
// verify transmit data register is empty, will return true if the bit is set
while(!(USART2->SR & USART_SR_TXE)) {};
// write a single char to the data register
USART2->DR = (char_ & 0xFF);
}
char usart2_read_char(void)
{
// verify receive data register is empty, will return true if the bit is set
while(!(USART2->SR & USART_SR_RXNE)) {};
// return a single char from the data register
return USART2->DR;
}
void input(char *buffer, size_t buffer_size)
{
char input;
size_t i = 0;
while (1)
{
input = usart2_read_char();
// check for newline or carriage return
if (input == '\n' || input == '\r')
{
// null-terminate the string
buffer[i] = '\0';
break;
}
// append new char from usart into buffer
buffer[i++] = input;
// ensure we don't overflow the buffer
if (i >= buffer_size - 1)
{
// null-terminate the string
buffer[i] = '\0';
break;
}
}
}

View File

@@ -1,11 +0,0 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

Binary file not shown.

7763
PicoW-A4-Pinout.pdf Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

14
openocd.ps1 Normal file
View File

@@ -0,0 +1,14 @@
# store the current location
$originalLocation = Get-Location
try {
# change the location to the OpenOCD scripts directory
Set-Location -Path "C:\Program Files\Raspberry Pi\Pico SDK v1.5.0\openocd\scripts"
# run OpenOCD
../openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"
}
finally {
# return to the original location
Set-Location -Path $originalLocation
}

BIN
pico-w-datasheet.pdf Normal file

Binary file not shown.

BIN
raspberry-pi-pico-c-sdk.pdf Normal file

Binary file not shown.

BIN
rp2040-datasheet.pdf Normal file

Binary file not shown.