port/stm32-*: fix all builds

This commit is contained in:
Dirk Helbig 2024-06-20 09:56:44 +02:00 committed by Matthias Ringwald
parent 4e21d086f7
commit 44ce5de30f
5 changed files with 175 additions and 9 deletions

View File

@ -218,9 +218,7 @@ void hal_uart_dma_receive_block(uint8_t *data, uint16_t size){
* @param len
* @return
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
ssize_t _write(int file, const void *buf, size_t len);
ssize_t _write(int file, const void *buf, size_t len){
#if 1

View File

@ -37,6 +37,10 @@
#define BTSTACK_FILE__ "port.c"
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
// include STM32 first to avoid warning about redefinition of UNUSED
#include "stm32f4xx_hal.h"
#include "main.h"
@ -104,6 +108,43 @@ void hal_cpu_enable_irqs_and_sleep(void){
int btstack_main(int argc, char ** argv);
ssize_t _read(int fd, void * buf, size_t count){
UNUSED(fd);
UNUSED(buf);
UNUSED(count);
return -1;
}
int _close(int file){
UNUSED(file);
return -1;
}
int _isatty(int file){
UNUSED(file);
return -1;
}
int _lseek(int file){
UNUSED(file);
return -1;
}
int _fstat(int file){
UNUSED(file);
return -1;
}
int _kill (pid_t pid, int sig) {
UNUSED(pid);
UNUSED(sig);
return -1;
}
pid_t _getpid (void) {
return 0;
}
// main.c
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(size);

View File

@ -39,7 +39,10 @@
#define DEBUG
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
// to get cpu intrinsics, .e.g __dissble_irq(), before BTstack includes to avoid re-defining UNUSED
#include "stm32l4xx.h"
@ -65,6 +68,43 @@
#include "hci_dump_embedded_stdout.h"
#endif
ssize_t _read(int fd, void * buf, size_t count){
UNUSED(fd);
UNUSED(buf);
UNUSED(count);
return -1;
}
int _close(int file){
UNUSED(file);
return -1;
}
int _isatty(int file){
UNUSED(file);
return -1;
}
int _lseek(int file){
UNUSED(file);
return -1;
}
int _fstat(int file){
UNUSED(file);
return -1;
}
int _kill (pid_t pid, int sig) {
UNUSED(pid);
UNUSED(sig);
return -1;
}
pid_t _getpid (void) {
return 0;
}
void btstack_assert_failed(const char * file, uint16_t line_nr){
printf("Assert: file %s, line %u\n", file, line_nr);
while (1);

View File

@ -39,7 +39,10 @@
#define DEBUG
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
// to get cpu intrinsics, .e.g __dissble_irq(), before BTstack includes to avoid re-defining UNUSED
#include "stm32l4xx.h"
@ -65,6 +68,43 @@
#include "hci_dump_embedded_stdout.h"
#endif
ssize_t _read(int fd, void * buf, size_t count){
UNUSED(fd);
UNUSED(buf);
UNUSED(count);
return -1;
}
int _close(int file){
UNUSED(file);
return -1;
}
int _isatty(int file){
UNUSED(file);
return -1;
}
int _lseek(int file){
UNUSED(file);
return -1;
}
int _fstat(int file){
UNUSED(file);
return -1;
}
int _kill (pid_t pid, int sig) {
UNUSED(pid);
UNUSED(sig);
return -1;
}
pid_t _getpid (void) {
return 0;
}
void btstack_assert_failed(const char * file, uint16_t line_nr){
printf("Assert: file %s, line %u\n", file, line_nr);
while (1);

View File

@ -45,6 +45,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "btstack_config.h"
#include "main.h"
@ -61,11 +63,12 @@
*******************************************/
extern UART_HandleTypeDef hTuart;
int _write(int file, char* ptr, int len)
ssize_t _write(int fd, const void* buf, size_t count)
{
const uint8_t *ptr = buf;
// expand '/n' to '/r/n'
int pos;
for (pos=0;pos<len;pos++){
for (pos=0;pos<count;pos++){
uint8_t next_char = *ptr++;
if (next_char == '\n'){
const uint8_t NEWLINE[] = "\r\n";
@ -75,17 +78,61 @@ int _write(int file, char* ptr, int len)
}
}
return len;
return count;
}
int _read(int file, char* ptr, int len)
ssize_t _read(int file, void * buf, size_t count)
{
HAL_UART_Receive(&hTuart, (uint8_t*)ptr, len, 1000);
uint8_t *ptr = buf;
HAL_UART_Receive(&hTuart, ptr, count, 1000);
return count;
}
#else
ssize_t _write(int fd, const void* buf, size_t count){
UNUSED(fd);
UNUSED(buf);
UNUSED(count);
return -1
}
return len;
ssize_t _read(int fd, void* buf, size_t count){
UNUSED(fd);
UNUSED(buf);
UNUSED(count);
return -1;
}
#endif
int _close(int file){
UNUSED(file);
return -1;
}
int _isatty(int file){
UNUSED(file);
return -1;
}
int _lseek(int file){
UNUSED(file);
return -1;
}
int _fstat(int file){
UNUSED(file);
return -1;
}
int _kill (pid_t pid, int sig) {
UNUSED(pid);
UNUSED(sig);
return -1;
}
pid_t _getpid (void) {
return 0;
}
/********************************************
* hal_time_ms.h implementation
*******************************************/